Пример #1
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])
Пример #2
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])
Пример #3
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])
Пример #4
0
def p_sign(t):
    """sign : PLUS
    | MINUS
    | DIV
    | MOD
    | EQ
    | NEQ
    | LT
    | LTE
    | GT
    | GTE
    """
    t[0] = Node('sign', t[1])
Пример #5
0
def p_real(t):
    """ real : REAL """
    t[0] = Node('real', t[1])
Пример #6
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])
Пример #7
0
def p_identifier(t):
    """ identifier : IDENTIFIER """
    t[0] = Node('identifier', str(t[1]).lower())
Пример #8
0
def p_subrange_type(t):
    """subrange_type : element RANGE element"""
    t[0] = Node('subrange', t[1], t[3])
Пример #9
0
def p_array(t):
    """array : ARRAY LBRACKET base_type RBRACKET OF type"""
    t[0] = Node('type', t[1].lower(), t[3], t[6])
Пример #10
0
def p_block(t):
    """block : variable_declaration_part procedure_or_function statement_part
    """
    t[0] = Node('block', t[1], t[2], t[3])
Пример #11
0
def p_type(t):
    """ type : TREAL 
    | TINTEGER
    | TCHAR
    | TSTRING """
    t[0] = Node('type', t[1].lower())
Пример #12
0
def p_char(t):
    """ char : CHAR """
    t[0] = Node('char', t[1])
Пример #13
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])
Пример #14
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])
Пример #15
0
def p_assignment_statement(t):
    """assignment_statement : identifier ASSIGNMENT expression"""
    t[0] = Node('assign', t[1], 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_while_statement(t):
    """while_statement : WHILE expression DO statement"""
    t[0] = Node('while', t[2], t[4])
Пример #18
0
def p_param(t):
    """ param : expression """
    t[0] = Node("parameter", t[1])
Пример #19
0
def p_integer(t):
    """ integer : INTEGER """
    t[0] = Node('integer', t[1])
Пример #20
0
def p_program_start(t):
    'program : header SEMICOLON block DOT'
    t[0] = Node('program', t[1], t[3])
Пример #21
0
def p_string(t):
    """ string : STRING """
    t[0] = Node('string', t[1])
Пример #22
0
def p_set_type(t):
    """set_type : SET OF base_type"""
    t[0] = Node('type', t[1].lower(), t[3])
Пример #23
0
def p_variable_declaration(t):
    """variable_declaration : identifier COLON type SEMICOLON
    | identifier EQ structured_type SEMICOLON
    | identifier COLON structured_type SEMICOLON
    """
    t[0] = Node('var', t[1], t[3])
Пример #24
0
def p_and_or(t):
    """ and_or : AND
    | OR """
    t[0] = Node('and_or', t[1])
Пример #25
0
def p_procedure_declaration(t):
    """procedure_declaration : procedure_heading SEMICOLON block"""
    t[0] = Node("procedure", t[1], t[3])
Пример #26
0
def p_psign(t):
    """psign : TIMES
    | DIVISION"""
    t[0] = Node('sign', t[1])
Пример #27
0
def p_function_declaration(t):
    """ function_declaration : function_heading SEMICOLON block"""
    t[0] = Node('function', t[1], t[3])
Пример #28
0
def p_parameter(t):
    """ parameter : identifier COLON type"""
    t[0] = Node("parameter", t[1], t[3])