|Get allowed-next-tokens in yacc? firstname.lastname@example.org (R Faulds) (1998-03-03)|
|Re: Get allowed-next-tokens in yacc? email@example.com (Maurizio Vitale) (1998-03-06)|
|Re: Get allowed-next-tokens in yacc? firstname.lastname@example.org (Vladimir Alexiev) (1998-03-07)|
|From:||Vladimir Alexiev <email@example.com>|
|Date:||7 Mar 1998 22:41:41 -0500|
|Organization:||University of Alberta, Computing Science|
"R Faulds" <firstname.lastname@example.org> writes:
> 1) Is there a way (without hacking y.tab.c) to get the list of allowed
> tokens for some (any) point in the parse process?
Sure. This would be yacc-dependent though.
> >show interface<help-key>
> <num> - numeric input required
> ALL - display all
This sounds good, but for some tokens (the "syntactic noise" tokens)
you can't give sensible help. Eg '(' may mean signify the beginning of
an "argument list" or a "nested expression", and ALL may mean "all
interfaces or "all widgets", etc.
> 2) When I'm parsing down a specific rule, how do I use error to localize
> the error handling?
> >set interface address <CR>
> trap the error at the rule's action code so I could issue
> "numeric required, choose an interface between [1..7]".
This is related to the previous point. If you can figure out the set
of allowed tokens, you can make a sensible error message.
> [Honestly, I wouldn't use yacc. Getting the actual list of allowed tokens
> at each point is really hard due to the state and table compaction that
> yacc does. And the error recovery is no prize-winner. -John]
I don't know what compaction yacc does, but I'd suggest you use bison.
Look at the skeleton file bison.simple, after a "#ifdef
YYERROR_VERBOSE" label. If that is defined, bison calls yyerror with
eg "parse error, expecting `foo' or `bar' or `'+'' or `NUM' or
'ALL'". It's a simple matter to enrich this with more detailed
explanations taken from the table containing the help texts. Note that
some of the expected tokens could be non-terminals.
Return to the
Search the comp.compilers archives again.