tcp server #include <stdio.h> #include <netinet/in.h> #include <unistd.h> int main() { int s = socket(AF_INET, SOCK_STREAM, 0); struct sockaddr_in a = {AF_INET, htons(1234), INADDR_ANY}; bind(s, (void*)&a, sizeof(a)); listen(s, 1); int c = accept(s, NULL, NULL); char msg[100]; read(c, msg, 100); printf("Client: %s\n", msg); write(c, "Hi Client", 10); close(c); close(s); return 0; } tcp client #include <stdio.h> #include <netinet/in.h> #include <unistd.h> #include <arpa/inet.h> int main() { int s = socket(AF_INET, SOCK_STREAM, 0); struct sockaddr_in a = {AF_INET, htons(1234)}; inet_pton(AF_INET, "127.0.0.1", &a.sin_addr); connect(s, (void*)&a, sizeof(a)); write(s, "Hi Server", 10); char msg[100]; read(s, msg, 100); printf("Server: %s\n", msg); close(s); return 0; } udp server #include <stdio.h> #include <netinet/in.h> int main() { int s = socket(AF_INET, SOCK_DGRAM, 0);...
Posts
- Get link
- X
- Other Apps
Table html <!DOCTYPE html> <html> <head> <title>Seminar Schedule</title> </head> <body> <h2>Seminar Schedule</h2> <table border="1"> <tr> <th rowspan="2">Day</th> <th colspan="2">Schedule</th> <th rowspan="2">Topic</th> </tr> <tr> <th>Begin</th> <th>End</th> </tr> <tr> <td rowspan="2">Monday</td> <td rowspan="2">8:00 a.m.</td> ...
- Get link
- X
- Other Apps
Compiler Lab Solutions (Corrected LEX Codes Q1 to Q11) Q1. Count lines, spaces, tabs, meta characters, and others %{ int lines = 0, spaces = 0, tabs = 0, meta = 0, others = 0; %} %% \n { lines++; } [ ] { spaces++; } \t { tabs++; } [!@#$%^&*()_+=<>?/\\|] { meta++; } . { others++; } %% int main() { yylex(); printf("Lines: %d\nSpaces: %d\nTabs: %d\nMeta Characters: %d\nOther Characters: %d\n", lines, spaces, tabs, meta, others); return 0; } int yywrap() { return 1; } Q2. Identify valid identifiers %{ #include <stdio.h> %} %% [a-zA-Z_][a-zA-Z0-9_]* { printf("Valid Identifier: %s\n", yytext); } .|\n { /* ignore */ } %% int main() { yylex(); return 0; } int yywrap() { return 1; } Q3. Identify integer and float values %{ #include <stdio.h> %} %% [0-9]+\.[0-9]+ { printf("Float: %s\n", yytext); } [0-9]+ { printf("Integer: %s\n", yytext); } .|\n { /* ignore */ } %% int main() { yylex(); return 0; } int yywrap() { return 1; } Q...
- Get link
- X
- Other Apps
===== Page 6 ===== Q1. Design a LEX Code to count the number of lines, space, tab-meta character, and rest of characters in each Input pattern. Solution: % { #include<stdio.h> int line = 0 , space = 0 , tab = 0 , meta = 0 , other = 0; % } %% "\n" {line++;} " " {space++;} "\t" {tab++;} [\^\$\%\*\+\^\&\()\{}\}[]\v\"] {meta++;} . {other++;} %% int main(){ yylex(); printf("Line:%d\n",line); printf("Space:%d\n",space); printf("Tab:%d\n",tab); printf("Meta:%d\n",meta); printf("Other:%d\n",other); return 0; } int yywrap(){ return 1; } Output: int main(){ cout << "hello"; } Line:3 Space:3 Tab:1 Meta:7 Other:18 ===== Page 7 ===== Q2. Design a LEX Code to identify and print valid Identifier of C/C++ in given Input pattern. Solution: % { #include<stdio.h> % } %% int|float|return|void|if|...