Author: bernhard
Date: Sat Sep 24 12:59:18 2005
New Revision: 9236
Modified:
trunk/languages/bc/grammar/bc_python.g
trunk/languages/bc/python/lib/bc/BcTreeWalker.py
trunk/languages/bc/t/basic.t
Log:
Add support for '<=, '!=', '>' and '>=' in Parrot bc.
Modified: trunk/languages/bc/grammar/bc_python.g
==============================================================================
--- trunk/languages/bc/grammar/bc_python.g (original)
+++ trunk/languages/bc/grammar/bc_python.g Sat Sep 24 12:59:18 2005
@@ -66,7 +66,7 @@ NEWLINE
// String literals are everything in double quotes, no escaping
STRING
- : '"'! ( ~'"' )* '"'!
+ : '"'! ( ~'"' )* '"'!
;
LETTER
@@ -480,9 +480,16 @@ relational_expr! returns[reg_name]
}
| #( op:REL_OP reg_name_left=e2:expr reg_name_right=e3:expr )
{
- reg_name = "temp_int"
+ reg_name = "temp_int" // this will be returned
+ pir_op_for_rel_op = { "<": "islt",
+ "<=": "isle",
+ ">": "isgt",
+ ">=": "isge",
+ "==": "iseq",
+ "!=": "isne",
+ }
pir = "\n" + \
- "temp_int = islt " + reg_name_left + ", " + reg_name_right + "\n
#"
+ reg_name + " = " + pir_op_for_rel_op[op.getText()] + ' ' +
reg_name_left + ", " + reg_name_right + "\n #"
#relational_expr = #( [ PIR_NOOP, "noop" ], #e2, e3, [PIR_OP, pir] )
}
;
Modified: trunk/languages/bc/python/lib/bc/BcTreeWalker.py
==============================================================================
--- trunk/languages/bc/python/lib/bc/BcTreeWalker.py (original)
+++ trunk/languages/bc/python/lib/bc/BcTreeWalker.py Sat Sep 24 12:59:18 2005
@@ -853,9 +853,16 @@ class Walker(antlr.TreeParser):
_t = _t104
_t = _t.getNextSibling()
relational_expr_AST = currentAST.root
- reg_name = "temp_int"
+ reg_name = "temp_int" # this will be returned
+ pir_op_for_rel_op = { "<": "islt",
+ "<=": "isle",
+ ">": "isgt",
+ ">=": "isge",
+ "==": "iseq",
+ "!=": "isne",
+ }
pir = "\n" + \
- "temp_int = islt " + reg_name_left + ", " +
reg_name_right + "\n #"
+ reg_name + " = " + pir_op_for_rel_op[op.getText()] + ' '
+ reg_name_left + ", " + reg_name_right + "\n #"
relational_expr_AST =
antlr.make(self.astFactory.create(PIR_NOOP,"noop"), e2_AST, e3_AST,
self.astFactory.create(PIR_OP,pir))
currentAST.root = relational_expr_AST
if (relational_expr_AST != None) and
(relational_expr_AST.getFirstChild() != None):
Modified: trunk/languages/bc/t/basic.t
==============================================================================
--- trunk/languages/bc/t/basic.t (original)
+++ trunk/languages/bc/t/basic.t Sat Sep 24 12:59:18 2005
@@ -15,8 +15,8 @@ use strict;
use FindBin;
use lib "$FindBin::Bin/../../lib", "$FindBin::Bin/../../../../lib";
+use Parrot::Test tests => 72;
use Test::More;
-use Parrot::Test tests => 55;
sub run_tests
{
@@ -108,23 +108,46 @@ my @tests =
# If
[ "1; if ( 1 ) 2; 3", [1,2,3], 'if with a true condition' ],
[ "1; if ( 0 ) 2; 3", [1,3], 'if with a true condition' ],
- [ "1; if ( 1 < 2 ) 2; 3", [1,2,3] ],
- [ "1; if ( 3 + 4 < 8*2 - 10 ) 2; 3", [1,3] ],
+ [ "1; if ( 1 < 2 ) 2; 3", [1, 2, 3], 'if with a relational operator' ],
+ # If with '<'
+ [ "1; if ( 3 + 4 < 8*2 - 10 ) 2; 3", [1, 3] ],
+ [ "1; if ( 3 + 4 < 8*2 - 9 ) 2; 3", [1, 3] ],
+ [ "1; if ( 3 + 4 < 8*2 + 10 ) 2; 3", [1, 2, 3] ],
+ # If with '<='
+ [ "1; if ( 3 + 4 <= 8*2 - 10 ) 2; 3", [1, 3] ],
+ [ "1; if ( 3 + 4 <= 8*2 - 9 ) 2; 3", [1, 2, 3] ],
+ [ "1; if ( 3 + 4 <= 8*2 + 10 ) 2; 3", [1, 2, 3] ],
+ # If with '==', still TODO
+ # If with '!='
+ [ "1; if ( 3 + 4 != 8*2 - 10 ) 2; 3", [1, 2, 3] ],
+ [ "1; if ( 3 + 4 != 8*2 - 9 ) 2; 3", [1, 3] ],
+ [ "1; if ( 3 + 4 != 8*2 + 10 ) 2; 3", [1, 2, 3] ],
+ # If with '>='
+ [ "1; if ( 3 + 4 >= 8*2 - 10 ) 2; 3", [1, 2, 3] ],
+ [ "1; if ( 3 + 4 >= 8*2 - 9 ) 2; 3", [1, 2, 3] ],
+ [ "1; if ( 3 + 4 >= 8*2 + 10 ) 2; 3", [1, 3] ],
+ # If with '>'
+ [ "1; if ( 3 + 4 > 8*2 - 10 ) 2; 3", [1, 2, 3] ],
+ [ "1; if ( 3 + 4 > 8*2 - 9 ) 2; 3", [1, 3] ],
+ [ "1; if ( 3 + 4 > 8*2 + 10 ) 2; 3", [1, 3] ],
);
-my @todo_tests =
+run_tests( [EMAIL PROTECTED] );
+
+TODO:
+{
+ local $TODO = 'not implemented';
+ my @todo_tests =
( # floats
[ '.1', '.1', 'Parrot bc says 0.1' ],
[ '-.1', '-.1', 'Parrot bc says -0.1'],
[ '-1.0000001', '-1.0000001', 'propably limited precission of Float
PMC' ],
# keyword quit
[ "0\n1; 2; quit; 3", [ 0 ], 'is that correct in GNU bc?' ],
+ # If with '==', propable not correctly parsed
+ [ "1; if ( 3 + 4 == 8*2 - 10 ) 2; 3", [1, 3], 'strange ==' ],
+ [ "1; if ( 3 + 4 == 8*2 - 9 ) 2; 3", [1, 2, 3], 'strange ==' ],
+ [ "1; if ( 3 + 4 == 8*2 + 10 ) 2; 3", [1, 3], 'strange ==' ],
);
-
-run_tests( [EMAIL PROTECTED] );
-
-TODO:
-{
- local $TODO = 'not implemented';
run_tests( [EMAIL PROTECTED] );
-}
+};