本文整理汇总了C#中SymbolTable.CreateNewType方法的典型用法代码示例。如果您正苦于以下问题:C# SymbolTable.CreateNewType方法的具体用法?C# SymbolTable.CreateNewType怎么用?C# SymbolTable.CreateNewType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SymbolTable
的用法示例。
在下文中一共展示了SymbolTable.CreateNewType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PreGenerate
//.........这里部分代码省略.........
Console.ReadKey();
return null;
}
var rootNode = Program.getRoot(System.IO.File.ReadAllText(filename), new TSharpCompiler.TuringGrammarBroken());
if (rootNode == null)
{
Console.WriteLine("Parsing failed");
Console.ReadKey();
return null;
}
return PreGenerate(rootNode, symbolTable);
}
else if (stmt.Term.Name == "functionDefinition")
{
string functionName = stmt.ChildNodes[0].ChildNodes[1].Token.ValueString;
if (symbolTable.functionTable.ContainsKey(functionName))
{
throw new Exception(functionName + " has already been defined");
}
var parameterList = new List<FunctionDefinition.Argument>();
if (stmt.ChildNodes[0].ChildNodes[2].ChildNodes.Count > 0)
{
var currParam = stmt.ChildNodes[0].ChildNodes[2].ChildNodes[0];
while (true)
{
var parameterType = TypeOfExpr(currParam.ChildNodes[0].ChildNodes[1].ChildNodes[0], symbolTable);
var paramIdentifier = currParam.ChildNodes[0].ChildNodes[0];
while (true)
{
var parameterName = paramIdentifier.ChildNodes[0].Token.ValueString;
parameterList.Add(new FunctionDefinition.Argument() { argName = parameterName, argType = parameterType });
if (paramIdentifier.ChildNodes.Count == 1)
break;
paramIdentifier = paramIdentifier.ChildNodes[1];
}
if (currParam.ChildNodes.Count == 1)
break;
currParam = currParam.ChildNodes[1];
}
}
Type type = null;
if (stmt.ChildNodes[0].ChildNodes.Count > 3)//if there's a 4th childnode then it's the type specifier
type = TypeOfExpr(stmt.ChildNodes[0].ChildNodes[3].ChildNodes[0], symbolTable);
symbolTable.AddFunctionHeader(functionName, MethodAttributes.Static, type, parameterList.ToArray());
//MethodBuilder methodDeclaration;
//if (stmt.ChildNodes[0].ChildNodes.Count > 3)//if there's a 4th childnode then it's the type specifier
// methodDeclaration = mainProgram.DefineMethod(functionName, MethodAttributes.Static, TypeOfExpr(stmt.ChildNodes[0].ChildNodes[3].ChildNodes[0], symbolTable), parameterList.Select(x => x.argType).ToArray());
//else
// methodDeclaration = mainProgram.DefineMethod(functionName, MethodAttributes.Static, null, parameterList.Select(x => x.argType).ToArray());
//var methodDec = new FunctionDefinition
//(
// methodDeclaration,
// parameterList
//);
//symbolTable.functionTable.AddHeader(functionName, methodDec);
}
else if (stmt.Term.Name == "type")
{
if (stmt.ChildNodes[1].ChildNodes[0].ChildNodes[0].Term.Name == "recordList")
{
symbolTable.CreateNewType(stmt.ChildNodes[1].ChildNodes[0].ChildNodes[0], stmt.ChildNodes[0].Token.ValueString);
//var parameterList = new List<FunctionDefinition.Argument>();
//var newType = mainProgram.DefineNestedType(stmt.ChildNodes[0].Token.ValueString);
//var currParam = stmt.ChildNodes[0].ChildNodes[2].ChildNodes[0];
//while (true)
//{
// var parameterType = TypeOfExpr(currParam.ChildNodes[0].ChildNodes[1].ChildNodes[0], symbolTable);
// var paramIdentifier = currParam.ChildNodes[0].ChildNodes[0];
// while (true)
// {
// var parameterName = paramIdentifier.ChildNodes[0].Token.ValueString;
// parameterList.Add(new FunctionDefinition.Argument() { argName = parameterName, argType = parameterType });
// if (paramIdentifier.ChildNodes.Count == 1)
// break;
// paramIdentifier = paramIdentifier.ChildNodes[1];
// }
// if (currParam.ChildNodes.Count == 1)
// break;
// currParam = currParam.ChildNodes[1];
//}
/*ParseTreeNode field = stmt.ChildNodes[1].ChildNodes[0].ChildNodes[0];
while (true)
{
if (field.ChildNodes.Count > 1)
{
field = field.ChildNodes[1];
}
else
break;
}*/
}
}
return stmt;
}