dcsimg
nondeterminism, lookahead depth
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   klas_eriksson
Posted On:   Tuesday, July 16, 2002 04:15 AM

Hi I have a grammar with a lot of conflicts. "left-factor the rules combining identical left-prefixes" would make my grammar impossible to read and understand. I'm new to antlr (but I've used yacc), so I've adjusted the lookahead (k) and tried to use "!" (semantics similar to prolog, right?). No success. My problems come down to: Is it possible to make the rule r : ( A B | B A ) | A A ; compile without warnings without left-factoring? (http://www.antlr.org/doc/options.html#_bb4) I want to handle each conflict individually. Not just turn all warnings off. /klas    More>>

Hi


I have a grammar with a lot of conflicts.
"left-factor the rules combining identical left-prefixes"
would make my grammar impossible to read and understand.


I'm new to antlr (but I've used yacc), so I've adjusted
the lookahead (k) and tried to use "!" (semantics similar
to prolog, right?). No success.

My problems come down to:

Is it possible to make the rule

r :  ( A B | B A ) |  A A ;

compile without warnings without left-factoring?
(http://www.antlr.org/doc/options.html#_bb4)


I want to handle each conflict individually. Not just
turn all warnings off.


/klas

   <<Less

Re: nondeterminism, lookahead depth

Posted By:   Monty_Zukowski  
Posted On:   Wednesday, July 17, 2002 08:41 AM

! doesn't affect the parsing, just whether that token is included in automatic tree building.


Since you are using a left-recursive system it's hard to escape left factoring.


The only solution I see for your rule is to allow more than you want and then check it later.


r
{int aCount=0;bCount=0;}
: ( A {aCount++;}
| B {bCount++;}
)+ { if (!((A==1&&B==1) || A==2))
{ throw new SemanticException(); }
}

If you really want the rule to exactly match two and only two tokens you can use another counter and a semantic predicate. However, this is a pretty arbitrary rule. Perhaps you have a real life example of what you want to accomplish?
About | Sitemap | Contact