Exemple #1
0
 public forStatementConCondFuntAST(exprAST d, conditionAST c, exprAST f, statementAST s)
 {
     this.decl      = d;
     this.condition = c;
     this.funtion   = f;
     this.statement = s;
 }
Exemple #2
0
        public condFactAST parseCndFac()
        {   //CondFact
            //CondFact = Expr Relop Expr
            exprAST  expr  = parseExpr();
            relopAST rel   = parseRelop();
            exprAST  expr2 = parseExpr();

            return(new condFactAST(expr, rel, expr2));
        }
Exemple #3
0
        public actParsAST parseActPars()
        {
            listExprAST temp   = null;
            listExprAST temp2  = null;
            listExprAST result = null;
            exprAST     expr   = null;

            if (currentToken.sym == sym.RES || currentToken.sym == sym.ID || currentToken.sym == sym.NUM || currentToken.sym == sym.CHARCONS || currentToken.sym == sym.TRUE || currentToken.sym == sym.FALSE || currentToken.sym == sym.NEW || currentToken.sym == sym.P_ABI)
            {
                expr = parseExpr();
                temp = new unExprAST(expr);
                Boolean ind = false;
                while (currentToken.sym == sym.COMA)
                {
                    if (ind == false)
                    {
                        acceptIt();
                        expr   = parseExpr();
                        temp2  = new unExprAST(expr);
                        result = new varExprAST(temp2, temp);
                        ind    = true;
                    }
                    else
                    {
                        acceptIt();
                        expr   = parseExpr();
                        temp2  = new unExprAST(expr);
                        result = new varExprAST(result, temp2);
                    }
                }
                if (temp2 == null && result == null)
                {
                    return(new  actParsAST(temp));
                }

                return(new actParsAST(result));
            }
            else
            {
                error(currentToken, " '-' o 'ID'");
                return(null);
            }
        }
Exemple #4
0
 public writeStatementSinNumAST(exprAST e)
 {
     this.expr = e;
 }
Exemple #5
0
 public designatorStatementAsignacionAST(exprAST e)
 {
     this.expre = e;
 }
Exemple #6
0
 public returnStatementConExprAST(exprAST exp)
 {
     this.expr = exp;
 }
Exemple #7
0
        public designatorAST parseDesignator()
        {//Designator
            //Designator = ident { "." ident | "[" Expr "]" }
            listIdentExprAST temp        = null;
            listIdentExprAST result      = null;
            Symbol           tempsimbol2 = null;
            exprAST          expr        = null;
            Symbol           tempsimbol  = currentToken;

            accept(sym.ID, "ident");
            Boolean ind  = false;
            Boolean ind2 = false;

            while (currentToken.sym == sym.PUNTO || currentToken.sym == sym.C_ABI)
            {
                if (currentToken.sym == sym.PUNTO)
                {
                    if (ind == false)
                    {
                        acceptIt();
                        tempsimbol2 = currentToken;
                        accept(sym.ID, "ident");
                        result = new unIdentExpreConIdentAST(tempsimbol2);
                        ind    = true;
                    }
                    else
                    {
                        acceptIt();
                        tempsimbol2 = currentToken;
                        accept(sym.ID, "ident");
                        temp   = new unIdentExpreConIdentAST(tempsimbol2);
                        result = new varIdentExpreAST(result, temp);
                    }
                }
                else
                {
                    if (ind2 == false)
                    {
                        acceptIt();
                        expr = parseExpr();
                        accept(sym.C_CER, "]");
                        result = new unIdentExpreConExprAST(expr);
                        ind2   = true;
                    }
                    else
                    {
                        acceptIt();
                        expr = parseExpr();
                        accept(sym.C_CER, "]");
                        temp   = new unIdentExpreConExprAST(expr);
                        result = new varIdentExpreAST(result, temp);
                    }
                }
            }

            if (tempsimbol2 == null && result == null)
            {
                return(new designatorSinIdentExprAST(tempsimbol));
            }
            else
            {
                return(new designatorConIdentExprAST(tempsimbol, result));
            }
        }
Exemple #8
0
 public condFactAST(exprAST exp1, relopAST rlp, exprAST exp2)
 {
     this.expr1 = exp1;
     this.relop = rlp;
     this.expr2 = exp2;
 }
Exemple #9
0
 public unExprAST(exprAST e)
 {
     expr = e;
 }
Exemple #10
0
 public unIdentExpreConExprAST(exprAST ex)
 {
     expr = ex;
 }
 public forStatementSoloDeclAST(exprAST d,statementAST s)
 {
     this.decl = d;
     this.statement = s;
 }
