本文整理汇总了C#中SymbolTable.define方法的典型用法代码示例。如果您正苦于以下问题:C# SymbolTable.define方法的具体用法?C# SymbolTable.define怎么用?C# SymbolTable.define使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SymbolTable
的用法示例。
在下文中一共展示了SymbolTable.define方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestDefine
public void TestDefine()
{
var table = new SymbolTable();
var variable = new Symbol("foo", "bar");
table.define(variable);
Assert.That(table.resolve("foo").Type, Is.EqualTo("bar"));
}
示例2: SetUp
public void SetUp()
{
symboltable = new SymbolTable();
symboltable.define(new Symbol("op1", "int"));
symboltable.define(new Symbol("op2", "int"));
symboltable.define(new Symbol("result", "int"));
program = new List<Statement>();
program.Add(op1assignment);
program.Add(op2assignment);
interpreter = new InterpretingNodeVisitor(symboltable);
}
示例3: AssignVariableToVariable
public void AssignVariableToVariable()
{
var x = new VariableDeclaration("x", "int", 0);
var assignment = new Assignment(x, new IntegerLiteral("1", 0), 0);
var y = new VariableDeclaration("y", "int", 0);
var assignvariable = new Assignment(y, new VariableReference("x", 0), 0);
var statements = new List<Statement>();
statements.Add(assignment);
statements.Add(assignvariable);
var program = new Program(statements);
var symboltable = new SymbolTable();
symboltable.define(new Symbol("x", "int"));
symboltable.define(new Symbol("y", "int"));
var interpreter = new InterpretingNodeVisitor(symboltable);
interpreter.Run(program);
Assert.That(interpreter.Valuetable[symboltable.resolve("y")], Is.EqualTo(1));
}
示例4: LoopTest
public void LoopTest()
{
var loopvardecl = new VariableDeclaration("loopvariable", "int", 0);
var loopvarref = new VariableReference("loopvariable", 0);
var range = new Range(new IntegerLiteral("2", 0), new IntegerLiteral("5", 0), 0);
var loopbody = new List<Statement>();
var resultdecl = new VariableDeclaration("result", "int", 0);
var resultref = new VariableReference("result", 0);
loopbody.Add(new Assignment(resultref,
new ArithmeticOp("+", resultref, loopvarref, 0), 0));
var program = new List<Statement>();
program.Add(resultdecl);
program.Add(loopvardecl);
program.Add(new Loop(loopvarref, range, loopbody, 0));
var symboltable = new SymbolTable();
symboltable.define(new Symbol("loopvariable", "int"));
symboltable.define(new Symbol("result", "int"));
var interpreter = new InterpretingNodeVisitor(symboltable);
interpreter.Run(new Program(program));
Assert.That(interpreter.Valuetable[symboltable.resolve("result")], Is.EqualTo(14));
}