[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->DF'
F'->ifthen F | epsilon
D->CD'
D'->or CD' | epsilon
C->NC'
C'->and NC' | epsilon
N->not N | P
P->var | (F)
In ANTLR it is like:
formula
returns [Formula f]
{ f = null; Formula f1; Formula f2; }
: f1=disjunction f2=sformula
{
if (f2!=null) {
f = new Formula();
f.setType(CONDITIONAL);
f.attachLeft (f1);
f.attachRight (f2);
} else
f = f1;
}
;
sformula
returns [Formula f]
{ f = null; }
: IF_THEN f=formula
| //epsilon
;
disjunction
returns [Formula f]
{ f = null; Formula f1; Formula f2;}
: f1=conjunction f2=sdisjunction
{
if (f2!= null) {
f = new Formula();
f.setType(DISJUNCTION);
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. :-)
--
Pozdrawiam
Marcin Rzeznicki
Yahoo! Groups Links
To visit your group on the web, go to:
http://groups.yahoo.com/group/antlr-interest/
To unsubscribe from this group, send an email to:
antlr-interest-unsubscribe at yahoogroups.com
Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list