Hi,

I love replying to myself ;-)

I found some way of achieving the implicit uppercast, but not using a tree grammar.
I wrote my grammar to distinguish between int and float expressions right from the start.
Unfortunately I now run into trouble. I added boolean expressions to my grammar and cannot find a way to
make boolean _expression_ like:

bool a := 3<4

work, but prevent my grammar from accepting things like

bool a:=4

which is obviously bad. 
So I had a look at the Java grammars on antlr.org and found that, they do not impose type restrictions
on the parser side. E.g. with Terrence's Java 1.5 grammar:

private boolean b = 3;

is totally valid.

I know that trying to catch violations in typing via the parser-grammar was a bad idea.
But I cannot come up with a good solution to do this in an extra stage via a TreeWalker.

Any help would be greatly appreciated.

Attachment: Arith.g
Description: Binary data

 

Attachment: Arith.testsuite
Description: Binary data

Tilman Bender
Student des Software Engineering
Hochschule Heilbronn



Am 09.04.2009 um 13:35 schrieb Tilman Bender:

Hi there,

I am still playing with my interpreter for arithmetic expressions.
Now I would like to work with mixed expressions containing integer and floating point numbers.

When doing so I would like to have the integers automatically "uppercasted" when
they occur in an _expression_ together with floats. 

So what I currently do is, that I have a Java class providing methods for the respective
arithmetic operations and invoke it from my interpreter:

 ^(MINUS a=expr b=expr)  { $value = Arithmetic.subtract($a.value,$b.value);}

In the add-method I check for the type of the parameters passed in and do the conversion 
to BigDecimal magic.

However I would like to make this "implicit uppercast" independant from the host language for
my interpreter to minimize the amount of code I have to change, when switching the host language. 

Has anyone already done such a thing via a TreeWalker?

Tilman Bender
Student des Software Engineering
Hochschule Heilbronn




List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

Reply via email to