Exemplo n.º 1
0
        internal override bool NameAnalysis(SymbolTable table)
        {
            if (SecondPassAnalysis)
            {
                table.AddScope();
                CurrentFunction = this;
                parameterList.NameAnalysis(table); // only add new symbol, no possible error
                bool pass = statementList.NameAnalysis(table);
                CurrentFunction = null;
                table.RemoveScope();
                return(pass);
            }

            // first pass for function definition
            if (table.GlobalSearch(functionName) is not null)
            {
                Error($"{functionName} is declared in the same scope");
                return(false);
            }
            List <Type> parameterType = new List <Type>();

            table.AddSymbol(functionName, new Symbol(returnType, functionName, true, parameterType, this));
            foreach (var type in parameterList.Types()) // must take care of parameter type before type checking
            {
                parameterType.Add(type);
            }
            return(true);
        }
Exemplo n.º 2
0
        internal override bool NameAnalysis(SymbolTable table)
        {
            table.AddScope();
            bool pass = statementList.NameAnalysis(table);

            table.RemoveScope();
            return(pass);
        }