[antlr-interest] how to call a rule/token from its including rule

Bart Kiers bkiers at gmail.com
Wed Jul 18 05:01:11 PDT 2012


On Mon, Jul 16, 2012 at 5:41 PM, Marinos Georgiades
<marinos at studyhood.com>wrote:

> Hello,
>
> 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
> :'Description' ':' primaryActor.actorName ......
> ;
>
> primaryActor
> :actorName PA_TYPE
> ;
>
> secondaryActor
> :actorName | SA_TYPE
> ;
>
> actorName
> :ARTICLE SMALL_NOUN
> ;
> 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
:'Description' ':' actorName
;

Regards,

Bart.


More information about the antlr-interest mailing list