예제 #1
0
def p_dimension(p):
    '''
    dimension : const_expr
    '''
    if not isinstance(p[1], int):
        syntax_error("Must have integer DIM", p[1].lexpos, p[1].lineno)
    p[0] = p[1]
예제 #2
0
def p_const_bool_expr_uminus(p):
    """
    const_expr : NOT const_expr
    """
    if not isinstance(p[2], bool):
        syntax_error("Must have boolean operand for unary NOT", p[2].lexpos,
                     p[2].lineno)
    p[0] = not p[2]
예제 #3
0
def p_const_numeric_expr_uminus(p):
    """
    const_expr : '-' const_expr               %prec UMINUS
    """
    if not isinstance(p[2], (int, float)):
        syntax_error("Must have numeric operand for unary negate", p[2].lexpos,
                     p[2].lineno)
    p[0] = -p[2]
예제 #4
0
def p_dim(p):
    '''
    vartype : DIM IDENT '[' dimensions ']' newlines
    '''
    var = current_namespace().make_variable(p[2])
    if var.dimensions:
        syntax_error("Duplicate variable DIM declaration", p[2].lexpos,
                     p[2].lineno)
    var.dimensions = p[4]
예제 #5
0
def p_vartype(p):
    '''
    vartype : VAR IDENT IS type newlines
    '''
    var = current_namespace().make_variable(p[2])
    if var.explicit_typedef:
        syntax_error("Duplicate variable type declaration", p[2].lexpos,
                     p[2].lineno)
    var.type = p[4]
    var.explicit_typedef = True
예제 #6
0
def p_const_numeric_expr_binary(p):
    """
    const_expr : const_expr '^' const_expr
               | const_expr '*' const_expr
               | const_expr '/' const_expr
               | const_expr '%' const_expr
               | const_expr '+' const_expr
               | const_expr '-' const_expr
    """
    if not isinstance(p[1], (int, float)):
        syntax_error(f"Must have numeric operand for {p[2]}", p[1].lexpos,
                     p[1].lineno)
    if not isinstance(p[3], (int, float)):
        syntax_error(f"Must have numeric operand for {p[2]}", p[3].lexpos,
                     p[3].lineno)
    p[0] = ops[p[2]](p[1], p[3])
예제 #7
0
def find_module(ref_token, path):
    full_name = _find_module(ref_token.value, path)
    if full_name is None:
        syntax_error(f"module {ref_token.value} not found", ref_token.lexpos,
                     ref_token.lineno, ref_token.filename)
    return full_name
예제 #8
0
def p_error(t):
    print("p_error", t)
    syntax_error("p_error: Syntax Error", t.lexpos, t.lineno)