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 } }
public CompoundStatement(Sentence listaSentencias) { Sentencias = listaSentencias; }
public void DoWhileInit(Expr expr, Sentence cpStmnt) { expresion = expr; compoundStatement = cpStmnt; }
public void ForInit(Sentence forInit, Sentence forCtrl, Sentence forIter, Sentence cpStmnt) { forInitialization = forInit; forControl = forCtrl; forIteration = forIter; CompoundStatement = cpStmnt; }
public WhileStatement(Expr expr, Sentence cpStmnt) { expresion = expr; compoundstatement = cpStmnt; }
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; }
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; }
public SentenceSenquence(Sentence s1, Sentence s2) { sent1 = s1; sent2 = s2; }
public Statement() { enclosingCycle = Parser.cicloActual; enclosingFunction = Parser.funcionActual; }
public void IfElseInit(Expr cond, Sentence bloqueTrue, Sentence bloqueFalse) { condicion = cond; BloqueVerdadero = bloqueTrue; BloqueFalso = bloqueFalse; }
public void ProgramInit(Sentence sents) { sentences = sents; }
public IfElseStatement(Expr cond, Sentence bloqueTrue, Sentence bloqueFalse) { condicion = cond; BloqueVerdadero = bloqueTrue; BloqueFalso = bloqueFalse; }
public void init(string nombreFuncion, Tipo ret, Sentence cpStmnt) { idFuncion = nombreFuncion; Tiporetorno = ret; compoundStatement = cpStmnt; entornoTiposLocal = Parser.entornoTipos; }
public FunctionDefinition(string nombreFuncion, Tipo ret, Sentence cpStmnt) { idFuncion = nombreFuncion; Tiporetorno = ret; compoundStatement = cpStmnt; entornoTiposLocal = Parser.entornoTipos; entornoValoresLocal = Parser.entornoValores; ValorRetorno = null; returned = false; }
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 } }
public StatementSequence(Sentence s1, Sentence s2) { stmt1 = s1; stmt2 = s2; }
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; }
public ValorFuncion(Sentence func) { funcion = func; }
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; }
public VariableDeclaration() { //entornoValores = Parser.entornoValores; enclosing = Parser.funcionActual; }
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 } }
public Expr() { entornoTiposActual = Parser.entornoTipos; enclosing = Parser.funcionActual; }