本文整理汇总了C#中ParseTreeNode.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# ParseTreeNode.GetType方法的具体用法?C# ParseTreeNode.GetType怎么用?C# ParseTreeNode.GetType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ParseTreeNode
的用法示例。
在下文中一共展示了ParseTreeNode.GetType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenExpr
//.........这里部分代码省略.........
{
deliveredType = typeof(string);
il.Emit(OpCodes.Ldstr, expr.Token.ValueString);
}
else if (expr.Term.Name == "number")
{
if (expr.Token.Value is int)
{
deliveredType = typeof(int);
il.Emit(OpCodes.Ldc_I4, (int)expr.Token.Value);
}
else
{
deliveredType = typeof(float);
il.Emit(OpCodes.Ldc_R4, float.Parse(expr.Token.ValueString));
}
}
else if (expr.Term.Name == "binExpr")
{
deliveredType = TypeOfExpr(expr.ChildNodes[0], symbolTable);
GenExpr(expr.ChildNodes[0], deliveredType, il, symbolTable);
GenExpr(expr.ChildNodes[2], deliveredType, il, symbolTable);
switch (expr.ChildNodes[1].Term.Name)
{
case "+":
il.Emit(OpCodes.Add);
break;
case "*":
il.Emit(OpCodes.Mul);
break;
case "-":
il.Emit(OpCodes.Sub);
break;
case "/":
il.Emit(OpCodes.Div);
break;
case "mod":
il.Emit(OpCodes.Rem);
break;
default:
throw new Exception("Unrecognized operator " + expr.ChildNodes[1].Term.Name);
}
}
else if (expr.Term.Name == "identifier")
{
string ident = expr.Token.ValueString;
symbolTable.PushVar(ident, ref il);
deliveredType = this.TypeOfExpr(expr, symbolTable);
}
else if (expr.Term.Name == "functionCall")
{
deliveredType = TypeOfExpr(expr, symbolTable);
string funcName = expr.ChildNodes[0].Token.ValueString;
if (!this.functionTable.ContainsKey(funcName))
{
throw new System.Exception("undeclared function or procedure '" + funcName+ "'");
}
var parameters = this.functionTable[funcName].arguments;
int currentArgument = 0;
if (expr.ChildNodes[1].ChildNodes.Count > 0)
{//push all the arguments onto the stack
ParseTreeNode argItem = expr.ChildNodes[1];
while (true)
{
this.GenExpr(argItem.ChildNodes[0], parameters[currentArgument].argType, il, symbolTable);
if (argItem.ChildNodes.Count == 1)
break;
argItem = argItem.ChildNodes[1];
currentArgument++;
}
}
il.Emit(OpCodes.Call, this.functionTable[funcName].methodDefinition);
}
else
{
throw new System.Exception("don't know how to generate " + expr.GetType().Name);
}
if (deliveredType != expectedType)
{
if (deliveredType == typeof(int) &&
expectedType == typeof(string))
{
il.Emit(OpCodes.Box, typeof(int));
il.Emit(OpCodes.Callvirt, typeof(object).GetMethod("ToString"));
}
else if (deliveredType==typeof(float)&&expectedType==typeof(string))
{
il.Emit(OpCodes.Box, typeof(float));
il.Emit(OpCodes.Callvirt, typeof(object).GetMethod("ToString"));
}
else
{
throw new System.Exception("can't coerce a " + deliveredType.Name + " to a " + expectedType.Name);
}
}
}