Exemple #1
0
 // ArrayLen ---
 // Exp array;
 public IrExp visit(AstArrayLen n)
 {
     return new IrMem(n.array.accept(this));
 }
Exemple #2
0
        /* throws ParseException */
        /* final */
        public static AstExp astExp()
        {
            AstType t;
            AstToken n;
            AstRelop.OP relop;
            AstBinop.OP binop;
            AstUnop.OP unop;
            AstExp e, e1, e2;
            AstExpList el;

            jj_consume_token(AstRegExpId.kw56);
            switch ((jj_ntk == AstRegExpId.UNDEFINED)?jj_ntk_fn():jj_ntk) {
            case AstRegExpId.kwArrayElm:
              jj_consume_token(AstRegExpId.kwArrayElm);
              e1 = astExp();
              e2 = astExp();
                                  e = new AstArrayElm(e1,e2);
              break;
            case AstRegExpId.kwArrayLen:
              jj_consume_token(AstRegExpId.kwArrayLen);
              e1 = astExp();
                                  e = new AstArrayLen(e1);
              break;
            case AstRegExpId.kwBinop:
              jj_consume_token(AstRegExpId.kwBinop);
              binop = binOp();
              e1 = astExp();
              e2 = astExp();
                                  e = new AstBinop(binop,e1,e2);
              break;
            case AstRegExpId.kwBoolVal:
              jj_consume_token(AstRegExpId.kwBoolVal);
              switch ((jj_ntk == AstRegExpId.UNDEFINED)?jj_ntk_fn():jj_ntk) {
              case AstRegExpId.kwTrue:
            jj_consume_token(AstRegExpId.kwTrue);
                                  e = new AstBoolVal(true);
            break;
              case AstRegExpId.kwFalse:
            jj_consume_token(AstRegExpId.kwFalse);
                                  e = new AstBoolVal(false);
            break;
              default:
            jj_la1[12] = jj_gen;
            jj_consume_token(AstRegExpId.UNDEFINED);
            throw new AstParseException();
              }
              break;
            case AstRegExpId.kwCall:
              jj_consume_token(AstRegExpId.kwCall);
              e1 = astExp();
              e2 = astExp();
              el = astExpList();
                                  e = new AstCall(e1,(AstId)e2,el);
              break;
            case AstRegExpId.kwId:
              jj_consume_token(AstRegExpId.kwId);
              n = jj_consume_token(AstRegExpId.ID);
                                  e = new AstId(n.image);
              break;
            case AstRegExpId.kwIntVal:
              jj_consume_token(AstRegExpId.kwIntVal);
              n = jj_consume_token(AstRegExpId.INTVAL);
                                  e = new AstIntVal(int.Parse(n.image));
              break;
            case AstRegExpId.kwField:
              jj_consume_token(AstRegExpId.kwField);
              e1 = astExp();
              e2 = astExp();
                                  e = new AstField(e1,(AstId)e2);
              break;
            case AstRegExpId.kwNewArray:
              jj_consume_token(AstRegExpId.kwNewArray);
              t = astType();
              n = jj_consume_token(AstRegExpId.INTVAL);
              e = new AstNewArray((AstType)t, int.Parse(n.image));
              break;
            case AstRegExpId.kwNewObj:
              jj_consume_token(AstRegExpId.kwNewObj);
              e1 = astExp();
              el = astExpList();
                                  e = new AstNewObj((AstId)e1,el);
              break;
            case AstRegExpId.kwRelop:
              jj_consume_token(AstRegExpId.kwRelop);
              relop = relOp();
              e1 = astExp();
              e2 = astExp();
              e = new AstRelop(relop, e1, e2);
              break;
            case AstRegExpId.kwStrVal:
              jj_consume_token(AstRegExpId.kwStrVal);
              n = jj_consume_token(AstRegExpId.STRVAL);
                                  String s = n.image;
                                  e = new AstStrVal(s.Substring(1, s.Length-2));
              break;
            case AstRegExpId.kwThis:
              jj_consume_token(AstRegExpId.kwThis);
                                  e = new AstThis();
              break;
            case AstRegExpId.kwUnop:
              jj_consume_token(AstRegExpId.kwUnop);
              unop = unOp();
              e1 = astExp();
                                   e = new AstUnop(unop,e1);
              break;
            case AstRegExpId.kwNullExp:
              jj_consume_token(AstRegExpId.kwNullExp);
                                  e = null;
              break;

            default:
              jj_la1[13] = jj_gen;
              jj_consume_token(AstRegExpId.UNDEFINED);
              throw new AstParseException();
            }
            jj_consume_token(AstRegExpId.kw57);
            {if (true) return e;}
            throw new Error("Missing return statement in function");
        }
