/* csimple2.l MR Jun 2001 */ /* Simple Lex input file for a minimal C lexical analyzer. */ /* Does not recognize line continuations with \ plus newline, */ /* does not recognize preprocessor directives, does not */ /* recognize C comments, does not recognize C-style escape sequences */ /* (e.g. "\n", "\b") in string and character literals. These things */ /* must be filtered out of the source file before running the scanner */ /* generated from this Lex specification. */ /* */ /* Leaves the things on the same lines as in the input file. */ /* */ /* Run flex as follows: flex csimple2.l */ /* Then compile as follows: gcc lex.yy.c -o scanc2 -lfl */ digit [0-9] letter [A-Za-z_] identifier {letter}({letter}|{digit})* numliteral (0x)?{digit}+(\.{digit}+)?(e[+\-])?({digit}+)? strliteral \"[^"]*\" chrliteral \'[^']*\' type_kywd int|char|long|short|float|double|void type_mdfr unsigned|static|extern|register|const tpdf_kywd struct|typedef|enum cnstr_kywd if|else|for|while|switch|case|default|goto|break|continue|return op1 "*"|"&"|"sizeof"|"!"|"~"|"+"|"-"|"++"|"--"|"/"|"%" op2 "."|"->"|"?"|":" op3 "<<"|">>"|"&"|"|"|"^" op4 "=="|"!="|"<"|"<="|">"|">=" op5 "="|"+="|"-="|"*="|"/="|"%="|"&="|"|="|"^="|"<<="|">>=" op6 "||"|"&&" operator {op1}|{op2}|{op3}|{op4}|{op5}|{op6} %% /* The output of the scanner has one line per token in the C input */ /* file. Each symbol or token in the input is replaced with */ /* a one-character key indicating the type of token */ /* plus immediately after that the string contents of the symbol */ /* exactly as occurring in the input, plus immediately after */ /* that a space character. */ [ \t]+ /* Eat up white space */ [ \t\f]+ { printf( "\n" ); } {type_kywd} { printf( "T%s ", yytext ); } {type_mdfr} { printf( "M%s ", yytext ); } {tpdf_kywd} { printf( "D%s ", yytext ); } {cnstr_kywd} { printf( "K%s ", yytext ); } {numliteral} { printf( "N%s ", yytext ); } {chrliteral} { printf( "C " ); /* printf( "C%s ", yytext ); */ } {strliteral} { printf( "S " ); /* printf( "S%s ", yytext ); */ } /* String possibly continued on next line */ /* {strliteral}([ \t]*\\? [ \t]*{strliteral})* { */ /* printf( "S%s ", yytext ); } */ {operator} { printf( "O%s ", yytext ); } "," { printf( ", " ); } ";" { printf( "; " ); } "(" { printf( "( " ); } ")" { printf( ") " ); } "[" { printf( "[ " ); } "]" { printf( "] " ); } "{" { printf( "{ " ); } "}" { printf( "} " ); } {identifier} { printf( "I%s ", yytext ); } . { printf( "?%s ", yytext ); } %%