[antlr-interest] How to support a new type

Johannes Luber jaluber at gmx.de
Tue Apr 15 03:09:26 PDT 2008


Yixun Liu schrieb:
> I have two compilers, let's say compiler1 and compiler2. The data type
> Dim is support by compiler2, but doesn't by compiler1. My source code
> should firstly be compiled by compiler1 and then compiled by compiler2.

Does compiler1 feed the its output to compiler2?

> However, the data type Dim cannot pass the compilation of compiler1.
> This is the reason I want to modify the grammar file to make compiler1
> support this kind of data type.
> In another word, I want the code "Dim d;" to pass the compilation of
> compiler1. The question is how to make Dim as a build-in type like int,
 > short etc.?

Somewhere in the grammar file there should be a rule, which defines the 
tokens 'int', 'short', etc. Add there the alternative 'Dim'. But that's 
only the easy part. You have to add code which handles the new type. As 
you didn't tell us, what Dim is supposed to be, I can't give you any 
further tips there. It would be also good to know what languages 
compiler1 and compiler2 understand.

Johannes

> Johannes Luber wrote:
>> Yixun Liu schrieb:
>>> Hi,
>>> I want to write a parser.g to support a new type, e.g, dim3. How to
>>> do it?
>> What so you mean with a new type? Do you want to parse a new type in
>> some sourcecode, or do you want to use dim3 as return type for some
>> rule, or is it something else?
>>
>> Johannes
> 



More information about the antlr-interest mailing list