Friday, January 07, 2011

For Loop Compiled

Made a pass today at updating the tree grammar for the Ctrl to include a description of the for loop AST structure. The structure of the tree was pretty much copied verbatim from the parser grammar, with a few minor tweaks. ANTLR uses the same notation for both types of grammars so tree structures are easily ported between the two.

During tree traversal, while visiting a node in the tree, the tree walker executes an "action". In our tree walker, an action is a transformation step that goes from AST to an instance of a Java object from our Ctrl model. The action essentially takes node values from the AST and copies them into a RuleStatement. This is what Ctrl compilation comes down to. A few getters and setters were missing, so I added these as well as toString() implementations to all of the Java classes in the model supporting the for loop.

I took a screenshot of my debugging session. The breakpoint in the screenshot is set in my TestRig. Whenever the grammars are touched, I run the TestRig. It is a suite of tests that compiles a wide range of statements in the Ctrl, from simple one-liners, to complex multi-line if-then-else statements.



We are in good shape so far. The screenshot shows a compiled RuleStatement object that contains an initialized ForStatement, in the "Variables" view of the debugger.

No comments:

Post a Comment