[antlr-interest] syntactic predicate question

damarcus Leacock damalee5 at gmail.com
Tue May 15 15:48:58 PDT 2007


Hi,

I'm sure this question has been asked before, I just couldn't find it in the
documentation or mailing list. I wonder why the following doesn't work (see
below). The fragment is useless, but it is a problem that I isolated from a
real grammar I am working on. I just can't understand why the syntactic
predicate does not come to the rescue here. Surely the look-ahead is fixed,
so it should be possible to generate a recursive descent parser for this no?


What do I fail to see?


Many thanks,
d.

(ps. doubt that it matters, but I am using antler 2.5.7 under Java)



-----------------------------------------------------------
class AmbiguousParser extends Parser;
options {
      buildAST = true;
      k = 1;
}

expr
  : sexpr (OP^ sexpr)*
  ;

sexpr
  :  Literal {/* do something */}
  |  ( Literal DOT^ ) => Literal DOT expr {/* do something else */}
  ;


class AmbiguousLexer extends Lexer;

DOT    : '.';
OP     : "*";

Literal
    : ( "a" | "b" )
    ;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20070515/3b51af4e/attachment.html 


More information about the antlr-interest mailing list