[antlr-interest] Rookie problem

Marko Simovic markobarko at gmail.com
Thu Apr 3 15:15:41 PDT 2008


You're right on the money with that Adam. For the life of me i can't
figure out a solution either. Forget the if-then statement thing from
before and here is a simpler example:

union:  name ('union' name)*;

this rule works well on stuff with syntax:

abcxyz union qrtabc

however, what would be the modification needed to do this:

abc xyz union qrtabc

I'm not smart enough for that problem
Marko

-----Original Message-----
From: Adam Connelly <adam.rpconnelly at googlemail.com>
To: Marko Simovic <markobarko at gmail.com>
Cc: antlr-interest at antlr.org
Subject: Re: [antlr-interest] Rookie problem
Date: Thu, 3 Apr 2008 17:31:53 +0100

Not 100% on this, but I would guess that the "name" rule that's part of
"condition" is consuming the "then".  Basically if I'm right about this,
antlr thinks that the "then" keyword of the if statement is part of a
name.
 
Unfortunately I don't know a solution for this of the top of my head.
 
Sorry,
Adam

 
On 03/04/2008, Marko Simovic <markobarko at gmail.com> wrote: 
        Hi all,
        
        I've just started using Antlr and I'm having a bit of a problem
        with a grammar definiton. I want my grammar to support a
        language with multi-word variable names. However, making the
        adjustment breaks my if-then conditional recognition.
        
        The grammar at the end of this e-mail works fine for variable
        names without spaces. If i change the 'name' definition to the
        following:
        
        name: String (' ' String)*;
        
        then the 'if' statement can no longer be recognized. What am i
        doing wrong?
        
        Thanks,
        Marko
        
        grammar test;
        
        String : ('a'..'z' | 'A'..'Z')+;
        
        ConditionOperator
        : '<' | '>';
        
        name 
        : String;
        
        condition
        : name (ConditionOperator name)*;
        selection
        : 'if' condition 'then' condition;
        
        statement
        : selection;
        
         

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080403/c6edd9ea/attachment.html 


More information about the antlr-interest mailing list