public override bool Std(out Stmt s) { s = null; if (this.Column != 0) throw new ParseException("CON must be in 1st column", this); Tokenizer.Advance(); // past "CON" if (Tokenizer.Current.Text == "(eol)") Tokenizer.Advance("(eol)"); Expr conOrgExpr = new IntExpr(new SimpleToken(Tokenizer, SimpleTokenType.IntLiteral, "0", 0, 0, 0), 0); while (true) { if (Tokenizer.Current.Text == "#") { Tokenizer.Advance("#"); conOrgExpr = ParseExpression(Tokenizer, 13); } else if (Tokenizer.Current is IdToken) { IdToken constantName = Tokenizer.GetToken() as IdToken; if (Tokenizer.Current.Text == "=") { Tokenizer.Advance("="); SymbolTable.AddConSymbol(constantName, ParseExpression(Tokenizer, 13)); } else { SymbolTable.AddConSymbol(constantName, conOrgExpr); if (Tokenizer.Current.Text == "[") { Tokenizer.Advance("["); Expr incrExpr = ParseExpression(Tokenizer, 13); Tokenizer.Advance("]"); conOrgExpr = new BinaryExpr( new SimpleToken(Tokenizer, SimpleTokenType.Op, "+", 0, 0), 666, // fake opcode conOrgExpr, incrExpr); } else { Expr incrExpr = new IntExpr(new SimpleToken(Tokenizer, SimpleTokenType.IntLiteral, "(1)", 0, 0, 1), 1); conOrgExpr = new BinaryExpr( new SimpleToken(Tokenizer, SimpleTokenType.Op, "+", 0, 0), 666, // fake opcode conOrgExpr, incrExpr); } } } else break; if (Tokenizer.Current.Text == ",") Tokenizer.Advance(","); else Tokenizer.Advance("(eol)"); } return true; }
public override Expr Nud() { bool negativeIntLiteral = Tokenizer.Current.Type == SimpleTokenType.IntLiteral; bool negativeFloatLiteral = Tokenizer.Current.Type == SimpleTokenType.FloatLiteral; Expr right = ParseExpression(Tokenizer, 1); Expr u; if (negativeIntLiteral) { u = new IntExpr(right.Token, -(right as IntExpr).IntValue); } else if (negativeFloatLiteral) { u = new FloatExpr(right.Token, -(right as FloatExpr).FloatValue); } else { u = new UnaryExpr(this, 0xe6, right); // NEG } if (right is VariableExpr || right is MemoryAccessExpr) { /// u.IsAssignment = true; } return u; }
public void Visit(IntExpr e) { result = new FloInt(e.IntValue); }