Ejemplo n.º 1
0
        Sentence statement_listP(Sentence statement1)
        {
            switch (currentToken.Tipo)
            {
                case TokenType.SEMICOLON:
                case TokenType.CIN:
                case TokenType.COUT:

                case TokenType.STRING:
                case TokenType.BOOL:
                case TokenType.CHAR:
                case TokenType.FLOAT:
                case TokenType.INT:
                case TokenType.VOID:
                case TokenType.STRUCT:
                case TokenType.ID:

                case TokenType.DECREMENT:
                case TokenType.INCREMENT:

                case TokenType.IF:
                case TokenType.DO:
                case TokenType.WHILE:
                case TokenType.FOR:
                case TokenType.RETURN:
                case TokenType.BREAK:
                case TokenType.CONTINUE:
                    Sentence statement2 = statement();

                    StatementSequence statementList = new StatementSequence(statement1, statement2);
                    return statement_listP(statementList);

                default:
                    return statement1;//null
            }
        }
Ejemplo n.º 2
0
 public CompoundStatement(Sentence listaSentencias)
 {
     Sentencias = listaSentencias;
 }
Ejemplo n.º 3
0
 public void DoWhileInit(Expr expr, Sentence cpStmnt)
 {
     expresion = expr;
     compoundStatement = cpStmnt;
 }
Ejemplo n.º 4
0
 public void ForInit(Sentence forInit, Sentence forCtrl, Sentence forIter, Sentence cpStmnt)
 {
     forInitialization = forInit;
     forControl = forCtrl;
     forIteration = forIter;
     CompoundStatement = cpStmnt;
 }
Ejemplo n.º 5
0
 public WhileStatement(Expr expr, Sentence cpStmnt)
 {
     expresion = expr;
     compoundstatement = cpStmnt;
 }
Ejemplo n.º 6
0
        Sentence do_while()
        {
            EnvTypes savedEnvTypes = entornoTipos;
            entornoTipos = new EnvTypes(entornoTipos);

            EnvValues savedEnvValues = entornoValores;
            entornoValores = new EnvValues(entornoValores);

            DoWhileStatement doWhileStmnt = new DoWhileStatement();
            Sentence cicloAnterior = cicloActual;
            cicloActual = doWhileStmnt;

            match("do");
            Sentence stmnt = compound_statement();
            match("while");
            match("(");
            Expr expresion = expr();
            match(")");
            match(";");

            doWhileStmnt.DoWhileInit(expresion, stmnt);
            cicloActual = cicloAnterior;

            entornoTipos = savedEnvTypes;
            entornoValores = savedEnvValues;
            return doWhileStmnt;
        }
Ejemplo n.º 7
0
        Sentence function_declaration(Tipo retorno, string id)
        {
            EnvTypes savedEnvTypes = entornoTipos;
            entornoTipos = new EnvTypes(entornoTipos);

            //EnvValues savedEnvValues = entornoValores;
            //entornoValores = new EnvValues(entornoValores);
            EnvValues savedEnvValues = Parser.pilaValores.Peek();
            Parser.pilaValores.Push(new EnvValues(Parser.pilaValores.Peek()));

            match("(");
            Dictionary<string,Tipo> paramsTypeList = parameter_type_list();
            match(")");

            FunctionDefinition funcDefinition = new FunctionDefinition();
            funcionActual = funcDefinition;

            Sentence compoundStmnt = function_definition();

            funcDefinition.init(id, retorno, compoundStmnt);
            entornoTipos = savedEnvTypes;
            entornoValores = savedEnvValues;

            Parser.pilaValores.Pop();

            Funcion funcion = new Funcion(retorno, paramsTypeList);
            entornoTipos.put(id, funcion);

            ValorFuncion funcionVal = new ValorFuncion(funcDefinition);
            //entornoValores.put(id, funcionVal);
            Parser.pilaValores.Peek().put(id, funcionVal);

            funcionActual = null;

            if (id == "main")
            {
                main = funcDefinition;
            }

            return funcDefinition;
        }
