Menu

[r57]: / trunk / lang / python / lime / python.lang  Maximize  Restore  History

Download this file

364 lines (304 with data), 5.4 kB

%class lang_python_lang
%start stmt_start

%left PLUS MINUS
%left STAR SLASH 

stmt_start 
	= stmt_loads ENDMARKER	
	.

stmt_loads
	= stmt_loads stmt_block
	| stmt_block
	.

stmt_block	
	= simple_stmt
	| compound_stmt 
	.

simple_stmt 
	= small_stmt NEWLINE 	
	.

small_stmt 
	= expr_stmt 
	| print_stmt  
	| flow_stmt
	| import_stmt 
	. 

import_stmt
	= import_name 
	| import_from
	.

import_name
	= IMPORT dotted_as_names { static::python_import($2); }
	.

import_from	
	= FROM dotted_name IMPORT STAR 
	| FROM dotted_name IMPORT import_as_names 	
	.

import_as_name
	= NAME
	| NAME AS NAME
	.

dotted_as_name
	= dotted_name 
	| dotted_name AS NAME
	.

import_as_names
	= import_as_name 
	| import_as_name COLON import_as_names
	.

dotted_as_names
	= dotted_as_name
	| dotted_as_name COLON dotted_as_names
	.

dotted_name
	= NAME 
	| NAME DOT dotted_name
	.

funcdef
	= DEF NAME parameters COLON 
		{ lang_python_stmt::def_begin($2,$3); } 
		suite 
		{ lang_python_stmt::def_end(); }
	.

parameters
	= RBO varargslist RBC { $$ = $2; }
	| RBO RBC { $$ = null; }
	.
  
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	
	| testlist augassign testlist	
	| testlist ASSIGN yield_expr		
	| testlist ASSIGN testlist { lang_python_memory::assign($1,$3); }
	| testlist { static::python_resolve_testlist(); }
	.					
									
augassign
	= PLUSEQUAL 
	| MINUSEQUAL 
	| STAREQUAL 
	| SLASHEQUAL 
	| MODEQUAL 
	| AMPEQUAL 
	| PIPEEQUAL 
	| ACUEQUAL  
	| LSHIFTEQUAL            
	| RSHIFTEQUAL 
	| DSTAREQUAL 
	| DSLASHEQUAL
	.

compound_stmt 
	= if_stmt
	| while_stmt
	| funcdef
	| classdef
	.

if_stmt
	= if_stmt_simple  
	| if_stmt_with_else 
	.

if_stmt_simple
	= IF test COLON 
		{ lang_python_stmt::if_begin($2); } 
		suite 
		{ lang_python_stmt::if_end(); }
	.

if_stmt_with_else 
	= IF test COLON 
		{ lang_python_stmt::if_begin($2); } 
		suite 
		ELSE COLON 
		{ lang_python_stmt::if_else(); } 
		suite
		{ lang_python_stmt::if_end(); }  
	.

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

print_stmt	
	= PRINT test { lang_python_io::__print__($2); }
	.

flow_stmt
	= return_stmt
	.

return_stmt
	= RETURN testlist	{ lang_python_stmt::__return__($2); }
	| RETURN			{ lang_python_stmt::__return__(); }
	.

suite 
	= simple_stmt
	| NEWLINE INDENT stmt_loads DEDENT
	.

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 { $$ = static::python_comparison($1,$2,$3); }
	| expr
	.

comp_op
	= LESS 
	| GREAT
	| EQUAL 
	| 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	{ $$ = lang_python_op::plus($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  suite 
	| CLASS NAME RBO RBC COLON			 suite 
	| CLASS NAME COLON { static::python_class($2); } suite { static::python_class_end(); }
	.
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.