Exemple #3
0
        /* throws Exception */
        // ArrayLen ---
        // Exp array;
        public AstType visit(AstArrayLen n)
        {
            AstType t = n.array.accept(this);

            if (null == (t as AstArrayType))
                throw new TypeException("ArrayLen object is not an array: " + t);

            return IntType;
        }
Exemple #4
0
 public AstType visit(AstArrayLen n)
 {
     return null;
 }
Exemple #5
0
        /* throws ParseException */
        // ----------------------------------------------------------------
        // Factor  ->  [ "-" | "!" ] Factor
        //             | Lvalue [ "." "length" "(" ")" | ["(" Args ")]" ]
        //             | "(" Expr ")"
        //             | Literal
        // ----------------------------------------------------------------
        /* final */
        public static AstExp Factor()
        {
            AstExp e = null;
            AstExp factor = null;
            bool neg = false;
            bool not = false;
            AstExpList args = null;
            bool isCall = false;

            switch ((jj_ntk == MpRegExpId.UNDEFINED) ? jj_ntk_fn() : jj_ntk)
            {
                case MpRegExpId.SUB:

                    switch ((jj_ntk == MpRegExpId.UNDEFINED) ? jj_ntk_fn() : jj_ntk)
                    {
                        case MpRegExpId.SUB:
                            jj_consume_token(MpRegExpId.SUB);
                            neg = true;
                            break;
                        case MpRegExpId.NOT:
                            jj_consume_token(MpRegExpId.NOT);
                            not = true;
                            break;
                        default:
                            jj_la1[34] = jj_gen;
                            jj_consume_token(MpRegExpId.UNDEFINED);
                            throw new MiniParseException();
                    }
                    factor = Factor();
                    if (neg)
                        return new AstUnop(AstUnop.OP.NEG, factor);
                    else if (not)
                        return new AstUnop(AstUnop.OP.NOT, factor);
                    else
                        return factor;

                case MpRegExpId.NOT:

                    switch ((jj_ntk == MpRegExpId.UNDEFINED) ? jj_ntk_fn() : jj_ntk)
                    {
                        case MpRegExpId.SUB:
                            jj_consume_token(MpRegExpId.SUB);
                            neg = true;
                            break;
                        case MpRegExpId.NOT:
                            jj_consume_token(MpRegExpId.NOT);
                            not = true;
                            break;
                        default:
                            jj_la1[34] = jj_gen;
                            jj_consume_token(MpRegExpId.UNDEFINED);
                            throw new MiniParseException();
                    }
                    factor = Factor();
                    if ( neg )
                        return new AstUnop( AstUnop.OP.NEG, factor );
                    else if ( not )
                        return new AstUnop( AstUnop.OP.NOT, factor );
                    else
                        return factor;

                case MpRegExpId.THIS:
                    e = Lvalue();
                    switch ((jj_ntk == MpRegExpId.UNDEFINED) ? jj_ntk_fn() : jj_ntk)
                    {
                        case MpRegExpId.LPAREN:
                            switch ((jj_ntk == MpRegExpId.UNDEFINED) ? jj_ntk_fn() : jj_ntk)
                            {
                                case MpRegExpId.DOT:

                                    jj_consume_token(MpRegExpId.DOT);
                                    jj_consume_token(MpRegExpId.LENGTH);
                                    jj_consume_token(MpRegExpId.LPAREN);
                                    jj_consume_token(MpRegExpId.RPAREN);
                                    e = new AstArrayLen(e);
                                    break;

                                case MpRegExpId.LPAREN:

                                    jj_consume_token(MpRegExpId.LPAREN);
                                    isCall = true;
                                    switch ((jj_ntk == MpRegExpId.UNDEFINED) ? jj_ntk_fn() : jj_ntk)
                                    {
                                        case MpRegExpId.FALSE: args = Args(); break;
                                        case MpRegExpId.THIS: args = Args(); break;
                                        case MpRegExpId.TRUE: args = Args(); break;
                                        case MpRegExpId.ID: args = Args(); break;
                                        case MpRegExpId.LPAREN: args = Args(); break;
                                        case MpRegExpId.SUB: args = Args(); break;
                                        case MpRegExpId.NOT: args = Args(); break;
                                        case MpRegExpId.INTVAL: args = Args(); break;
                                        default: jj_la1[35] = jj_gen; break;
                                    }
                                    jj_consume_token(MpRegExpId.RPAREN);
                                    break;
                                default:
                                    jj_la1[36] = jj_gen;
                                    jj_consume_token(MpRegExpId.UNDEFINED);
                                    throw new MiniParseException();
                            }
                            break;
                        case MpRegExpId.DOT:
                            switch ((jj_ntk == MpRegExpId.UNDEFINED) ? jj_ntk_fn() : jj_ntk)
                            {
                                case MpRegExpId.DOT:

                                    jj_consume_token(MpRegExpId.DOT);
                                    jj_consume_token(MpRegExpId.LENGTH);
                                    jj_consume_token(MpRegExpId.LPAREN);
                                    jj_consume_token(MpRegExpId.RPAREN);
                                    e = new AstArrayLen(e);
                                    break;

                                case MpRegExpId.LPAREN:

                                    jj_consume_token(MpRegExpId.LPAREN);
                                    isCall = true;
                                    switch ((jj_ntk == MpRegExpId.UNDEFINED) ? jj_ntk_fn() : jj_ntk)
                                    {
                                        case MpRegExpId.FALSE: args = Args(); break;
                                        case MpRegExpId.THIS: args = Args(); break;
                                        case MpRegExpId.TRUE: args = Args(); break;
                                        case MpRegExpId.ID: args = Args(); break;
                                        case MpRegExpId.LPAREN: args = Args(); break;
                                        case MpRegExpId.SUB: args = Args(); break;
                                        case MpRegExpId.NOT: args = Args(); break;
                                        case MpRegExpId.INTVAL: args = Args(); break;
                                        default: jj_la1[35] = jj_gen; break;
                                    }
                                    jj_consume_token(MpRegExpId.RPAREN);
                                    break;
                                default:
                                    jj_la1[36] = jj_gen;
                                    jj_consume_token(MpRegExpId.UNDEFINED);
                                    throw new MiniParseException();
                            }
                            break;
                        default:
                            jj_la1[37] = jj_gen;
                            break;
                    }
                    if (isCall)
                    {
                        if (null != (e as AstId))
                            return new AstCall(new AstThis(), (AstId)e, args);
                        if (null != (e as AstField))
                            return new AstCall(((AstField)e).obj, ((AstField)e).var, args);
                        else
                            return null;
                    }
                    else
                    {
                        return e;
                    }

                case MpRegExpId.ID:
                    e = Lvalue();
                    switch ((jj_ntk == MpRegExpId.UNDEFINED) ? jj_ntk_fn() : jj_ntk)
                    {
                        case MpRegExpId.LPAREN:
                            switch ((jj_ntk == MpRegExpId.UNDEFINED) ? jj_ntk_fn() : jj_ntk)
                            {
                                case MpRegExpId.DOT:

                                    jj_consume_token(MpRegExpId.DOT);
                                    jj_consume_token(MpRegExpId.LENGTH);
                                    jj_consume_token(MpRegExpId.LPAREN);
                                    jj_consume_token(MpRegExpId.RPAREN);
                                    e = new AstArrayLen(e);
                                    break;

                                case MpRegExpId.LPAREN:

                                    jj_consume_token(MpRegExpId.LPAREN);
                                    isCall = true;
                                    switch ((jj_ntk == MpRegExpId.UNDEFINED) ? jj_ntk_fn() : jj_ntk)
                                    {
                                        case MpRegExpId.FALSE: args = Args(); break;
                                        case MpRegExpId.THIS: args = Args(); break;
                                        case MpRegExpId.TRUE: args = Args(); break;
                                        case MpRegExpId.ID: args = Args(); break;
                                        case MpRegExpId.LPAREN: args = Args(); break;
                                        case MpRegExpId.SUB: args = Args(); break;
                                        case MpRegExpId.NOT: args = Args(); break;
                                        case MpRegExpId.INTVAL: args = Args(); break;
                                        default: jj_la1[35] = jj_gen; break;
                                    }
                                    jj_consume_token(MpRegExpId.RPAREN);
                                    break;
                                default:
                                    jj_la1[36] = jj_gen;
                                    jj_consume_token(MpRegExpId.UNDEFINED);
                                    throw new MiniParseException();
                            }
                            break;
                        case MpRegExpId.DOT:
                            switch ((jj_ntk == MpRegExpId.UNDEFINED) ? jj_ntk_fn() : jj_ntk)
                            {
                                case MpRegExpId.DOT:

                                    jj_consume_token(MpRegExpId.DOT);
                                    jj_consume_token(MpRegExpId.LENGTH);
                                    jj_consume_token(MpRegExpId.LPAREN);
                                    jj_consume_token(MpRegExpId.RPAREN);
                                    e = new AstArrayLen( e );
                                    break;

                                case MpRegExpId.LPAREN:

                                    jj_consume_token(MpRegExpId.LPAREN);
                                    isCall = true;
                                    switch ((jj_ntk == MpRegExpId.UNDEFINED) ? jj_ntk_fn() : jj_ntk)
                                    {
                                        case MpRegExpId.FALSE: args = Args(); break;
                                        case MpRegExpId.THIS: args = Args(); break;
                                        case MpRegExpId.TRUE: args = Args(); break;
                                        case MpRegExpId.ID: args = Args(); break;
                                        case MpRegExpId.LPAREN: args = Args(); break;
                                        case MpRegExpId.SUB: args = Args(); break;
                                        case MpRegExpId.NOT: args = Args(); break;
                                        case MpRegExpId.INTVAL: args = Args(); break;
                                        default: jj_la1[35] = jj_gen; break;
                                    }
                                    jj_consume_token(MpRegExpId.RPAREN);
                                    break;
                                default:
                                    jj_la1[36] = jj_gen;
                                    jj_consume_token(MpRegExpId.UNDEFINED);
                                    throw new MiniParseException();
                            }
                            break;
                        default:
                            jj_la1[37] = jj_gen;
                            break;
                    }
                    if ( isCall )
                    {
                        if (null != (e as AstId))
                           return new AstCall( new AstThis(), (AstId)e, args );
                        if (null != (e as AstField))
                            return new AstCall( ((AstField)e).obj, ((AstField)e).var, args );
                        else
                            return null;
                    }
                    else
                    {
                        return e;
                    }

                case MpRegExpId.LPAREN:

                    jj_consume_token(MpRegExpId.LPAREN);
                    e = Expr();
                    jj_consume_token(MpRegExpId.RPAREN);
                    return e;

                case MpRegExpId.FALSE: e = Literal(); return e;
                case MpRegExpId.TRUE: e = Literal(); return e;
                case MpRegExpId.INTVAL: e = Literal(); return e;

                default:
                    jj_la1[38] = jj_gen;
                    jj_consume_token(MpRegExpId.UNDEFINED);
                    throw new MiniParseException();
            }
            throw new Error("Missing return statement in function");
        }