Given root grammar R and imported grammars A and B, ANTLR generates classes R, R_A, and R_B. Class R has two delegate pointers to instances of type R_A and R_B so that rules in R can access the imported rules. The delegate classes have delegator pointers back to the root so that any rule can get to any other rule. There is no need to copy any rules from the delegate grammars into the root grammar. Every import of a delegate grammar results in the generation of a delegate parser not just the root parser. So if two root grammars import A, ANTLR will generate two different classes from A.
ANTLR must do this because a rule overridden in the root grammar often changes the prediction lookahead sets of rules in the imported grammar. Additionally, all token types must be consistent across rules from all delegate grammars. There is little choice but to regenerate classes for delegate grammars.
This requirement raises the issue of multiple code regeneration for top node classes in our environment. This problem will get compounded because the node depth of the tree in our case is at least 4. Is there a way SableCC provides to stop this regeneration of classes and support multilevel grammar files. If yes, please provide me with detailed steps.... Tokens // normal tokens if = 'if'; while = 'while'; identifier = letter (letter | digit)*; ... // virtual token (not matched by the generated lexer) a_start = ; b_start = ; Productions start = {a} a_start a | {b} b_start b; // grammar A a = x y; y = while identifier ...; // grammar B b = z x; z = identifier ...; // shared productions x = if identifier ... ;In order to make it work, you'll need to write a custom lexer class that extends the generated lexer and automatically returns a leading TAStart or TBStart token to the parser, to select the grammar you wish to parse.
Etienne Gagnon, Ph.D. http://sablecc.org
Given root grammar R and imported grammars A and B, ANTLR generates classes R, R_A, and R_B. Class R has two delegate pointers to instances of type R_A and R_B so that rules in R can access the imported rules. The delegate classes have delegator pointers back to the root so that any rule can get to any other rule. There is no need to copy any rules from the delegate grammars into the root grammar. Every import of a delegate grammar results in the generation of a delegate parser not just the root parser. So if two root grammars import A, ANTLR will generate two different classes from A.
ANTLR must do this because a rule overridden in the root grammar often changes the prediction lookahead sets of rules in the imported grammar. Additionally, all token types must be consistent across rules from all delegate grammars. There is little choice but to regenerate classes for delegate grammars.
This requirement raises the issue of multiple code regeneration for top node classes in our environment. This problem will get compounded because the node depth of the tree in our case is at 1least 4. Is there a way SableCC provides to stop this regeneration of classes and support multilevel grammar files. If yes, please provide me with detailed steps. --
--
-- You received this message because you are subscribed to the SableCC group. To post to this group, send email to sab...@googlegroups.com. To unsubscribe from this group, send email to sablecc+u...@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/sablecc?hl=en
---
You received this message because you are subscribed to the Google Groups "SableCC" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sablecc+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Lexer lexer = new Lexer(new PushbackReader(new BufferedReader(new FileReader(arguments[0])), 1024)); Parser parser = new Parser(lexer); Node ast = parser.parse(); // create an instance of a subclass of DepthFirstAdapter // to print "Vivek" on each ENDIF // and apply it to the AST ast.apply(new DepthFirstAdapter() { @Override public void outAIfStatement(AIfStatement node) { System.out.println("Vivek"); } });
I actually just want to add custom action when ever ENDIF is encountered when i pass my input file to SableCC. For Example "Say i want to print my name on the console".
Suppose my INPUT file for minibasic.jar is like this
[...]