Does antl4 support adaptive grammars that allows the user to specify new rules, such as enforcing the number of arguments specified in a function declaration?
Example: Base language includes the following token definitions:
- Token#1 is defined as [a-z][0-9]*
- token#2 is [A-Z][0-9]*
The uppercase are reserved for function names, and the lower case are reserved for variables passed to the function.
The user can "declare" Fxy, and every following instance of F has to have two variables. I want the parser to enforce the "new rule".
Perhaps this is standard fair in compilers, I know the compilers I use for C, python, etc. bitch when I don't pass the right number of arguments for a function I declared elsewhere. However, I don't know how to do this myself in my own grammar; the undergrad course I took on compilers was more than 15 years ago and I don't recall it including how to enforce # of arguments required for user declared functions. I've written some simple languages with five keywords and scoping (brackets), somewhat akin to the calculator examples you find in textbooks, but nothing complex.
So, I guess what I also want to know is whether the ANTLR books will teach me how to do this (don't want to spend the money if the books don't explain what I want to achieve).