[antlr-interest] ANTLR 3.1.2: Simplest action

Bart Kiers bkiers at gmail.com
Wed Jul 13 13:39:52 PDT 2011


Hi Udo,

Ah yes, apologies: you can only reference parser rules like that:

parserRule : LexerRule { print($parserRule.text) } ;


and *not*:

LexerRule : OtherLexerRule { print($LexerRule.text) } ;


Regards,

Bart.


On Wed, Jul 13, 2011 at 10:27 PM, Udo Weik <WeikEngOff at aol.com> wrote:

> Hello again Bart,
>
>
>  `$text` is just a shorthand notation for `$XYZ.text` where `XYZ` is the
>> rule you're currently in.
>>
>
> $INTEGER.text doesn't work ("rule INTEGER has no defined parameters"), but
> your $text does.
> That's what I don't understand ;(.
>
>
>
> Many thanks and greetings
> Udo
>
>
>  On Wed, Jul 13, 2011 at 10:18 PM, Udo Weik <WeikEngOff at aol.com <mailto:
>> WeikEngOff at aol.com>> wrote:
>>
>>    Hello Bart and others,
>>
>>    yep, thanks, it works...
>>
>>
>>        Try:
>>
>>            INTEGER
>>               :  DIGIT+ { print($text) }
>>               ;
>>
>>
>>    1. Why do I not need the name, here INTEGER, like $INTEGER.text?
>>    2. With 12345 the result is
>>       L: (DIGIT): 1
>>       L: (DIGIT): 12
>>       L: (DIGIT): 123
>>       L: (DIGIT): 1234
>>       L: (DIGIT): 12345
>>       L: (INTEGER): 12345
>>
>>       I expected
>>       L: (DIGIT): 1
>>       L: (DIGIT): 2
>>       L: (DIGIT): 3
>>       L: (DIGIT): 4
>>       L: (DIGIT): 5
>>       L: (INTEGER): 12345
>>
>>
>>    Many thanks and greetings
>>    Udo
>>
>>
>>
>>        On Wed, Jul 13, 2011 at 9:57 PM, Udo Weik <WeikEngOff at aol.com<mailto:
>> WeikEngOff at aol.com> <mailto:WeikEngOff at aol.com <mailto:WeikEngOff at aol.com>>>
>> wrote:
>>
>>            Hello,
>>
>>            I just want to access the attributes of INTEGER
>>            and DIGIT - but how?
>>
>>            INTEGER: DIGIT+ { print( "L: (INTEGER): " ) } ;
>>
>>            fragment
>>            DIGIT: '0'..'9' { print( "L: (DIGIT): " ) } ;
>>
>>
>>            Thanks and greetings
>>            Udo
>>
>
>


More information about the antlr-interest mailing list