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]
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]
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]
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]
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
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])
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
def p_error(t): print("p_error", t) syntax_error("p_error: Syntax Error", t.lexpos, t.lineno)