Ejemplo n.º 8
0
 public SentenceSenquence(Sentence s1, Sentence s2)
 {
     sent1 = s1;
     sent2 = s2;
 }
Ejemplo n.º 9
0
 public Statement()
 {
     enclosingCycle = Parser.cicloActual;
     enclosingFunction = Parser.funcionActual;
 }
Ejemplo n.º 10
0
 public void IfElseInit(Expr cond, Sentence bloqueTrue, Sentence bloqueFalse)
 {
     condicion = cond;
     BloqueVerdadero = bloqueTrue;
     BloqueFalso = bloqueFalse;
 }
Ejemplo n.º 11
0
 public void ProgramInit(Sentence sents)
 {
     sentences = sents;
 }
Ejemplo n.º 12
0
 public IfElseStatement(Expr cond, Sentence bloqueTrue, Sentence bloqueFalse)
 {
     condicion = cond;
     BloqueVerdadero = bloqueTrue;
     BloqueFalso = bloqueFalse;
 }
Ejemplo n.º 13
0
 public void init(string nombreFuncion, Tipo ret, Sentence cpStmnt)
 {
     idFuncion = nombreFuncion;
     Tiporetorno = ret;
     compoundStatement = cpStmnt;
     entornoTiposLocal = Parser.entornoTipos;
 }
Ejemplo n.º 14
0
        public FunctionDefinition(string nombreFuncion, Tipo ret, Sentence cpStmnt)
        {
            idFuncion = nombreFuncion;
            Tiporetorno = ret;
            compoundStatement = cpStmnt;
            entornoTiposLocal = Parser.entornoTipos;
            entornoValoresLocal = Parser.entornoValores;

            ValorRetorno = null;
            returned = false;
        }
Ejemplo n.º 15
0
        Sentence variable_declaration_listP(Sentence primerDeclaracionVariable, EnvTypes savedEnvTypes, EnvValues savedEnvValues)
        {
            switch (currentToken.Tipo)
            {
                case TokenType.STRING:
                case TokenType.BOOL:
                case TokenType.CHAR:
                case TokenType.FLOAT:
                case TokenType.INT:
                    Tipo tipoVariables = variable_type();
                    string idVariable = direct_variable_declarator();
                    Tipo tipoVariable = variable_array(tipoVariables);
                    match(";");

                    VariableSubDeclarator segundaVariable = new VariableSubDeclarator(tipoVariable, idVariable);
                    VariableDeclarator segundaDeclaracionVariable = new VariableDeclarator(segundaVariable, null);

                    SentenceSenquence stSeq = new SentenceSenquence(primerDeclaracionVariable, segundaDeclaracionVariable);
                    entornoTipos.put(idVariable, tipoVariable);
                    return variable_declaration_listP(stSeq, savedEnvTypes, savedEnvValues);

                case TokenType.STRUCT:
                    string structName = struct_declarator();

                    Tipo varRecord = savedEnvTypes.get(structName);
                    Valor valRecord = savedEnvValues.get(structName);

                    string structVarName = variable_name();
                    match(";");

                    StructVariableDeclaration strVarDec = new StructVariableDeclaration(structName, structVarName, varRecord, valRecord);

                    SentenceSenquence stSeq2 = new SentenceSenquence(primerDeclaracionVariable, strVarDec);
                    entornoTipos.put(structVarName, varRecord);
                    return variable_declaration_listP(stSeq2, savedEnvTypes, savedEnvValues);

                case TokenType.ENUM:
                    string enumName = enum_declarator();
                    Tipo varEnum = savedEnvTypes.get(enumName);
                    Valor valEnum = savedEnvValues.get(enumName);

                    string enumVarName = currentToken.Lexema;
                    match(TokenType.ID);

                    entornoTipos.put(enumName, varEnum);
                    EnumerationVariableDeclaration enumVarDec = new EnumerationVariableDeclaration(enumName, enumVarName, varEnum, valEnum);
                    SentenceSenquence stSeq3 = new SentenceSenquence(primerDeclaracionVariable, enumVarDec);
                    return variable_declaration_listP(stSeq3, savedEnvTypes, savedEnvValues);

                default:
                    return primerDeclaracionVariable;//null
            }
        }
