Menu

[r30]: / trunk / python / python.lime  Maximize  Restore  History

Download this file

219 lines (183 with data), 2.9 kB

%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 
	.

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
	| classdef
	.

while_stmt 
	= WHILE test COLON suite 
	| WHILE test COLON suite ELSE COLON suite
	.

print_stmt	
	= PRINT test { python_print($2); } 
	.

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 trailer DSTAR factor
	| atom DSTAR factor
	| atom
	.

trailer
	= RBO arglist RBC 
	| SBO subscriptlist SBC 
	| DOT NAME
	.

argslist 
	= NUMBER COMMA NUMBER 
	.

testlist_comp 
	= testlist_comp_for
	| test test_tail { $$ = array("ciao"); echo "ad"; }
	| test 
	|
	.

test_tail 
	= COMMA test test_tail
	| COMMA test {echo "as";}
	|
	.

atom 
	= RBO argslist RBC 
	| 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); }
	.
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.