Page 1 of 1

lex and yacc

Posted: Tue Jun 12, 2007 1:47 pm
by kenna
howcome this simple code doesn't work:

Code: Select all

D		[0-9]

%%

if      printf ("IF statement\n");
[a-z]+  printf ("tag, value %s\n", yytext);
{D}+    printf ("decimal number %s\n", yytext);
"++"    printf ("unary op\n");
"+"     printf ("binary op\n");

%%
I compile it with "flex foo.txt" and then try "tcc foo.yy.c", but always get:

tcc: undefined symbol "yywrap"
tcc: undefined symbol "main"

Posted: Tue Jun 12, 2007 2:41 pm
by nick8325
Try adding the following lines

Code: Select all

%option noyywrap
%option main
to the beginning of the file. The lexer calls yywrap() when it reaches the end of the file; you probably don't need to use it, and %option noyywrap will tell flex not to call it. By default, flex generates a function called yylex(); %option main tells it to also generate a main() function that calls yylex.