Ejemplo n.º 1
0
        bool s_exp16()
        {
            bool r = true;

            if (lex.sy == SYMBOL.EQUAL)                 // A=1
            {
                Operand var = gen.IV[gen.IP - 1].operand;
                lex.InSymbol();
                r = s_exp1();
                gen.emit(INSTYPE.STO);          //,var);
            }
            else if (lex.sy == SYMBOL.ASSIGNOP) // A+=1;
            {
                SYMBOL2 Opr = lex.opr;
                lex.InSymbol();
                repeatvar();
                r = s_exp1();
                s_assignop(Opr);
            }

            return(r);
        }
Ejemplo n.º 2
0
        bool s_incop(SYMBOL2 opr)
        {
            switch (opr)
            {
            case SYMBOL2.PPLUS:
                repeatvar();
                gen.emit(INSTYPE.MOV, new Operand(new Numeric(1)));
                gen.emit(INSTYPE.ADD);
                gen.emit(INSTYPE.STO);
                break;

            case SYMBOL2.MMINUS:
                repeatvar();
                gen.emit(INSTYPE.MOV, new Operand(new Numeric(1)));
                gen.emit(INSTYPE.SUB);
                gen.emit(INSTYPE.STO);
                break;

            default: return(false);
            }

            return(true);
        }
Ejemplo n.º 3
0
        bool s_varnext(bool typevar)
        {
            bool compvar = false;  //compound variable

L1:
            switch (lex.sy)
            {
            case SYMBOL.LB:
                lex.InSymbol();
                if (lex.sy == SYMBOL.RB)
                {
                    s_call(Constant.FUNC_MAKE_ARRAY_TYPE, 1);

                    gen.emit(INSTYPE.NOP);
                    lex.InSymbol();
                }
                else if (lex.sy == SYMBOL.COMMA)
                {
                    int rank = 1;
                    do
                    {
                        rank++;
                        lex.InSymbol();
                    }while (lex.sy == SYMBOL.COMMA);
                    expect(SYMBOL.RB);
                    gen.emit(INSTYPE.MOV, new Operand(new Numeric(rank)));
                    s_call(Constant.FUNC_MAKE_ARRAY_TYPE, 2);
                    gen.emit(INSTYPE.NOP);
                }
                else
                {
                    int L0 = gen.emit(INSTYPE.NOP);
                    s_exp1();
                    if (lex.sy == SYMBOL.COMMA)
                    {
                        gen.remit(L0, INSTYPE.MARK);
                        lex.InSymbol();
                        s_expr1();
                        gen.emit(INSTYPE.END);
                    }

                    expect(SYMBOL.RB);
                    gen.emit(INSTYPE.ARR);
                }
                break;

            case SYMBOL.STRUCTOP:
                compvar = true;
                SYMBOL2 Opr = lex.opr;
                lex.InSymbol();
                if (lex.sy == SYMBOL.LP)
                {
                    lex.InSymbol();
                    s_var1(typevar);
                    expect(SYMBOL.RP);
                }
                else
                {
                    Operand x = Operand.Ident(lex.sym.id);
                    gen.emit(INSTYPE.MOV, x);    //LOAD
                    lex.InSymbol();
                }

                switch (Opr)
                {
                case SYMBOL2.DOT: gen.emit(INSTYPE.OFS); break;

                case SYMBOL2.ARROW: gen.emit(INSTYPE.OFS); break;
                }
                break;

            case SYMBOL.LP:             //Call    ex.System.Math.sin(30) ==> sin(System.Math,30)
                s_funcarg(compvar, -1);
                break;

            case SYMBOL.RELOP:
                if (lex.opr == SYMBOL2.LSS)
                {
                    Operand generic;

                    if (compvar)
                    {
                        generic = gen.IV[gen.IP - 2].operand;
                    }
                    else
                    {
                        generic = gen.IV[gen.IP - 1].operand;
                    }


                    if (generic.ty != OPRTYPE.identcon)
                    {
                        if (typevar)
                        {
                            error.OnError(2);                  //ident expected
                        }
                        else
                        {
                            return(true);
                        }
                    }

                    if (compvar)
                    {
                        gen.IP -= 2;
                    }
                    else
                    {
                        gen.IP -= 1;
                    }

                    int index = lex.Index();
                    int IP    = gen.IP;

                    lex.InSymbol();
                    int L0 = gen.emit(INSTYPE.MARK);
                    s_var(true);
                    int count = 1;
                    while (lex.sy == SYMBOL.COMMA)
                    {
                        lex.InSymbol();
                        s_var(true);
                        count++;
                    }
                    gen.emit(INSTYPE.END);

                    if (lex.sy == SYMBOL.RELOP && lex.opr == SYMBOL2.GTR)
                    {
                        lex.InSymbol();
                    }
                    else if (lex.sy == SYMBOL.SHIFTOP && lex.opr == SYMBOL2.SHR)
                    {
                        lex.Traceback(lex.Index(), new Token(SYMBOL.RELOP, SYMBOL2.GTR));
                    }
                    else
                    {
                        if (typevar)
                        {
                            error.OnError(54);         // '>' expected
                        }
                        else
                        {
                            goto TRACEBACK;
                        }
                    }

                    if (typevar || lex.sy != SYMBOL.LP)
                    {
                        generic.value = (string)generic.value + '`' + count;
                    }

                    gen.emit(INSTYPE.GNRC, generic);
                    break;

TRACEBACK:
                    lex.Traceback(index, new Token(SYMBOL.RELOP, SYMBOL2.LSS));
                    gen.IP = IP;
                    gen.emit(INSTYPE.MOV, generic);
                    if (compvar)
                    {
                        gen.emit(INSTYPE.OFS);
                    }

                    return(true);
                }
                else
                {
                    return(true);
                }

            default:
                return(true);
            }
            goto L1;
        }
