/* c.l MR 18/09/98 - 19/09/98 */ /* Lex input file for a C lexical analyzer. */ /* Looted from Aho, Sethi, Ullman, 196, p.109, and */ /* from gnu flex man page version 2.5, April 1995. */ /* Run flex as follows: flex c.l */ /* Then compile as follows: gcc lex.yy.c -o scanc -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 type_mdfr unsigned|static|extern|register tpdf_kywd struct|typedef|enum cnstr_kywd if|else|for|while|switch|case|default|goto|break|continue interp ","|";" op1 "*"|"&"|"sizeof"|"!"|"~"|"+"|"-"|"++"|"--"|"/"|"%" op2 "."|"->"|"?"|":" op3 "<<"|">>"|"&"|"|"|"^" op4 "=="|"!="|"<"|"<="|">"|">=" op5 "="|"+="|"-="|"*="|"/="|"%="|"&="|"|="|"^="|"<<="|">>=" op6 "||"|"&&" operator {op1}|{op2}|{op3}|{op4}|{op5}|{op6} rnd_brckt "("|")" sqr_brckt "["|"]" fnc_brckt "{"|"}" %% /* The output of the scanner has one line per token in the C input */ /* file. Each symbol in the input is replaced with Cxxxx in the */ /* output, where C = a character specific for the kind of symbol */ /* and xxxx = the string value of the symbol exactly as in the input. */ int linenr = 1; "/*" { /* Eat up comments. */ int c; for(;;) { while( (c=input()) != '*' && c != EOF ) { if ( c == '\n' ) { linenr++; } } while ( (c=input()) == '*' ) { ; } if ( c == '/' ) { break; } } } \#.*(\\\n.*)*/\n { /* Preprocessor directive */ printf( "#... ", yytext ); } [ \t]+ /* Eat up white space */ \n { linenr++; printf( "\n" ); } {type_kywd} { printf( "T%s ", yytext ); } {type_mdfr} { printf( "M%s ", yytext ); } {tpdf_kywd} { printf( "D%s ", yytext ); } {cnstr_kywd} { printf( "C%s ", yytext ); } {numliteral} { printf( "N%s ", yytext ); } {chrliteral} { printf( "C%s ", yytext ); } {strliteral} { printf( "S... ", yytext ); } /* String possibly continued on next line */ /* {strliteral}([ \t]*\\?\n[ \t]*{strliteral})* { */ /* printf( "S... ", yytext ); } */ {operator} { printf( "+%s ", yytext ); } {interp} { printf( ";%s ", yytext ); } {rnd_brckt} { printf( "(%s ", yytext ); } {sqr_brckt} { printf( "[%s ", yytext ); } {fnc_brckt} { printf( "{%s ", yytext ); } {identifier} { printf( "I%s ", yytext ); } . { printf( "?%s ", yytext ); } %%