Hello,
I have some problems with a very simple yacc/lex program. I have maybe forgotten some basic steps (it's been a long time since I've used these tools).
In my lex program I give some basic values like :
word [a-zA-Z][a-zA-Z]*
%%
":" return(PV);
{word} {
yylval = yytext;
printf("yylval = %s\n",yylval);
return(WORD);
}
"\n" return(ENDLINE);
In my yacc program the beginning of my grammar is (where TranslationUnit is my %start) :
TranslationUnit:
/* Nothing */
| InfoBlock Data
;
InfoBlock:
/* Nothing */
| InfoBlock InfoExpression {}
;
InfoExpression:
WORD PV WORD ENDLINE { printf("$1 = %s\n",$1);
printf("$2 = %s\n",$2);
printf("$3 = %s\n",$3);
printf("$4 = %s\n",$4);
}
| ... /* other things */
;
Data:
... /* other things */
When I run my program with input :
keyword : value
I thought that I would get at least :
$1 = keyword
$2 = keyword // yylval not changed for token PV
$3 = value
$4 = value // yylval not changed for token ENDLINE
Actually I get :
$1 = keyword : value
$2 = keyword : value
$3 = value
$4 = value
I do not understand this result. I have studied grammars some time ago and even if I don't remember everything right now, I do not see any important mistake...
Thanks in advance for your help.