Beispiel #1
0
        Access offset(Id a)
        {
            Expr i;
            Expr w;
            Expr t1, t2;
            Expr loc;

            symbols.Type type = a.type;
            match('[');
            i = bool_expr();
            match(']');
            type = ((symbols.Array)type).of;
            w    = new Constant(type.width, compileRows);
            t1   = new Arith(new Token('*'), i, w, compileRows);
            loc  = t1;
            while (look.tag == '[')
            {
                match('[');
                i = bool_expr();
                match(']');
                type = ((symbols.Array)type).of;
                w    = new Constant(type.width, compileRows);
                t1   = new Arith(new Token('*'), i, w, compileRows);
                t2   = new Arith(new Token('+'), loc, t1, compileRows);
                loc  = t2;
            }
            return(new Access(a, loc, type, compileRows));
        }
Beispiel #2
0
 public virtual symbols.Type check(symbols.Type p1, symbols.Type p2)
 {
     if (p1 == symbols.Type.Bool && p2 == symbols.Type.Bool)
     {
         return(symbols.Type.Bool);
     }
     else
     {
         return(null);
     }
 }
Beispiel #3
0
        symbols.Type dims(symbols.Type p)
        {
            match('[');
            Token tok = look;

            match(Tag.NUM);
            match(']');
            if (look.tag == '[')
            {
                p = dims(p);
            }
            return(new symbols.Array(((Num)tok).value, p));
        }
Beispiel #4
0
 symbols.Type type()
 {
     symbols.Type p = (symbols.Type)look;
     match(Tag.BASIC);
     if (look.tag != '[')
     {
         return(p);
     }
     else
     {
         return(dims(p));
     }
 }
Beispiel #5
0
 void decls()
 {
     while (look.tag == Tag.BASIC)
     {
         symbols.Type p   = type();
         Token        tok = look;
         match(Tag.ID);
         match(';');
         Id id = new Id((Word)tok, p, used, compileRows);
         top.put(tok, id);
         used = used + p.width;
     }
 }
Beispiel #6
0
 public symbols.Type check(symbols.Type p1, symbols.Type p2)
 {
     if (symbols.Type.numeric(p1) && symbols.Type.numeric(p2))
     {
         return(p2);
     }
     else if (p1 == symbols.Type.Bool && p2 == symbols.Type.Bool)
     {
         return(p2);
     }
     else
     {
         return(null);
     }
 }
Beispiel #7
0
 public override symbols.Type check(symbols.Type p1, symbols.Type p2)
 {
     if (p1 is symbols.Array || p1 is symbols.Array)
     {
         return(null);
     }
     else if (p1 == p2)
     {
         return(symbols.Type.Bool);
     }
     else
     {
         return(null);
     }
 }
Beispiel #8
0
 public symbols.Type check(symbols.Type p1, symbols.Type p2)
 {
     if ((p1 is symbols.Array) || (p2 is symbols.Array))
     {
         return(null);
     }
     else if (p1 == p2)
     {
         return(p2);
     }
     else if (symbols.Type.numeric(p1) && symbols.Type.numeric(p2))
     {
         return(p2);
     }
     else
     {
         return(null);
     }
 }
Beispiel #9
0
 public Expr(Token tok, symbols.Type p, List <CodeRow> outputList)
 {
     op   = tok;
     type = p;
     rows = outputList;
 }
Beispiel #10
0
 public Access(Id a, Expr i, symbols.Type p, List <CodeRow> outputList) : base(new Word("[]", Tag.INDEX), p, outputList)
 {
     array = a;
     index = i;
 }
Beispiel #11
0
 public Constant(Token tok, symbols.Type p, List <CodeRow> outputList) : base(tok, p, outputList)
 {
 }
Beispiel #12
0
 public Temp(symbols.Type p, List <CodeRow> outputList) : base(Word.temp, p, outputList)
 {
     number = ++count;
 }
Beispiel #13
0
 public Id(Word id, symbols.Type p, int b, List <CodeRow> outputList) : base(id, p, outputList)
 {
     offset = b;
 }