Mail Archives: djgpp/1997/06/06/11:58:14
> I created the program in example 1-7 (a Yacc Parser) of chapter one, but
That example is just bad.
> main( )
> {
> while(!feof(yyin)){
Normally, if you don't do anything else, yyin will be initialized
to be stdin. This happens in the yylex function
lex.yy.c
YY_DECL prototype
<snip>
if (!yyin) yyin = stdin;
which won't get called until you are in yyparse. So, you can just
manually assign yyin=stdin first thing in main. I would probably be
better though, to change to grammar file so that it accepts
an infinite number of sentences, and then write a special rule for eof.
sentence_list : sentence
| sentence_list sentence
sentence : subject VERB object
<more stuff here from example>
Then maybe add a
<<EOF>> {return 0}
in lex.
Now you can just call yyparse directly in main.
int main()
{
yyparse();
return 0;
}
HTH
Andrew
- Raw text -