示例#1
0
def p_function_heading(t):
    """ function_heading : FUNCTION identifier RETURNS type
		| FUNCTION identifier LPAREN parameter_list RPAREN RETURNS type"""
    if len(t) == 5:
        t[0] = Node("function_head", t[2], t[3])
    else:
        t[0] = Node("function_head", t[2], t[4], t[7])
示例#2
0
def p_procedure_heading(t):
	""" procedure_heading : PROCEDURE identifier 
	| PROCEDURE identifier LPAREN parameter_list RPAREN"""
	
	if len(t) == 3:
		t[0] = Node("procedure_head",t[2])
	else:
		t[0] = Node("procedure_head",t[2],t[4])
示例#3
0
def p_procedure_or_function_call(t):
	""" procedure_or_function_call : identifier LPAREN param_list RPAREN
	| identifier """
	
	if len(t) == 2:
		t[0] = Node("function_call", t[1])
	else:
		t[0] = Node("function_call",t[1],t[3])
示例#4
0
def p_if_statement(t):
	"""if_statement : IF expression THEN statement ELSE statement
	| IF expression THEN statement
	"""
	
	if len(t) == 5:
		t[0] = Node('if',t[2],t[4])
	else:
		t[0] = Node('if',t[2],t[4],t[6])
示例#5
0
def p_expression_s(t):
	""" expression_s : element 
	| expression_s psign element"""
	if len(t) == 2:
		t[0] = t[1]
	else:
		t[0] = Node('op',t[2],t[1],t[3])
示例#6
0
def p_expression_m(t):
	""" expression_m : expression_s
	| expression_m sign expression_s"""
	if len(t) == 2:
		t[0] = t[1]
	else:
		t[0] = Node('op',t[2],t[1],t[3])
示例#7
0
def p_param_list(t):
	""" param_list : param_list COMMA param
	 | param """
	if len(t) == 2:
		t[0] = t[1]
	else:
		t[0] = Node("parameter_list",t[1],t[3])
示例#8
0
def p_statement_sequence(t):
	"""statement_sequence : statement SEMICOLON statement_sequence
	 | statement"""
	if len(t) == 2:
		t[0] = t[1]
	else:
		t[0] = Node('statement_list',t[1],t[3])
示例#9
0
def p_parameter_list(t):
	""" parameter_list : parameter COMMA parameter_list
	| parameter"""
	if len(t) == 4:
		t[0] = Node("parameter_list", t[1], t[3])
	else:
		t[0] = t[1]
示例#10
0
def p_expression(t):
	"""expression : expression and_or expression_m
	| expression_m
	"""
	if len(t) == 2:
		t[0] = t[1]
	else:
		t[0] = Node('op',t[2],t[1],t[3])
示例#11
0
def p_variable_declaration_list(t):
    """variable_declaration_list : variable_declaration variable_declaration_list
	 | variable_declaration
	"""
    if len(t) == 2:
        t[0] = t[1]
    else:
        t[0] = Node('var_list', t[1], t[2])
示例#12
0
def p_element(t):
	"""element : identifier
	| real
	| integer
	| string
	| char
	| LPAREN expression RPAREN
	| NOT element
	| function_call_inline
	"""
	if len(t) == 2:
		t[0] = Node("element",t[1])
	elif len(t) == 3:
		# not e
		t[0] = Node('not',t[2])
	else:
		# ( e )
		t[0] = Node('element',t[2])
示例#13
0
def p_variable_declaration_list(t):
	"""variable_declaration_list : variable_declaration variable_declaration_list
	 | variable_declaration
	"""
	# function and procedure missing here
	if len(t) == 2:
		t[0] = t[1]
	else:
		t[0] = Node('var_list',t[1],t[2])
示例#14
0
def p_sign(t):
    """sign : PLUS
	| MINUS
	| MOD
	| EQ
	| NEQ
	| LT
	| LTE
	| GT
	| GTE
	"""
    t[0] = Node('sign', t[1])
示例#15
0
def p_block(t):
	"""block : variable_declaration_part procedure_or_function statement_part
	"""
	t[0] = Node('block',t[1],t[2],t[3])
示例#16
0
def p_repeat_statement(t):
	"""repeat_statement : REPEAT statement UNTIL expression"""
	t[0] = Node('repeat',t[2],t[4])
示例#17
0
def p_function_declaration(t):
	""" function_declaration : function_heading SEMICOLON block"""
	t[0] = Node('function',t[1],t[3])
示例#18
0
def p_procedure_or_function(t):
	"""procedure_or_function : proc_or_func_declaration SEMICOLON procedure_or_function
		| """
		
	if len(t) == 4:
		t[0] = Node('function_list',t[1],t[3])
示例#19
0
def p_procedure_declaration(t):
	"""procedure_declaration : procedure_heading SEMICOLON block"""
	t[0] = Node("procedure",t[1],t[3])
示例#20
0
def p_for_statement(t):
	"""for_statement : FOR assignment_statement TO expression DO statement
	| FOR assignment_statement DOWNTO expression DO statement
	"""
	t[0] = Node('for',t[2],t[3],t[4],t[6])
示例#21
0
def p_variable_declaration(t):
	"""variable_declaration : identifier COLON type SEMICOLON"""
	t[0] = Node('var',t[1],t[3])
示例#22
0
def p_string(t):
	""" string : STRING """
	t[0] = Node('string',t[1])
示例#23
0
def p_char(t):
	""" char : CHAR """
	t[0] = Node('char',t[1])
示例#24
0
def p_real(t):
	""" real : REAL """
	t[0] = Node('real',t[1])
示例#25
0
def p_integer(t):
	""" integer : INTEGER """
	t[0] = Node('integer',t[1])
示例#26
0
def p_identifier(t):
	""" identifier : IDENTIFIER """
	t[0] = Node('identifier',str(t[1]).lower())
示例#27
0
def p_function_call_inline(t):
	""" function_call_inline : identifier LPAREN param_list RPAREN"""
	t[0] = Node('function_call_inline',t[1],t[3])
示例#28
0
def p_assignment_statement(t):
	"""assignment_statement : identifier ASSIGNMENT expression"""
	t[0] = Node('assign',t[1],t[3])
示例#29
0
def p_and_or(t):
	""" and_or : AND
	| OR """
	t[0] = Node('and_or',t[1])
示例#30
0
def p_psign(t):
	"""psign : TIMES
	| DIVISION"""
	t[0] = Node('sign',t[1])