本文整理汇总了C#中SymbolTable.HasVar方法的典型用法代码示例。如果您正苦于以下问题:C# SymbolTable.HasVar方法的具体用法?C# SymbolTable.HasVar怎么用?C# SymbolTable.HasVar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SymbolTable
的用法示例。
在下文中一共展示了SymbolTable.HasVar方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TypeOfExpr
public static Type TypeOfExpr(ParseTreeNode expr, SymbolTable symbolTable)
{
if (expr.Term.Name == "stringLiteral")
{
return typeof(string);
}
if (expr.Term.Name == "number")
{
if (expr.Token.Value is int)
{
return typeof(int);
}
else
{
return typeof(double);
}
}
else if (expr.Term.Name == "binExpr")
{
//Type type1 = TypeOfExpr(expr.ChildNodes[0], symbolTable);
//Type type2 = TypeOfExpr(expr.ChildNodes[2], symbolTable);
return TypeOfAny(symbolTable, expr.ChildNodes[0], expr.ChildNodes[2]);
//if (type1 == typeof(float) || type2 == typeof(float))
// return typeof(float);
//return typeof(int);
}
else if (expr.Term.Name == "identifier")
{
string ident = expr.Token.ValueString;
return symbolTable.TypeOfVar(ident);
}
else if (expr.Term.Name == "functionCall")
{
string funcName = expr.ChildNodes[0].Token.ValueString;
if (!symbolTable.functionTable.ContainsKey(funcName))
{
//it might be an array, so we should check for that
if (symbolTable.HasVar(funcName) && symbolTable.TypeOfVar(funcName).IsArray)
{
//it is an array, so just return the appropriate type for the array
return symbolTable.TypeOfVar(funcName).GetElementType();
}
else//nope, throw an error
throw new System.Exception("undeclared function or procedure '" + funcName + "'");
}
return symbolTable.functionTable[funcName].methodDefinition.ReturnType;
}
else if (expr.Term.Name == "memberCall")
{
return symbolTable.functionTable[GetIdentifier(expr)].methodDefinition.ReturnType;
}
else if (expr.Term.Name == "varType")
{
switch (expr.ChildNodes[0].Token.ValueString)
{
case "int":
return typeof(int);
case "real":
return typeof(double);
default:
throw new Exception("Did not recognize type: " + expr.ChildNodes[0].Token.ValueString);
}
}
else if (expr.Term.Name == "initExpr")
{
return TypeOfAny(symbolTable, expr.ChildNodes[0].ChildNodes.ToArray()).MakeArrayType();
}
else
{
throw new System.Exception("don't know how to calculate the type of " + expr.Term.Name);
}
}
示例2: GenExpr
//.........这里部分代码省略.........
case "div":
il.Emit(OpCodes.Div);
expectedType = typeof(int);
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, il);
deliveredType = TypeOfExpr(expr, symbolTable);
if (deliveredType == typeof(float))
{
throw new NotImplementedException();
}
}
else if (expr.Term.Name == "functionCall"|expr.Term.Name=="memberCall")
{
deliveredType = TypeOfExpr(expr, symbolTable);
if (deliveredType == typeof(float))
{
throw new NotImplementedException();
}
string funcName = GetIdentifier(expr);
if (!symbolTable.functionTable.ContainsKey(funcName))
{
if (symbolTable.HasVar(funcName) && symbolTable.TypeOfVar(funcName).IsArray)
{
//this is an array, return the appropriate value
symbolTable.PushVar(funcName, il);
if (expr.ChildNodes[1].ChildNodes.Count > 1)
throw new NotImplementedException("Multi-Dimensional arrays are not yet supported");
this.GenExpr(expr.ChildNodes[1].ChildNodes[0], typeof(int), il, symbolTable);
il.Emit(OpCodes.Stelem, symbolTable.TypeOfVar(funcName).GetElementType());
}
else
throw new System.Exception("undeclared function or procedure '" + funcName + "'");
}
else
{
var parameters = symbolTable.functionTable[funcName].arguments;
int currentArgument = 0;
foreach (var arg in GetArgs(expr))//expr.ChildNodes[1].ChildNodes)
{
this.GenExpr(arg, parameters[currentArgument].argType, il, symbolTable);
currentArgument++;
}
il.Emit(OpCodes.Call, symbolTable.functionTable[funcName].methodDefinition);
}
}
else if (expr.Term.Name == "initExpr")
{
deliveredType = TypeOfAny(symbolTable, expr.ChildNodes[0].ChildNodes.ToArray());
int arraySize = expr.ChildNodes[0].ChildNodes.Count;
//LocalBuilder paramValues = il.DeclareLocal(deliveredType.MakeArrayType());
//paramValues.SetLocalSymInfo("parameters");