Let's say I have a simple grammar (lexer and parser) for parsing and evaluating simple mathematical expressions (as in several antlr examples), which also allow you to define simple variables (i.e. assign float values) and use these variables. For instance. You can do the following:
r = 2.5; PI = 3.14; PI * r * r;
This is supposed to be used in more complex grammar. In fact, several different. The problem is that the lexer for the above contains basically recognizes each line as an identifier of the type of token, that is, the name of a potential variable, but more complex grammars may contain other keywords.
If i do
lexer grammar ComplexLexer; import SimpleMathExprLexer; // ... IF : 'if'|'IF'; THEN : 'then'|'THEN'; // ...
itβs not very useful that the ID already matches these keywords. Simply moving the import statement below these rules does not work. Is there any way around this, or am I on the wrong track when I look at a composition?
source share