[antlr-interest] Multiplication and pointers in C-style language

Johannes Luber jaluber at gmx.de
Thu Apr 10 11:32:37 PDT 2008


David Olsson schrieb:
> Stuart Watt wrote:
>>
>> if you need pointers and multiplication, in C syntax, I suspect you're 
>> going to need to build a (scoped) type symbol table and semantic 
>> predicates. Then if the first identifier is a type, you can treat it 
>> is a pointer, if not, multiplication. As Jim said, the code to do this 
>> is in the C ANTLR example.
>>
> Unfortunately, my language is not like C in all cases. Specifically, my 
> language is a two pass language. In the first pass, all the parsing is 
> done. In the second, type checks and such is done. This means that I 
> don't need a preprocessor nor includes. This, however, also means that 
> there is no easy way of telling if an identifier is a type or a variable 
> during parsing; that information isn't available until the second pass.
> 
> I've looked at Terence Parr's example Java grammar but since there are 
> no pointers in Java it is of little help. Maybe the only solution is to 
> change the pointer syntax so that there are no conflicts with other 
> operators (the benefit of inventing your own language ;-))... Or can 
> anyone think of a better solution?

Changing the grammar to remove conflicts is of course the best variant, 
but may end with a different recognized language. A possibility is to us 
tree rewriting. Use semantic meaningless names like STAR and change in 
the the second pass the AST, once you have sufficiently knowledge about 
the context.

Johannes



More information about the antlr-interest mailing list