本文整理汇总了C#中SymbolTable.Lookup方法的典型用法代码示例。如果您正苦于以下问题:C# SymbolTable.Lookup方法的具体用法?C# SymbolTable.Lookup怎么用?C# SymbolTable.Lookup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SymbolTable
的用法示例。
在下文中一共展示了SymbolTable.Lookup方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Insert_Lookup_WriteTable_SymbolTableTest
public void Insert_Lookup_WriteTable_SymbolTableTest()
{
var count = 0;
var symTable = new SymbolTable();
symTable.Printer = (val) => { count++; };
symTable.Insert(Token.CreateToken("x", 0), 0);
symTable.Insert(Token.CreateToken("y", 0), 0);
symTable.Insert(Token.CreateToken("z", 0), 0);
symTable.Lookup("x").Content = CreateVariableContent();
symTable.Lookup("y").Content = CreateVariableContent();
symTable.Lookup("z").Content = CreateVariableContent();
symTable.Insert(Token.CreateToken("a", 0), 1);
symTable.Insert(Token.CreateToken("x", 0), 1);
symTable.Insert(Token.CreateToken("y", 0), 1);
symTable.Insert(Token.CreateToken("z", 0), 1);
symTable.Lookup("a").Content = CreateVariableContent();
symTable.Lookup("x").Content = CreateVariableContent();
symTable.Lookup("y").Content = CreateVariableContent();
symTable.Lookup("z").Content = CreateVariableContent();
symTable.WriteTable(0);
Assert.AreEqual(3, count);
count = 0;
symTable.WriteTable(1);
Assert.AreEqual(4, count);
count = 0;
symTable.WriteTable(2);
Assert.AreEqual(0, count);
}
示例2: Evaluate
public override int Evaluate(SymbolTable symbols)
{
throw new BerylError(this.Position, "Constant expressions not yet implemented");
#if false
Symbol symbol = symbols.Lookup(_name);
if (symbol.Declaration.Kind != SymbolKind.Constant)
throw new CheckerError(this.Position, "Function or variable '" + _name + "' referenced in constant initializer");
return symbol.Value;
#endif
}
示例3: CRUD_SymbolTableTest
public void CRUD_SymbolTableTest()
{
var count = 0;
var symTable = new SymbolTable();
symTable.Printer = (val) => { count++; };
symTable.Insert(Token.CreateToken("a", 0), 0);
symTable.Insert(Token.CreateToken("b", 0), 0);
symTable.Lookup("a").Content = CreateVariableContent();
symTable.Lookup("b").Content = CreateVariableContent();
symTable.Insert(Token.CreateToken("x", 0), 1);
symTable.Insert(Token.CreateToken("y", 0), 1);
symTable.Insert(Token.CreateToken("z", 0), 1);
symTable.Lookup("x").Content = CreateVariableContent();
symTable.Lookup("y").Content = CreateVariableContent();
symTable.Lookup("z").Content = CreateVariableContent();
symTable.Insert(Token.CreateToken("j", 0), 2);
symTable.Lookup("j").Content = CreateVariableContent();
// Delete depth 9, this should do nothing
symTable.DeleteDepth(9);
symTable.WriteTable(0);
symTable.WriteTable(1);
symTable.WriteTable(2);
Assert.AreEqual(6, count);
// Delete depth 1, 3 items should be deleted
symTable.DeleteDepth(1);
count = 0;
symTable.WriteTable(0);
symTable.WriteTable(1);
symTable.WriteTable(2);
Assert.AreEqual(3, count);
// Delete depth 0, 2 items should be deleted
symTable.DeleteDepth(0);
count = 0;
symTable.WriteTable(0);
symTable.WriteTable(1);
symTable.WriteTable(2);
Assert.AreEqual(1, count);
// Try deleting depth 0 again. This should have no effect
symTable.DeleteDepth(0);
count = 0;
symTable.WriteTable(0);
symTable.WriteTable(1);
symTable.WriteTable(2);
Assert.AreEqual(1, count);
}
示例4: Compile
static IASTNode Compile(SymbolTable symTable, object exp)
{
if (exp is string) {
string name = (string)exp;
if (symTable != null && symTable.Lookup(name) != -1) {
return new ASTNode_GetLocalVar(){Index=symTable.Lookup(name)};
}
int envIndex = 0;
for (; symTable != null && symTable.Lookup(name) == -1; symTable = symTable.PrevTalbe, ++envIndex);
if (symTable == null) {
return new ASTNode_GetGlobalVar(){Index=GlobalSymbolTable.Instance().LookupOrDefine(name)};
} else {
return new ASTNode_GetFreeVar(){EnvIndex=envIndex, Index=symTable.Lookup(name)};
}
} else if (!(exp is List<object>)) {
return new ASTNode_Literal(){Value=exp};
}
List<object> l = (List<object>)exp;
switch (l[0] as string) {
case "quote":
return new ASTNode_Literal() { Value = ListExpToPairExp(l[1]) };
case "if":
return new ASTNode_If() { PredNode = Compile(symTable, l[1]), ThenNode = Compile(symTable, l[2]), ElseNode = Compile(symTable, l[3]) };
case "lambda": {
SymbolTable newSymTable = new SymbolTable(symTable);
foreach (string name in ((List<object>)l[1])) {
newSymTable.Define(name);
}
List<string> defines = new List<string>();
FindDefinition(defines, (List<object>)l[2], 1);
foreach (string name in defines) {
newSymTable.Define(name);
}
return new ASTNode_Lambda() { LocalVarCount = newSymTable.GetSymbolCount(), BodyNode = Compile(newSymTable, l[2]) };
}
case "begin":
return new ASTNode_Begin() { Nodes = l.Skip(1).Select(e => Compile(symTable, e)).ToArray() };
case "define":
return Compile(symTable, new List<object>() { "set!", l[1], l[2] });
case "set!": {
IASTNode right = Compile(symTable, l[2]);
string name = (string)l[1];
if (symTable != null && symTable.Lookup(name) != -1) {
return new ASTNode_SetLocalVar() { Index = symTable.Lookup(name), RightNode = right };
}
int envIndex = 0;
for (; symTable != null && symTable.Lookup(name) == -1; symTable = symTable.PrevTalbe, ++envIndex) ;
if (symTable == null) {
return new ASTNode_SetGlobalVar() { Index = GlobalSymbolTable.Instance().LookupOrDefine(name), RightNode = right };
} else {
return new ASTNode_SetFreeVar() { EnvIndex = envIndex, Index = symTable.Lookup(name), RightNode = right };
}
}
default: {
return new ASTNode_Application() { ProcedureNode = Compile(symTable, l[0]), ActualNodes = l.Skip(1).Select(e => Compile(symTable, e)).ToArray() };
}
}
}