[antlr-interest] Type Checking/Semantic Analysis

José María García Rodríguez darthia at gmail.com
Tue Aug 2 00:27:04 PDT 2005


> 
> Hello Everyone,
> 

Hi! :)

> 
> I am developing a simple typed language.  So far things have been going very
> well. Thanks to ANTLR and existing grammar samples, I have been able to
> create an AST without too much trouble.  
> 
> However, now I find that my grammar allows for statements such as TRUE >
> FALSE.  I would like to catch issues like this through semantic/type
> checking routines.
> 
> ------>QUESTION 1: Is this a correct approach?  I mean should I catch these
> types of errors through semantic analysis or should I be relying on the
> parser to catch them?
> 

My choice would be to do type checking through semantic analysis,
because that kind of construction is sintactically correct, IMO.

> 
> My grammar also allows for variables so I really doubt that I can rely on
> the parser for all type checking.  So I decided to use 'my own' AST nodes
> and attempt type checking either recursively or using the VISITOR design
> pattern.
> 

What I've been doing in my translators is to do type checking
recursively within actions in a tree parser, using my own AST nodes,
as you said. These nodes store information about the expression they
represent, like type, L-Value, and so...

> 
>> 

HTH

Regards,

José María García Rodríguez


More information about the antlr-interest mailing list