Author: leo
Date: Wed Sep 21 05:13:51 2005
New Revision: 9226
Modified:
branches/leo-ctx5/languages/bc/bc.py
branches/leo-ctx5/languages/bc/grammar/bc_python.g
branches/leo-ctx5/languages/bc/python/lib/bc/BcParser.py
branches/leo-ctx5/languages/bc/python/lib/bc/BcTreeWalker.py
branches/leo-ctx5/languages/bc/t/basic.t
Log:
merge -r9223:9225 from trunk
Modified: branches/leo-ctx5/languages/bc/bc.py
==============================================================================
--- branches/leo-ctx5/languages/bc/bc.py (original)
+++ branches/leo-ctx5/languages/bc/bc.py Wed Sep 21 05:13:51 2005
@@ -126,7 +126,8 @@ def main():
#!/usr/bin/env parrot
.sub "main" @MAIN
- .local pmc a_lex, b_lex, c_lex, d_lex, e_lex, f_lex, g_lex, h_lex, i_lex,
j_lex, k_lex, l_lex, m_lex, n_lex, o_lex, p_lex, q_lex, r_lex, s_lex, t_lex,
u_lex, v_lex, w_lex, x_lex, y_lex, z_lex
+ .local int temp_int
+ .local pmc a_lex, b_lex, c_lex, d_lex, e_lex, f_lex, g_lex, h_lex, i_lex,
j_lex, k_lex, l_lex, m_lex, n_lex, o_lex, p_lex, q_lex, r_lex, s_lex, t_lex,
u_lex, v_lex, w_lex, x_lex, y_lex, z_lex
a_lex = new .Float
b_lex = new .Float
c_lex = new .Float
Modified: branches/leo-ctx5/languages/bc/grammar/bc_python.g
==============================================================================
--- branches/leo-ctx5/languages/bc/grammar/bc_python.g (original)
+++ branches/leo-ctx5/languages/bc/grammar/bc_python.g Wed Sep 21 05:13:51 2005
@@ -66,7 +66,7 @@ NEWLINE
// String literals are everything in double quotes, no escaping
STRING
- : '"'! ( ~'"' )* '"'!
+ : '"'! ( ~'"' )* '"'!
;
LETTER
@@ -257,9 +257,9 @@ argument_list
: expression
;
-//TODO
-relational_expression
- : expression ( REL_OP expression )?
+// a relational expression
+relational_expression returns[reg_name]
+ : expression ( REL_OP^ expression )?
;
//TODO
@@ -462,7 +462,7 @@ expr_line!
lex_name + " = " + lex_name + " - 1 \n # "
#expr_line = #( [ PIR_NOOP, "noop" ], [PIR_OP, pir], [PIR_OP, "\nprint
"], [PIR_OP,lex_name], [PIR_NEWLINE, "\nprint \"\\n\" # "] )
}
- | #( If reg_name=E3:expr p2:expr_line )
+ | #( If reg_name=E3:relational_expr p2:expr_line )
{
pir = "\n" + \
"unless " + reg_name + " goto LABEL_%d\n#" % self.label_num
@@ -473,6 +473,20 @@ expr_line!
#expr_line = #p
};
+relational_expr! returns[reg_name]
+ : reg_name=e1:expr
+ {
+ #relational_expr = #e1
+ }
+ | #( op:REL_OP reg_name_left=e2:expr reg_name_right=e3:expr )
+ {
+ reg_name = "temp_int"
+ pir = "\n" + \
+ "temp_int = islt " + reg_name_left + ", " + reg_name_right + "\n
#"
+ #relational_expr = #( [ PIR_NOOP, "noop" ], #e2, e3, [PIR_OP, pir] )
+ }
+ ;
+
expr_list
: (expr_line|PIR_FUNCTION_DEF)+
;
Modified: branches/leo-ctx5/languages/bc/python/lib/bc/BcParser.py
==============================================================================
--- branches/leo-ctx5/languages/bc/python/lib/bc/BcParser.py (original)
+++ branches/leo-ctx5/languages/bc/python/lib/bc/BcParser.py Wed Sep 21
05:13:51 2005
@@ -383,6 +383,7 @@ class Parser(antlr.LLkParser):
self.returnAST = printable_expression_AST
def relational_expression(self):
+ reg_name = None
self.returnAST = None
currentAST = antlr.ASTPair()
@@ -398,7 +399,7 @@ class Parser(antlr.LLkParser):
pass
tmp30_AST = None
tmp30_AST = self.astFactory.create(self.LT(1))
- self.addASTChild(currentAST, tmp30_AST)
+ self.makeASTRoot(currentAST, tmp30_AST)
self.match(REL_OP)
self.expression()
self.addASTChild(currentAST, self.returnAST)
@@ -415,6 +416,7 @@ class Parser(antlr.LLkParser):
self.consumeUntil(_tokenSet_7)
self.returnAST = relational_expression_AST
+ return reg_name
def opt_parameter_list(self):
Modified: branches/leo-ctx5/languages/bc/python/lib/bc/BcTreeWalker.py
==============================================================================
--- branches/leo-ctx5/languages/bc/python/lib/bc/BcTreeWalker.py
(original)
+++ branches/leo-ctx5/languages/bc/python/lib/bc/BcTreeWalker.py Wed Sep
21 05:13:51 2005
@@ -746,7 +746,7 @@ class Walker(antlr.TreeParser):
self.match(_t,If)
_t = _t.getFirstChild()
E3 = antlr.ifelse(_t == antlr.ASTNULL, None, _t)
- reg_name=self.expr(_t)
+ reg_name=self.relational_expr(_t)
_t = self._retTree
E3_AST = self.returnAST
p2 = antlr.ifelse(_t == antlr.ASTNULL, None, _t)
@@ -793,6 +793,89 @@ class Walker(antlr.TreeParser):
self.returnAST = expr_line_AST
self._retTree = _t
+ def relational_expr(self, _t):
+ reg_name = None
+
+ relational_expr_AST_in = None
+ if _t != antlr.ASTNULL:
+ relational_expr_AST_in = _t
+ self.returnAST = None
+ currentAST = antlr.ASTPair()
+ relational_expr_AST = None
+ e1_AST = None
+ e1 = None
+ op = None
+ op_AST = None
+ e2_AST = None
+ e2 = None
+ e3_AST = None
+ e3 = None
+ try: ## for error handling
+ if not _t:
+ _t = antlr.ASTNULL
+ la1 = _t.getType()
+ if False:
+ pass
+ elif la1 and la1 in
[LETTER,NUMBER,MUL,DIV,MOD,PLUS,MINUS,UNARY_MINUS]:
+ pass
+ e1 = antlr.ifelse(_t == antlr.ASTNULL, None, _t)
+ reg_name=self.expr(_t)
+ _t = self._retTree
+ e1_AST = self.returnAST
+ relational_expr_AST = currentAST.root
+ relational_expr_AST = e1_AST
+ currentAST.root = relational_expr_AST
+ if (relational_expr_AST != None) and
(relational_expr_AST.getFirstChild() != None):
+ currentAST.child = relational_expr_AST.getFirstChild()
+ else:
+ currentAST.child = relational_expr_AST
+ currentAST.advanceChildToEnd()
+ elif la1 and la1 in [REL_OP]:
+ pass
+ _t104 = _t
+ op = antlr.ifelse(_t == antlr.ASTNULL, None, _t)
+ op_AST_in = None
+ op_AST = self.astFactory.create(op)
+ _currentAST104 = currentAST.copy()
+ currentAST.root = currentAST.child
+ currentAST.child = None
+ self.match(_t,REL_OP)
+ _t = _t.getFirstChild()
+ e2 = antlr.ifelse(_t == antlr.ASTNULL, None, _t)
+ reg_name_left=self.expr(_t)
+ _t = self._retTree
+ e2_AST = self.returnAST
+ e3 = antlr.ifelse(_t == antlr.ASTNULL, None, _t)
+ reg_name_right=self.expr(_t)
+ _t = self._retTree
+ e3_AST = self.returnAST
+ currentAST = _currentAST104
+ _t = _t104
+ _t = _t.getNextSibling()
+ relational_expr_AST = currentAST.root
+ reg_name = "temp_int"
+ pir = "\n" + \
+ "temp_int = islt " + 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):
+ currentAST.child = relational_expr_AST.getFirstChild()
+ else:
+ currentAST.child = relational_expr_AST
+ currentAST.advanceChildToEnd()
+ else:
+ raise antlr.NoViableAltException(_t)
+
+
+ except antlr.RecognitionException, ex:
+ self.reportError(ex)
+ if _t:
+ _t = _t.getNextSibling()
+
+ self.returnAST = relational_expr_AST
+ self._retTree = _t
+ return reg_name
+
def expr_list(self, _t):
expr_list_AST_in = None
@@ -803,7 +886,7 @@ class Walker(antlr.TreeParser):
expr_list_AST = None
try: ## for error handling
pass
- _cnt105= 0
+ _cnt107= 0
while True:
if not _t:
_t = antlr.ASTNULL
@@ -827,8 +910,8 @@ class Walker(antlr.TreeParser):
else:
break
- _cnt105 += 1
- if _cnt105 < 1:
+ _cnt107 += 1
+ if _cnt107 < 1:
raise antlr.NoViableAltException(_t)
expr_list_AST = currentAST.root
Modified: branches/leo-ctx5/languages/bc/t/basic.t
==============================================================================
--- branches/leo-ctx5/languages/bc/t/basic.t (original)
+++ branches/leo-ctx5/languages/bc/t/basic.t Wed Sep 21 05:13:51 2005
@@ -16,7 +16,7 @@ use FindBin;
use lib "$FindBin::Bin/../../lib", "$FindBin::Bin/../../../../lib";
use Test::More;
-use Parrot::Test tests => 53;
+use Parrot::Test tests => 54;
sub run_tests
{
@@ -108,6 +108,7 @@ 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] ],
);
my @todo_tests =