示例#1
0
 public BasicType check(BasicType p1, BasicType p2)
 {
     if (p1 == BasicType.Bool && p2 == BasicType.Bool)
     {
         return(BasicType.Bool);
     }
     else
     {
         return(null);
     }
 }
示例#2
0
 public static bool numeric(BasicType p)
 {
     if (p == BasicType.Char || p == BasicType.Int || p == BasicType.Float)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
示例#3
0
        public BasicType dims(BasicType p)
        {
            match('[');
            Token tok = look;

            match(Tag.NUM);
            match(']');
            if (look.tag == '[')
            {
                p = dims(p);
            }
            return(new BasicArray(((Num)tok).value, p));
        }
示例#4
0
 public void decls()
 {
     while (look.tag == Tag.BASIC)
     {
         BasicType p   = type();
         Token     tok = look;
         match(Tag.ID);
         match(';');
         Id id = new Id((Word)tok, p, used);
         top.put(tok, id);
         used += p.width;
     }
 }
示例#5
0
        public BasicType type()
        {
            BasicType p = (BasicType)look;

            match(Tag.BASIC);
            if (look.tag != '[')
            {
                return(p);
            }
            else
            {
                return(dims(p));
            }
        }
示例#6
0
 public BasicType check(BasicType p1, BasicType p2)
 {
     if (p1 is BasicArray || p2 is BasicArray)
     {
         return(null);
     }
     else if (p1 == p2)
     {
         return(BasicType.Bool);
     }
     else
     {
         return(null);
     }
 }
示例#7
0
 public BasicType check(BasicType p1, BasicType p2)
 {
     if (BasicType.numeric(p1) && BasicType.numeric(p2))
     {
         return(p2);
     }
     else if (p1 == BasicType.Bool && p2 == BasicType.Bool)
     {
         return(p2);
     }
     else
     {
         return(null);
     }
 }
示例#8
0
 public BasicType check(BasicType p1, BasicType p2)
 {
     if (p1 is BasicArray || p2 is BasicArray)
     {
         return(null);
     }
     else if (p1 == p2)
     {
         return(p2);
     }
     else if (BasicType.numeric(p1) && BasicType.numeric(p2))
     {
         return(p2);
     }
     else
     {
         return(null);
     }
 }
示例#9
0
 public static BasicType max(BasicType p1, BasicType p2)
 {
     if (!numeric(p1) || !numeric(p2))
     {
         return(null);
     }
     else if (p1 == BasicType.Float || p2 == BasicType.Float)
     {
         return(BasicType.Float);
     }
     else if (p1 == BasicType.Int || p2 == BasicType.Int)
     {
         return(BasicType.Int);
     }
     else
     {
         return(BasicType.Char);
     }
 }
示例#10
0
 public Access(Id a, Expr i, BasicType p) : base(new Word(Tag.INDEX, "[]"), p)
 {
     array = a;
     index = i;
 }
示例#11
0
 public Expr(Token tok, BasicType p)
 {
     op   = tok;
     type = p;
 }
示例#12
0
 public Temp(BasicType p) : base(Word.temp, p)
 {
     number = ++count;
 }
示例#13
0
 public BasicArray(int sz, BasicType p) : base(Tag.INDEX, "[]", sz * p.width)
 {
     size = sz;
     of   = p;
 }
示例#14
0
 public Id(Word id, BasicType p, int b) : base(id, p)
 {
     offset = b;
 }
示例#15
0
 public Op(Token tok, BasicType p) : base(tok, p)
 {
 }
示例#16
0
 public Constant(Token tok, BasicType p) : base(tok, p)
 {
 }