On Fri, Mar 19, 2010 at 10:37 AM, Kaleb Pederson <kaleb.peder...@gmail.com> wrote: > Venkat, > > One way to do what you've mentioned is to create a tree walker which > walks the AST. Then, within the AST, you'll need to do a couple of > things. > > First, you need to populate a symbol table. That symbol table will > store the different objects/variables that are declared. In your > example, it would store a and b, their values, if known, and their > types. > > Second, you need to do an analysis of the structure while using the > symbol table. Here's a fragment from one of my tree walking grammars: > > plusMinusExpression returns [Type type] > : ^(PLUS lhs=baseExpression rhs=baseExpression) > { > typeChecker.assertIsNumericType($lhs.type); > typeChecker.assertIsNumericType($rhs.type); > typeChecker.assertEqualTypes($lhs.type, $rhs.type); > $type = $lhs.type; > } > /* ... */ > ;
I realized that doesn't fully explain everything. In the various expressions, I resolve any necessary symbols and then resolve their types by: * using the symbol table if it's a variable, OR * using the type of the literal I then return the type of the expression so I can verify that the types match throughout the entire expression. -- Kaleb Pederson http://kalebpederson.com http://twitter.com/kalebpederson List: http://www.antlr.org/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address -- You received this message because you are subscribed to the Google Groups "il-antlr-interest" group. To post to this group, send email to il-antlr-inter...@googlegroups.com. To unsubscribe from this group, send email to il-antlr-interest+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/il-antlr-interest?hl=en.