[antlr-interest] how to call a rule/token from its including rule
marinos at studyhood.com
Wed Jul 18 05:10:05 PDT 2012
and thank you for your reply.
If I just call the 'actorName', then once I write the actual syntax and replace 'actorName' with a value, (e.g. 'Doctor'), the parser will not be able to distinguish if it is the actorName of the PrimaryActor or the actorName of the SecondaryActor. Both 'primaryActor' and 'secondaryActor' have an actorName of the same type. I don't want to create an actorName for each one of them but being able to distinguish the actorName (sub-rule/token) through its including rule.
From: Bart Kiers <bkiers at gmail.com>
To: Marinos Georgiades <marinos at studyhood.com>
Cc: "antlr-interest at antlr.org interest" <antlr-interest at antlr.org>
Sent: Wednesday, July 18, 2012 3:01 PM
Subject: Re: [antlr-interest] how to call a rule/token from its including rule
On Mon, Jul 16, 2012 at 5:41 PM, Marinos Georgiades <marinos at studyhood.com> wrote:
>I am new to ANTLR, so I am trying to learn the basics.
>I would like to know how I can call a rule or token which is defined within another rule, as in the example below:
>:'Description' ':' primaryActor.actorName ......
>:actorName | SA_TYPE
>So, 'primaryActor' and 'secondaryActor' both have an 'actorName'. When the user will write the actual syntax "e.g. 'Description: a Doctor...", 'Doctor should be assigned to 'primaryActor.actorName. Because 'actorName' is of the same type for both primary and secondary actors, I don't want to create an actorName for each one of them but being able to distinguish the actorName (sub-rule/token) through its including rule.
I don't quite follow. If you want to match an `actorName`, why would you want to write `primaryActor.actorName` (which isn't possible, btw) instead of just writing `actorName` like this:
:'Description' ':' actorName
More information about the antlr-interest