[vox-tech] how to get yacc/bison to say "i'm confused"

Jeff Newmiller vox-tech@lists.lugod.org
Thu, 27 Dec 2001 11:23:15 -0800 (PST)


On Thu, 27 Dec 2001, Peter Jay Salzman wrote:

> newbie here.
> 
> i'm using flex/bison for processing a program's user input, and have a
> list of rules that define the user input grammar.
> 
> after bison processes all it's input, is there a way of telling it:
> 
>    if no rule matched the input, take your input and feed it to
>    ParseError(const char *error)?
> 
> the problem i'm having is typically:
> 
> 	ruleset:    TOK_RULESET NUMBER    { ChangeRuleset($2); }
> 		|        TOK_RULESET           { ChangeRuleset(-1); }
> 
> if the user types something like "ruleset asdf", it'll match
> "TOK_RULESET", and (i think) "asdf" gets put back into the buffer since
> it's not a NUMBER, and is processed the next time the user inputs
> something.  in other words, bison gets out of sync and confused.

I think your rules do not convey that you feel the "asdf" must be
associated with "ruleset" even though it isn't a number.  Your definition
of "ruleset" says a bare "ruleset" token can be a valid ruleset, so
any non-number following it must be associated with another rule.

I think you need to specify a terminal "end of arguments" token in your
syntax to identify "optional argument" behavior.  This could be
end-of-line, or semicolon, or parentheses.  Then, the "ruleset" rule
cannot match "ruleset asdf" because the end-of-arguments token will follow
the unrecognized "asdf".

I say "I think" because I haven't built an interactive parser before.

---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil@dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...2k
---------------------------------------------------------------------------