# New Ticket Created by  Klaas-Jan Stol 
# Please include the string:  [perl #41750]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=41750 >


hi,
attached a patch for pynie:

* fixed rule for floatingpoints and imag.numbers. TGE not correct yet (+ 
some reorderings of rules)
* added compound_stmt TGE
* added tests to literals, but some are still commented out (no correct 
transform yet)
* renamed "is_not" to "is" and "not_in" to "in" (~test) rules
* fixed the transforms for those rules, as well as not_test
* added some things to while_stmt

regards,
kjs

Index: languages/pynie/src/parser/Grammar.pg
===================================================================
--- languages/pynie/src/parser/Grammar.pg	(revision 17392)
+++ languages/pynie/src/parser/Grammar.pg	(working copy)
@@ -322,17 +322,17 @@
 }
 
 token literal {
-    | <stringliteral>
-    | <integer>
-    | <longinteger>
-    | <floatnumber>
+    | <stringliteral>    
     | <imagnumber>
+    | <floatnumber>    
+    | <longinteger>     
+    | <integer> 
 }
 
-token integer {
-    | <[1..9]> \d* | <'0'>
+token integer {    
     | <'0'> <[0..7]>+
     | <'0'> <[xX]> [ \d | <[a..f]> | <[A..F]> ]+
+    | <[1..9]> \d* | <'0'>
 }
 
 token intpart { \d+ }
@@ -341,10 +341,10 @@
 
 token imagnumber { [ <floatnumber> | <intpart> ] <[jJ]> }
 
-token floatnumber {
-    | \d* <'.'> \d+
-    | \d+ <'.'>
-    | [ <'.'>? \d+ ] <[eE]> <[+\-]> \d+
+token floatnumber {    
+    | \d* <'.'> \d+ [ <[eE]> <[+\-]>? \d+ ]?
+    | \d+ <'.'> [ <[eE]> <[+\-]>? \d+ ]?
+    | \d+ <[eE]> <[+\-]>? \d+
 }
 
 token stringliteral {
@@ -482,15 +482,15 @@
 
 rule not_test {
     | <'not'> <not_test>
-    | <not_in_test>
+    | <in_test>
 }
 
-rule not_in_test {
-    <is_not_test> [ <'not'>? <'in'> <is_not_test> ]*
+rule in_test {
+    <is_test> [ (<'not'>)? <'in'> <is_test> ]*
 }
 
-rule is_not_test {
-    <comparison> [ <'is'> <'not'>? <comparison> ]*
+rule is_test {
+    <comparison> [ <'is'> (<'not'>)? <comparison> ]*
 }
 
 token 'comparison' is optable { ... }
Index: languages/pynie/src/PAST/Grammar.tg
===================================================================
--- languages/pynie/src/PAST/Grammar.tg	(revision 17392)
+++ languages/pynie/src/PAST/Grammar.tg	(working copy)
@@ -28,7 +28,14 @@
     .return tree.'get'('past', $P0, $S0)
 }
 
+transform past (Pynie::Grammar::compound_stmt) :language('PIR') {
+    $S0 = node.'find_key'()
+    $P0 = node[$S0]
+    $S0 = concat 'Pynie::Grammar::', $S0
+    .return tree.'get'('past', $P0, $S0)
+}
 
+
 transform past (Pynie::Grammar::stmt_list) :language('PIR') {
     .local pmc past
     past = new 'PAST::Stmts'
@@ -226,30 +233,94 @@
 }
 
 transform past (Pynie::Grammar::and_test) :language('PIR') {
-    $P0 = node['not_test']
-    $P0 = $P0[0] # this is a hack, 'rule expression' has 1 or more <or_test>s, so it stores them in an array. Handle $P0[1] later.
-    #printerr "pynie::grammar::and_test\n"
-    .return tree.'get'('past', $P0, 'Pynie::Grammar::not_test')
+  .local pmc past, iter, clist, cnode
+    clist = node['not_test']
+    clist = clone clist
+    cnode = pop clist
+    past = tree.'get'('past', cnode, 'Pynie::Grammar::not_test')
+    unless clist goto end
+  clist_loop:
+    cnode = pop clist
+    $P0 = tree.'get'('past', cnode, 'Pynie::Grammar::not_test')
+    past = past.'new'('PAST::Op', $P0, past, 'node'=>node, 'pasttype'=>'if')
+    if clist goto clist_loop
+  end:
+    .return (past)
 }
 
 transform past (Pynie::Grammar::not_test) :language('PIR') {
-    $P0 = node['not_in_test']
-    #printerr "pynie::grammar::not_test\n"
-    .return tree.'get'('past', $P0, 'Pynie::Grammar::not_in_test')
+    .local string key, fullkey
+    .local pmc cnode, past, notpast
+
+    cnode = node['not_test']
+    if null cnode goto do_in_test
+    notpast = tree.'get'('past', cnode, 'Pynie::Grammar::not_test')
+
+    past = new 'PAST::Op'
+    past.'init'('node'=>cnode, 'pasttype'=>'pirop', 'pirop'=>'not')
+    past.'push'(notpast)
+
+    .return (past)
+
+  do_in_test:
+    cnode = node['in_test']
+    past = tree.'get'('past', cnode, 'Pynie::Grammar::in_test')
+    .return (past)
 }
 
-transform past (Pynie::Grammar::not_in_test) :language('PIR') {
-    $P0 = node['is_not_test']
-    $P0 = $P0[0] # this is a hack, 'rule expression' has 1 or more <or_test>s, so it stores them in an array. Handle $P0[1] later.
-    #printerr "pynie::grammar::not_in_test\n"
-    .return tree.'get'('past', $P0, 'Pynie::Grammar::is_not_test')
+transform past (Pynie::Grammar::in_test) :language('PIR') {
+    .local pmc past, iter, clist, cnode
+    clist = node['is_test']
+    clist = clone clist
+    cnode = pop clist
+    past = tree.'get'('past', cnode, 'Pynie::Grammar::is_test')
+    unless clist goto end
+  clist_loop:
+    cnode = pop clist
+    $P0 = tree.'get'('past', cnode, 'Pynie::Grammar::is_test')
+    #
+    # FIX THIS; also check for "not"
+    #
+    past = past.'new'('PAST::Op', $P0, past, 'node'=>node, 'pasttype'=>'pirop', 'pirop'=>'IN (FIX)')
+    if clist goto clist_loop
+  end:
+    .return (past)
 }
 
-transform past (Pynie::Grammar::is_not_test) :language('PIR') {
-    $P0 = node['comparison']
-    $P0 = $P0[0]
-    $P0 = $P0['expr']
-    #printerr "pynie::grammar::is_not_test\n"
+transform past (Pynie::Grammar::is_test) :language('PIR') {
+    .local pmc past, iter, clist, cnode
+    .local int hasnot
+
+    hasnot = 1
+    # HACK:
+    # TODO: figure out how presence of "not" can be checked.
+    # then set flag for each iteration.
+
+    clist = node['comparison']
+    clist = clone clist
+
+    cnode = pop clist
+    past = tree.'get'('past', cnode, 'Pynie::Grammar::comparison')
+    unless clist goto end
+
+  clist_loop:
+    cnode = pop clist
+    $P0 = tree.'get'('past', cnode, 'Pynie::Grammar::comparison')
+  if hasnot == 0 goto do_issame
+    $S0 = "isntsame"
+    goto done
+  do_issame:
+    $S0 = "issame"
+  done:
+    past = past.'new'('PAST::Op', $P0, past, 'node'=>node, 'pasttype'=>'pirop', 'pirop'=>$S0)
+    if clist goto clist_loop
+  end:
+    .return (past)
+}
+
+
+transform past (Pynie::Grammar::comparison) :language('PIR') {
+    $P0 = node['expr']
     .return tree.'get'('past', $P0, 'Pynie::Grammar::expr')
 }
 
@@ -323,6 +394,29 @@
     .return (past)
 }
 
+transform past (Pynie::Grammar::longinteger) :language('PIR') {
+    .local pmc past
+    past = new 'PAST::Val'
+    past.'init'('node'=>node, 'vtype'=>'.Integer', 'name'=>node, 'ctype'=>'i+')
+    .return (past)
+}
+
+transform past (Pynie::Grammar::floatnumber) :language('PIR') {
+    .local pmc past
+    past = new 'PAST::Val'
+    # FIX
+    #past.'init'('node'=>node, 'vtype'=>'.Integer', 'name'=>node, 'ctype'=>'i+')
+    .return (past)
+}
+
+transform past (Pynie::Grammar::imagnumber) :language('PIR') {
+    .local pmc past
+    past = new 'PAST::Val'
+    # FIX
+    #past.'init'('node'=>node, 'vtype'=>'.Integer', 'name'=>node, 'ctype'=>'i+')
+    .return (past)
+}
+
 transform past (Pynie::Grammar::stringliteral) :language('PIR') {
     .local pmc past
     past = new 'PAST::Val'
@@ -439,8 +533,9 @@
     if suitec <= exprc goto expr_suite_pair
     dec suitec
     elsenode = suitelist[suitec]
-    elsepast = tree.'get'('past', elsenode, 'Pynie::Grammar::suite')
-    elsepast.'suitetype'('immediate')
+    elsepast = tree.'get'('past', elsenode, 'Pynie::Grammar::suite')    
+    # 'suitetype' does not exist...
+    ##elsepast.'suitetype'('immediate')
 
   expr_suite_pair:
     ##   each remaining suite is paired with an "if" (or "elsif")
@@ -462,23 +557,30 @@
 
 
 transform past (Pynie::Grammar::while_stmt) :language('PIR') {
-   # .local pmc past
-   # past = new 'PAST::Op'
-   # past.'init'('node'=>node, 'pasttype'=>'inline', 'inline'=>'# while stmt not implemented')
-   # .return (past)
-
-    .local pmc exprnode, stmtnode
+    .local pmc exprnode, stmtnode, suitenode
     exprnode = node['expression']
-    stmtnode = node['suite']
-    stmtnode = stmtnode[0]
+    suitenode = node['suite']
+    stmtnode = suitenode[0]
 
-    .local pmc past, exprpast, stmtpast
-    past = new 'PAST::Op'
-    past.'init'('node'=>node, 'pasttype'=>'while')
+    .local pmc past, whilepast, exprpast, stmtpast
+    past = new 'PAST::Stmts'
+    past.'init'('node'=>node)
+
+    whilepast = new 'PAST::Op'
+    whilepast.'init'('node'=>node, 'pasttype'=>'while')
     exprpast = tree.'get'('past', exprnode, 'Pynie::Grammar::expression')
-    past.'push'(exprpast)
+    whilepast.'push'(exprpast)
     stmtpast = tree.'get'('past', stmtnode, 'Pynie::Grammar::suite')
+    whilepast.'push'(stmtpast)
+    past.'push'(whilepast)
+
+    stmtnode = suitenode[1]
+    if null stmtnode goto no_else
+    unless stmtnode goto no_else # check for .Undef # why does that happen?
+    stmtpast = tree.'get'('past', stmtnode, 'Pynie::Grammar::suite')
     past.'push'(stmtpast)
+
+  no_else:
     .return (past)
 }
 
Index: languages/pynie/t/00-parrot/01-literals.t
===================================================================
--- languages/pynie/t/00-parrot/01-literals.t	(revision 17392)
+++ languages/pynie/t/00-parrot/01-literals.t	(working copy)
@@ -2,12 +2,78 @@
 
 # check literals
 
-print '1..3'
+print '1..5'
 
+0
+1
+12
+
+#123l
+#1234L
+
+
+
 print 'ok 1'
 
+
+01
+02
+03
+04
+05
+06
+07
+
+print 'ok 2'
+
+0x1
+0x2
+0x3
+0x4
+0x5
+0x6
+0x7
+0x8
+0x9
+0xa
+0xA
+0xb
+0xB
+0xc
+0xC
+0xd
+0xD
+0xe
+0xE
+0xf
+0xF
+0xdeadbeef
+
+print 'ok 3'
+
+#3.14
+#10.
+#.001
+#1e100
+#
+#3.14e-10
+#0e0
+#0E0
+#
+
 print 'ok',
-print 2
 
-print "ok 3\n",
+print 4
 
+#3.14j
+#10.j
+#10j
+#.001j
+#1e100j
+#3.14e-10j
+#1J
+
+print "ok 5\n",
+
+
+

Reply via email to