public void Visit(ReadNode node) { if (node.Children.Count != 1) { throw new InternalCompilerError("Invalid node count for read node"); } if (!(node.Children[0] is IdentifierNode)) { throw new InternalCompilerError("Invalid node type for read node"); } var identifier = (IdentifierNode)node.Children[0]; if (!SymbolTable.ContainsKey(identifier.Name)) { ReportUndeclaredVariable(identifier); return; } identifier.Accept(this); if (identifier.NodeType() == VariableType.BOOLEAN) { reporter.ReportError( Error.SEMANTIC_ERROR, "Variable has invalid type '" + VariableType.BOOLEAN.Name() + "'" + " when '" + VariableType.INTEGER.Name() + "' or '" + VariableType.STRING.Name() + "' were expected", identifier.Line, identifier.Column ); NoteVariableWasDeclaredHere(identifier.Name); } }
public void Visit(ReadNode node) { switch (node.Children[0].NodeType()) { case VariableType.INTEGER: Emit(Bytecode.READ_INT); break; case VariableType.STRING: Emit(Bytecode.READ_STRING); break; default: throw new InternalCompilerError("Invalid type for readnode"); } var name = ((IdentifierNode)node.Children[0]).Name; Emit(symbolTable[name].id); }