Beispiel #1
0
        public Node ParameterDeclaration()
        {
            var paramList = new ParameterDeclarationList();

            while (CurrentToken == TokenCategory.IDENTIFIER)
            {
                var  tempList = new VariableDeclarationList();
                Node idToken  = new Identifier()
                {
                    AnchorToken = Expect(TokenCategory.IDENTIFIER)
                };

                tempList.Add(idToken);

                while (CurrentToken == TokenCategory.COMMA)
                {
                    Expect(TokenCategory.COMMA);
                    tempList.Add(new Identifier()
                    {
                        AnchorToken = Expect(TokenCategory.IDENTIFIER)
                    });
                }
                Expect(TokenCategory.DECLARATION);
                var tipo = Type();
                //declarationList.Add(Type());
                foreach (var node in tempList)
                {
                    tipo.Add(node);
                }
                paramList.Add(tipo);
                Expect(TokenCategory.ENDLINE);
            }

            return(paramList);
        }
        //-----------------------------------------------------------
        private Type Visit(ParameterDeclarationList node, Table table)
        {
            int i = 0;

            foreach (var n in node)
            {
                Visit((dynamic)n, table, ref i);
            }
            return(Type.VOID);
        }
        public TypeG Visit(ParameterDeclarationList node)
        {
            CurrentContext.paramDetect = true;
            Console.WriteLine("PD");
            TypeG tipo = Visit((dynamic)node[0]);

            foreach (var i in node)
            {
                var     variableName  = i[0].AnchorToken.Lexeme;
                dynamic variableValue = false;

                Console.WriteLine("ROOT");
                if (CurrentContext.context == "GLOBAL")
                {
                    if (GloabalDeclaratonT.Contains(variableName))
                    {
                        throw new SemanticError(
                                  "Duplicated variable (" + CurrentContext.context + "): " + variableName,
                                  node[0].AnchorToken);
                    }
                    else
                    {
                        GloabalDeclaratonT[variableName] =
                            new GlobalDeclarationType(variableName, tipo, variableValue, TypeG.PARAM);
                    }
                }
                else if (CurrentContext.context == "LOCAL")
                {
                    if (ListLocalDeclarationTable[CurrentContext.index].Contains(variableName))
                    {
                        throw new SemanticError(
                                  "Duplicated variable: " + variableName,
                                  node[0].AnchorToken);
                    }
                    else
                    {
                        Console.WriteLine("GUARDANDO!!!");
                        ListLocalDeclarationTable[CurrentContext.index][variableName] = new LocalDeclarationType(variableName, tipo, variableValue, -1, TypeG.PARAM);
                        Console.WriteLine("TABLA" + ListLocalDeclarationTable[CurrentContext.index]);
                    }
                }
            }

            //VisitChildren(node);
            return(TypeG.VOID);

            //return TypeG.VOID;
        }
Beispiel #4
0
 public Type Visit(ParameterDeclarationList node)
 {
     VisitChildren(node);
     return(Type.VOID);
 }
Beispiel #5
0
        public Node ProcedureDeclaration()
        {
            var result = new ProcedureDeclaration()
            {
                AnchorToken = Expect(TokenCategory.PROCEDURE)
            };

            result.Add(new Identifier()
            {
                AnchorToken = Expect(TokenCategory.IDENTIFIER)
            });

            Expect(TokenCategory.PARENTHESIS_OPEN);

            var parameterList = new ParameterDeclarationList();

            if (CurrentToken == TokenCategory.IDENTIFIER)
            {
                while (CurrentToken == TokenCategory.IDENTIFIER)
                {
                    parameterList.Add(VariableDeclaration());
                }
            }
            result.Add(parameterList);

            Expect(TokenCategory.PARENTHESIS_CLOSE);

            var type = new TypeNode();

            if (CurrentToken == TokenCategory.COLON)
            {
                Expect(TokenCategory.COLON);

                if (CurrentToken != TokenCategory.LIST)
                {
                    type.Add(SimpleType());
                }

                else if (CurrentToken == TokenCategory.LIST)
                {
                    type.Add(ListType());
                }
            }
            result.Add(type);

            Expect(TokenCategory.SEMICOLON);

            var constantList = new ConstantDeclarationList();

            if (firstOfDeclaration.Contains(CurrentToken) && CurrentToken == TokenCategory.CONST)
            {
                constantList.AnchorToken = Expect(TokenCategory.CONST);

                do
                {
                    constantList.Add(ConstantDeclaration());
                } while (CurrentToken == TokenCategory.IDENTIFIER);
            }
            result.Add(constantList);

            var variableList = new VariableDeclarationList();

            if (firstOfDeclaration.Contains(CurrentToken) && CurrentToken == TokenCategory.VAR)
            {
                variableList.AnchorToken = Expect(TokenCategory.VAR);

                do
                {
                    variableList.Add(VariableDeclaration());
                } while (CurrentToken == TokenCategory.IDENTIFIER);
            }
            result.Add(variableList);

            Expect(TokenCategory.BEGIN);

            var statementList = new StatementList();

            if (firstOfStatement.Contains(CurrentToken))
            {
                while (firstOfStatement.Contains(CurrentToken))
                {
                    statementList.Add(Statement());
                }
            }
            result.Add(statementList);


            Expect(TokenCategory.END);
            Expect(TokenCategory.SEMICOLON);
            return(result);
        }
Beispiel #6
0
        public Node ProcedureDeclaration()
        {
            var result = new ProcedureDeclaration();

            Expect(TokenCategory.PROCEDURE);
            result.AnchorToken = Expect(TokenCategory.IDENTIFIER);
            Expect(TokenCategory.LEFT_PAR);

            var parameterDeclarationList = new ParameterDeclarationList();

            while (CurrentToken == TokenCategory.IDENTIFIER)
            {
                parameterDeclarationList.Add(ParameterDeclaration());
            }
            result.Add(parameterDeclarationList);

            Expect(TokenCategory.RIGHT_PAR);

            if (CurrentToken == TokenCategory.COLON)
            {
                Expect(TokenCategory.COLON);
                result.Add(Type());
            }

            Expect(TokenCategory.SEMICOLON);

            if (CurrentToken == TokenCategory.CONST)
            {
                var constantDeclarationList = new ConstantDeclarationList()
                {
                    AnchorToken = Expect(TokenCategory.CONST)
                };
                do
                {
                    constantDeclarationList.Add(ConstantDeclaration());
                } while (CurrentToken == TokenCategory.IDENTIFIER);

                result.Add(constantDeclarationList);
            }

            if (CurrentToken == TokenCategory.VAR)
            {
                var variableDeclarationList = new VariableDeclarationList()
                {
                    AnchorToken = Expect(TokenCategory.VAR)
                };
                do
                {
                    variableDeclarationList.Add(VariableDeclaration());
                } while (CurrentToken == TokenCategory.IDENTIFIER);

                result.Add(variableDeclarationList);
            }

            Expect(TokenCategory.BEGIN);

            var statementList = new StatementList();

            while (firstOfStatement.Contains(CurrentToken))
            {
                statementList.Add(Statement());
            }
            result.Add(statementList);

            Expect(TokenCategory.END);
            Expect(TokenCategory.SEMICOLON);

            return(result);
        }