Exemple #12
0
        public factorAST parseFactor()
        {
            designatorAST desi = null;
            actParsAST    actP = null;
            exprAST       expr = null;

            switch (currentToken.sym)
            {
            case sym.ID:
            {
                desi = parseDesignator();
                if (currentToken.sym == sym.P_ABI)
                {
                    accept(sym.P_ABI, "(");
                    if (currentToken.sym == sym.COMA)
                    {
                        actP = parseActPars();
                    }
                    accept(sym.P_CER, ")");
                }

                if (actP == null)
                {
                    return(new factorDesignatorSinActParsAST(desi));
                }

                else
                {
                    return(new  factorDesignatorConActParsAST(desi, actP));
                }

                break;
            }

            case sym.NUM:
            {
                Symbol num = currentToken;
                accept(sym.NUM, "NUMERO");
                return(new factorNumberAST(num));
            }

            case sym.CHARCONS:
            {
                Symbol charc = currentToken;
                accept(sym.CHARCONS, "CHARCONS");
                return(new factorCharConstAST(charc));
            }

            case sym.TRUE: {
                Symbol temp = currentToken;
                accept(sym.TRUE, "TRUE");
                return(new factorBoolAST(temp));
            }

            case sym.FALSE: {
                Symbol temp = currentToken;
                accept(sym.FALSE, "FALSE");
                return(new factorBoolAST(temp));
            }

            case sym.NEW: {
                acceptIt();
                Symbol temp = currentToken;
                accept(sym.ID, "ident");
                if (currentToken.sym == sym.C_ABI)
                {
                    acceptIt();
                    expr = parseExpr();
                    accept(sym.C_CER, "]");
                }
                if (expr == null)
                {
                    return(new factorNewSinExprAST(temp));
                }

                else
                {
                    return(new factorNewConExprAST(temp, expr));
                }
            }

            case sym.P_ABI:
            {
                expr = parseExpr();
                accept(sym.P_CER);
                return(new  factorExprAST(expr));
            }
            }
            return(null);
        }
