public Stmt Assign() { Stmt stmt; var tok = _look; this.Match(Tag.ID); var id = Top.Get(tok); if (id == null) { this.Error(tok.ToString() + " undeclared"); } if (_look.TagValue == '=') { this.Move(); stmt = new Set(id, this.Bool()); } else { Access x = this.Offset(id); this.Match('='); stmt = new SetElem(x, this.Bool()); } this.Match(';'); return(stmt); }
public void TestSetElem() { var acc = new Access(new Id(new Word("arr", Tag.ID), Sara.Type.Int,0x20), new Constant(20),Sara.Type.Int); var setElem = new SetElem(acc, new Constant(42)); setElem.Gen(10, 20); //Output: // arr [ 20 ] = 42 }
public Stmt Assign() { Stmt stmt; var tok = _look; this.Match(Tag.ID); var id = Top.Get(tok); if (id == null) this.Error(tok.ToString() + " undeclared"); if(_look.TagValue == '=') { this.Move(); stmt = new Set(id, this.Bool()); } else { Access x = this.Offset(id); this.Match('='); stmt = new SetElem(x, this.Bool()); } this.Match(';'); return stmt; }