[antlr-interest] ANTLR Optional statements
Ric Klaren
klaren at cs.utwente.nl
Wed Apr 10 09:24:41 PDT 2002
Hi,
I'll post the solution for the problem in question also to the group..
In context there is a calling rule:
external_declaration:
( ( (TYPEDEF | template_head )? class_head LCURLY) =>
( template_head )? declaration
| .. more ..
.
> > class_head
> > :
> > ( STRUCT
> > | UNION
> > | CLASS
> > )
> > (ID ( base_clause)? )?
> > ;
The problem here was the fact that class_head was not called inside the
grammar it was an unreferenced rule. As a result ANTLR set the followset to
EOF. In stead of to EOF and LCURLY.
If class_head had been used inside template_head/declaration rules the
problem would not have occured.
Which leads to the following rule of thumb:
Do not use loose (unreferenced) rules inside predicates.
ANTLR should probably give a warning for unreferenced rules especially if
they occur inside predicates. (Or would this have been caught by hoisting?
I'm not familiar with PCCTS's hoisting)
Cheers,
Ric
--
-----+++++*****************************************************+++++++++-------
---- Ric Klaren ----- klaren at cs.utwente.nl ----- +31 53 4893722 ----
-----+++++*****************************************************+++++++++-------
Wit is cultured insolence. --- Aristotle
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list