示例#1
0
        public void AddClassVar(AstId vid, DemiTasse.ast.AstType type, AstExp e)
        {
            if(GetClassVar(vid) != null)
                throw new SymbolException("ClassVar " + vid.s + " already defined");

            _vars.Add(new VarRec(vid, type, VarRec.CLASS, _vars.Count+1, e));
        }
示例#2
0
 public VarRec(AstId id, AstType type, int kind, int idx)
 {
     _id = id;
     _type = type;
     _kind = kind;
     _idx = idx;
     _init = null;
 }
示例#3
0
 public VarRec(AstId id, AstType type, int kind, int idx, AstExp e)
 {
     _id = id;
     _type = type;
     _kind = kind;
     _idx = idx;
     _init = e;
 }
示例#4
0
文件: Ast.cs 项目: robin5/DemiTasse
 public static void Append(AstExp e)
 {
     if (e == null)
         _astData.Append("(NullExp) ");
     else
         e.GenerateAstData();
 }
示例#5
0
 public AstCall(AstExp e, AstId mi, AstExpList el)
 {
     obj = e; mid = mi; args = el;
 }
示例#6
0
文件: AstIf.cs 项目: robin5/DemiTasse
 public AstIf(AstExp ae, AstStmt as1, AstStmt as2)
 {
     e = ae; s1 = as1; s2 = as2;
 }
示例#7
0
 public void Add(AstExp n)
 {
     base.Add(n);
 }
示例#8
0
 public AstWhile(AstExp ae, AstStmt _as)
 {
     e=ae; s=_as;
 }
示例#9
0
 /* throws ParseException */
 // --------------------------------------------------------------------------
 // FieldId  ->  Id
 // --------------------------------------------------------------------------
 /* final */
 public static AstExp FieldId(AstExp e)
 {
     AstId id;
     id = Id();
     return e == null ? (AstExp)id : (AstExp)(new AstField(e, id));
 }
示例#10
0
        /* throws ParseException */
        // --------------------------------------------------------------------------
        // Binop  ->  <ADD> | <SUB> | <MUL> | <DIV> | <AND> | <OR>
        // --------------------------------------------------------------------------
        /* final */
        public static AstBinop Binop(AstExp e1, AstExp e2)
        {
            ast.AstBinop.OP op;
            switch ((jj_ntk == MpRegExpId.UNDEFINED) ? jj_ntk_fn() : jj_ntk)
            {
                case MpRegExpId.ADD:
                    jj_consume_token(MpRegExpId.ADD);
                    op = ast.AstBinop.OP.ADD;
                    break;

                case MpRegExpId.SUB:
                    jj_consume_token(MpRegExpId.SUB);
                    op = ast.AstBinop.OP.SUB;
                    break;

                case MpRegExpId.MUL:
                    jj_consume_token(MpRegExpId.MUL);
                    op = ast.AstBinop.OP.MUL;
                    break;

                case MpRegExpId.DIV:
                    jj_consume_token(MpRegExpId.DIV);
                    op = ast.AstBinop.OP.DIV;
                    break;

                case MpRegExpId.AND:
                    jj_consume_token(MpRegExpId.AND);
                    op = ast.AstBinop.OP.AND;
                    break;

                case MpRegExpId.OR:
                    jj_consume_token(MpRegExpId.OR);
                    op = ast.AstBinop.OP.OR;
                    return new AstBinop( op, e1, e2 );

                default:
                    jj_la1[44] = jj_gen;
                    jj_consume_token(MpRegExpId.UNDEFINED);
                    throw new MiniParseException();
            }
            throw new Error("Missing return statement in function");
        }
示例#11
0
 /* throws ParseException */
 // --------------------------------------------------------------------------
 // ArrayElm  ->  "[" Expr "]"
 // --------------------------------------------------------------------------
 /* final */
 public static AstExp ArrayElm(AstExp pid)
 {
     AstExp e;
     jj_consume_token(MpRegExpId.LBRACKET);
     e = Expr();
     jj_consume_token(MpRegExpId.RBRACKET);
     return new AstArrayElm( pid, e );
 }
示例#12
0
        /* throws ParseException */
        // ----------------------------------------------------------------
        // ArithTail  ->  [ ( "+" | "-" ) Term ArithTail ]
        // ----------------------------------------------------------------
        /* final */
        public static AstExp ArithTail(AstExp e0)
        {
            AstExp e1 = null;
            AstExp e2 = null;
            DemiTasse.ast.AstBinop.OP op;

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

                    switch ((jj_ntk == MpRegExpId.UNDEFINED) ? jj_ntk_fn() : jj_ntk)
                    {
                        case MpRegExpId.ADD:
                            jj_consume_token(MpRegExpId.ADD);
                            op = DemiTasse.ast.AstBinop.OP.ADD;
                            break;
                        case MpRegExpId.SUB:
                            jj_consume_token(MpRegExpId.SUB);
                            op = DemiTasse.ast.AstBinop.OP.SUB;
                            break;
                        default:
                            jj_la1[30] = jj_gen;
                            jj_consume_token(MpRegExpId.UNDEFINED);
                            throw new MiniParseException();
                    }
                    e1 = Term();
                    e1 = new AstBinop(op, e0, e1);
                    e2 = ArithTail(e1);
                    break;

                case MpRegExpId.SUB:

                    switch ((jj_ntk == MpRegExpId.UNDEFINED) ? jj_ntk_fn() : jj_ntk)
                    {
                        case MpRegExpId.ADD:
                            jj_consume_token(MpRegExpId.ADD);
                            op = DemiTasse.ast.AstBinop.OP.ADD;
                            break;
                        case MpRegExpId.SUB:
                            jj_consume_token(MpRegExpId.SUB);
                            op = DemiTasse.ast.AstBinop.OP.SUB;
                            break;
                        default:
                            jj_la1[30] = jj_gen;
                            jj_consume_token(MpRegExpId.UNDEFINED);
                            throw new MiniParseException();
                    }
                    e1 = Term();
                    e1 = new AstBinop( op, e0, e1 );
                    e2 = ArithTail(e1);
                    break;

                default:
                jj_la1[31] = jj_gen;
                break;
            }
            return e2 == null ? e1 : e2;
        }
