lex and yacc

Programming, for all ages and all languages.
Post Reply
kenna
Posts: 8
Joined: Fri Apr 13, 2007 1:26 pm

lex and yacc

Post 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"
nick8325
Member
Member
Posts: 200
Joined: Wed Oct 18, 2006 5:49 am

Post 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.
Post Reply