Any YACC / BISON gurus out there?
Richard Thombs
richard at ssf.uucp
Tue Oct 24 19:27:16 AEST 1989
Hi, I'm trying to write a YACC grammar to parse an adventure game description
database and I need YOUR help!
I need to be able to get YACC (or BISON if need be) to fail a parse when an
action tells it to. As an example, character level names are described using
a format like this:-
...
male levelname1
levelname2
levelname3
female levelname1
levelname2
levelname3
...
I use a symbol table entry that allows the symbol to be defined as a reserved
word (in this case 'male' and 'female') and / or many other things including
actions, object names etc. The lexical analyser returns all names as being of
type SYMBOL, and the grammar does the deciding on what really constitutes a
valid symbol at the point of parsing. In this case, a level name can be any
symbol so long as its not the reserved words 'male' or 'female' which are
identified by having a reserved word class of 'SEX'.
The grammar I came up with is this one:-
level_name_decl_list : level_name_decl_list
level_name_decl
| level_name_decl
;
level_name_decl : sex
level_name_list
;
sex : SYMBOL
{
if ($1->reserved != 1 || $1->reserved_data->class != SEX) YYERROR;
}
level_name_list : level_name_list
level_name
| level_name
;
level_name : SYMBOL
{
if ($1->reserved == 1 && $1->reserved_data->class == SEX) YYERROR;
}
And my trouble is that the YYERROR directives don't do what I hoped they'd do,
which is fail the current non-terminal as being unparsable and trying further
rules, indstead it just fails the non-terminal and generates a syntax error.
What I need to be able to encapsulate in a non-terminal is an action that will
only allow the non-terminal to be parsed if I want it to be. I thought there
would be a YYREJECT or similar, but I can't find any mention of it in the
documentation or sources.
So, if you know of any ways to do this, then let me know either by mail or
news.
Thanks in advance,
Richard Thombs
--
Post: System Software Factors, Chiltern Chambers, Caversham, Reading, England.
Mail: richard at ssf.{co.uk,uucp}
Phone: +44 734 476644
More information about the Comp.unix.questions
mailing list