object IVisitor <object> .visit(IdNode node) { string type = SymbolTable.lookupType(node.value); string value = SymbolTable.lookup(node.value); if (value != null) { node.type = type; return(node.type); } else { new SemanticError(node, "Semantic Error: " + node.value + " does not exist in this context."); } return(null); }
public void checkOperationIsAllowed(Node operation, Node left, Node right) { if (SymbolTable.lookup(left.value) == null || SymbolTable.lookup(right.value) == null) { return; // return as one of the children does not exist } bool allowed = false; foreach (var rule in allowedOperations) { if (operation.value.Equals(rule[0]) & left.type.Equals(rule[1]) & right.type.Equals(rule[2])) { allowed = true; } } if (!allowed) { new SemanticError(operation, "Semantic Error: Operation not allowed: " + left.type + " " + operation.value + " " + right.type); } }
object IVisitor <object> .visit(IdNode node) { return(SymbolTable.lookup(node.value)); }