phpython Code
a python interpreter written in php
Status: Pre-Alpha
Brought to you by:
francescobianco
%class python %start stmt_start %left PLUS MINUS %left STAR SLASH stmt_start = stmt_loads ENDMARKER . stmt_loads = stmt_loads stmt_block | stmt_block . stmt_block = newlines stmt newlines . newlines = newlines NEWLINE | NEWLINE | . stmt = simple_stmt | compound_stmt . simple_stmt = small_stmt NEWLINE newlines . small_stmt = expr_stmt | print_stmt | flow_stmt . funcdef = DEF NAME parameters COLON { python_def_start($2); } suite { python_def_end($2); } . parameters = RBO varargslist RBC | RBO RBC . varargslist = fpdef_rc_star STAR NAME COMMA DSTAR NAME | fpdef_rc_star STAR NAME | fpdef_rc_star DSTAR NAME | fpdef EQUAL test fpdef_lc_star COMMA | fpdef fpdef_lc_star COMMA | fpdef EQUAL test fpdef_lc_star | fpdef fpdef_lc_star . fpdef_rc_star = fpdef_rc_star fpdef_rc | fpdef_rc | . fpdef_rc = fpdef EQUAL test COMMA | fpdef COMMA . fpdef_lc_star = fpdef_lc_star fpdef_lc | fpdef_lc | . fpdef_lc = COMMA fpdef EQUAL test | COMMA fpdef . fpdef = NAME | RBO fplist RBC . fplist = fpdef fpdefs COMMA | fpdef fpdefs . fpdefs = fpdefs COMMA fpdef | COMMA fpdef | . expr_stmt = testlist augassign yield_expr { python_assign($1,$2,$3); } | testlist augassign testlist { python_assign($1,$2,$3); } | testlist EQUAL yield_expr { python_assign($1,$2,$3); } | testlist EQUAL testlist { python_assign($1,$2,$3); } | testlist . augassign = PLUSEQUAL | MINUSEQUAL | STAREQUAL | SLASHEQUAL | MODEQUAL | AMPEQUAL | PIPEEQUAL | ACUEQUAL | LSHIFTEQUAL | RSHIFTEQUAL | DSTAREQUAL | DSLASHEQUAL . compound_stmt = while_stmt | funcdef | classdef . while_stmt = WHILE test COLON suite | WHILE test COLON suite ELSE COLON suite . print_stmt = PRINT test { python_print($2); } . flow_stmt = return_stmt . return_stmt = RETURN testlist | RETURN . suite = simple_stmt | NEWLINE INDENT stmts DEDENT . stmts = stmts stmt | stmt . testlist = test . test = or_test IF or_test ELSE test | or_test | lambdef . or_test = and_test OR and_test | and_test . and_test = not_test AND not_test | not_test . not_test = NOT not_test | comparison . comparison = expr comp_op expr | expr . comp_op = LESS | GREAT | DEQUAL | GREATEQUAL | LESSEQUAL | DIFF | NOTEQUAL | IN | NOT IN | IS | IS NOT . expr = xor_expr PIPE xor_expr | xor_expr . xor_expr = and_expr ACUE and_expr | and_expr . and_expr = shift_expr AMPE shift_expr | shift_expr . shift_expr = arith_expr LSHIFT arith_expr | arith_expr RSHIFT arith_expr | arith_expr . arith_expr = term PLUS term { $$ = $1 + $3; } | term MINUS term { $$ = $1 - $3; } | term . term = factor STAR factor { $$ = $1 * $3; } | factor SLASH factor { $$ = $1 / $3; } | factor MOD factor { $$ = python_mod($1,$3); } | factor DSLASH factor | factor . factor = PLUS factor | MINUS factor | TILDE factor | power . power = atom trailers DSTAR factor | atom trailers . trailers = trailers trailer | trailer | . trailer = RBO RBC | RBO arglist RBC | SBO subscriptlist SBC | DOT NAME . arglist = arglists_rc argument COMMA | arglists_rc argument | arglists_rc STAR test arglists_lc COMMA DSTAR test | arglists_rc STAR test arglists_lc | arglists_rc DSTAR test . arglists_rc = arglists_rc argument COMMA | argument COMMA | . arglists_lc = arglists_lc COMMA argument | COMMA argument | . argument = test | test EQUAL test . testlist_comp = testlist_comp_for | test test_tail { $$ = array("ciao"); echo "ad"; } | test | . test_tail = COMMA test test_tail | COMMA test {echo "as";} | . atom = SBO testlist_comp SBC { $$ = python_list($2); } | BO dictorsetmaker BC | NAME | NUMBER | STRING | TRIPLEDOT | NONE | TRUE | FALSE . classdef = CLASS NAME RBO testlist RBC COLON { python_class_start($2); } suite { python_class_end($2); } | CLASS NAME RBO RBC COLON { python_class_start($2); } suite { python_class_end($2); } | CLASS NAME COLON { python_class_start($2); } suite { python_class_end($2); } .