Пример: int =
Я понимаю, что говорится: «Переменная (ident) этого типа данных (int ) принимает (=) целое число (expr),, но я не понимаю, как его преобразовать в это:
Из класса Аст
Код: Выделить всё
public class Int : Stmt
{
public string Ident;
public Expr Expr;
}
Код: Выделить всё
#region INTEGER VARIABLE
else if (this.tokens[this.index].Equals("int"))
{
this.index++;
Int Integer = new Int();
if (this.index < this.tokens.Count &&
this.tokens[this.index] is string)
{
Integer.Ident = (string)this.tokens[this.index];
}
else
{
throw new System.Exception("expected variable name after 'int'");
}
this.index++;
if (this.index == this.tokens.Count ||
this.tokens[this.index] != Scanner.EqualSign)
{
throw new System.Exception("expected = after 'int ident'");
}
this.index++;
Integer.Expr = this.ParseExpr();
result = Integer;
}
#endregion
Код: Выделить всё
#region INTEGER
else if (stmt is Int)
{
// declare a local
Int integer = (Int)stmt;
this.symbolTable[integer.Ident] = this.il.DeclareLocal(this.TypeOfExpr(integer.Expr));
// set the initial value
Assign assign = new Assign();
assign.Ident = integer.Ident;
assign.Expr = integer.Expr;
this.GenStmt(assign);
}
#endregion
Подробнее здесь: https://stackoverflow.com/questions/129 ... r-compiler
Мобильная версия