public void EnterSymbol(string symbolName, ASTnode astnode) { if (!IsDeclaredLocally(symbolName)) { CurrentScope.Symbols.Add(symbolName, astnode); } else { throw new SemanticException($"Error on line {astnode.line}: Symbol {symbolName} already declared locally."); } }
public ASTnode RetrieveSymbol(string symbolName, ASTnode problemNode = null) { ASTnode returnValue; Scope viewingScope = CurrentScope; do { if (viewingScope.Symbols.TryGetValue(symbolName, out returnValue)) { return(returnValue); } viewingScope = viewingScope.Parent; }while (viewingScope != null); if (problemNode != null) { throw new SemanticException($"Error on line {problemNode.line}: Symbol {symbolName} not found. Potentially missing declaration or not visible in scope."); } else { throw new SemanticException($"Symbol {symbolName} not found. Potentially missing declaration or not visible in scope."); } }
public void Visit(ASTnode ast) { ast.Accept(this); }