phpython Code
a python interpreter written in php
Status: Pre-Alpha
Brought to you by:
francescobianco
--- a/trunk/python/python.class +++ b/trunk/python/python.class @@ -27,11 +27,13 @@ 'compound_stmt' => 's 2', 'small_stmt' => 's 3', 'cmd_stmt' => 's 6', - 'for_stmt' => 's 9', - 'NAME' => 's 7', - 'FOR' => 's 10', - '\'for_stmt\'7' => 's 25', - 'stmt' => 's 32', + 'assign_stmt' => 's 7', + 'for_stmt' => 's 45', + 'NAME' => 's 8', + 'varlist' => 's 10', + 'FOR' => 's 46', + '\'for_stmt\'11' => 's 52', + 'stmt' => 's 59', '\'start\'' => 'a \'start\'', ), 1 => @@ -53,7 +55,9 @@ 'small_stmt' => 's 3', 'simple_stmt' => 's 5', 'cmd_stmt' => 's 6', - 'NAME' => 's 7', + 'assign_stmt' => 's 7', + 'NAME' => 's 8', + 'varlist' => 's 10', 'DEDENT' => 'r 3', '#' => 'r 3', ), @@ -68,130 +72,353 @@ ), 7 => array ( - 'DSTRING' => 's 8', + 'NEWLINE' => 'r 5', ), 8 => array ( - 'NEWLINE' => 'r 6', + 'DSTRING' => 's 9', + 'EQUAL' => 'r 9', ), 9 => array ( - 'DEDENT' => 'r 5', - '#' => 'r 5', + 'NEWLINE' => 'r 7', ), 10 => array ( - 'exprlist' => 's 11', - 'NAME' => 's 24', + 'EQUAL' => 's 11', ), 11 => array ( - 'IN' => 's 12', + 'exprlist' => 's 12', + 'atom' => 's 13', + 'RBO' => 's 14', + 'SBO' => 's 20', + 'BO' => 's 33', + 'NAME' => 's 44', + 'NUMBER' => 's 36', + 'DSTRING' => 's 37', + 'TRIPLEDOT' => 's 38', + 'NONE' => 's 39', + 'TRUE' => 's 40', + 'FALSE' => 's 41', ), 12 => array ( - 'testlist' => 's 13', - 'test' => 's 15', - 'expr' => 's 16', - 'NAME' => 's 17', + 'NEWLINE' => 'r 8', ), 13 => array ( - 'COLON' => 's 14', + 'NEWLINE' => 'r 10', + 'IN' => 'r 10', ), 14 => array ( - 'NEWLINE' => 'r 7', - 'NAME' => 'r 7', + 'NUMBER' => 's 15', + 'argslist' => 's 18', ), 15 => array ( - 'COLON' => 'r 12', + 'COMMA' => 's 16', ), 16 => array ( - 'COLON' => 'r 13', + 'NUMBER' => 's 17', ), 17 => array ( - 'RBO' => 's 18', + 'RBC' => 'r 19', ), 18 => array ( - 'argslist' => 's 19', - 'NUMBER' => 's 21', + 'RBC' => 's 19', ), 19 => array ( - 'RBC' => 's 20', + 'NEWLINE' => 'r 27', + 'COMMA' => 'r 27', + 'IN' => 'r 27', + 'COLON' => 'r 27', + 'SBC' => 'r 27', ), 20 => array ( - 'COLON' => 'r 14', + 'expr' => 's 21', + 'NAME' => 's 22', + 'atom' => 's 26', + 'testlist_comp_for' => 's 27', + 'test' => 's 28', + 'RBO' => 's 14', + 'SBO' => 's 20', + 'testlist_comp' => 's 42', + 'BO' => 's 33', + 'NUMBER' => 's 36', + 'DSTRING' => 's 37', + 'TRIPLEDOT' => 's 38', + 'NONE' => 's 39', + 'TRUE' => 's 40', + 'FALSE' => 's 41', + 'SBC' => 'r 23', ), 21 => array ( - 'COMMA' => 's 22', + 'COMMA' => 'r 16', + 'COLON' => 'r 16', + 'SBC' => 'r 16', ), 22 => array ( - 'NUMBER' => 's 23', + 'RBO' => 's 23', + 'COMMA' => 'r 30', + 'COLON' => 'r 30', + 'SBC' => 'r 30', ), 23 => array ( - 'RBC' => 'r 15', + 'argslist' => 's 24', + 'NUMBER' => 's 15', ), 24 => array ( - 'IN' => 'r 11', + 'RBC' => 's 25', ), 25 => + array ( + 'COMMA' => 'r 17', + 'COLON' => 'r 17', + 'SBC' => 'r 17', + ), + 26 => + array ( + 'COMMA' => 'r 18', + 'COLON' => 'r 18', + 'SBC' => 'r 18', + ), + 27 => + array ( + 'SBC' => 'r 20', + ), + 28 => + array ( + 'test_tail' => 's 29', + 'COMMA' => 's 30', + 'SBC' => 'r 22', + ), + 29 => + array ( + 'SBC' => 'r 21', + ), + 30 => + array ( + 'expr' => 's 21', + 'NAME' => 's 22', + 'atom' => 's 26', + 'test' => 's 31', + 'RBO' => 's 14', + 'SBO' => 's 20', + 'BO' => 's 33', + 'NUMBER' => 's 36', + 'DSTRING' => 's 37', + 'TRIPLEDOT' => 's 38', + 'NONE' => 's 39', + 'TRUE' => 's 40', + 'FALSE' => 's 41', + ), + 31 => + array ( + 'COMMA' => 's 30', + 'test_tail' => 's 32', + 'SBC' => 'r 25', + ), + 32 => + array ( + 'SBC' => 'r 24', + ), + 33 => + array ( + 'dictorsetmaker' => 's 34', + ), + 34 => + array ( + 'BC' => 's 35', + ), + 35 => + array ( + 'NEWLINE' => 'r 29', + 'COMMA' => 'r 29', + 'IN' => 'r 29', + 'COLON' => 'r 29', + 'SBC' => 'r 29', + ), + 36 => + array ( + 'NEWLINE' => 'r 31', + 'COMMA' => 'r 31', + 'IN' => 'r 31', + 'COLON' => 'r 31', + 'SBC' => 'r 31', + ), + 37 => + array ( + 'NEWLINE' => 'r 32', + 'COMMA' => 'r 32', + 'IN' => 'r 32', + 'COLON' => 'r 32', + 'SBC' => 'r 32', + ), + 38 => + array ( + 'NEWLINE' => 'r 33', + 'COMMA' => 'r 33', + 'IN' => 'r 33', + 'COLON' => 'r 33', + 'SBC' => 'r 33', + ), + 39 => + array ( + 'NEWLINE' => 'r 34', + 'COMMA' => 'r 34', + 'IN' => 'r 34', + 'COLON' => 'r 34', + 'SBC' => 'r 34', + ), + 40 => + array ( + 'NEWLINE' => 'r 35', + 'COMMA' => 'r 35', + 'IN' => 'r 35', + 'COLON' => 'r 35', + 'SBC' => 'r 35', + ), + 41 => + array ( + 'NEWLINE' => 'r 36', + 'COMMA' => 'r 36', + 'IN' => 'r 36', + 'COLON' => 'r 36', + 'SBC' => 'r 36', + ), + 42 => + array ( + 'SBC' => 's 43', + ), + 43 => + array ( + 'NEWLINE' => 'r 28', + 'COMMA' => 'r 28', + 'IN' => 'r 28', + 'COLON' => 'r 28', + 'SBC' => 'r 28', + ), + 44 => + array ( + 'NEWLINE' => 'r 30', + 'IN' => 'r 30', + ), + 45 => + array ( + 'DEDENT' => 'r 6', + '#' => 'r 6', + ), + 46 => + array ( + 'atom' => 's 13', + 'exprlist' => 's 47', + 'RBO' => 's 14', + 'SBO' => 's 20', + 'BO' => 's 33', + 'NAME' => 's 44', + 'NUMBER' => 's 36', + 'DSTRING' => 's 37', + 'TRIPLEDOT' => 's 38', + 'NONE' => 's 39', + 'TRUE' => 's 40', + 'FALSE' => 's 41', + ), + 47 => + array ( + 'IN' => 's 48', + ), + 48 => + array ( + 'testlist' => 's 49', + 'test' => 's 51', + 'expr' => 's 21', + 'NAME' => 's 22', + 'atom' => 's 26', + 'RBO' => 's 14', + 'SBO' => 's 20', + 'BO' => 's 33', + 'NUMBER' => 's 36', + 'DSTRING' => 's 37', + 'TRIPLEDOT' => 's 38', + 'NONE' => 's 39', + 'TRUE' => 's 40', + 'FALSE' => 's 41', + ), + 49 => + array ( + 'COLON' => 's 50', + ), + 50 => + array ( + 'NEWLINE' => 'r 11', + 'NAME' => 'r 11', + ), + 51 => + array ( + 'COLON' => 'r 15', + ), + 52 => array ( 'small_stmt' => 's 3', 'cmd_stmt' => 's 6', - 'NAME' => 's 7', - 'suite' => 's 26', - 'simple_stmt' => 's 27', - 'NEWLINE' => 's 28', - ), - 26 => - array ( - 'DEDENT' => 'r 8', - '#' => 'r 8', - ), - 27 => - array ( - 'DEDENT' => 'r 9', - '#' => 'r 9', - ), - 28 => - array ( - 'INDENT' => 's 29', - ), - 29 => + 'assign_stmt' => 's 7', + 'NAME' => 's 8', + 'varlist' => 's 10', + 'suite' => 's 53', + 'simple_stmt' => 's 54', + 'NEWLINE' => 's 55', + ), + 53 => + array ( + 'DEDENT' => 'r 12', + '#' => 'r 12', + ), + 54 => + array ( + 'DEDENT' => 'r 13', + '#' => 'r 13', + ), + 55 => + array ( + 'INDENT' => 's 56', + ), + 56 => array ( 'simple_stmt' => 's 1', 'compound_stmt' => 's 2', 'small_stmt' => 's 3', 'cmd_stmt' => 's 6', - 'for_stmt' => 's 9', - 'NAME' => 's 7', - 'FOR' => 's 10', - '\'for_stmt\'7' => 's 25', - 'stmt' => 's 30', - ), - 30 => - array ( - 'DEDENT' => 's 31', - ), - 31 => - array ( - 'DEDENT' => 'r 10', - '#' => 'r 10', - ), - 32 => - array ( - '#' => 'r 16', + 'assign_stmt' => 's 7', + 'for_stmt' => 's 45', + 'NAME' => 's 8', + 'varlist' => 's 10', + 'FOR' => 's 46', + '\'for_stmt\'11' => 's 52', + 'stmt' => 's 57', + ), + 57 => + array ( + 'DEDENT' => 's 58', + ), + 58 => + array ( + 'DEDENT' => 'r 14', + '#' => 'r 14', + ), + 59 => + array ( + '#' => 'r 37', ), ); function reduce_0_stmt_1($tokens, &$result) { @@ -234,97 +461,265 @@ } -function reduce_5_compound_stmt_1($tokens, &$result) { -# -# (5) compound_stmt := for_stmt -# -$result = reset($tokens); - -} - -function reduce_6_cmd_stmt_1($tokens, &$result) { -# -# (6) cmd_stmt := NAME DSTRING +function reduce_5_small_stmt_2($tokens, &$result) { +# +# (5) small_stmt := assign_stmt +# +$result = reset($tokens); + +} + +function reduce_6_compound_stmt_1($tokens, &$result) { +# +# (6) compound_stmt := for_stmt +# +$result = reset($tokens); + +} + +function reduce_7_cmd_stmt_1($tokens, &$result) { +# +# (7) cmd_stmt := NAME DSTRING # $result = reset($tokens); python_command($tokens[0],$tokens[1]); } -function reduce_7_for_stmt7_1($tokens, &$result) { -# -# (7) 'for_stmt'7 := FOR exprlist IN testlist COLON +function reduce_8_assign_stmt_1($tokens, &$result) { +# +# (8) assign_stmt := varlist EQUAL exprlist +# +$result = reset($tokens); + python_assign($tokens[0],$tokens[2]); +} + +function reduce_9_varlist_1($tokens, &$result) { +# +# (9) varlist := NAME +# +$result = reset($tokens); + +} + +function reduce_10_exprlist_1($tokens, &$result) { +# +# (10) exprlist := atom +# +$result = reset($tokens); + +} + +function reduce_11_for_stmt11_1($tokens, &$result) { +# +# (11) 'for_stmt'11 := FOR exprlist IN testlist COLON # $result = reset($tokens); python_for(); } -function reduce_8_for_stmt_1($tokens, &$result) { -# -# (8) for_stmt := 'for_stmt'7 suite +function reduce_12_for_stmt_1($tokens, &$result) { +# +# (12) for_stmt := 'for_stmt'11 suite # $result = reset($tokens); python_end_for(); } -function reduce_9_suite_1($tokens, &$result) { -# -# (9) suite := simple_stmt -# -$result = reset($tokens); - -} - -function reduce_10_suite_2($tokens, &$result) { -# -# (10) suite := NEWLINE INDENT stmt DEDENT -# -$result = reset($tokens); - -} - -function reduce_11_exprlist_1($tokens, &$result) { -# -# (11) exprlist := NAME -# -$result = reset($tokens); - -} - -function reduce_12_testlist_1($tokens, &$result) { -# -# (12) testlist := test -# -$result = reset($tokens); - -} - -function reduce_13_test_1($tokens, &$result) { -# -# (13) test := expr -# -$result = reset($tokens); - -} - -function reduce_14_expr_1($tokens, &$result) { -# -# (14) expr := NAME RBO argslist RBC -# -$result = reset($tokens); - -} - -function reduce_15_argslist_1($tokens, &$result) { -# -# (15) argslist := NUMBER COMMA NUMBER -# -$result = reset($tokens); - -} - -function reduce_16_start_1($tokens, &$result) { -# -# (16) 'start' := stmt +function reduce_13_suite_1($tokens, &$result) { +# +# (13) suite := simple_stmt +# +$result = reset($tokens); + +} + +function reduce_14_suite_2($tokens, &$result) { +# +# (14) suite := NEWLINE INDENT stmt DEDENT +# +$result = reset($tokens); + +} + +function reduce_15_testlist_1($tokens, &$result) { +# +# (15) testlist := test +# +$result = reset($tokens); + +} + +function reduce_16_test_1($tokens, &$result) { +# +# (16) test := expr +# +$result = reset($tokens); + +} + +function reduce_17_expr_1($tokens, &$result) { +# +# (17) expr := NAME RBO argslist RBC +# +$result = reset($tokens); + +} + +function reduce_18_expr_2($tokens, &$result) { +# +# (18) expr := atom +# +$result = reset($tokens); + +} + +function reduce_19_argslist_1($tokens, &$result) { +# +# (19) argslist := NUMBER COMMA NUMBER +# +$result = reset($tokens); + +} + +function reduce_20_testlist_comp_1($tokens, &$result) { +# +# (20) testlist_comp := testlist_comp_for +# +$result = reset($tokens); + +} + +function reduce_21_testlist_comp_2($tokens, &$result) { +# +# (21) testlist_comp := test test_tail +# +$result = reset($tokens); + $result = array("ciao"); echo "ad"; +} + +function reduce_22_testlist_comp_3($tokens, &$result) { +# +# (22) testlist_comp := test +# +$result = reset($tokens); + +} + +function reduce_23_testlist_comp_4($tokens, &$result) { +# +# (23) testlist_comp := +# +$result = reset($tokens); + +} + +function reduce_24_test_tail_1($tokens, &$result) { +# +# (24) test_tail := COMMA test test_tail +# +$result = reset($tokens); + +} + +function reduce_25_test_tail_2($tokens, &$result) { +# +# (25) test_tail := COMMA test +# +$result = reset($tokens); +echo "as"; +} + +function reduce_26_test_tail_3($tokens, &$result) { +# +# (26) test_tail := +# +$result = reset($tokens); + +} + +function reduce_27_atom_1($tokens, &$result) { +# +# (27) atom := RBO argslist RBC +# +$result = reset($tokens); + +} + +function reduce_28_atom_2($tokens, &$result) { +# +# (28) atom := SBO testlist_comp SBC +# +$result = reset($tokens); + $result = python_list($tokens[1]); +} + +function reduce_29_atom_3($tokens, &$result) { +# +# (29) atom := BO dictorsetmaker BC +# +$result = reset($tokens); + +} + +function reduce_30_atom_4($tokens, &$result) { +# +# (30) atom := NAME +# +$result = reset($tokens); + +} + +function reduce_31_atom_5($tokens, &$result) { +# +# (31) atom := NUMBER +# +$result = reset($tokens); + +} + +function reduce_32_atom_6($tokens, &$result) { +# +# (32) atom := DSTRING +# +$result = reset($tokens); + +} + +function reduce_33_atom_7($tokens, &$result) { +# +# (33) atom := TRIPLEDOT +# +$result = reset($tokens); + +} + +function reduce_34_atom_8($tokens, &$result) { +# +# (34) atom := NONE +# +$result = reset($tokens); + +} + +function reduce_35_atom_9($tokens, &$result) { +# +# (35) atom := TRUE +# +$result = reset($tokens); + +} + +function reduce_36_atom_10($tokens, &$result) { +# +# (36) atom := FALSE +# +$result = reset($tokens); + +} + +function reduce_37_start_1($tokens, &$result) { +# +# (37) 'start' := stmt # $result = reset($tokens); @@ -336,18 +731,39 @@ 2 => 'reduce_2_simple_stmt_1', 3 => 'reduce_3_simple_stmt_2', 4 => 'reduce_4_small_stmt_1', - 5 => 'reduce_5_compound_stmt_1', - 6 => 'reduce_6_cmd_stmt_1', - 7 => 'reduce_7_for_stmt7_1', - 8 => 'reduce_8_for_stmt_1', - 9 => 'reduce_9_suite_1', - 10 => 'reduce_10_suite_2', - 11 => 'reduce_11_exprlist_1', - 12 => 'reduce_12_testlist_1', - 13 => 'reduce_13_test_1', - 14 => 'reduce_14_expr_1', - 15 => 'reduce_15_argslist_1', - 16 => 'reduce_16_start_1', + 5 => 'reduce_5_small_stmt_2', + 6 => 'reduce_6_compound_stmt_1', + 7 => 'reduce_7_cmd_stmt_1', + 8 => 'reduce_8_assign_stmt_1', + 9 => 'reduce_9_varlist_1', + 10 => 'reduce_10_exprlist_1', + 11 => 'reduce_11_for_stmt11_1', + 12 => 'reduce_12_for_stmt_1', + 13 => 'reduce_13_suite_1', + 14 => 'reduce_14_suite_2', + 15 => 'reduce_15_testlist_1', + 16 => 'reduce_16_test_1', + 17 => 'reduce_17_expr_1', + 18 => 'reduce_18_expr_2', + 19 => 'reduce_19_argslist_1', + 20 => 'reduce_20_testlist_comp_1', + 21 => 'reduce_21_testlist_comp_2', + 22 => 'reduce_22_testlist_comp_3', + 23 => 'reduce_23_testlist_comp_4', + 24 => 'reduce_24_test_tail_1', + 25 => 'reduce_25_test_tail_2', + 26 => 'reduce_26_test_tail_3', + 27 => 'reduce_27_atom_1', + 28 => 'reduce_28_atom_2', + 29 => 'reduce_29_atom_3', + 30 => 'reduce_30_atom_4', + 31 => 'reduce_31_atom_5', + 32 => 'reduce_32_atom_6', + 33 => 'reduce_33_atom_7', + 34 => 'reduce_34_atom_8', + 35 => 'reduce_35_atom_9', + 36 => 'reduce_36_atom_10', + 37 => 'reduce_37_start_1', ); var $a = array ( 0 => @@ -382,71 +798,197 @@ ), 5 => array ( + 'symbol' => 'small_stmt', + 'len' => 1, + 'replace' => true, + ), + 6 => + array ( 'symbol' => 'compound_stmt', 'len' => 1, 'replace' => true, ), - 6 => + 7 => array ( 'symbol' => 'cmd_stmt', 'len' => 2, 'replace' => true, ), - 7 => - array ( - 'symbol' => '\'for_stmt\'7', + 8 => + array ( + 'symbol' => 'assign_stmt', + 'len' => 3, + 'replace' => true, + ), + 9 => + array ( + 'symbol' => 'varlist', + 'len' => 1, + 'replace' => true, + ), + 10 => + array ( + 'symbol' => 'exprlist', + 'len' => 1, + 'replace' => true, + ), + 11 => + array ( + 'symbol' => '\'for_stmt\'11', 'len' => 5, 'replace' => false, ), - 8 => + 12 => array ( 'symbol' => 'for_stmt', 'len' => 7, 'replace' => true, ), - 9 => + 13 => array ( 'symbol' => 'suite', 'len' => 1, 'replace' => true, ), - 10 => + 14 => array ( 'symbol' => 'suite', 'len' => 4, 'replace' => true, ), - 11 => - array ( - 'symbol' => 'exprlist', - 'len' => 1, - 'replace' => true, - ), - 12 => + 15 => array ( 'symbol' => 'testlist', 'len' => 1, 'replace' => true, ), - 13 => + 16 => array ( 'symbol' => 'test', 'len' => 1, 'replace' => true, ), - 14 => + 17 => array ( 'symbol' => 'expr', 'len' => 4, 'replace' => true, ), - 15 => + 18 => + array ( + 'symbol' => 'expr', + 'len' => 1, + 'replace' => true, + ), + 19 => array ( 'symbol' => 'argslist', 'len' => 3, 'replace' => true, ), - 16 => + 20 => + array ( + 'symbol' => 'testlist_comp', + 'len' => 1, + 'replace' => true, + ), + 21 => + array ( + 'symbol' => 'testlist_comp', + 'len' => 2, + 'replace' => true, + ), + 22 => + array ( + 'symbol' => 'testlist_comp', + 'len' => 1, + 'replace' => true, + ), + 23 => + array ( + 'symbol' => 'testlist_comp', + 'len' => 0, + 'replace' => true, + ), + 24 => + array ( + 'symbol' => 'test_tail', + 'len' => 3, + 'replace' => true, + ), + 25 => + array ( + 'symbol' => 'test_tail', + 'len' => 2, + 'replace' => true, + ), + 26 => + array ( + 'symbol' => 'test_tail', + 'len' => 0, + 'replace' => true, + ), + 27 => + array ( + 'symbol' => 'atom', + 'len' => 3, + 'replace' => true, + ), + 28 => + array ( + 'symbol' => 'atom', + 'len' => 3, + 'replace' => true, + ), + 29 => + array ( + 'symbol' => 'atom', + 'len' => 3, + 'replace' => true, + ), + 30 => + array ( + 'symbol' => 'atom', + 'len' => 1, + 'replace' => true, + ), + 31 => + array ( + 'symbol' => 'atom', + 'len' => 1, + 'replace' => true, + ), + 32 => + array ( + 'symbol' => 'atom', + 'len' => 1, + 'replace' => true, + ), + 33 => + array ( + 'symbol' => 'atom', + 'len' => 1, + 'replace' => true, + ), + 34 => + array ( + 'symbol' => 'atom', + 'len' => 1, + 'replace' => true, + ), + 35 => + array ( + 'symbol' => 'atom', + 'len' => 1, + 'replace' => true, + ), + 36 => + array ( + 'symbol' => 'atom', + 'len' => 1, + 'replace' => true, + ), + 37 => array ( 'symbol' => '\'start\'', 'len' => 1,