Following this old tutorial, I am trying to get a lemon parser to automatically terminate parsing on an EOL
token. The relevant part of the parser looks like this:
start ::= in .
in ::= .
in ::= in commandList EOL .
{
printf("start ::= commandList .\n");
printf("> ");
}
Here's how I'm executing the parser with tokens scanned by Flex:
int lexCode;
do {
lexCode = yylex(scanner);
Parse(shellParser, lexCode, yyget_text(scanner));
// XXX This line should not be necessary; EOL should automatically
// terminate parsing. :-(
if (lexCode == EOL) Parse(shellParser, 0, NULL);
} while (lexCode > 0);
I'd like to eliminate the need to check for the EOL
token here, and just let the parser figure out when it's done. How do I do that?
Thanks!
In EBNF terms your definition of
in
isWhich allows multiple EOLs. What you want is
Which should work out to
Note that this does not allow for completely empty input (not even an EOL); you can tweak things as necessary if this is a problem.