示例#13
0
        /* throws ParseException */
        // ----------------------------------------------------------------
        // TermTail  -> ("*" | "/" ) Factor TermTail
        // ----------------------------------------------------------------
        /* final */
        public static AstExp TermTail(AstExp e0)
        {
            AstExp e1 = null;
            AstExp e2 = null;
            DemiTasse.ast.AstBinop.OP op;

            switch ((jj_ntk == MpRegExpId.UNDEFINED) ? jj_ntk_fn() : jj_ntk)
            {
                case MpRegExpId.MUL:
                    switch ((jj_ntk == MpRegExpId.UNDEFINED) ? jj_ntk_fn() : jj_ntk)
                    {
                        case MpRegExpId.MUL:
                            jj_consume_token(MpRegExpId.MUL);
                            op = DemiTasse.ast.AstBinop.OP.MUL;
                            break;

                        case MpRegExpId.DIV:
                            jj_consume_token(MpRegExpId.DIV);
                            op = DemiTasse.ast.AstBinop.OP.DIV;
                            break;

                        default:
                            jj_la1[32] = jj_gen;
                            jj_consume_token(MpRegExpId.UNDEFINED);
                            throw new MiniParseException();
                    }
                    e1 = Factor();
                    e1 = new AstBinop(op, e0, e1);
                    e2 = TermTail(e1);
                    break;

                case MpRegExpId.DIV:
                    switch ((jj_ntk == MpRegExpId.UNDEFINED) ? jj_ntk_fn() : jj_ntk)
                    {
                        case MpRegExpId.MUL:
                            jj_consume_token(MpRegExpId.MUL);
                            op = DemiTasse.ast.AstBinop.OP.MUL;
                            break;

                        case MpRegExpId.DIV:
                            jj_consume_token(MpRegExpId.DIV);
                            op = DemiTasse.ast.AstBinop.OP.DIV;
                            break;

                        default:
                            jj_la1[32] = jj_gen;
                            jj_consume_token(MpRegExpId.UNDEFINED);
                            throw new MiniParseException();
                    }
                    e1 = Factor();
                    e1 = new AstBinop( op, e0, e1 );
                    e2 = TermTail(e1);
                    break;

                default:
                    jj_la1[33] = jj_gen;
                    break;
            }
            return e2 == null ? e1 : e2;
        }
示例#14
0
        /* throws ParseException */
        // ----------------------------------------------------------------
        // AndTail  ->  [ "&&" RelExpr AndTail ]
        // ----------------------------------------------------------------
        /* final */
        public static AstExp AndTail(AstExp e0)
        {
            AstExp e1 = null;
            AstExp e2 = null;

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

                    jj_consume_token(MpRegExpId.AND);
                    e1 = RelExpr();
                    e1 = new AstBinop(DemiTasse.ast.AstBinop.OP.AND, e0, e1);
                    e2 = AndTail(e1);
                    break;

                default:

                    jj_la1[28] = jj_gen;
                    break;
            }
            return e2 == null ? e1 : e2;
        }
示例#15
0
 public AstArrayElm(AstExp e1, AstExp e2)
 {
     _array = e1;
     _idx = e2;
 }
示例#16
0
 public AstCallStmt(AstExp astExp, AstId astId, AstExpList astExpList)
 {
     _obj = astExp;
     _mid = astId;
     _el = astExpList;
 }
示例#17
0
 public AstPrint(AstExp ae)
 {
     e = ae;
 }
示例#18
0
 public AstField(AstExp e, AstId v)
 {
     obj = e; var = v;
 }
示例#19
0
 public AstUnop(OP o, AstExp ae)
 {
     op=o; e=ae;
 }
示例#20
0
 public AstArrayLen(AstExp e)
 {
     array = e;
 }
示例#21
0
 public AstAssign(AstExp e1, AstExp e2)
 {
     lhs = e1; rhs = e2;
 }
示例#22
0
 public AstVarDecl(AstType at, AstId i, AstExp ae)
 {
     t = at;
     var = i;
     e = ae;
 }
示例#23
0
 public AstRelop(OP o, AstExp ae1, AstExp ae2)
 {
     op = o; e1 = ae1; e2 = ae2;
 }
示例#24
0
 public AstReturn(AstExp ae)
 {
     e = ae;
 }