unable to understand the error in lex program to count no of tokens -
i wrote lex program calculate count of tokens using gedit in linux. not running.i m new in this. m not able find out problem in code.
this program code :
count=0 digit [0-9] letter [a-z][a-z] %% {letter} | ({letter}|{digit})* count++ %% int main() { yylex() printf("no. of identifier=%d",count); } error msg :
scanner.l:9: error: expected declaration specifiers before ‘yylex’ scanner.l:10: error: expected ‘{’ @ end of input
your initialization in definitions section of lex spec isn't quite right. should syntactially correct c statement, indented. also, code increment count must on same line pattern goes with. want this:
int count = 0; digit [0-9] letter [a-z][a-z] %% {letter}|({letter}|{digit})* count++; %% int main() { yylex(); printf("no. of identifier=%d",count); }
Comments
Post a Comment