Exemple #1
0
 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.");
     }
 }
Exemple #2
0
        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.");
            }
        }
Exemple #3
0
 public void Visit(ASTnode ast)
 {
     ast.Accept(this);
 }