compiler design mid
1. Design a LEX code to count the number of lines space tab meta character and rest of the characters in each input pattern in C/C++. %{ 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; } 2. Design a LEX code to Identify and print valid identifiers of C/C++ in given input pattern. %{ #include <stdio.h> %} %% [a-zA-Z_][a-zA-Z0-9_]* ...