Replies: 1 comment 1 reply
-
This is an example of when you need to move the syntax into a static semantics analysis. You should not be adding these checks into the grammar. Separate context-free syntax and semantic checks into completely different docs: the CFG is in the Antlr4 .g4 file; semantic checks need to be defined elsewhere. You can have a constraint system called post-parse on the entire tree, or during the parse on partial trees. For example, with the grammars-v4/vba grammar, to handle
Note, the vba grammar defines a SHORTLITERAL with |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
In VBA, the following are valid:
But these are both invalid:
In the official VBA syntax, an
INTEGER
is only a sequence of digits, and this is what my current grammar is expecting in these cases. In most mathematical cases, theMINUS
is a unary operator defined in the parser.I’m struggling with trying to figure out how to either define a
MINUS_ONE
token, or a Lexer rule that will only match “-1”. Should I instead just add `MINUS INTEGER” to the parser rule and let a Lint tool sort it out later if the minus exists and the value of the integer is anything other than a “1”?Beta Was this translation helpful? Give feedback.
All reactions