Exemplo n.º 1
0
        public Node FunDef()
        {
            var node = new FunDefNode()
            {
                AnchorToken = Expect(TokenCategory.IDENTIFIER)
            };

            Expect(TokenCategory.PARENTHESIS_OPEN);
            node.Add(IdList());
            Expect(TokenCategory.PARENTHESIS_CLOSE);
            Expect(TokenCategory.LLAVE_OPEN);
            node.Add(VarDefList());
            node.Add(StmtList());
            Expect(TokenCategory.LLAVE_CLOSE);
            return(node);
        }
Exemplo n.º 2
0
        public void Visit(FunDefNode node)
        {
            var functionName = node.AnchorToken.Lexeme;

            if (isFirstEncounter)
            {
                if (globalScopeFunctionTable.Contains(functionName))
                {
                    throw new SemanticError("Duplicated function definition: " + functionName, node.AnchorToken);
                }
                else
                {
                    if (node[0] is IdListNode)
                    {
                        var ndecount = 0;
                        foreach (var subnode in node[0])
                        {
                            ndecount++;
                        }
                        globalScopeFunctionTable[functionName] = ndecount;
                    }
                    else
                    {
                        globalScopeFunctionTable[functionName] = 0;
                    }
                }
            }
            else
            {
                localScopeSymbolTable = new SymbolTable();
                functionDepth         = true;
                foreach (var subnode in node)
                {
                    Visit((dynamic)subnode);
                }
                localSymbolTables[functionName] = localScopeSymbolTable;
                functionDepth         = false;
                localScopeSymbolTable = new SymbolTable();
            }
        }