[antlr-interest] assign a value to a token

Bart Kiers bkiers at gmail.com
Wed Jul 18 12:48:54 PDT 2012


Hi,

I am (again) not entirely clear what it is you're trying to so. But it
looks to be a bit the same as your other question: you're trying to resolve
all kind of semantics in the parser. This is not something the parser
(parser rules, if you will) should be doing. You let the parser create a
(abstract) syntax tree and when this is done, you walk through your tree
and check if the nodes in your tree have the proper/expected value (i.e.
you evaluate the tree).

As suggested earlier: better do a bit of reading on ANTLR because I don't
think you're on the right path if you think ANTLR can be used in the way
you're trying to tackle your problem at this moment.

Regards,

Bart.


On Wed, Jul 18, 2012 at 3:08 PM, Marinos Georgiades
<marinos at studyhood.com>wrote:

> I would like to assign the value of a token to a variable, so as I will be
> able to use that variable through my grammar (I am sorry if I don't use the
> right terminology).
>
>  For example, I have the following rules (I am quoting part of them for
> simplification):
>
> useCaseSpecification
> :'UseCase:' ucName '='
> description
> statePre
> .......
> ;
>
> ucName
> :caren io
> ;
>
> caren
> : 'create' | 'alter' | 'read'
> ;
>
> io
> :ioName ioType
> ;
>
> ioName
> : ARTICLE NOUN
> ;
>
> description
> :'Description' ':' ucName ......
> ;
>
> statePre
> :io 'is 'at' state 'state' '.' 'Triggered' 'by' 'UseCase' ':' ucName
> ;
>
> A test syntax can go like this:
>
> UseCase: create Prescription =
> Description: create Prescription
> Examination is at ....... Triggered by UseCase: Create Examination
>
> In this example, ucName is assigned the values 'create Prescription' for
> line 1 and 2, and the value 'Create Examination' for line 3. However,
> someone can write something else, e.g. 'read Book' for line 2. And I don't
> want it to be like this. I want the ucName of the rule 'description' to be
> the same with the ucName of the rule useCaseSpecificaton. And I want the
> ucName of the rule statePre to be different from the others.
> >From what I read , there must be a way with the use of Java code, but I
> haven't managed to make it work. I would really appreciate if someone could
> help me.
>
> Thank you,
>
> Marinos
>
> 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