Hello everybody
I am trying to implement a for-loop in my Math parser but it doesn't really
work.
I have some problem with seeking the input to the right destination in the
tree which
was generated by the parser. Following tree grammar describes the for-loop:
enterForLoop
@init { int mark = 0; }
: ^('for' assignStat c=condExpr incStat[true]
block) {
input.Seek($c.start.TokenStartIndex);
object condResult =
condExpr();
/*ForLoopSymbol symbol = new
ForLoopSymbol("forLoop", _CurrentScope);
_CurrentScope.DefineSymbol(symbol);
_CurrentScope = symbol;
incStat(true); // Doesn't
work this way
input.Release(mark);*/
}
;
exitForLoop
: /*'for' {
_CurrentScope =
_CurrentScope.EnclosingScope;
}*/
;
condExpr returns [bool value]
: ^('<' ID INT) {
Symbol symbol =
globalTable.ResolveSymbol($ID.text);
if(symbol != null) {
if(symbol is
VariableSymbol) {
if(((VariableSymbol)symbol).SymType.Equals("int")) {
$value=(int)((VariableSymbol)symbol).Value < int.Parse($INT.text);
} else if(((VariableSymbol)symbol).SymType.Equals("float")) {
$value=(float)((VariableSymbol)symbol).Value < int.Parse($INT.text);
}
}
} else {
Console.WriteLine("Undefined variable: " + $ID.text + " (" + $ID.line + ":"
+ $ID.pos + ")");
}
}
| ^('>' ID INT) {
Symbol symbol =
globalTable.ResolveSymbol($ID.text);
if(symbol != null) {
if(symbol is
VariableSymbol) {
if(((VariableSymbol)symbol).SymType.Equals("int")) {
$value=(int)((VariableSymbol)symbol).Value > int.Parse($INT.text);
} else if(((VariableSymbol)symbol).SymType.Equals("float")) {
$value=(float)((VariableSymbol)symbol).Value > int.Parse($INT.text);
}
}
} else {
Console.WriteLine("Undefined variable: " + $ID.text + " (" + $ID.line + ":"
+ $ID.pos + ")");
}
}
;
I tried to jump to the conditional expression of the for loop. But I don't
get there in
the tree node stream.
Can anybody help me to get it right? I tried a few times with different
options but
I don't get anywhere. I'm just beginning to learn ANTLR.
Greetings
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org/mailman/options/antlr-interest/your-email-address
--
You received this message because you are subscribed to the Google Groups
"il-antlr-interest" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/il-antlr-interest?hl=en.