当前位置: 首页>>代码示例>>C#>>正文


C# SymbolTable.define方法代码示例

本文整理汇总了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"));
 }
开发者ID:Lateks,项目名称:Mini-PL-Interpreter,代码行数:7,代码来源:SemanticAnalysisTest.cs

示例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);
        }
开发者ID:Lateks,项目名称:Mini-PL-Interpreter,代码行数:13,代码来源:InterpretingNodeVisitorTest.cs

示例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));
        }
开发者ID:Lateks,项目名称:Mini-PL-Interpreter,代码行数:18,代码来源:InterpretingNodeVisitorTest.cs

示例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));
        }
开发者ID:Lateks,项目名称:Mini-PL-Interpreter,代码行数:23,代码来源:InterpretingNodeVisitorTest.cs


注:本文中的SymbolTable.define方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。