//check if variable (int x) is declared in symbol table and add if not public void VisitNode(LocalVariableDeclarationStatement node) { AbstractNode typeName = node.Child; AbstractNode idName = typeName.Sib.Child; TypeVisitor typeVisitor = new TypeVisitor(); typeName.Accept(typeVisitor); while (idName != null) { string name = ((Identifier)idName).Name; try { VariableAttributes attr = new VariableAttributes(null, typeName.TypeRef); idName.TypeRef = typeName.TypeRef; table.enter(name, attr); idName.AttributesRef = attr; } catch (FoundKeyException e) { Console.WriteLine(e.Message); node.TypeRef = new ErrorTypeDescriptor(); node.AttributesRef = null; } idName = idName.Sib; } }
public void VisitNode(LocalVariableDeclarationStatement node) { string type = node.Child.TypeRef.type; Identifier dcls = (Identifier)node.Child.Sib.Child; using (FileStream fs = File.Open(GlobalVar.PATH, FileMode.Append)) { using (StreamWriter sw = new StreamWriter(fs)) { sw.Write(".locals init ("); while (dcls != null) { dcls.AttributesRef.Location = stlocCount++; sw.Write(type); dcls = (Identifier)dcls.Sib; if (dcls != null) { sw.Write(", "); } } sw.WriteLine(")"); } } }