示例#1
0
        public void TestSet()
        {
            var foo = new Id(new Word("foo", Tag.ID), Sara.Type.Int, 0x20);
            var bar = new Constant(55);
            var set = new Set(foo, bar);

            set.Gen(10, 20);
            //output:
            //      	foo = 55
        }
示例#2
0
        public void TestEnv()
        {
            var global = new Env(null);
            var main = new Env(global);

            var tok = new Word("some_var", Tag.ID);
            var id = new Id(tok, Sara.Type.Int, 0xff);
            global.AddIdentifier(tok, id);
            
            Assert.ReferenceEquals(id, main.Get(tok));
            Assert.IsNull(global.Get(new Token(Tag.ID)));
        }
示例#3
0
 public void TestId()
 {
     var id = new Id(new Word("some_var", Tag.ID), Sara.Type.Int, 42);
     Assert.AreEqual(42, id.Offset);
 }
示例#4
0
 public void AddIdentifier(Token tok, Id id)
 {
     this.SymbolTable.Add(tok, id);
 }
示例#5
0
        /// <summary>
        /// Result in symbol-table for identifiers
        /// </summary>
        public void Declarations()
        {
            while(_look.TagValue == Tag.BASIC)  //D -> type ID
            {
                var type = this.Type();
                var tok = _look;
                this.Match(Tag.ID);
                this.Match(';');

                var id = new Id(tok as Word, type, this.Used);
                this.Top.AddIdentifier(tok, id);
                this.Used += type.Width;
            }
        }
示例#6
0
 public Access Offset(Id a)
 {
     Expr i, w, t1, t2, loc;
     Type type = a.Type;
     this.Match('[');
     i = this.Bool();
     this.Match(']');
     type = (type as Array).Of;
     w = new Constant(type.Width);
     t1 = new Arith(new Token('*'), i, w);
     loc = t1;
     while(_look.TagValue == '[')
     {
         this.Match('[');
         i = this.Bool();
         this.Match(']');
         type = (type as Array).Of;
         w = new Constant(type.Width);
         t1 = new Arith(new Token('*'), i, w);
         t2 = new Arith(new Token('+'), loc, t1);
         loc = t2;
     }
     return new Access(a, loc, type);
 }