Ejemplo n.º 16
0
 public StatementSequence(Sentence s1, Sentence s2)
 {
     stmt1 = s1;
     stmt2 = s2;
 }
Ejemplo n.º 17
0
        Sentence while_statement()
        {
            EnvTypes savedEnvTypes = entornoTipos;
            entornoTipos = new EnvTypes(entornoTipos);

            WhileStatement whileStmnt = new WhileStatement();
            Sentence cicloAnterior = cicloActual;
            cicloActual = whileStmnt;

            match("while");
            match("(");
            Expr expresion = expr();
            match(")");
            Sentence ifCpStmnt = if_compound_statement();

            whileStmnt.WhileInit(expresion, ifCpStmnt);
            cicloActual = cicloAnterior;

            entornoTipos = savedEnvTypes;

            return whileStmnt;
        }
Ejemplo n.º 18
0
 public ValorFuncion(Sentence func)
 {
     funcion = func;
 }
Ejemplo n.º 19
0
        Sentence for_statement()
        {
            EnvTypes savedEnvTypes = entornoTipos;
            entornoTipos = new EnvTypes(entornoTipos);

            EnvValues savedEnvValues = ((FunctionDefinition)funcionActual).entornoValoresLocal;
            ((FunctionDefinition)funcionActual).entornoValoresLocal = new EnvValues(((FunctionDefinition)funcionActual).entornoValoresLocal);

            ForStatement forStmnt = new ForStatement();
            Sentence cicloAnterior = cicloActual;
            cicloActual = forStmnt;

            match("for");
            match("(");
            Sentence forInitialization = for_initialization();
            match(";");
            Sentence forControl = for_control();
            match(";");
            Sentence forIteration = for_iteration();
            match(")");

            EnvValues savedEnvValues2 = ((FunctionDefinition)funcionActual).entornoValoresLocal;
            ((FunctionDefinition)funcionActual).entornoValoresLocal = new EnvValues(((FunctionDefinition)funcionActual).entornoValoresLocal);

            Sentence compoundStatement = if_compound_statement();

            ((FunctionDefinition)funcionActual).entornoValoresLocal = savedEnvValues2;

            forStmnt.ForInit(forInitialization, forControl, forIteration, compoundStatement);
            cicloActual = cicloAnterior;

            entornoTipos = savedEnvTypes;
            ((FunctionDefinition)funcionActual).entornoValoresLocal = savedEnvValues;
            return forStmnt;
        }
Ejemplo n.º 20
0
 public VariableDeclaration()
 {
     //entornoValores = Parser.entornoValores;
     enclosing = Parser.funcionActual;
 }
Ejemplo n.º 21
0
        Sentence global_sentenceP(Sentence sentencia1)
        {
            switch(currentToken.Tipo)
            {
                case TokenType.STRING:
                case TokenType.BOOL:
                case TokenType.CHAR:
                case TokenType.FLOAT:
                case TokenType.INT:
                case TokenType.VOID:
                case TokenType.CONST:
                case TokenType.STRUCT:
                case TokenType.ENUM:

                case TokenType.CIN:
                case TokenType.COUT:
                    Sentence sentencia2 = sentence();
                    SentenceSenquence sentSequence = new SentenceSenquence(sentencia1, sentencia2);
                    return global_sentenceP(sentSequence);

                default:
                    return sentencia1;//null
            }
        }
Ejemplo n.º 22
0
 public Expr()
 {
     entornoTiposActual = Parser.entornoTipos;
     enclosing = Parser.funcionActual;
 }