From: <fwi...@us...> - 2007-11-19 15:13:18
|
Revision: 3704 http://jython.svn.sourceforge.net/jython/?rev=3704&view=rev Author: fwierzbicki Date: 2007-11-19 07:13:17 -0800 (Mon, 19 Nov 2007) Log Message: ----------- some if/elif/else support Modified Paths: -------------- trunk/sandbox/wierzbicki/antlr/grammar/Python.g trunk/sandbox/wierzbicki/antlr/grammar/PythonWalker.g Modified: trunk/sandbox/wierzbicki/antlr/grammar/Python.g =================================================================== --- trunk/sandbox/wierzbicki/antlr/grammar/Python.g 2007-11-19 03:48:52 UTC (rev 3703) +++ trunk/sandbox/wierzbicki/antlr/grammar/Python.g 2007-11-19 15:13:17 UTC (rev 3704) @@ -100,6 +100,7 @@ Dict; If; Else; + Elif; While; Pass; Print; @@ -305,7 +306,7 @@ -> ^(Assert $t1 $t2?) ; -compound_stmt : if_stmt -> ^(If if_stmt) +compound_stmt : if_stmt | while_stmt | for_stmt | try_stmt -> ^(Try try_stmt) @@ -313,9 +314,14 @@ | classdef ; -if_stmt: 'if' test COLON! s1=suite ('elif' test COLON! suite)* ('else' COLON! suite)? +if_stmt: 'if' test COLON ifsuite=suite elif_clause* ('else' COLON elsesuite=suite)? + -> ^(If test $ifsuite elif_clause* ^(Else $elsesuite)?) ; +elif_clause : 'elif' test COLON suite + -> ^(Elif test suite) + ; + while_stmt : 'while' test COLON s1=suite ('else' COLON s2=suite)? -> ^(While test $s1 ^(Else $s2)?) ; @@ -349,7 +355,7 @@ | comparison ; -comparison: expr (comp_op expr)* +comparison: expr (comp_op^ expr)* ; //comparison : expr Modified: trunk/sandbox/wierzbicki/antlr/grammar/PythonWalker.g =================================================================== --- trunk/sandbox/wierzbicki/antlr/grammar/PythonWalker.g 2007-11-19 03:48:52 UTC (rev 3703) +++ trunk/sandbox/wierzbicki/antlr/grammar/PythonWalker.g 2007-11-19 15:13:17 UTC (rev 3704) @@ -51,6 +51,7 @@ // | assert_stmt | funcdef | classdef + | if_stmt ; expr_stmt @@ -79,7 +80,7 @@ ; print_stmt - : ^(Print RIGHTSHIFT? testlist) + : ^(Print RIGHTSHIFT? testlist?) { } ; @@ -130,6 +131,12 @@ } ; +if_stmt: ^(If test suite elif_clause* (^(Else suite))?) + ; + +elif_clause : ^(Elif test suite) + ; + suite : INDENT stmt+ DEDENT ; @@ -139,8 +146,9 @@ : ^('and' test test) {} | ^('or' test test) {} | ^('not' test) {} - | ^(comp_op left=test targs=test) {} + | ^(comp_op left=test targs=test) | ^(PLUS test test) + | ^(MINUS left=test right=test) {System.out.println("MINUS left:" + $left.text + "; right:" + $right.text);} | atom (trailer)* {} ; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |