%{ /* need this for the call to atof() below */ #include #include "mp4.tab.h" int line=1; int pos =0; int id_count=0; int int_count=0; int float_count=0; int char_count=0; int string_count=0; int op_count=0; int key_count=0; int i=0; int save=0; int flag=0; %} DIGIT [0-9] ID [a-zA-Z_][a-zA-Z0-9_]* X [0-7] %% "//"[^\n]* /* eat up one-line comments */ "/*"([^*]*|[*][^/])*"*/" { for(i=0;i>" {return IN;} "->" {return INS;} "||" {return OR;} "&&" {return AND;} "<=" {return LE;} ">=" {return GE;} "!=" {return NE;} "==" {return EE;} {ID} { pos = pos + strlen(yytext); id_count++; return ident; } "+"|"-"|"*"|"/"|"{"|"}"|"("|")"|"|"|"||"|"&"|'%'|"!"|";"|"="|"" { pos = pos + strlen(yytext); op_count++; return yytext[0]; } "."|":"|"["|"]"|","|"%" { pos = pos + strlen(yytext); op_count++; return yytext[0]; } [\n] {line++;pos=0;} [ ] {pos++;} [\t] {pos=pos+8;} . {printf( "Unknown token:\t"); for(i=0;i 0 ) { yyin = fopen( argv[0], "r" ); if(yyin==0) { printf("file not found\n"); return; } } else {printf("syntax: lex \n"); /* yyin = stdin;*/ return; } yyparse(); printf("parsing completed\n"); }