Example #1
0
        public declAST parseConstDecl()
        {
            accept(sym.CONST);
            typeAST type = parseType();
            Symbol  temp = currentToken;

            accept(sym.ID);
            if (currentToken.sym == sym.IGUAL)
            {
                acceptIt();
                Symbol temp2;
                if (currentToken.sym == sym.NUM)
                {
                    temp2 = currentToken;
                    acceptIt();
                    return(new constDeclAST(type, temp2));

                    if (currentToken.sym == sym.PYCOMA)
                    {
                        acceptIt();
                    }
                    else
                    {
                        error(currentToken, ";");
                    }
                }
                if (currentToken.sym == sym.CHARCONS)
                {
                    temp2 = currentToken;
                    acceptIt();
                    return(new constDeclAST(type, temp2));

                    if (currentToken.sym == sym.PYCOMA)
                    {
                        accept(sym.PYCOMA);
                        return(new constDeclAST(type, temp2));
                    }
                    else
                    {
                        error(currentToken, ";");
                    }
                }
                else
                {
                    error(currentToken, "TIPO: NUM O CHARCONS");
                }
            }
            else
            {
                error(currentToken, "=");
            }
            return(null);
        }
Example #2
0
        public declAST parseVarDecl()
        {
            typeAST      type   = parseType();
            identListAST result = new unIdentAST(currentToken);

            accept(sym.ID);
            while (currentToken.sym == sym.COMA)
            {
                acceptIt();
                unIdentAST temp = new unIdentAST(currentToken);
                result = new varIdentAST(result, temp);
                accept(sym.ID);
            }
            accept(sym.PYCOMA);
            return(new varDeclAST(type, result));
        }
Example #3
0
        public formParsAST parseFormPars()
        {
            listTipoIdentAST temp       = null;
            listTipoIdentAST result     = null;
            typeAST          type       = parseType();
            Symbol           tempsymbol = currentToken;

            temp = new unTipoIdentAST(tempsymbol, type);
            accept(sym.ID, "Identificador");

            while (currentToken.sym == sym.COMA)
            {
                accept(sym.COMA, ",");
                tempsymbol = currentToken;
                type       = parseType();
                temp       = new unTipoIdentAST(tempsymbol, type);
                result     = new varTipoIdentAST(result, temp);
            }
            return(new formParsAST(result));
        }
Example #4
0
 public unTipoIdentAST(Symbol s, typeAST t)
 {
     ident = s;
     tipo = t;
 }
Example #5
0
        public declAST parseMethodDecl()
        {
            declAST  varD  = null;
            declsAST varD2 = null;
            declsAST varD3 = null;
            Symbol   temp  = currentToken;
            typeAST  type  = null;

            if (currentToken.sym == sym.ID || currentToken.sym == sym.VOID)
            {
                if (currentToken.sym == sym.ID)
                {
                    type = parseType();
                }

                if (currentToken.sym == sym.VOID)
                {
                    accept(sym.VOID, "void");
                }
                temp = currentToken;
                accept(sym.ID, "ident");
                accept(sym.P_ABI, "(");
                formParsAST formP = null;
                if (currentToken.sym == sym.ID)
                {
                    formP = parseFormPars();
                }
                else
                {
                    accept(sym.P_CER, ")");
                }

                Boolean ind = false;
                while (currentToken.sym == sym.ID)
                {
                    if (ind == false)
                    {
                        varD  = parseVarDecl();
                        varD2 = new undeclAST(varD);
                        varD3 = varD2;
                        ind   = true;
                    }
                    else
                    {
                        varD  = parseVarDecl();
                        varD2 = new undeclAST(varD);
                        varD3 = varD2;
                        varD2 = new varsdeclAST(varD2, varD3);
                    }
                }
                blockAST parseB = parseBlock();
                if (type == null && formP == null)
                {
                    if (ind == true)
                    {
                        return(new methodVoidSinFormDeclsAST(temp));
                    }
                    else
                    {
                        return(new  methodTipoSinFormParsAST(temp, varD2));
                        // return voidSinFormParsAST(temp, varD, parseB);
                    }
                }
                if (type == null && varD == null)
                {
                    return(new methodTipoSinVarDeclAST(temp, formP));
                    // return voidSinVarDeclAST(temp,formP,parseB);
                }
                if (type == null && varD != null && formP != null)
                {
                    if (ind == true)
                    {
                        return(new methodVoidConFormDeclsAST(varD2, formP, temp));
                    }
                    // return voidConForm_DeclsAST(temp, varD2, formP, parseB);

                    else //return voidConForm_DeclsAST(temp, varD, formP, parseB);
                    {
                        return(new methodVoidSinVarDeclAST(formP, temp));
                    }
                }

                if (type == null && varD == null && formP == null)
                {
                    return(new methodVoidSinFormDeclsAST(temp));
                }
            }
            return(null);
        }