[antlr-interest] Epsilon productions and end of file

Marcin Rzeznicki marcin-rzeznicki at wp.pl
Thu Dec 18 13:14:38 PST 2003

----- Wiadomosc oryginalna ----- 
Od: "Arnar Birgisson" <arnarb at oddi.is>
Do: <antlr-interest at yahoogroups.com>
Wyslano: 18 grudnia 2003 14:22
Temat: RE: [antlr-interest] Epsilon productions and end of file

> Hello Marcin,
> Could you post a portion of your ANTLR grammar?

Of course, this grammar is meant to be well-formed logical formulae grammar.
I have eliminated left recursion, also performed factorization of the
grammar. It is :
F'->ifthen F | epsilon
D'->or CD' | epsilon
C'->and NC' | epsilon
N->not N | P
P->var | (F)

In ANTLR it is like:
 returns [Formula f]
 { f = null; Formula f1; Formula f2; }
  :  f1=disjunction f2=sformula
   if (f2!=null) {
    f = new Formula();
      f.attachLeft (f1);
    f.attachRight (f2);
   } else
    f = f1;

 returns [Formula f]
 { f = null; }
  :  IF_THEN f=formula
                | //epsilon

 returns [Formula f]
 { f = null; Formula f1; Formula f2;}
  :  f1=conjunction f2=sdisjunction
   if (f2!= null) {
    f = new Formula();
    f.attachLeft (f1);
    f.attachRight (f2);
   } else
    f = f1;
and so on

> Btw: Are you eliminating left-recursion by adding F'? If so it's
> convenient to use ANTLR-specific syntax instead (the ? or + operators).

What do you mean by using ? and + instead eliminating left recursion? I
don't quite catch it. :-)

Marcin Rzeznicki


Yahoo! Groups Links

To visit your group on the web, go to:

To unsubscribe from this group, send an email to:
 antlr-interest-unsubscribe at yahoogroups.com

Your use of Yahoo! Groups is subject to:

More information about the antlr-interest mailing list