[antlr-interest] semantic analysis

John B. Brodie jbb at acm.org
Fri Mar 19 17:35:27 PDT 2010


Greetings!

On Fri, 2010-03-19 at 17:01 -0400, venkat medhaj wrote:
> Hi,
> 
> I have a simple grammar for which I was able to walk through the AST and
> printout the input text to the console. I learned that we need to put the
> information in the symbol table and do the semantic analysis from there on.
> How , what information should I put into the symbol table and how do I check
> for type errors ?
> 
> Let say, I have something like a + b, given that I am able to walk through
> the AST, how do I do the type checking for this little case?
> Any simple code snippets would be appreciated.
> 

Attached please find an example Expression parsing suite for ANTLRv3. I
intended for this to be a simple tutorial example for tree rewriting. It
is complete, but not documented. So, as is, it is not a very good
example, but hopefully you can see one possibility for your solution (i
hope).

It has 4 phases: 1) parsing, 2) type checking, 3) instruction selection,
and 4) evaluation. There is a grammar that drives each phase. Probably
start by looking at the Main.java and try to figure out where we go from
there... (sorry for the lack of commentary/documentation)

Hope this helps....
   -jbb

-------------- next part --------------
A non-text attachment was scrubbed...
Name: expressions.tgz
Type: application/x-compressed-tar
Size: 8571 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20100319/984caea2/attachment.bin 


More information about the antlr-interest mailing list