public override void Visit(AST_leaf node) { switch (node.Tag) { case NodeType.Empty: // no type break; case NodeType.Break: // no type break; case NodeType.IntConst: node.Type = CbType.Int; break; case NodeType.StringConst: node.Type = CbType.String; break; case NodeType.Ident: CbType typ; string str = node.Sval; // check for null value if (str == "null") { typ = CbType.Null; } else { // check symbol table for identifer SymTabEntry result = localSymbols.Lookup(str); if (result != null) { typ = result.Type; } // if identifier not in symbol table, check in Consts, then if not found report error else if (!(Consts.TryGetValue(str, out typ))) { ReportError(node.LineNumber, "Use of undeclared identifier: '{0}'", str); // add undeclared variable to the symbol table to prevent additional errors localSymbols.Binding(str, node.LineNumber); typ = CbType.Error; } } node.Type = typ; break; default: throw new Exception("{0} is not a tag compatible with an AST_leaf node"); } }
public override void Visit(AST_leaf node) { printTag(node); switch(node.Tag) { case NodeType.Ident: case NodeType.StringConst: f.WriteLine(" \"{0}\"", node.Sval); break; case NodeType.IntConst: f.WriteLine(" {0}", node.Ival); break; default: f.WriteLine(); break; } }
public override void Visit(AST_leaf node) { printTag(node); switch (node.Tag) { case NodeType.Ident: case NodeType.StringConst: f.WriteLine(" \"{0}\"", node.Sval); break; case NodeType.IntConst: f.WriteLine(" {0}", node.Ival); break; default: f.WriteLine(); break; } }
public override void Visit(AST_leaf node) { switch(node.Tag) { case NodeType.Empty: // no type break; case NodeType.Break: // no type break; case NodeType.IntConst: node.Type = CbType.Int; break; case NodeType.StringConst: node.Type = CbType.String; break; case NodeType.Ident: CbType typ; string str = node.Sval; // check for null value if (str == "null") typ = CbType.Null; else { // check symbol table for identifer SymTabEntry result = localSymbols.Lookup(str); if (result != null) typ = result.Type; // if identifier not in symbol table, check in Consts, then if not found report error else if (!(Consts.TryGetValue(str, out typ))) { ReportError(node.LineNumber, "Use of undeclared identifier: '{0}'", str); // add undeclared variable to the symbol table to prevent additional errors localSymbols.Binding(str, node.LineNumber); typ = CbType.Error; } } node.Type = typ; break; default: throw new Exception("{0} is not a tag compatible with an AST_leaf node"); } }
public virtual void Visit(AST_leaf n) { Console.WriteLine("Internal compiler error! This method should have been overridden"); }