Identifier terminal except certain keywords

438 views Asked by At

I'm using Irony framework and I have:

IdentifierTerminal variable = new IdentifierTerminal("variable");

a terminal for identifying an entry terminal.

This variable terminal can hold any string, except for a predefined list of reserved strings. This identifier does not start or any with quotes or double quotes.

I want something like:

IdentifierTerminal variable = any contiguos string EXCEPT "event", "delegate";

How can I enforce this rule for this terminal?

1

There are 1 answers

2
Matt On

Have you declared your keywords explicitly? If not, this page: https://en.wikibooks.org/wiki/Irony_-_Language_Implementation_Kit/Grammar/Terminals#Keywords will show you how. It seems that you don't need to explicitly say that an identifier cannot be a keyword, as the parser is able to figure this out. I found the following quote

Finally, in most cases, the Irony scanner does not need to distinguish between keywords and identifiers. It simply tokenizes all alpha-numeric words as identifiers, leaving it to the parser to differentiate them from each other. Some LEX-based solutions try to put too much responsibility on the scanner and make it recognize not only the token itself, but also its role in the surrounding context. This, in turn, requires extensive look-aheads, making the scanner code quite complex. In the author's opinion, identifying the token role is the responsibility of the parser, not the scanner. The scanner should recognize tokens without using any contextual information.

source: http://www.codeproject.com/Articles/22650/Irony-NET-Compiler-Construction-Kit