Ejemplo n.º 4
0
        bool s_exp14()
        {
            if (s_exp15())
            {
                return(true);
            }

            if (lex.sy == SYMBOL.UNOP || lex.sy == SYMBOL.PLUS || lex.sy == SYMBOL.MINUS || lex.sy == SYMBOL.AND || lex.sy == SYMBOL.STAR)              // !exp ~exp -exp, &var, *adr
            {
                SYMBOL2 Opr = lex.opr;
                lex.InSymbol();
                s_exp14();
                switch (Opr)
                {
                case SYMBOL2.BNOT: gen.emit(INSTYPE.NOT); break;

                case SYMBOL2.NOT: gen.emit(INSTYPE.NOTNOT); break;

                case SYMBOL2.NEG: gen.emit(INSTYPE.NEG, lex.sy == SYMBOL.PLUS? 1:-1); break;

                case SYMBOL2.ADR: gen.emit(INSTYPE.ADR); break;

                case SYMBOL2.VLU: gen.emit(INSTYPE.VLU); break;

                default: return(false);
                }
                return(true);
            }

            else if (lex.sy == SYMBOL.INCOP)            //++i
            {
                SYMBOL2 Opr = lex.opr;
                lex.InSymbol();
                if (s_var(false))
                {
                    s_incop(Opr);
                    return(true);
                }
                else
                {
                    return(false);
                }
            }

            else if (s_var(false))
            {
                if (lex.sy == SYMBOL.INCOP)     //i++
                {
                    switch (lex.opr)
                    {
                    case SYMBOL2.PPLUS: gen.emit(INSTYPE.INC); break;

                    case SYMBOL2.MMINUS: gen.emit(INSTYPE.DEC); break;
                    }
                    lex.InSymbol();
                }

                return(true);
            }

            return(false);
        }
Ejemplo n.º 5
0
 public Token(SYMBOL sy, SYMBOL2 opr)
     : this()
 {
     this.sy = sy;
     this.opr = opr;
 }
Ejemplo n.º 6
0
 public Token(SYMBOL sy, SYMBOL2 opr)
     : this()
 {
     this.sy  = sy;
     this.opr = opr;
 }