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 }
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))); }
public void TestId() { var id = new Id(new Word("some_var", Tag.ID), Sara.Type.Int, 42); Assert.AreEqual(42, id.Offset); }
public void AddIdentifier(Token tok, Id id) { this.SymbolTable.Add(tok, id); }
/// <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; } }
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); }