コード例 #1
0
ファイル: Tdop.cs プロジェクト: ZiCog/HomeSpun
 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);
 }
コード例 #2
0
ファイル: Tdop.cs プロジェクト: ZiCog/HomeSpun
 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;
 }
コード例 #3
0
ファイル: Tdop.cs プロジェクト: ZiCog/HomeSpun
 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);
 }
コード例 #4
0
ファイル: Exprs.cs プロジェクト: ZiCog/HomeSpun
 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);
         }
     }
 }