[antlr-interest] learning pitfall....

Ric Klaren klaren at cs.utwente.nl
Tue Apr 2 02:36:03 PST 2002


On Tue, Apr 02, 2002 at 08:24:07PM +1000, Lloyd Dupont wrote:
> But if I add this production in the grammar:
> // ------- added in java.g, in JavaRecognizer class ----------
> script : (statement | importDefinition) *  ;
> //---------------------------------------------------------------------

The problem is that this rule can be empty (zero or more times something).
Which will not work (antlr needs lookahead to decide things if a rule can
be empty there's nothing to decide with...) Rewriting to something like

calling_rule: yyy (script)? xxx ;
script: (statement | importDefinition)+ ;

Will solve the problem.

> By the way, reading anything I could about nondeterminism I see an example with a token set like that :
> -------------
> ('b' | )
> --------------
> I hardly figure out what this could mean ! could you explain ?

Its a 'b' or nothing or in other words an optional 'b'. Or alternatively (
'b' )? Sometimes its covenient to write an optional alternative like this
in order to add specific action code for the empty alternative.

Hope this helps,

Ric
-- 
-----+++++*****************************************************+++++++++-------
    ---- Ric Klaren ----- klaren at cs.utwente.nl ----- +31 53 4893722  ----
-----+++++*****************************************************+++++++++-------
 'And this 'rebooting' business? Give it a good kicking, do you?' 'Oh, no,
  of course, we ... that is ... well, yes, in fact,' said Ponder. 'Adrian
    goes round the back and ... er ... prods it with his foot. But in a
     technical way,' he added. --- From: Hogfather by Terry Pratchett.


 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



More information about the antlr-interest mailing list