/* csimple1.l MR 19/09/98 - 20/09/98 */ /* 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. */ /* Run flex as follows: flex csimple1.l */ /* Then compile as follows: gcc lex.yy.c -o scanc1 -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 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 line */ /* consisting of 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. */ [ \t\n\f]+ /* Eat up white space */ {type_kywd} { printf( "T%s\n", yytext ); } {type_mdfr} { printf( "M%s\n", yytext ); } {tpdf_kywd} { printf( "D%s\n", yytext ); } {cnstr_kywd} { printf( "K%s\n", yytext ); } {numliteral} { printf( "N%s\n", yytext ); } {chrliteral} { printf( "C%s\n", yytext ); } {strliteral} { printf( "S%s\n", yytext ); } /* String possibly continued on next line */ /* {strliteral}([ \t]*\\?\n[ \t]*{strliteral})* { */ /* printf( "S%s\n", yytext ); } */ {operator} { printf( "+%s\n", yytext ); } "," { printf( ",%s\n", yytext ); } ";" { printf( ";%s\n", yytext ); } "(" { printf( "(%s\n", yytext ); } ")" { printf( ")%s\n", yytext ); } "[" { printf( "[%s\n", yytext ); } "]" { printf( "]%s\n", yytext ); } "{" { printf( "{%s\n", yytext ); } "}" { printf( "}%s\n", yytext ); } {identifier} { printf( "I%s\n", yytext ); } . { printf( "?%s\n", yytext ); } %%