1

Is it possible to dynamically assign possible values to a field in a Grammar file?

For example: I want the 'NAME' field of the example below to be one of the following words: 'name', 'age' or 'city'. So, I have define it in my Grammar file.

But, if later I want to accept another word ('job', for example), I need always to update this Grammar file, or is it possible to pass to the file a List < String > with the possible words for that field, and only update the list in my Java code?

equality_expr
    :   NAME equality_op atom   -> ^(equality_op NAME atom)
    ;

NAME
    :   'name'
    |   'age'
    |   'city'
    ;
user2144555
  • 1,315
  • 11
  • 34
  • 55
  • Why not create an `IDENTIFIER` token as `\w+` and check in the program whether it has one of the acceptable values? So e.g., "foo" will parse, but be rejected later on as an invalid name. – yshavit May 28 '14 at 13:11
  • That's an idea :) However, I was curious to know if that was possible. – user2144555 May 28 '14 at 16:41
  • It isn't to my knowledge, but I don't know enough to put that down as an answer. – yshavit May 28 '14 at 16:59

0 Answers0