[antlr-interest] Reading rule modifiers from common tree

Selim Ciraci ciraci at gmail.com
Wed Jul 14 13:18:59 PDT 2010


Hi,

Thanks for the reply. I'm trying to use antlr to parse antlr grammar files.
The problem is that when I parse the grammar file, the rule modifiers go
missing.
The previous example I showed you is from Sql.g. I use antlr to parse this
grammar file (I use AntlrV3.2.g). Now the Sql.g contains the following rule:
fragment A:  'a' | 'A';

When I parse the file, somehow the fragment gets lost. Hence, the call to
toStringTree() on the rule node does not show a node with token fragment.
For example the parse tree of the rule A is printed as:
(RULE A (BLOCK (ALT (BLOCK (ALT 'a' EOA) (ALT 'A' EOA) EOB) EOA) EOB) EOR)
no mentioning of the "fragment". So somehow I cannot access the modifier of
the rule from it is parse tree. Is there a way to do that?

Kind regards,
Selim Ciraci

On Wed, Jul 14, 2010 at 9:51 PM, Matt Palmer <mattpalms at gmail.com> wrote:

> Selim,
>
> I may have misunderstood your problem, but fragment rules don't form tokens
> in the output.  They are just convenient patterns to re-use in other, actual
> tokens.
>
> Regards,
>
> Matt
>
> On 14 July 2010 17:28, Selim Ciraci <ciraci at gmail.com> wrote:
>
>> Hi all,
>>
>> I'm trying to write a program to parse a grammar file, modify it and write
>> it back as a grammar file. For this I use the builtin parser:
>> org.antlr.grammar.v3.ANTLRv3Lexer, org.antlr.grammar.v3.ANTLRv3Parser.
>> Everything seems to work ok but somehow the modifier of a rule is not
>> visible from the rule node.
>> For example: I have the following rule: fragment A:('a'|'A');
>>
>> When I do a toStringTree() on the rule node I get the following output
>> (RULE A (BLOCK (ALT (BLOCK (ALT 'a' EOA) (ALT 'A' EOA) EOB) EOA) EOB) EOR)
>>
>> somehow the fragment is missing and I cannot access the modifier of the
>> rule. is there something I'm doing wrong here? if so how can I access the
>> modifier?
>>
>> With kind regards,
>> Selim Ciraci
>>
>> List: http://www.antlr.org/mailman/listinfo/antlr-interest
>> Unsubscribe:
>> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>>
>
>


More information about the antlr-interest mailing list