Exemple #13
0
        public statementAST parseStat()
        { //Statement
            //case id
            designatorAST desig = null;
            exprAST       expr  = null;
            actParsAST    actP  = null;
            designatorStatementAumentoAST    aum  = null;
            designatorStatementDecrementoAST decr = null;
            Boolean actPBoo = false;
            //case if
            conditionAST      condi = null;
            statementAST      stat = null;
            statementAST      stat2 = null;
            Boolean           elseBoo = false;
            listStatementsAST tempStat, tempStat2, result;
            exprAST           forexpr1 = null;
            conditionAST      forexpr2 = null;
            exprAST           forexpr3 = null;
            statementAST      forstat  = null;

            switch (currentToken.sym)
            {
            case sym.ID:
            {
                desig = parseDesignator();
                switch (currentToken.sym)
                {
                case sym.IGUAL:
                {
                    acceptIt();
                    expr = parseExpr();
                    break;
                }

                case sym.P_ABI:
                {
                    acceptIt();
                    if (currentToken.sym == sym.RES || currentToken.sym == sym.ID || currentToken.sym == sym.NUM || currentToken.sym == sym.CHARCONS || currentToken.sym == sym.TRUE || currentToken.sym == sym.FALSE || currentToken.sym == sym.NEW || currentToken.sym == sym.P_ABI)
                    {
                        actP    = parseActPars();
                        actPBoo = true;
                    }
                    accept(sym.P_CER, ")");
                    break;
                }

                case sym.SUM_SUM:
                {
                    aum = new designatorStatementAumentoAST();
                    acceptIt();
                    break;
                }

                case sym.IGU_IGU:
                {
                    decr = new designatorStatementDecrementoAST();
                    acceptIt();
                    break;
                }
                    accept(sym.PYCOMA, ";");
                    //Designator ( "=" Expr | "(" [ ActPars ] ")" | "++" | "--" ) ";"
                }
                if (expr != null)
                {
                    return(new designatorStatementAsignacionAST(expr));
                }
                else

                if (actP != null)
                {
                    return(new designatorStatementUnActParsAST(actP));            //revisar
                }

                else

                if (actPBoo == true)
                {
                    return(new designatorStatementUnActParsAST(actP));        //revisar
                }

                else

                if (actPBoo == false)              //analizar posible fallo
                {
                    return(new designatorStatementSinActParsAST());
                }


                break;
            }

            case sym.IF:
            {
                accept(sym.IF, "if");
                accept(sym.P_ABI, "(");
                condi = parseCondition();
                accept(sym.P_CER, ")");
                stat = parseStat();
                //tempStat = new unStatementAST(stat);
                if (currentToken.sym == sym.ELSE)
                {
                    elseBoo = true;
                    stat2   = parseStat();
                }
                if (elseBoo == true)
                {
                    return(new ifStatementConELseAST(condi, stat, stat2));
                }
                else
                {
                    return(new ifStatementSinELseAST(condi, stat));
                }
                break;
            }

            case sym.FOR:
            {
                accept(sym.FOR, "for");
                accept(sym.P_ABI, "(");
                forexpr1 = parseExpr();
                accept(sym.PYCOMA, ";");
                if (currentToken.sym == sym.RES || currentToken.sym == sym.ID || currentToken.sym == sym.NUM || currentToken.sym == sym.CHARCONS || currentToken.sym == sym.TRUE || currentToken.sym == sym.FALSE || currentToken.sym == sym.NEW || currentToken.sym == sym.P_ABI)
                {
                    forexpr2 = parseCondition();
                }
                accept(sym.PYCOMA, ";");
                if (currentToken.sym == sym.RES || currentToken.sym == sym.ID || currentToken.sym == sym.NUM || currentToken.sym == sym.CHARCONS || currentToken.sym == sym.TRUE || currentToken.sym == sym.FALSE || currentToken.sym == sym.NEW || currentToken.sym == sym.P_ABI)
                {
                    forexpr3 = parseExpr();
                }
                accept(sym.PYCOMA, ";");
                forstat = parseStat();
                if (forexpr2 != null && forexpr3 == null)
                {
                    return(new forStatementConConditionAST(forexpr1, forexpr2, forstat));
                }

                if (forexpr3 != null && forexpr2 == null)
                {
                    return(new forStatementConFuntionAST(forexpr1, forexpr3, forstat));
                }
                if (forexpr3 == null && forexpr2 == null)
                {
                    return(new forStatementSoloDeclAST(forexpr1, forstat));
                }
                if (forexpr3 != null && forexpr2 != null)
                {
                    return(new forStatementConCondFuntAST(forexpr1, forexpr2, forexpr3, forstat));
                }


                break;
            }

            case sym.WHILE:
            {
                accept(sym.WHILE, "WHILE");
                accept(sym.P_ABI, "(");
                condi = parseCondition();
                accept(sym.P_CER, ")");
                stat = parseStat();
                return(new whileStatementAST(condi, stat));

                break;
            }

            case sym.BREAK: {
                accept(sym.PYCOMA);
                break;
            }

            case sym.RETURN:
            { Boolean ind = false;
              acceptIt();
              if (currentToken.sym == sym.RES || currentToken.sym == sym.ID || currentToken.sym == sym.NUM || currentToken.sym == sym.CHARCONS || currentToken.sym == sym.TRUE || currentToken.sym == sym.FALSE || currentToken.sym == sym.NEW || currentToken.sym == sym.P_ABI)
              {
                  expr = parseExpr();
                  ind  = true;
              }
              accept(sym.PYCOMA, ";");
              if (ind == true)
              {
                  return(new returnStatementConExprAST(expr));
              }
              else
              {
                  return(new returnStatementSinExprAST());
              }
              break; }

            case sym.READ:
            {
                acceptIt();
                accept(sym.P_ABI, "(");
                desig = parseDesignator();

                accept(sym.P_CER, ")");
                accept(sym.PYCOMA, ";");
                return(new readStatementAST(desig));        //revisar este return

                break;
            }

            case sym.WRITE:
            {
                accept(sym.P_ABI, "(");
                expr = parseExpr();
                Symbol tempsimbol = null;
                if (currentToken.sym == sym.COMA)
                {
                    accept(sym.COMA, ",");
                    tempsimbol = currentToken;
                    accept(sym.NUM, "number");
                }
                accept(sym.P_CER, ")");
                accept(sym.PYCOMA, ";");
                if (tempsimbol != null)
                {
                    return(new writeStatementConNumAST(tempsimbol, expr));
                }
                else
                {
                    return(new writeStatementSinNumAST(expr));
                }
                //                    "write" "(" Expr [ "," number ] ")" ";"
            }

            case sym.COR_A:
            {
                parseBlock();
                break;
            }

            case sym.PYCOMA:
            {
                acceptIt();
                break;
            }
            }


            return(null);
        }
Exemple #14
0
 public unExprAST(exprAST e)
 {
     expr = e;
 }
Exemple #15
0
 public forStatementSoloDeclAST(exprAST d, statementAST s)
 {
     this.decl      = d;
     this.statement = s;
 }
Exemple #16
0
 public factorNewConExprAST(Symbol s, exprAST e)
 {
     this.ident = s;
     expr       = e;
 }
Exemple #17
0
 public factorExprAST(exprAST e)
 {
     expr = e;
 }
 public forStatementConConditionAST(exprAST d, conditionAST c, statementAST s)
 {
     this.decl = d;
     this.condition = c;
     this.statement = s;
 }
Exemple #19
0
 public writeStatementConNumAST(Symbol i, exprAST e)
 {
     ident     = i;
     this.expr = e;
 }
Exemple #20
0
 public forStatementConFuntionAST(exprAST d, exprAST f, statementAST s)
 {
     this.decl      = d;
     this.funtion   = f;
     this.statement = s;
 }
Exemple #21
0
 public condFactAST(exprAST exp1, relopAST rlp, exprAST exp2)
 {
     this.expr1 = exp1;
     this.relop = rlp;
     this.expr2 = exp2;
 }