Example #1
0
 public override Expr Nud()
 {
     Expr right = ParseExpression(Tokenizer, 0);
     if (CouldBeLvalue(right))
     {
         UnaryExpr u = new UnaryExpr(this, preOpcode, right);
         return u;
     }
     ///		Console.WriteLine("-------------");
     ///		right.Accept( new RPNPrintVisitor() );
     ///		Console.WriteLine();
     ///		Console.WriteLine("-------------");
     throw new ParseException("bad lvalue", this);
 }
Example #2
0
 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;
 }
Example #3
0
 public override Expr Led(Expr left)
 {
     if (CouldBeLvalue(left))
     {
         UnaryExpr u = new UnaryExpr(this, postOpcode, left);
         return u;
     }
     ///		Console.WriteLine("-------------");
     ///		left.Accept( new RPNPrintVisitor() );
     ///		Console.WriteLine();
     ///		Console.WriteLine("-------------");
     throw new ParseException("bad lvalue", this);
 }
Example #4
0
 public void Visit(UnaryExpr e)
 {
     if (e.Token.Text == "@")
     {
         result = new FloInt(EvaluateAt(e.Operand));
         return;
     }
     result = Expr.EvaluateConstant(e.Operand, insideDat);
     if (result.IsInt)
     {
         switch (e.Token.Text.ToUpper())
         {
             case "^^": result = new FloInt((int)Math.Sqrt((uint)result.IntValue)); break;
             case "||": result = new FloInt(Math.Abs(result.IntValue)); break;
             case "|<": result = new FloInt(1 << result.IntValue); break;
             case ">|": result = new FloInt(Encode(result.IntValue)); break;
             case "!": result = new FloInt(~result.IntValue); break;
             case "NOT": result = new FloInt(result.IntValue != 0 ? 0 : -1); break;
             case "-": result = new FloInt(-result.IntValue); break;
             default: throw new ParseException("Bad operator in constant expression: " + e.Token.Text, e.Token);
         }
     }
     else
     {
         switch (e.Token.Text.ToUpper())
         {
             case "^^": result = new FloInt((float)Math.Sqrt(result.FloatValue)); break;
             case "||": result = new FloInt(Math.Abs(result.FloatValue)); break;
             case "NOT": result = new FloInt(result.FloatValue != 0.0f ? 0.0f : 1.0f); break;
             case "-": result = new FloInt(-result.FloatValue); break;
             default: throw new ParseException("Bad operator in constant expression: " + e.Token.Text, e.Token);
         }
     }
 }