Exemplo n.º 1
0
def p_increment_decrement_identifiers(p):
    """
    expression : identifier DOUBLE_PLUS
               | identifier DOUBLE_MINUS
    """
    if p[2] == "++":
        p[0] = ast.BinaryOperation(p[1], ast.Primitive(1), "+")
    else:
        p[0] = ast.BinaryOperation(p[1], ast.Primitive(1), "-")
Exemplo n.º 2
0
def p_increment_decrement_identifiers(p):
    '''
    expression : identifier DOUBLE_PLUS
               | identifier DOUBLE_MINUS
    '''
    if p[2] == '++':
        p[0] = ast.BinaryOperation(p[1], ast.Primitive(1), '+')
    else:
        p[0] = ast.BinaryOperation(p[1], ast.Primitive(1), '-')
Exemplo n.º 3
0
def p_indexable(p):
    """
    indexable : identifier
              | STRING
              | array
    """
    if isinstance(p[1], ast.BaseExpression):
        p[0] = p[1]
    else:  # we need to handle the strings
        p[0] = ast.Primitive(p[1])
Exemplo n.º 4
0
def p_primitive(p):
    """
    primitive : NUM_INT
              | NUM_FLOAT
              | STRING
              | boolean
    """
    if isinstance(p[1], ast.BaseExpression):
        p[0] = p[1]
    else:
        p[0] = ast.Primitive(p[1])
Exemplo n.º 5
0
def p_for_loop_infinite(p):
    """
    statement : FOR LBRACK statement_list RBRACK
    """
    p[0] = ast.While(ast.Primitive(True), p[3])
Exemplo n.º 6
0
def p_boolean(p):
    """
    boolean : TRUE
            | FALSE
    """
    p[0] = ast.Primitive(p[1])
Exemplo n.º 7
0
def p_paren(p):
    """
    expression : LPAREN expression RPAREN
    """
    p[0] = p[2] if isinstance(p[2], ast.BaseExpression) else ast.Primitive(
        p[2])
Exemplo n.º 8
0
def p_boolean(p):
    '''
    boolean : TRUE
            | FALSE
    '''
    p[0] = ast.Primitive(p[1])