repository_name
stringlengths
5
67
func_path_in_repository
stringlengths
4
234
func_name
stringlengths
0
314
whole_func_string
stringlengths
52
3.87M
language
stringclasses
6 values
func_code_string
stringlengths
52
3.87M
func_code_tokens
sequencelengths
15
672k
func_documentation_string
stringlengths
1
47.2k
func_documentation_tokens
sequencelengths
1
3.92k
split_name
stringclasses
1 value
func_code_url
stringlengths
85
339
boriel/zxbasic
zxbparser.py
p_statement_draw3_attr
def p_statement_draw3_attr(p): """ statement : DRAW attr_list expr COMMA expr COMMA expr """ p[0] = make_sentence('DRAW3', make_typecast(TYPE.integer, p[3], p.lineno(4)), make_typecast(TYPE.integer, p[5], p.lineno(6)), make_typecast(TYPE.float_, p[7], p.lineno(6)), p[2])
python
def p_statement_draw3_attr(p): """ statement : DRAW attr_list expr COMMA expr COMMA expr """ p[0] = make_sentence('DRAW3', make_typecast(TYPE.integer, p[3], p.lineno(4)), make_typecast(TYPE.integer, p[5], p.lineno(6)), make_typecast(TYPE.float_, p[7], p.lineno(6)), p[2])
[ "def", "p_statement_draw3_attr", "(", "p", ")", ":", "p", "[", "0", "]", "=", "make_sentence", "(", "'DRAW3'", ",", "make_typecast", "(", "TYPE", ".", "integer", ",", "p", "[", "3", "]", ",", "p", ".", "lineno", "(", "4", ")", ")", ",", "make_typecast", "(", "TYPE", ".", "integer", ",", "p", "[", "5", "]", ",", "p", ".", "lineno", "(", "6", ")", ")", ",", "make_typecast", "(", "TYPE", ".", "float_", ",", "p", "[", "7", "]", ",", "p", ".", "lineno", "(", "6", ")", ")", ",", "p", "[", "2", "]", ")" ]
statement : DRAW attr_list expr COMMA expr COMMA expr
[ "statement", ":", "DRAW", "attr_list", "expr", "COMMA", "expr", "COMMA", "expr" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L895-L901
boriel/zxbasic
zxbparser.py
p_statement_draw
def p_statement_draw(p): """ statement : DRAW expr COMMA expr """ p[0] = make_sentence('DRAW', make_typecast(TYPE.integer, p[2], p.lineno(3)), make_typecast(TYPE.integer, p[4], p.lineno(3)))
python
def p_statement_draw(p): """ statement : DRAW expr COMMA expr """ p[0] = make_sentence('DRAW', make_typecast(TYPE.integer, p[2], p.lineno(3)), make_typecast(TYPE.integer, p[4], p.lineno(3)))
[ "def", "p_statement_draw", "(", "p", ")", ":", "p", "[", "0", "]", "=", "make_sentence", "(", "'DRAW'", ",", "make_typecast", "(", "TYPE", ".", "integer", ",", "p", "[", "2", "]", ",", "p", ".", "lineno", "(", "3", ")", ")", ",", "make_typecast", "(", "TYPE", ".", "integer", ",", "p", "[", "4", "]", ",", "p", ".", "lineno", "(", "3", ")", ")", ")" ]
statement : DRAW expr COMMA expr
[ "statement", ":", "DRAW", "expr", "COMMA", "expr" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L904-L909
boriel/zxbasic
zxbparser.py
p_statement_draw_attr
def p_statement_draw_attr(p): """ statement : DRAW attr_list expr COMMA expr """ p[0] = make_sentence('DRAW', make_typecast(TYPE.integer, p[3], p.lineno(4)), make_typecast(TYPE.integer, p[5], p.lineno(4)), p[2])
python
def p_statement_draw_attr(p): """ statement : DRAW attr_list expr COMMA expr """ p[0] = make_sentence('DRAW', make_typecast(TYPE.integer, p[3], p.lineno(4)), make_typecast(TYPE.integer, p[5], p.lineno(4)), p[2])
[ "def", "p_statement_draw_attr", "(", "p", ")", ":", "p", "[", "0", "]", "=", "make_sentence", "(", "'DRAW'", ",", "make_typecast", "(", "TYPE", ".", "integer", ",", "p", "[", "3", "]", ",", "p", ".", "lineno", "(", "4", ")", ")", ",", "make_typecast", "(", "TYPE", ".", "integer", ",", "p", "[", "5", "]", ",", "p", ".", "lineno", "(", "4", ")", ")", ",", "p", "[", "2", "]", ")" ]
statement : DRAW attr_list expr COMMA expr
[ "statement", ":", "DRAW", "attr_list", "expr", "COMMA", "expr" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L912-L917
boriel/zxbasic
zxbparser.py
p_statement_circle
def p_statement_circle(p): """ statement : CIRCLE expr COMMA expr COMMA expr """ p[0] = make_sentence('CIRCLE', make_typecast(TYPE.byte_, p[2], p.lineno(3)), make_typecast(TYPE.byte_, p[4], p.lineno(5)), make_typecast(TYPE.byte_, p[6], p.lineno(5)))
python
def p_statement_circle(p): """ statement : CIRCLE expr COMMA expr COMMA expr """ p[0] = make_sentence('CIRCLE', make_typecast(TYPE.byte_, p[2], p.lineno(3)), make_typecast(TYPE.byte_, p[4], p.lineno(5)), make_typecast(TYPE.byte_, p[6], p.lineno(5)))
[ "def", "p_statement_circle", "(", "p", ")", ":", "p", "[", "0", "]", "=", "make_sentence", "(", "'CIRCLE'", ",", "make_typecast", "(", "TYPE", ".", "byte_", ",", "p", "[", "2", "]", ",", "p", ".", "lineno", "(", "3", ")", ")", ",", "make_typecast", "(", "TYPE", ".", "byte_", ",", "p", "[", "4", "]", ",", "p", ".", "lineno", "(", "5", ")", ")", ",", "make_typecast", "(", "TYPE", ".", "byte_", ",", "p", "[", "6", "]", ",", "p", ".", "lineno", "(", "5", ")", ")", ")" ]
statement : CIRCLE expr COMMA expr COMMA expr
[ "statement", ":", "CIRCLE", "expr", "COMMA", "expr", "COMMA", "expr" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L920-L926
boriel/zxbasic
zxbparser.py
p_statement_circle_attr
def p_statement_circle_attr(p): """ statement : CIRCLE attr_list expr COMMA expr COMMA expr """ p[0] = make_sentence('CIRCLE', make_typecast(TYPE.byte_, p[3], p.lineno(4)), make_typecast(TYPE.byte_, p[5], p.lineno(6)), make_typecast(TYPE.byte_, p[7], p.lineno(6)), p[2])
python
def p_statement_circle_attr(p): """ statement : CIRCLE attr_list expr COMMA expr COMMA expr """ p[0] = make_sentence('CIRCLE', make_typecast(TYPE.byte_, p[3], p.lineno(4)), make_typecast(TYPE.byte_, p[5], p.lineno(6)), make_typecast(TYPE.byte_, p[7], p.lineno(6)), p[2])
[ "def", "p_statement_circle_attr", "(", "p", ")", ":", "p", "[", "0", "]", "=", "make_sentence", "(", "'CIRCLE'", ",", "make_typecast", "(", "TYPE", ".", "byte_", ",", "p", "[", "3", "]", ",", "p", ".", "lineno", "(", "4", ")", ")", ",", "make_typecast", "(", "TYPE", ".", "byte_", ",", "p", "[", "5", "]", ",", "p", ".", "lineno", "(", "6", ")", ")", ",", "make_typecast", "(", "TYPE", ".", "byte_", ",", "p", "[", "7", "]", ",", "p", ".", "lineno", "(", "6", ")", ")", ",", "p", "[", "2", "]", ")" ]
statement : CIRCLE attr_list expr COMMA expr COMMA expr
[ "statement", ":", "CIRCLE", "attr_list", "expr", "COMMA", "expr", "COMMA", "expr" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L929-L935
boriel/zxbasic
zxbparser.py
p_statement_randomize
def p_statement_randomize(p): """ statement : RANDOMIZE """ p[0] = make_sentence('RANDOMIZE', make_number(0, lineno=p.lineno(1), type_=TYPE.ulong))
python
def p_statement_randomize(p): """ statement : RANDOMIZE """ p[0] = make_sentence('RANDOMIZE', make_number(0, lineno=p.lineno(1), type_=TYPE.ulong))
[ "def", "p_statement_randomize", "(", "p", ")", ":", "p", "[", "0", "]", "=", "make_sentence", "(", "'RANDOMIZE'", ",", "make_number", "(", "0", ",", "lineno", "=", "p", ".", "lineno", "(", "1", ")", ",", "type_", "=", "TYPE", ".", "ulong", ")", ")" ]
statement : RANDOMIZE
[ "statement", ":", "RANDOMIZE" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L950-L953
boriel/zxbasic
zxbparser.py
p_statement_randomize_expr
def p_statement_randomize_expr(p): """ statement : RANDOMIZE expr """ p[0] = make_sentence('RANDOMIZE', make_typecast(TYPE.ulong, p[2], p.lineno(1)))
python
def p_statement_randomize_expr(p): """ statement : RANDOMIZE expr """ p[0] = make_sentence('RANDOMIZE', make_typecast(TYPE.ulong, p[2], p.lineno(1)))
[ "def", "p_statement_randomize_expr", "(", "p", ")", ":", "p", "[", "0", "]", "=", "make_sentence", "(", "'RANDOMIZE'", ",", "make_typecast", "(", "TYPE", ".", "ulong", ",", "p", "[", "2", "]", ",", "p", ".", "lineno", "(", "1", ")", ")", ")" ]
statement : RANDOMIZE expr
[ "statement", ":", "RANDOMIZE", "expr" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L956-L959
boriel/zxbasic
zxbparser.py
p_statement_beep
def p_statement_beep(p): """ statement : BEEP expr COMMA expr """ p[0] = make_sentence('BEEP', make_typecast(TYPE.float_, p[2], p.lineno(1)), make_typecast(TYPE.float_, p[4], p.lineno(3)))
python
def p_statement_beep(p): """ statement : BEEP expr COMMA expr """ p[0] = make_sentence('BEEP', make_typecast(TYPE.float_, p[2], p.lineno(1)), make_typecast(TYPE.float_, p[4], p.lineno(3)))
[ "def", "p_statement_beep", "(", "p", ")", ":", "p", "[", "0", "]", "=", "make_sentence", "(", "'BEEP'", ",", "make_typecast", "(", "TYPE", ".", "float_", ",", "p", "[", "2", "]", ",", "p", ".", "lineno", "(", "1", ")", ")", ",", "make_typecast", "(", "TYPE", ".", "float_", ",", "p", "[", "4", "]", ",", "p", ".", "lineno", "(", "3", ")", ")", ")" ]
statement : BEEP expr COMMA expr
[ "statement", ":", "BEEP", "expr", "COMMA", "expr" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L962-L966
boriel/zxbasic
zxbparser.py
p_statement_call
def p_statement_call(p): """ statement : ID arg_list | ID arguments | ID """ if len(p) > 2 and p[2] is None: p[0] = None elif len(p) == 2: entry = SYMBOL_TABLE.get_entry(p[1]) if not entry or entry.class_ in (CLASS.label, CLASS.unknown): p[0] = make_label(p[1], p.lineno(1)) else: p[0] = make_sub_call(p[1], p.lineno(1), make_arg_list(None)) else: p[0] = make_sub_call(p[1], p.lineno(1), p[2])
python
def p_statement_call(p): """ statement : ID arg_list | ID arguments | ID """ if len(p) > 2 and p[2] is None: p[0] = None elif len(p) == 2: entry = SYMBOL_TABLE.get_entry(p[1]) if not entry or entry.class_ in (CLASS.label, CLASS.unknown): p[0] = make_label(p[1], p.lineno(1)) else: p[0] = make_sub_call(p[1], p.lineno(1), make_arg_list(None)) else: p[0] = make_sub_call(p[1], p.lineno(1), p[2])
[ "def", "p_statement_call", "(", "p", ")", ":", "if", "len", "(", "p", ")", ">", "2", "and", "p", "[", "2", "]", "is", "None", ":", "p", "[", "0", "]", "=", "None", "elif", "len", "(", "p", ")", "==", "2", ":", "entry", "=", "SYMBOL_TABLE", ".", "get_entry", "(", "p", "[", "1", "]", ")", "if", "not", "entry", "or", "entry", ".", "class_", "in", "(", "CLASS", ".", "label", ",", "CLASS", ".", "unknown", ")", ":", "p", "[", "0", "]", "=", "make_label", "(", "p", "[", "1", "]", ",", "p", ".", "lineno", "(", "1", ")", ")", "else", ":", "p", "[", "0", "]", "=", "make_sub_call", "(", "p", "[", "1", "]", ",", "p", ".", "lineno", "(", "1", ")", ",", "make_arg_list", "(", "None", ")", ")", "else", ":", "p", "[", "0", "]", "=", "make_sub_call", "(", "p", "[", "1", "]", ",", "p", ".", "lineno", "(", "1", ")", ",", "p", "[", "2", "]", ")" ]
statement : ID arg_list | ID arguments | ID
[ "statement", ":", "ID", "arg_list", "|", "ID", "arguments", "|", "ID" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L969-L983
boriel/zxbasic
zxbparser.py
p_assignment
def p_assignment(p): """ statement : lexpr expr """ global LET_ASSIGNMENT LET_ASSIGNMENT = False # Mark we're no longer using LET p[0] = None q = p[1:] i = 1 if q[1] is None: return if isinstance(q[1], symbols.VAR) and q[1].class_ == CLASS.unknown: q[1] = SYMBOL_TABLE.access_var(q[1].name, p.lineno(i)) q1class_ = q[1].class_ if isinstance(q[1], symbols.VAR) else CLASS.unknown variable = SYMBOL_TABLE.access_id(q[0], p.lineno(i), default_type=q[1].type_, default_class=q1class_) if variable is None: return # HINT: This only happens if variable was not declared with DIM and --strict flag is in use if variable.class_ == CLASS.unknown: # The variable is implicit variable.class_ = CLASS.var if variable.class_ not in (CLASS.var, CLASS.array): api.errmsg.syntax_error_cannot_assing_not_a_var(p.lineno(i), variable.name) return if variable.class_ == CLASS.var and q1class_ == CLASS.array: syntax_error(p.lineno(i), 'Cannot assign an array to an scalar variable') return if variable.class_ == CLASS.array: if q1class_ != variable.class_: syntax_error(p.lineno(i), 'Cannot assign an scalar to an array variable') return if q[1].type_ != variable.type_: syntax_error(p.lineno(i), 'Arrays must have the same element type') return if variable.memsize != q[1].memsize: syntax_error(p.lineno(i), "Arrays '%s' and '%s' must have the same size" % (variable.name, q[1].name)) return if variable.count != q[1].count: warning(p.lineno(i), "Arrays '%s' and '%s' don't have the same number of dimensions" % (variable.name, q[1].name)) else: for b1, b2 in zip(variable.bounds, q[1].bounds): if b1.count != b2.count: warning(p.lineno(i), "Arrays '%s' and '%s' don't have the same dimensions" % (variable.name, q[1].name)) break # Array copy p[0] = make_sentence('ARRAYCOPY', variable, q[1]) return expr = make_typecast(variable.type_, q[1], p.lineno(i)) p[0] = make_sentence('LET', variable, expr)
python
def p_assignment(p): """ statement : lexpr expr """ global LET_ASSIGNMENT LET_ASSIGNMENT = False # Mark we're no longer using LET p[0] = None q = p[1:] i = 1 if q[1] is None: return if isinstance(q[1], symbols.VAR) and q[1].class_ == CLASS.unknown: q[1] = SYMBOL_TABLE.access_var(q[1].name, p.lineno(i)) q1class_ = q[1].class_ if isinstance(q[1], symbols.VAR) else CLASS.unknown variable = SYMBOL_TABLE.access_id(q[0], p.lineno(i), default_type=q[1].type_, default_class=q1class_) if variable is None: return # HINT: This only happens if variable was not declared with DIM and --strict flag is in use if variable.class_ == CLASS.unknown: # The variable is implicit variable.class_ = CLASS.var if variable.class_ not in (CLASS.var, CLASS.array): api.errmsg.syntax_error_cannot_assing_not_a_var(p.lineno(i), variable.name) return if variable.class_ == CLASS.var and q1class_ == CLASS.array: syntax_error(p.lineno(i), 'Cannot assign an array to an scalar variable') return if variable.class_ == CLASS.array: if q1class_ != variable.class_: syntax_error(p.lineno(i), 'Cannot assign an scalar to an array variable') return if q[1].type_ != variable.type_: syntax_error(p.lineno(i), 'Arrays must have the same element type') return if variable.memsize != q[1].memsize: syntax_error(p.lineno(i), "Arrays '%s' and '%s' must have the same size" % (variable.name, q[1].name)) return if variable.count != q[1].count: warning(p.lineno(i), "Arrays '%s' and '%s' don't have the same number of dimensions" % (variable.name, q[1].name)) else: for b1, b2 in zip(variable.bounds, q[1].bounds): if b1.count != b2.count: warning(p.lineno(i), "Arrays '%s' and '%s' don't have the same dimensions" % (variable.name, q[1].name)) break # Array copy p[0] = make_sentence('ARRAYCOPY', variable, q[1]) return expr = make_typecast(variable.type_, q[1], p.lineno(i)) p[0] = make_sentence('LET', variable, expr)
[ "def", "p_assignment", "(", "p", ")", ":", "global", "LET_ASSIGNMENT", "LET_ASSIGNMENT", "=", "False", "# Mark we're no longer using LET", "p", "[", "0", "]", "=", "None", "q", "=", "p", "[", "1", ":", "]", "i", "=", "1", "if", "q", "[", "1", "]", "is", "None", ":", "return", "if", "isinstance", "(", "q", "[", "1", "]", ",", "symbols", ".", "VAR", ")", "and", "q", "[", "1", "]", ".", "class_", "==", "CLASS", ".", "unknown", ":", "q", "[", "1", "]", "=", "SYMBOL_TABLE", ".", "access_var", "(", "q", "[", "1", "]", ".", "name", ",", "p", ".", "lineno", "(", "i", ")", ")", "q1class_", "=", "q", "[", "1", "]", ".", "class_", "if", "isinstance", "(", "q", "[", "1", "]", ",", "symbols", ".", "VAR", ")", "else", "CLASS", ".", "unknown", "variable", "=", "SYMBOL_TABLE", ".", "access_id", "(", "q", "[", "0", "]", ",", "p", ".", "lineno", "(", "i", ")", ",", "default_type", "=", "q", "[", "1", "]", ".", "type_", ",", "default_class", "=", "q1class_", ")", "if", "variable", "is", "None", ":", "return", "# HINT: This only happens if variable was not declared with DIM and --strict flag is in use", "if", "variable", ".", "class_", "==", "CLASS", ".", "unknown", ":", "# The variable is implicit", "variable", ".", "class_", "=", "CLASS", ".", "var", "if", "variable", ".", "class_", "not", "in", "(", "CLASS", ".", "var", ",", "CLASS", ".", "array", ")", ":", "api", ".", "errmsg", ".", "syntax_error_cannot_assing_not_a_var", "(", "p", ".", "lineno", "(", "i", ")", ",", "variable", ".", "name", ")", "return", "if", "variable", ".", "class_", "==", "CLASS", ".", "var", "and", "q1class_", "==", "CLASS", ".", "array", ":", "syntax_error", "(", "p", ".", "lineno", "(", "i", ")", ",", "'Cannot assign an array to an scalar variable'", ")", "return", "if", "variable", ".", "class_", "==", "CLASS", ".", "array", ":", "if", "q1class_", "!=", "variable", ".", "class_", ":", "syntax_error", "(", "p", ".", "lineno", "(", "i", ")", ",", "'Cannot assign an scalar to an array variable'", ")", "return", "if", "q", "[", "1", "]", ".", "type_", "!=", "variable", ".", "type_", ":", "syntax_error", "(", "p", ".", "lineno", "(", "i", ")", ",", "'Arrays must have the same element type'", ")", "return", "if", "variable", ".", "memsize", "!=", "q", "[", "1", "]", ".", "memsize", ":", "syntax_error", "(", "p", ".", "lineno", "(", "i", ")", ",", "\"Arrays '%s' and '%s' must have the same size\"", "%", "(", "variable", ".", "name", ",", "q", "[", "1", "]", ".", "name", ")", ")", "return", "if", "variable", ".", "count", "!=", "q", "[", "1", "]", ".", "count", ":", "warning", "(", "p", ".", "lineno", "(", "i", ")", ",", "\"Arrays '%s' and '%s' don't have the same number of dimensions\"", "%", "(", "variable", ".", "name", ",", "q", "[", "1", "]", ".", "name", ")", ")", "else", ":", "for", "b1", ",", "b2", "in", "zip", "(", "variable", ".", "bounds", ",", "q", "[", "1", "]", ".", "bounds", ")", ":", "if", "b1", ".", "count", "!=", "b2", ".", "count", ":", "warning", "(", "p", ".", "lineno", "(", "i", ")", ",", "\"Arrays '%s' and '%s' don't have the same dimensions\"", "%", "(", "variable", ".", "name", ",", "q", "[", "1", "]", ".", "name", ")", ")", "break", "# Array copy", "p", "[", "0", "]", "=", "make_sentence", "(", "'ARRAYCOPY'", ",", "variable", ",", "q", "[", "1", "]", ")", "return", "expr", "=", "make_typecast", "(", "variable", ".", "type_", ",", "q", "[", "1", "]", ",", "p", ".", "lineno", "(", "i", ")", ")", "p", "[", "0", "]", "=", "make_sentence", "(", "'LET'", ",", "variable", ",", "expr", ")" ]
statement : lexpr expr
[ "statement", ":", "lexpr", "expr" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L986-L1046
boriel/zxbasic
zxbparser.py
p_lexpr
def p_lexpr(p): """ lexpr : ID EQ | LET ID EQ | ARRAY_ID EQ | LET ARRAY_ID EQ """ global LET_ASSIGNMENT LET_ASSIGNMENT = True # Mark we're about to start a LET sentence if p[1] == 'LET': p[0] = p[2] i = 2 else: p[0] = p[1] i = 1 SYMBOL_TABLE.access_id(p[i], p.lineno(i))
python
def p_lexpr(p): """ lexpr : ID EQ | LET ID EQ | ARRAY_ID EQ | LET ARRAY_ID EQ """ global LET_ASSIGNMENT LET_ASSIGNMENT = True # Mark we're about to start a LET sentence if p[1] == 'LET': p[0] = p[2] i = 2 else: p[0] = p[1] i = 1 SYMBOL_TABLE.access_id(p[i], p.lineno(i))
[ "def", "p_lexpr", "(", "p", ")", ":", "global", "LET_ASSIGNMENT", "LET_ASSIGNMENT", "=", "True", "# Mark we're about to start a LET sentence", "if", "p", "[", "1", "]", "==", "'LET'", ":", "p", "[", "0", "]", "=", "p", "[", "2", "]", "i", "=", "2", "else", ":", "p", "[", "0", "]", "=", "p", "[", "1", "]", "i", "=", "1", "SYMBOL_TABLE", ".", "access_id", "(", "p", "[", "i", "]", ",", "p", ".", "lineno", "(", "i", ")", ")" ]
lexpr : ID EQ | LET ID EQ | ARRAY_ID EQ | LET ARRAY_ID EQ
[ "lexpr", ":", "ID", "EQ", "|", "LET", "ID", "EQ", "|", "ARRAY_ID", "EQ", "|", "LET", "ARRAY_ID", "EQ" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L1049-L1066
boriel/zxbasic
zxbparser.py
p_arr_assignment
def p_arr_assignment(p): """ statement : ARRAY_ID arg_list EQ expr | LET ARRAY_ID arg_list EQ expr """ i = 2 if p[1].upper() == 'LET' else 1 id_ = p[i] arg_list = p[i + 1] expr = p[i + 3] p[0] = None if arg_list is None or expr is None: return # There were errors entry = SYMBOL_TABLE.access_call(id_, p.lineno(i)) if entry is None: return if entry.type_ == TYPE.string: variable = gl.SYMBOL_TABLE.access_array(id_, p.lineno(i)) if len(variable.bounds) + 1 == len(arg_list): ss = arg_list.children.pop().value p[0] = make_array_substr_assign(p.lineno(i), id_, arg_list, (ss, ss), expr) return arr = make_array_access(id_, p.lineno(i), arg_list) if arr is None: return expr = make_typecast(arr.type_, expr, p.lineno(i)) if entry is None: return p[0] = make_sentence('LETARRAY', arr, expr)
python
def p_arr_assignment(p): """ statement : ARRAY_ID arg_list EQ expr | LET ARRAY_ID arg_list EQ expr """ i = 2 if p[1].upper() == 'LET' else 1 id_ = p[i] arg_list = p[i + 1] expr = p[i + 3] p[0] = None if arg_list is None or expr is None: return # There were errors entry = SYMBOL_TABLE.access_call(id_, p.lineno(i)) if entry is None: return if entry.type_ == TYPE.string: variable = gl.SYMBOL_TABLE.access_array(id_, p.lineno(i)) if len(variable.bounds) + 1 == len(arg_list): ss = arg_list.children.pop().value p[0] = make_array_substr_assign(p.lineno(i), id_, arg_list, (ss, ss), expr) return arr = make_array_access(id_, p.lineno(i), arg_list) if arr is None: return expr = make_typecast(arr.type_, expr, p.lineno(i)) if entry is None: return p[0] = make_sentence('LETARRAY', arr, expr)
[ "def", "p_arr_assignment", "(", "p", ")", ":", "i", "=", "2", "if", "p", "[", "1", "]", ".", "upper", "(", ")", "==", "'LET'", "else", "1", "id_", "=", "p", "[", "i", "]", "arg_list", "=", "p", "[", "i", "+", "1", "]", "expr", "=", "p", "[", "i", "+", "3", "]", "p", "[", "0", "]", "=", "None", "if", "arg_list", "is", "None", "or", "expr", "is", "None", ":", "return", "# There were errors", "entry", "=", "SYMBOL_TABLE", ".", "access_call", "(", "id_", ",", "p", ".", "lineno", "(", "i", ")", ")", "if", "entry", "is", "None", ":", "return", "if", "entry", ".", "type_", "==", "TYPE", ".", "string", ":", "variable", "=", "gl", ".", "SYMBOL_TABLE", ".", "access_array", "(", "id_", ",", "p", ".", "lineno", "(", "i", ")", ")", "if", "len", "(", "variable", ".", "bounds", ")", "+", "1", "==", "len", "(", "arg_list", ")", ":", "ss", "=", "arg_list", ".", "children", ".", "pop", "(", ")", ".", "value", "p", "[", "0", "]", "=", "make_array_substr_assign", "(", "p", ".", "lineno", "(", "i", ")", ",", "id_", ",", "arg_list", ",", "(", "ss", ",", "ss", ")", ",", "expr", ")", "return", "arr", "=", "make_array_access", "(", "id_", ",", "p", ".", "lineno", "(", "i", ")", ",", "arg_list", ")", "if", "arr", "is", "None", ":", "return", "expr", "=", "make_typecast", "(", "arr", ".", "type_", ",", "expr", ",", "p", ".", "lineno", "(", "i", ")", ")", "if", "entry", "is", "None", ":", "return", "p", "[", "0", "]", "=", "make_sentence", "(", "'LETARRAY'", ",", "arr", ",", "expr", ")" ]
statement : ARRAY_ID arg_list EQ expr | LET ARRAY_ID arg_list EQ expr
[ "statement", ":", "ARRAY_ID", "arg_list", "EQ", "expr", "|", "LET", "ARRAY_ID", "arg_list", "EQ", "expr" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L1069-L1101
boriel/zxbasic
zxbparser.py
p_substr_assignment_no_let
def p_substr_assignment_no_let(p): """ statement : ID LP expr RP EQ expr """ # This can be only a substr assignment like a$(i + 3) = ".", since arrays # have ARRAY_ID already entry = SYMBOL_TABLE.access_call(p[1], p.lineno(1)) if entry is None: return if entry.class_ == CLASS.unknown: entry.class_ = CLASS.var if p[6].type_ != TYPE.string: api.errmsg.syntax_error_expected_string(p.lineno(5), p[6].type_) lineno = p.lineno(2) base = make_number(OPTIONS.string_base.value, lineno, _TYPE(gl.STR_INDEX_TYPE)) substr = make_typecast(_TYPE(gl.STR_INDEX_TYPE), p[3], lineno) p[0] = make_sentence('LETSUBSTR', entry, make_binary(lineno, 'MINUS', substr, base, func=lambda x, y: x - y), make_binary(lineno, 'MINUS', substr, base, func=lambda x, y: x - y), p[6])
python
def p_substr_assignment_no_let(p): """ statement : ID LP expr RP EQ expr """ # This can be only a substr assignment like a$(i + 3) = ".", since arrays # have ARRAY_ID already entry = SYMBOL_TABLE.access_call(p[1], p.lineno(1)) if entry is None: return if entry.class_ == CLASS.unknown: entry.class_ = CLASS.var if p[6].type_ != TYPE.string: api.errmsg.syntax_error_expected_string(p.lineno(5), p[6].type_) lineno = p.lineno(2) base = make_number(OPTIONS.string_base.value, lineno, _TYPE(gl.STR_INDEX_TYPE)) substr = make_typecast(_TYPE(gl.STR_INDEX_TYPE), p[3], lineno) p[0] = make_sentence('LETSUBSTR', entry, make_binary(lineno, 'MINUS', substr, base, func=lambda x, y: x - y), make_binary(lineno, 'MINUS', substr, base, func=lambda x, y: x - y), p[6])
[ "def", "p_substr_assignment_no_let", "(", "p", ")", ":", "# This can be only a substr assignment like a$(i + 3) = \".\", since arrays", "# have ARRAY_ID already", "entry", "=", "SYMBOL_TABLE", ".", "access_call", "(", "p", "[", "1", "]", ",", "p", ".", "lineno", "(", "1", ")", ")", "if", "entry", "is", "None", ":", "return", "if", "entry", ".", "class_", "==", "CLASS", ".", "unknown", ":", "entry", ".", "class_", "=", "CLASS", ".", "var", "if", "p", "[", "6", "]", ".", "type_", "!=", "TYPE", ".", "string", ":", "api", ".", "errmsg", ".", "syntax_error_expected_string", "(", "p", ".", "lineno", "(", "5", ")", ",", "p", "[", "6", "]", ".", "type_", ")", "lineno", "=", "p", ".", "lineno", "(", "2", ")", "base", "=", "make_number", "(", "OPTIONS", ".", "string_base", ".", "value", ",", "lineno", ",", "_TYPE", "(", "gl", ".", "STR_INDEX_TYPE", ")", ")", "substr", "=", "make_typecast", "(", "_TYPE", "(", "gl", ".", "STR_INDEX_TYPE", ")", ",", "p", "[", "3", "]", ",", "lineno", ")", "p", "[", "0", "]", "=", "make_sentence", "(", "'LETSUBSTR'", ",", "entry", ",", "make_binary", "(", "lineno", ",", "'MINUS'", ",", "substr", ",", "base", ",", "func", "=", "lambda", "x", ",", "y", ":", "x", "-", "y", ")", ",", "make_binary", "(", "lineno", ",", "'MINUS'", ",", "substr", ",", "base", ",", "func", "=", "lambda", "x", ",", "y", ":", "x", "-", "y", ")", ",", "p", "[", "6", "]", ")" ]
statement : ID LP expr RP EQ expr
[ "statement", ":", "ID", "LP", "expr", "RP", "EQ", "expr" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L1104-L1125
boriel/zxbasic
zxbparser.py
p_substr_assignment
def p_substr_assignment(p): """ statement : LET ID arg_list EQ expr """ if p[3] is None or p[5] is None: return # There were errors p[0] = None entry = SYMBOL_TABLE.access_call(p[2], p.lineno(2)) if entry is None: return if entry.class_ == CLASS.unknown: entry.class_ = CLASS.var assert entry.class_ == CLASS.var and entry.type_ == TYPE.string if p[5].type_ != TYPE.string: api.errmsg.syntax_error_expected_string(p.lineno(4), p[5].type_) if len(p[3]) > 1: syntax_error(p.lineno(2), "Accessing string with too many indexes. Expected only one.") return if len(p[3]) == 1: substr = ( make_typecast(_TYPE(gl.STR_INDEX_TYPE), p[3][0].value, p.lineno(2)), make_typecast(_TYPE(gl.STR_INDEX_TYPE), p[3][0].value, p.lineno(2))) else: substr = (make_typecast(_TYPE(gl.STR_INDEX_TYPE), make_number(gl.MIN_STRSLICE_IDX, lineno=p.lineno(2)), p.lineno(2)), make_typecast(_TYPE(gl.STR_INDEX_TYPE), make_number(gl.MAX_STRSLICE_IDX, lineno=p.lineno(2)), p.lineno(2))) lineno = p.lineno(2) base = make_number(OPTIONS.string_base.value, lineno, _TYPE(gl.STR_INDEX_TYPE)) p[0] = make_sentence('LETSUBSTR', entry, make_binary(lineno, 'MINUS', substr[0], base, func=lambda x, y: x - y), make_binary(lineno, 'MINUS', substr[1], base, func=lambda x, y: x - y), p[5])
python
def p_substr_assignment(p): """ statement : LET ID arg_list EQ expr """ if p[3] is None or p[5] is None: return # There were errors p[0] = None entry = SYMBOL_TABLE.access_call(p[2], p.lineno(2)) if entry is None: return if entry.class_ == CLASS.unknown: entry.class_ = CLASS.var assert entry.class_ == CLASS.var and entry.type_ == TYPE.string if p[5].type_ != TYPE.string: api.errmsg.syntax_error_expected_string(p.lineno(4), p[5].type_) if len(p[3]) > 1: syntax_error(p.lineno(2), "Accessing string with too many indexes. Expected only one.") return if len(p[3]) == 1: substr = ( make_typecast(_TYPE(gl.STR_INDEX_TYPE), p[3][0].value, p.lineno(2)), make_typecast(_TYPE(gl.STR_INDEX_TYPE), p[3][0].value, p.lineno(2))) else: substr = (make_typecast(_TYPE(gl.STR_INDEX_TYPE), make_number(gl.MIN_STRSLICE_IDX, lineno=p.lineno(2)), p.lineno(2)), make_typecast(_TYPE(gl.STR_INDEX_TYPE), make_number(gl.MAX_STRSLICE_IDX, lineno=p.lineno(2)), p.lineno(2))) lineno = p.lineno(2) base = make_number(OPTIONS.string_base.value, lineno, _TYPE(gl.STR_INDEX_TYPE)) p[0] = make_sentence('LETSUBSTR', entry, make_binary(lineno, 'MINUS', substr[0], base, func=lambda x, y: x - y), make_binary(lineno, 'MINUS', substr[1], base, func=lambda x, y: x - y), p[5])
[ "def", "p_substr_assignment", "(", "p", ")", ":", "if", "p", "[", "3", "]", "is", "None", "or", "p", "[", "5", "]", "is", "None", ":", "return", "# There were errors", "p", "[", "0", "]", "=", "None", "entry", "=", "SYMBOL_TABLE", ".", "access_call", "(", "p", "[", "2", "]", ",", "p", ".", "lineno", "(", "2", ")", ")", "if", "entry", "is", "None", ":", "return", "if", "entry", ".", "class_", "==", "CLASS", ".", "unknown", ":", "entry", ".", "class_", "=", "CLASS", ".", "var", "assert", "entry", ".", "class_", "==", "CLASS", ".", "var", "and", "entry", ".", "type_", "==", "TYPE", ".", "string", "if", "p", "[", "5", "]", ".", "type_", "!=", "TYPE", ".", "string", ":", "api", ".", "errmsg", ".", "syntax_error_expected_string", "(", "p", ".", "lineno", "(", "4", ")", ",", "p", "[", "5", "]", ".", "type_", ")", "if", "len", "(", "p", "[", "3", "]", ")", ">", "1", ":", "syntax_error", "(", "p", ".", "lineno", "(", "2", ")", ",", "\"Accessing string with too many indexes. Expected only one.\"", ")", "return", "if", "len", "(", "p", "[", "3", "]", ")", "==", "1", ":", "substr", "=", "(", "make_typecast", "(", "_TYPE", "(", "gl", ".", "STR_INDEX_TYPE", ")", ",", "p", "[", "3", "]", "[", "0", "]", ".", "value", ",", "p", ".", "lineno", "(", "2", ")", ")", ",", "make_typecast", "(", "_TYPE", "(", "gl", ".", "STR_INDEX_TYPE", ")", ",", "p", "[", "3", "]", "[", "0", "]", ".", "value", ",", "p", ".", "lineno", "(", "2", ")", ")", ")", "else", ":", "substr", "=", "(", "make_typecast", "(", "_TYPE", "(", "gl", ".", "STR_INDEX_TYPE", ")", ",", "make_number", "(", "gl", ".", "MIN_STRSLICE_IDX", ",", "lineno", "=", "p", ".", "lineno", "(", "2", ")", ")", ",", "p", ".", "lineno", "(", "2", ")", ")", ",", "make_typecast", "(", "_TYPE", "(", "gl", ".", "STR_INDEX_TYPE", ")", ",", "make_number", "(", "gl", ".", "MAX_STRSLICE_IDX", ",", "lineno", "=", "p", ".", "lineno", "(", "2", ")", ")", ",", "p", ".", "lineno", "(", "2", ")", ")", ")", "lineno", "=", "p", ".", "lineno", "(", "2", ")", "base", "=", "make_number", "(", "OPTIONS", ".", "string_base", ".", "value", ",", "lineno", ",", "_TYPE", "(", "gl", ".", "STR_INDEX_TYPE", ")", ")", "p", "[", "0", "]", "=", "make_sentence", "(", "'LETSUBSTR'", ",", "entry", ",", "make_binary", "(", "lineno", ",", "'MINUS'", ",", "substr", "[", "0", "]", ",", "base", ",", "func", "=", "lambda", "x", ",", "y", ":", "x", "-", "y", ")", ",", "make_binary", "(", "lineno", ",", "'MINUS'", ",", "substr", "[", "1", "]", ",", "base", ",", "func", "=", "lambda", "x", ",", "y", ":", "x", "-", "y", ")", ",", "p", "[", "5", "]", ")" ]
statement : LET ID arg_list EQ expr
[ "statement", ":", "LET", "ID", "arg_list", "EQ", "expr" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L1128-L1170
boriel/zxbasic
zxbparser.py
p_str_assign
def p_str_assign(p): """ statement : ID substr EQ expr | LET ID substr EQ expr """ if p[1].upper() != 'LET': q = p[1] r = p[4] s = p[2] lineno = p.lineno(3) else: q = p[2] r = p[5] s = p[3] lineno = p.lineno(4) if q is None or s is None: p[0] = None return if r.type_ != TYPE.string: api.errmsg.syntax_error_expected_string(lineno, r.type_) entry = SYMBOL_TABLE.access_var(q, lineno, default_type=TYPE.string) if entry is None: p[0] = None return p[0] = make_sentence('LETSUBSTR', entry, s[0], s[1], r)
python
def p_str_assign(p): """ statement : ID substr EQ expr | LET ID substr EQ expr """ if p[1].upper() != 'LET': q = p[1] r = p[4] s = p[2] lineno = p.lineno(3) else: q = p[2] r = p[5] s = p[3] lineno = p.lineno(4) if q is None or s is None: p[0] = None return if r.type_ != TYPE.string: api.errmsg.syntax_error_expected_string(lineno, r.type_) entry = SYMBOL_TABLE.access_var(q, lineno, default_type=TYPE.string) if entry is None: p[0] = None return p[0] = make_sentence('LETSUBSTR', entry, s[0], s[1], r)
[ "def", "p_str_assign", "(", "p", ")", ":", "if", "p", "[", "1", "]", ".", "upper", "(", ")", "!=", "'LET'", ":", "q", "=", "p", "[", "1", "]", "r", "=", "p", "[", "4", "]", "s", "=", "p", "[", "2", "]", "lineno", "=", "p", ".", "lineno", "(", "3", ")", "else", ":", "q", "=", "p", "[", "2", "]", "r", "=", "p", "[", "5", "]", "s", "=", "p", "[", "3", "]", "lineno", "=", "p", ".", "lineno", "(", "4", ")", "if", "q", "is", "None", "or", "s", "is", "None", ":", "p", "[", "0", "]", "=", "None", "return", "if", "r", ".", "type_", "!=", "TYPE", ".", "string", ":", "api", ".", "errmsg", ".", "syntax_error_expected_string", "(", "lineno", ",", "r", ".", "type_", ")", "entry", "=", "SYMBOL_TABLE", ".", "access_var", "(", "q", ",", "lineno", ",", "default_type", "=", "TYPE", ".", "string", ")", "if", "entry", "is", "None", ":", "p", "[", "0", "]", "=", "None", "return", "p", "[", "0", "]", "=", "make_sentence", "(", "'LETSUBSTR'", ",", "entry", ",", "s", "[", "0", "]", ",", "s", "[", "1", "]", ",", "r", ")" ]
statement : ID substr EQ expr | LET ID substr EQ expr
[ "statement", ":", "ID", "substr", "EQ", "expr", "|", "LET", "ID", "substr", "EQ", "expr" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L1173-L1200
boriel/zxbasic
zxbparser.py
p_goto
def p_goto(p): """ statement : goto NUMBER | goto ID """ entry = check_and_make_label(p[2], p.lineno(2)) if entry is not None: p[0] = make_sentence(p[1].upper(), entry) else: p[0] = None
python
def p_goto(p): """ statement : goto NUMBER | goto ID """ entry = check_and_make_label(p[2], p.lineno(2)) if entry is not None: p[0] = make_sentence(p[1].upper(), entry) else: p[0] = None
[ "def", "p_goto", "(", "p", ")", ":", "entry", "=", "check_and_make_label", "(", "p", "[", "2", "]", ",", "p", ".", "lineno", "(", "2", ")", ")", "if", "entry", "is", "not", "None", ":", "p", "[", "0", "]", "=", "make_sentence", "(", "p", "[", "1", "]", ".", "upper", "(", ")", ",", "entry", ")", "else", ":", "p", "[", "0", "]", "=", "None" ]
statement : goto NUMBER | goto ID
[ "statement", ":", "goto", "NUMBER", "|", "goto", "ID" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L1203-L1211
boriel/zxbasic
zxbparser.py
p_if_sentence
def p_if_sentence(p): """ statement : if_then_part NEWLINE program_co endif | if_then_part NEWLINE endif | if_then_part NEWLINE statements_co endif | if_then_part NEWLINE co_statements_co endif | if_then_part NEWLINE LABEL statements_co endif """ cond_ = p[1] if len(p) == 6: lbl = make_label(p[3], p.lineno(3)) stat_ = make_block(lbl, p[4]) endif_ = p[5] elif len(p) == 5: stat_ = p[3] endif_ = p[4] else: stat_ = make_nop() endif_ = p[3] p[0] = make_sentence('IF', cond_, make_block(stat_, endif_), lineno=p.lineno(2))
python
def p_if_sentence(p): """ statement : if_then_part NEWLINE program_co endif | if_then_part NEWLINE endif | if_then_part NEWLINE statements_co endif | if_then_part NEWLINE co_statements_co endif | if_then_part NEWLINE LABEL statements_co endif """ cond_ = p[1] if len(p) == 6: lbl = make_label(p[3], p.lineno(3)) stat_ = make_block(lbl, p[4]) endif_ = p[5] elif len(p) == 5: stat_ = p[3] endif_ = p[4] else: stat_ = make_nop() endif_ = p[3] p[0] = make_sentence('IF', cond_, make_block(stat_, endif_), lineno=p.lineno(2))
[ "def", "p_if_sentence", "(", "p", ")", ":", "cond_", "=", "p", "[", "1", "]", "if", "len", "(", "p", ")", "==", "6", ":", "lbl", "=", "make_label", "(", "p", "[", "3", "]", ",", "p", ".", "lineno", "(", "3", ")", ")", "stat_", "=", "make_block", "(", "lbl", ",", "p", "[", "4", "]", ")", "endif_", "=", "p", "[", "5", "]", "elif", "len", "(", "p", ")", "==", "5", ":", "stat_", "=", "p", "[", "3", "]", "endif_", "=", "p", "[", "4", "]", "else", ":", "stat_", "=", "make_nop", "(", ")", "endif_", "=", "p", "[", "3", "]", "p", "[", "0", "]", "=", "make_sentence", "(", "'IF'", ",", "cond_", ",", "make_block", "(", "stat_", ",", "endif_", ")", ",", "lineno", "=", "p", ".", "lineno", "(", "2", ")", ")" ]
statement : if_then_part NEWLINE program_co endif | if_then_part NEWLINE endif | if_then_part NEWLINE statements_co endif | if_then_part NEWLINE co_statements_co endif | if_then_part NEWLINE LABEL statements_co endif
[ "statement", ":", "if_then_part", "NEWLINE", "program_co", "endif", "|", "if_then_part", "NEWLINE", "endif", "|", "if_then_part", "NEWLINE", "statements_co", "endif", "|", "if_then_part", "NEWLINE", "co_statements_co", "endif", "|", "if_then_part", "NEWLINE", "LABEL", "statements_co", "endif" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L1226-L1245
boriel/zxbasic
zxbparser.py
p_statement_if_then_endif
def p_statement_if_then_endif(p): """ statement : if_then_part statements_co endif | if_then_part co_statements_co endif """ cond_ = p[1] stat_ = p[2] endif_ = p[3] p[0] = make_sentence('IF', cond_, make_block(stat_, endif_), lineno=p.lineno(1))
python
def p_statement_if_then_endif(p): """ statement : if_then_part statements_co endif | if_then_part co_statements_co endif """ cond_ = p[1] stat_ = p[2] endif_ = p[3] p[0] = make_sentence('IF', cond_, make_block(stat_, endif_), lineno=p.lineno(1))
[ "def", "p_statement_if_then_endif", "(", "p", ")", ":", "cond_", "=", "p", "[", "1", "]", "stat_", "=", "p", "[", "2", "]", "endif_", "=", "p", "[", "3", "]", "p", "[", "0", "]", "=", "make_sentence", "(", "'IF'", ",", "cond_", ",", "make_block", "(", "stat_", ",", "endif_", ")", ",", "lineno", "=", "p", ".", "lineno", "(", "1", ")", ")" ]
statement : if_then_part statements_co endif | if_then_part co_statements_co endif
[ "statement", ":", "if_then_part", "statements_co", "endif", "|", "if_then_part", "co_statements_co", "endif" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L1263-L1270
boriel/zxbasic
zxbparser.py
p_single_line_if
def p_single_line_if(p): """ if_inline : if_then_part statements %prec ID | if_then_part co_statements_co %prec NEWLINE | if_then_part statements_co %prec NEWLINE | if_then_part co_statements %prec ID """ cond_ = p[1] stat_ = p[2] p[0] = make_sentence('IF', cond_, stat_, lineno=p.lineno(1))
python
def p_single_line_if(p): """ if_inline : if_then_part statements %prec ID | if_then_part co_statements_co %prec NEWLINE | if_then_part statements_co %prec NEWLINE | if_then_part co_statements %prec ID """ cond_ = p[1] stat_ = p[2] p[0] = make_sentence('IF', cond_, stat_, lineno=p.lineno(1))
[ "def", "p_single_line_if", "(", "p", ")", ":", "cond_", "=", "p", "[", "1", "]", "stat_", "=", "p", "[", "2", "]", "p", "[", "0", "]", "=", "make_sentence", "(", "'IF'", ",", "cond_", ",", "stat_", ",", "lineno", "=", "p", ".", "lineno", "(", "1", ")", ")" ]
if_inline : if_then_part statements %prec ID | if_then_part co_statements_co %prec NEWLINE | if_then_part statements_co %prec NEWLINE | if_then_part co_statements %prec ID
[ "if_inline", ":", "if_then_part", "statements", "%prec", "ID", "|", "if_then_part", "co_statements_co", "%prec", "NEWLINE", "|", "if_then_part", "statements_co", "%prec", "NEWLINE", "|", "if_then_part", "co_statements", "%prec", "ID" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L1273-L1281
boriel/zxbasic
zxbparser.py
p_if_elseif
def p_if_elseif(p): """ statement : if_then_part NEWLINE program_co elseiflist | if_then_part NEWLINE elseiflist """ cond_ = p[1] stats_ = p[3] if len(p) == 5 else make_nop() eliflist = p[4] if len(p) == 5 else p[3] p[0] = make_sentence('IF', cond_, stats_, eliflist, lineno=p.lineno(2))
python
def p_if_elseif(p): """ statement : if_then_part NEWLINE program_co elseiflist | if_then_part NEWLINE elseiflist """ cond_ = p[1] stats_ = p[3] if len(p) == 5 else make_nop() eliflist = p[4] if len(p) == 5 else p[3] p[0] = make_sentence('IF', cond_, stats_, eliflist, lineno=p.lineno(2))
[ "def", "p_if_elseif", "(", "p", ")", ":", "cond_", "=", "p", "[", "1", "]", "stats_", "=", "p", "[", "3", "]", "if", "len", "(", "p", ")", "==", "5", "else", "make_nop", "(", ")", "eliflist", "=", "p", "[", "4", "]", "if", "len", "(", "p", ")", "==", "5", "else", "p", "[", "3", "]", "p", "[", "0", "]", "=", "make_sentence", "(", "'IF'", ",", "cond_", ",", "stats_", ",", "eliflist", ",", "lineno", "=", "p", ".", "lineno", "(", "2", ")", ")" ]
statement : if_then_part NEWLINE program_co elseiflist | if_then_part NEWLINE elseiflist
[ "statement", ":", "if_then_part", "NEWLINE", "program_co", "elseiflist", "|", "if_then_part", "NEWLINE", "elseiflist" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L1284-L1291
boriel/zxbasic
zxbparser.py
p_elseif_part
def p_elseif_part(p): """ elseif_expr : ELSEIF expr then | LABEL ELSEIF expr then """ if p[1] == 'ELSEIF': label_ = make_nop() # No label cond_ = p[2] else: label_ = make_label(p[1], p.lineno(1)) cond_ = p[3] p[0] = label_, cond_
python
def p_elseif_part(p): """ elseif_expr : ELSEIF expr then | LABEL ELSEIF expr then """ if p[1] == 'ELSEIF': label_ = make_nop() # No label cond_ = p[2] else: label_ = make_label(p[1], p.lineno(1)) cond_ = p[3] p[0] = label_, cond_
[ "def", "p_elseif_part", "(", "p", ")", ":", "if", "p", "[", "1", "]", "==", "'ELSEIF'", ":", "label_", "=", "make_nop", "(", ")", "# No label", "cond_", "=", "p", "[", "2", "]", "else", ":", "label_", "=", "make_label", "(", "p", "[", "1", "]", ",", "p", ".", "lineno", "(", "1", ")", ")", "cond_", "=", "p", "[", "3", "]", "p", "[", "0", "]", "=", "label_", ",", "cond_" ]
elseif_expr : ELSEIF expr then | LABEL ELSEIF expr then
[ "elseif_expr", ":", "ELSEIF", "expr", "then", "|", "LABEL", "ELSEIF", "expr", "then" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L1294-L1305
boriel/zxbasic
zxbparser.py
p_elseif_list
def p_elseif_list(p): """ elseiflist : elseif_expr program_co endif | elseif_expr program_co else_part """ label_, cond_ = p[1] then_ = p[2] else_ = p[3] if isinstance(else_, list): # it's an else part else_ = make_block(*else_) else: then_ = make_block(then_, else_) else_ = None p[0] = make_block(label_, make_sentence('IF', cond_, then_, else_, lineno=p.lineno(1)))
python
def p_elseif_list(p): """ elseiflist : elseif_expr program_co endif | elseif_expr program_co else_part """ label_, cond_ = p[1] then_ = p[2] else_ = p[3] if isinstance(else_, list): # it's an else part else_ = make_block(*else_) else: then_ = make_block(then_, else_) else_ = None p[0] = make_block(label_, make_sentence('IF', cond_, then_, else_, lineno=p.lineno(1)))
[ "def", "p_elseif_list", "(", "p", ")", ":", "label_", ",", "cond_", "=", "p", "[", "1", "]", "then_", "=", "p", "[", "2", "]", "else_", "=", "p", "[", "3", "]", "if", "isinstance", "(", "else_", ",", "list", ")", ":", "# it's an else part", "else_", "=", "make_block", "(", "*", "else_", ")", "else", ":", "then_", "=", "make_block", "(", "then_", ",", "else_", ")", "else_", "=", "None", "p", "[", "0", "]", "=", "make_block", "(", "label_", ",", "make_sentence", "(", "'IF'", ",", "cond_", ",", "then_", ",", "else_", ",", "lineno", "=", "p", ".", "lineno", "(", "1", ")", ")", ")" ]
elseiflist : elseif_expr program_co endif | elseif_expr program_co else_part
[ "elseiflist", ":", "elseif_expr", "program_co", "endif", "|", "elseif_expr", "program_co", "else_part" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L1308-L1322
boriel/zxbasic
zxbparser.py
p_elseif_elseiflist
def p_elseif_elseiflist(p): """ elseiflist : elseif_expr program_co elseiflist """ label_, cond_ = p[1] then_ = p[2] else_ = p[3] p[0] = make_block(label_, make_sentence('IF', cond_, then_, else_, lineno=p.lineno(1)))
python
def p_elseif_elseiflist(p): """ elseiflist : elseif_expr program_co elseiflist """ label_, cond_ = p[1] then_ = p[2] else_ = p[3] p[0] = make_block(label_, make_sentence('IF', cond_, then_, else_, lineno=p.lineno(1)))
[ "def", "p_elseif_elseiflist", "(", "p", ")", ":", "label_", ",", "cond_", "=", "p", "[", "1", "]", "then_", "=", "p", "[", "2", "]", "else_", "=", "p", "[", "3", "]", "p", "[", "0", "]", "=", "make_block", "(", "label_", ",", "make_sentence", "(", "'IF'", ",", "cond_", ",", "then_", ",", "else_", ",", "lineno", "=", "p", ".", "lineno", "(", "1", ")", ")", ")" ]
elseiflist : elseif_expr program_co elseiflist
[ "elseiflist", ":", "elseif_expr", "program_co", "elseiflist" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L1325-L1331
boriel/zxbasic
zxbparser.py
p_else_part_endif
def p_else_part_endif(p): """ else_part_inline : ELSE NEWLINE program_co endif | ELSE NEWLINE statements_co endif | ELSE NEWLINE co_statements_co endif | ELSE NEWLINE endif | ELSE NEWLINE LABEL statements_co endif | ELSE NEWLINE LABEL co_statements_co endif | ELSE statements_co endif | ELSE co_statements_co endif """ if p[2] == '\n': if len(p) == 4: p[0] = [make_nop(), p[3]] elif len(p) == 6: p[0] = [make_label(p[3], p.lineno(3)), p[4], p[5]] else: p[0] = [p[3], p[4]] else: p[0] = [p[2], p[3]]
python
def p_else_part_endif(p): """ else_part_inline : ELSE NEWLINE program_co endif | ELSE NEWLINE statements_co endif | ELSE NEWLINE co_statements_co endif | ELSE NEWLINE endif | ELSE NEWLINE LABEL statements_co endif | ELSE NEWLINE LABEL co_statements_co endif | ELSE statements_co endif | ELSE co_statements_co endif """ if p[2] == '\n': if len(p) == 4: p[0] = [make_nop(), p[3]] elif len(p) == 6: p[0] = [make_label(p[3], p.lineno(3)), p[4], p[5]] else: p[0] = [p[3], p[4]] else: p[0] = [p[2], p[3]]
[ "def", "p_else_part_endif", "(", "p", ")", ":", "if", "p", "[", "2", "]", "==", "'\\n'", ":", "if", "len", "(", "p", ")", "==", "4", ":", "p", "[", "0", "]", "=", "[", "make_nop", "(", ")", ",", "p", "[", "3", "]", "]", "elif", "len", "(", "p", ")", "==", "6", ":", "p", "[", "0", "]", "=", "[", "make_label", "(", "p", "[", "3", "]", ",", "p", ".", "lineno", "(", "3", ")", ")", ",", "p", "[", "4", "]", ",", "p", "[", "5", "]", "]", "else", ":", "p", "[", "0", "]", "=", "[", "p", "[", "3", "]", ",", "p", "[", "4", "]", "]", "else", ":", "p", "[", "0", "]", "=", "[", "p", "[", "2", "]", ",", "p", "[", "3", "]", "]" ]
else_part_inline : ELSE NEWLINE program_co endif | ELSE NEWLINE statements_co endif | ELSE NEWLINE co_statements_co endif | ELSE NEWLINE endif | ELSE NEWLINE LABEL statements_co endif | ELSE NEWLINE LABEL co_statements_co endif | ELSE statements_co endif | ELSE co_statements_co endif
[ "else_part_inline", ":", "ELSE", "NEWLINE", "program_co", "endif", "|", "ELSE", "NEWLINE", "statements_co", "endif", "|", "ELSE", "NEWLINE", "co_statements_co", "endif", "|", "ELSE", "NEWLINE", "endif", "|", "ELSE", "NEWLINE", "LABEL", "statements_co", "endif", "|", "ELSE", "NEWLINE", "LABEL", "co_statements_co", "endif", "|", "ELSE", "statements_co", "endif", "|", "ELSE", "co_statements_co", "endif" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L1334-L1352
boriel/zxbasic
zxbparser.py
p_else_part_label
def p_else_part_label(p): """ else_part : LABEL ELSE program_co endif | LABEL ELSE statements_co endif | LABEL ELSE co_statements_co endif """ lbl = make_label(p[1], p.lineno(1)) p[0] = [make_block(lbl, p[3]), p[4]]
python
def p_else_part_label(p): """ else_part : LABEL ELSE program_co endif | LABEL ELSE statements_co endif | LABEL ELSE co_statements_co endif """ lbl = make_label(p[1], p.lineno(1)) p[0] = [make_block(lbl, p[3]), p[4]]
[ "def", "p_else_part_label", "(", "p", ")", ":", "lbl", "=", "make_label", "(", "p", "[", "1", "]", ",", "p", ".", "lineno", "(", "1", ")", ")", "p", "[", "0", "]", "=", "[", "make_block", "(", "lbl", ",", "p", "[", "3", "]", ")", ",", "p", "[", "4", "]", "]" ]
else_part : LABEL ELSE program_co endif | LABEL ELSE statements_co endif | LABEL ELSE co_statements_co endif
[ "else_part", ":", "LABEL", "ELSE", "program_co", "endif", "|", "LABEL", "ELSE", "statements_co", "endif", "|", "LABEL", "ELSE", "co_statements_co", "endif" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L1370-L1376
boriel/zxbasic
zxbparser.py
p_if_then_part
def p_if_then_part(p): """ if_then_part : IF expr then """ if is_number(p[2]): api.errmsg.warning_condition_is_always(p.lineno(1), bool(p[2].value)) p[0] = p[2]
python
def p_if_then_part(p): """ if_then_part : IF expr then """ if is_number(p[2]): api.errmsg.warning_condition_is_always(p.lineno(1), bool(p[2].value)) p[0] = p[2]
[ "def", "p_if_then_part", "(", "p", ")", ":", "if", "is_number", "(", "p", "[", "2", "]", ")", ":", "api", ".", "errmsg", ".", "warning_condition_is_always", "(", "p", ".", "lineno", "(", "1", ")", ",", "bool", "(", "p", "[", "2", "]", ".", "value", ")", ")", "p", "[", "0", "]", "=", "p", "[", "2", "]" ]
if_then_part : IF expr then
[ "if_then_part", ":", "IF", "expr", "then" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L1379-L1384
boriel/zxbasic
zxbparser.py
p_if_else
def p_if_else(p): """ statement : if_then_part NEWLINE program_co else_part """ cond_ = p[1] then_ = p[3] else_ = p[4][0] endif = p[4][1] p[0] = make_sentence('IF', cond_, then_, make_block(else_, endif), lineno=p.lineno(2))
python
def p_if_else(p): """ statement : if_then_part NEWLINE program_co else_part """ cond_ = p[1] then_ = p[3] else_ = p[4][0] endif = p[4][1] p[0] = make_sentence('IF', cond_, then_, make_block(else_, endif), lineno=p.lineno(2))
[ "def", "p_if_else", "(", "p", ")", ":", "cond_", "=", "p", "[", "1", "]", "then_", "=", "p", "[", "3", "]", "else_", "=", "p", "[", "4", "]", "[", "0", "]", "endif", "=", "p", "[", "4", "]", "[", "1", "]", "p", "[", "0", "]", "=", "make_sentence", "(", "'IF'", ",", "cond_", ",", "then_", ",", "make_block", "(", "else_", ",", "endif", ")", ",", "lineno", "=", "p", ".", "lineno", "(", "2", ")", ")" ]
statement : if_then_part NEWLINE program_co else_part
[ "statement", ":", "if_then_part", "NEWLINE", "program_co", "else_part" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L1394-L1401
boriel/zxbasic
zxbparser.py
p_for_sentence
def p_for_sentence(p): """ statement : for_start program_co label_next | for_start co_statements_co label_next """ p[0] = p[1] if is_null(p[0]): return p[1].appendChild(make_block(p[2], p[3])) gl.LOOPS.pop()
python
def p_for_sentence(p): """ statement : for_start program_co label_next | for_start co_statements_co label_next """ p[0] = p[1] if is_null(p[0]): return p[1].appendChild(make_block(p[2], p[3])) gl.LOOPS.pop()
[ "def", "p_for_sentence", "(", "p", ")", ":", "p", "[", "0", "]", "=", "p", "[", "1", "]", "if", "is_null", "(", "p", "[", "0", "]", ")", ":", "return", "p", "[", "1", "]", ".", "appendChild", "(", "make_block", "(", "p", "[", "2", "]", ",", "p", "[", "3", "]", ")", ")", "gl", ".", "LOOPS", ".", "pop", "(", ")" ]
statement : for_start program_co label_next | for_start co_statements_co label_next
[ "statement", ":", "for_start", "program_co", "label_next", "|", "for_start", "co_statements_co", "label_next" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L1412-L1420
boriel/zxbasic
zxbparser.py
p_next1
def p_next1(p): """ label_next : LABEL NEXT ID | NEXT ID """ if p[1] == 'NEXT': p1 = make_nop() p3 = p[2] else: p1 = make_label(p[1], p.lineno(1)) p3 = p[3] if p3 != gl.LOOPS[-1][1]: api.errmsg.syntax_error_wrong_for_var(p.lineno(2), gl.LOOPS[-1][1], p3) p[0] = make_nop() return p[0] = p1
python
def p_next1(p): """ label_next : LABEL NEXT ID | NEXT ID """ if p[1] == 'NEXT': p1 = make_nop() p3 = p[2] else: p1 = make_label(p[1], p.lineno(1)) p3 = p[3] if p3 != gl.LOOPS[-1][1]: api.errmsg.syntax_error_wrong_for_var(p.lineno(2), gl.LOOPS[-1][1], p3) p[0] = make_nop() return p[0] = p1
[ "def", "p_next1", "(", "p", ")", ":", "if", "p", "[", "1", "]", "==", "'NEXT'", ":", "p1", "=", "make_nop", "(", ")", "p3", "=", "p", "[", "2", "]", "else", ":", "p1", "=", "make_label", "(", "p", "[", "1", "]", ",", "p", ".", "lineno", "(", "1", ")", ")", "p3", "=", "p", "[", "3", "]", "if", "p3", "!=", "gl", ".", "LOOPS", "[", "-", "1", "]", "[", "1", "]", ":", "api", ".", "errmsg", ".", "syntax_error_wrong_for_var", "(", "p", ".", "lineno", "(", "2", ")", ",", "gl", ".", "LOOPS", "[", "-", "1", "]", "[", "1", "]", ",", "p3", ")", "p", "[", "0", "]", "=", "make_nop", "(", ")", "return", "p", "[", "0", "]", "=", "p1" ]
label_next : LABEL NEXT ID | NEXT ID
[ "label_next", ":", "LABEL", "NEXT", "ID", "|", "NEXT", "ID" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L1430-L1446
boriel/zxbasic
zxbparser.py
p_for_sentence_start
def p_for_sentence_start(p): """ for_start : FOR ID EQ expr TO expr step """ gl.LOOPS.append(('FOR', p[2])) p[0] = None if p[4] is None or p[6] is None or p[7] is None: return if is_number(p[4], p[6], p[7]): if p[4].value != p[6].value and p[7].value == 0: warning(p.lineno(5), 'STEP value is 0 and FOR might loop forever') if p[4].value > p[6].value and p[7].value > 0: warning(p.lineno(5), 'FOR start value is greater than end. This FOR loop is useless') if p[4].value < p[6].value and p[7].value < 0: warning(p.lineno(2), 'FOR start value is lower than end. This FOR loop is useless') id_type = common_type(common_type(p[4], p[6]), p[7]) variable = SYMBOL_TABLE.access_var(p[2], p.lineno(2), default_type=id_type) if variable is None: return variable.accessed = True expr1 = make_typecast(variable.type_, p[4], p.lineno(3)) expr2 = make_typecast(variable.type_, p[6], p.lineno(5)) expr3 = make_typecast(variable.type_, p[7], p.lexer.lineno) p[0] = make_sentence('FOR', variable, expr1, expr2, expr3)
python
def p_for_sentence_start(p): """ for_start : FOR ID EQ expr TO expr step """ gl.LOOPS.append(('FOR', p[2])) p[0] = None if p[4] is None or p[6] is None or p[7] is None: return if is_number(p[4], p[6], p[7]): if p[4].value != p[6].value and p[7].value == 0: warning(p.lineno(5), 'STEP value is 0 and FOR might loop forever') if p[4].value > p[6].value and p[7].value > 0: warning(p.lineno(5), 'FOR start value is greater than end. This FOR loop is useless') if p[4].value < p[6].value and p[7].value < 0: warning(p.lineno(2), 'FOR start value is lower than end. This FOR loop is useless') id_type = common_type(common_type(p[4], p[6]), p[7]) variable = SYMBOL_TABLE.access_var(p[2], p.lineno(2), default_type=id_type) if variable is None: return variable.accessed = True expr1 = make_typecast(variable.type_, p[4], p.lineno(3)) expr2 = make_typecast(variable.type_, p[6], p.lineno(5)) expr3 = make_typecast(variable.type_, p[7], p.lexer.lineno) p[0] = make_sentence('FOR', variable, expr1, expr2, expr3)
[ "def", "p_for_sentence_start", "(", "p", ")", ":", "gl", ".", "LOOPS", ".", "append", "(", "(", "'FOR'", ",", "p", "[", "2", "]", ")", ")", "p", "[", "0", "]", "=", "None", "if", "p", "[", "4", "]", "is", "None", "or", "p", "[", "6", "]", "is", "None", "or", "p", "[", "7", "]", "is", "None", ":", "return", "if", "is_number", "(", "p", "[", "4", "]", ",", "p", "[", "6", "]", ",", "p", "[", "7", "]", ")", ":", "if", "p", "[", "4", "]", ".", "value", "!=", "p", "[", "6", "]", ".", "value", "and", "p", "[", "7", "]", ".", "value", "==", "0", ":", "warning", "(", "p", ".", "lineno", "(", "5", ")", ",", "'STEP value is 0 and FOR might loop forever'", ")", "if", "p", "[", "4", "]", ".", "value", ">", "p", "[", "6", "]", ".", "value", "and", "p", "[", "7", "]", ".", "value", ">", "0", ":", "warning", "(", "p", ".", "lineno", "(", "5", ")", ",", "'FOR start value is greater than end. This FOR loop is useless'", ")", "if", "p", "[", "4", "]", ".", "value", "<", "p", "[", "6", "]", ".", "value", "and", "p", "[", "7", "]", ".", "value", "<", "0", ":", "warning", "(", "p", ".", "lineno", "(", "2", ")", ",", "'FOR start value is lower than end. This FOR loop is useless'", ")", "id_type", "=", "common_type", "(", "common_type", "(", "p", "[", "4", "]", ",", "p", "[", "6", "]", ")", ",", "p", "[", "7", "]", ")", "variable", "=", "SYMBOL_TABLE", ".", "access_var", "(", "p", "[", "2", "]", ",", "p", ".", "lineno", "(", "2", ")", ",", "default_type", "=", "id_type", ")", "if", "variable", "is", "None", ":", "return", "variable", ".", "accessed", "=", "True", "expr1", "=", "make_typecast", "(", "variable", ".", "type_", ",", "p", "[", "4", "]", ",", "p", ".", "lineno", "(", "3", ")", ")", "expr2", "=", "make_typecast", "(", "variable", ".", "type_", ",", "p", "[", "6", "]", ",", "p", ".", "lineno", "(", "5", ")", ")", "expr3", "=", "make_typecast", "(", "variable", ".", "type_", ",", "p", "[", "7", "]", ",", "p", ".", "lexer", ".", "lineno", ")", "p", "[", "0", "]", "=", "make_sentence", "(", "'FOR'", ",", "variable", ",", "expr1", ",", "expr2", ",", "expr3", ")" ]
for_start : FOR ID EQ expr TO expr step
[ "for_start", ":", "FOR", "ID", "EQ", "expr", "TO", "expr", "step" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L1449-L1478
boriel/zxbasic
zxbparser.py
p_end
def p_end(p): """ statement : END expr | END """ q = make_number(0, lineno=p.lineno(1)) if len(p) == 2 else p[2] p[0] = make_sentence('END', q)
python
def p_end(p): """ statement : END expr | END """ q = make_number(0, lineno=p.lineno(1)) if len(p) == 2 else p[2] p[0] = make_sentence('END', q)
[ "def", "p_end", "(", "p", ")", ":", "q", "=", "make_number", "(", "0", ",", "lineno", "=", "p", ".", "lineno", "(", "1", ")", ")", "if", "len", "(", "p", ")", "==", "2", "else", "p", "[", "2", "]", "p", "[", "0", "]", "=", "make_sentence", "(", "'END'", ",", "q", ")" ]
statement : END expr | END
[ "statement", ":", "END", "expr", "|", "END" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L1494-L1499
boriel/zxbasic
zxbparser.py
p_error_raise
def p_error_raise(p): """ statement : ERROR expr """ q = make_number(1, lineno=p.lineno(2)) r = make_binary(p.lineno(1), 'MINUS', make_typecast(TYPE.ubyte, p[2], p.lineno(1)), q, lambda x, y: x - y) p[0] = make_sentence('ERROR', r)
python
def p_error_raise(p): """ statement : ERROR expr """ q = make_number(1, lineno=p.lineno(2)) r = make_binary(p.lineno(1), 'MINUS', make_typecast(TYPE.ubyte, p[2], p.lineno(1)), q, lambda x, y: x - y) p[0] = make_sentence('ERROR', r)
[ "def", "p_error_raise", "(", "p", ")", ":", "q", "=", "make_number", "(", "1", ",", "lineno", "=", "p", ".", "lineno", "(", "2", ")", ")", "r", "=", "make_binary", "(", "p", ".", "lineno", "(", "1", ")", ",", "'MINUS'", ",", "make_typecast", "(", "TYPE", ".", "ubyte", ",", "p", "[", "2", "]", ",", "p", ".", "lineno", "(", "1", ")", ")", ",", "q", ",", "lambda", "x", ",", "y", ":", "x", "-", "y", ")", "p", "[", "0", "]", "=", "make_sentence", "(", "'ERROR'", ",", "r", ")" ]
statement : ERROR expr
[ "statement", ":", "ERROR", "expr" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L1502-L1509
boriel/zxbasic
zxbparser.py
p_stop_raise
def p_stop_raise(p): """ statement : STOP expr | STOP """ q = make_number(9, lineno=p.lineno(1)) if len(p) == 2 else p[2] z = make_number(1, lineno=p.lineno(1)) r = make_binary(p.lineno(1), 'MINUS', make_typecast(TYPE.ubyte, q, p.lineno(1)), z, lambda x, y: x - y) p[0] = make_sentence('STOP', r)
python
def p_stop_raise(p): """ statement : STOP expr | STOP """ q = make_number(9, lineno=p.lineno(1)) if len(p) == 2 else p[2] z = make_number(1, lineno=p.lineno(1)) r = make_binary(p.lineno(1), 'MINUS', make_typecast(TYPE.ubyte, q, p.lineno(1)), z, lambda x, y: x - y) p[0] = make_sentence('STOP', r)
[ "def", "p_stop_raise", "(", "p", ")", ":", "q", "=", "make_number", "(", "9", ",", "lineno", "=", "p", ".", "lineno", "(", "1", ")", ")", "if", "len", "(", "p", ")", "==", "2", "else", "p", "[", "2", "]", "z", "=", "make_number", "(", "1", ",", "lineno", "=", "p", ".", "lineno", "(", "1", ")", ")", "r", "=", "make_binary", "(", "p", ".", "lineno", "(", "1", ")", ",", "'MINUS'", ",", "make_typecast", "(", "TYPE", ".", "ubyte", ",", "q", ",", "p", ".", "lineno", "(", "1", ")", ")", ",", "z", ",", "lambda", "x", ",", "y", ":", "x", "-", "y", ")", "p", "[", "0", "]", "=", "make_sentence", "(", "'STOP'", ",", "r", ")" ]
statement : STOP expr | STOP
[ "statement", ":", "STOP", "expr", "|", "STOP" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L1512-L1521
boriel/zxbasic
zxbparser.py
p_do_loop
def p_do_loop(p): """ statement : do_start program_co label_loop | do_start label_loop | DO label_loop """ if len(p) == 4: q = make_block(p[2], p[3]) else: q = p[2] if p[1] == 'DO': gl.LOOPS.append(('DO',)) if q is None: warning(p.lineno(1), 'Infinite empty loop') # An infinite loop and no warnings p[0] = make_sentence('DO_LOOP', q) gl.LOOPS.pop()
python
def p_do_loop(p): """ statement : do_start program_co label_loop | do_start label_loop | DO label_loop """ if len(p) == 4: q = make_block(p[2], p[3]) else: q = p[2] if p[1] == 'DO': gl.LOOPS.append(('DO',)) if q is None: warning(p.lineno(1), 'Infinite empty loop') # An infinite loop and no warnings p[0] = make_sentence('DO_LOOP', q) gl.LOOPS.pop()
[ "def", "p_do_loop", "(", "p", ")", ":", "if", "len", "(", "p", ")", "==", "4", ":", "q", "=", "make_block", "(", "p", "[", "2", "]", ",", "p", "[", "3", "]", ")", "else", ":", "q", "=", "p", "[", "2", "]", "if", "p", "[", "1", "]", "==", "'DO'", ":", "gl", ".", "LOOPS", ".", "append", "(", "(", "'DO'", ",", ")", ")", "if", "q", "is", "None", ":", "warning", "(", "p", ".", "lineno", "(", "1", ")", ",", "'Infinite empty loop'", ")", "# An infinite loop and no warnings", "p", "[", "0", "]", "=", "make_sentence", "(", "'DO_LOOP'", ",", "q", ")", "gl", ".", "LOOPS", ".", "pop", "(", ")" ]
statement : do_start program_co label_loop | do_start label_loop | DO label_loop
[ "statement", ":", "do_start", "program_co", "label_loop", "|", "do_start", "label_loop", "|", "DO", "label_loop" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L1534-L1552
boriel/zxbasic
zxbparser.py
p_data
def p_data(p): """ statement : DATA arguments """ label_ = make_label(gl.DATA_PTR_CURRENT, lineno=p.lineno(1)) datas_ = [] funcs = [] if p[2] is None: p[0] = None return for d in p[2].children: value = d.value if is_static(value): datas_.append(d) continue new_lbl = '__DATA__FUNCPTR__{0}'.format(len(gl.DATA_FUNCTIONS)) entry = make_func_declaration(new_lbl, p.lineno(1), type_=value.type_) if not entry: continue func = entry.entry func.convention = CONVENTION.fastcall SYMBOL_TABLE.enter_scope(new_lbl) func.local_symbol_table = SYMBOL_TABLE.table[SYMBOL_TABLE.current_scope] func.locals_size = SYMBOL_TABLE.leave_scope() gl.DATA_FUNCTIONS.append(func) sent = make_sentence('RETURN', func, value) func.body = make_block(sent) datas_.append(entry) funcs.append(entry) gl.DATAS.append([label_, datas_]) id_ = api.utils.current_data_label() gl.DATA_PTR_CURRENT = id_
python
def p_data(p): """ statement : DATA arguments """ label_ = make_label(gl.DATA_PTR_CURRENT, lineno=p.lineno(1)) datas_ = [] funcs = [] if p[2] is None: p[0] = None return for d in p[2].children: value = d.value if is_static(value): datas_.append(d) continue new_lbl = '__DATA__FUNCPTR__{0}'.format(len(gl.DATA_FUNCTIONS)) entry = make_func_declaration(new_lbl, p.lineno(1), type_=value.type_) if not entry: continue func = entry.entry func.convention = CONVENTION.fastcall SYMBOL_TABLE.enter_scope(new_lbl) func.local_symbol_table = SYMBOL_TABLE.table[SYMBOL_TABLE.current_scope] func.locals_size = SYMBOL_TABLE.leave_scope() gl.DATA_FUNCTIONS.append(func) sent = make_sentence('RETURN', func, value) func.body = make_block(sent) datas_.append(entry) funcs.append(entry) gl.DATAS.append([label_, datas_]) id_ = api.utils.current_data_label() gl.DATA_PTR_CURRENT = id_
[ "def", "p_data", "(", "p", ")", ":", "label_", "=", "make_label", "(", "gl", ".", "DATA_PTR_CURRENT", ",", "lineno", "=", "p", ".", "lineno", "(", "1", ")", ")", "datas_", "=", "[", "]", "funcs", "=", "[", "]", "if", "p", "[", "2", "]", "is", "None", ":", "p", "[", "0", "]", "=", "None", "return", "for", "d", "in", "p", "[", "2", "]", ".", "children", ":", "value", "=", "d", ".", "value", "if", "is_static", "(", "value", ")", ":", "datas_", ".", "append", "(", "d", ")", "continue", "new_lbl", "=", "'__DATA__FUNCPTR__{0}'", ".", "format", "(", "len", "(", "gl", ".", "DATA_FUNCTIONS", ")", ")", "entry", "=", "make_func_declaration", "(", "new_lbl", ",", "p", ".", "lineno", "(", "1", ")", ",", "type_", "=", "value", ".", "type_", ")", "if", "not", "entry", ":", "continue", "func", "=", "entry", ".", "entry", "func", ".", "convention", "=", "CONVENTION", ".", "fastcall", "SYMBOL_TABLE", ".", "enter_scope", "(", "new_lbl", ")", "func", ".", "local_symbol_table", "=", "SYMBOL_TABLE", ".", "table", "[", "SYMBOL_TABLE", ".", "current_scope", "]", "func", ".", "locals_size", "=", "SYMBOL_TABLE", ".", "leave_scope", "(", ")", "gl", ".", "DATA_FUNCTIONS", ".", "append", "(", "func", ")", "sent", "=", "make_sentence", "(", "'RETURN'", ",", "func", ",", "value", ")", "func", ".", "body", "=", "make_block", "(", "sent", ")", "datas_", ".", "append", "(", "entry", ")", "funcs", ".", "append", "(", "entry", ")", "gl", ".", "DATAS", ".", "append", "(", "[", "label_", ",", "datas_", "]", ")", "id_", "=", "api", ".", "utils", ".", "current_data_label", "(", ")", "gl", ".", "DATA_PTR_CURRENT", "=", "id_" ]
statement : DATA arguments
[ "statement", ":", "DATA", "arguments" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L1579-L1615
boriel/zxbasic
zxbparser.py
p_restore
def p_restore(p): """ statement : RESTORE | RESTORE ID | RESTORE NUMBER """ if len(p) == 2: id_ = '__DATA__{0}'.format(len(gl.DATAS)) else: id_ = p[2] lbl = check_and_make_label(id_, p.lineno(1)) p[0] = make_sentence('RESTORE', lbl)
python
def p_restore(p): """ statement : RESTORE | RESTORE ID | RESTORE NUMBER """ if len(p) == 2: id_ = '__DATA__{0}'.format(len(gl.DATAS)) else: id_ = p[2] lbl = check_and_make_label(id_, p.lineno(1)) p[0] = make_sentence('RESTORE', lbl)
[ "def", "p_restore", "(", "p", ")", ":", "if", "len", "(", "p", ")", "==", "2", ":", "id_", "=", "'__DATA__{0}'", ".", "format", "(", "len", "(", "gl", ".", "DATAS", ")", ")", "else", ":", "id_", "=", "p", "[", "2", "]", "lbl", "=", "check_and_make_label", "(", "id_", ",", "p", ".", "lineno", "(", "1", ")", ")", "p", "[", "0", "]", "=", "make_sentence", "(", "'RESTORE'", ",", "lbl", ")" ]
statement : RESTORE | RESTORE ID | RESTORE NUMBER
[ "statement", ":", "RESTORE", "|", "RESTORE", "ID", "|", "RESTORE", "NUMBER" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L1618-L1629
boriel/zxbasic
zxbparser.py
p_read
def p_read(p): """ statement : READ arguments """ gl.DATA_IS_USED = True reads = [] if p[2] is None: return for arg in p[2]: entry = arg.value if entry is None: p[0] = None return if isinstance(entry, symbols.VARARRAY): api.errmsg.syntax_error(p.lineno(1), "Cannot read '%s'. It's an array" % entry.name) p[0] = None return if isinstance(entry, symbols.VAR): if entry.class_ != CLASS.var: api.errmsg.syntax_error_cannot_assing_not_a_var(p.lineno(2), entry.name) p[0] = None return entry.accessed = True if entry.type_ == TYPE.auto: entry.type_ = _TYPE(gl.DEFAULT_TYPE) api.errmsg.warning_implicit_type(p.lineno(2), p[2], entry.type_) reads.append(make_sentence('READ', entry)) continue if isinstance(entry, symbols.ARRAYLOAD): reads.append(make_sentence('READ', symbols.ARRAYACCESS(entry.entry, entry.args, entry.lineno))) continue api.errmsg.syntax_error(p.lineno(1), "Syntax error. Can only read a variable or an array element") p[0] = None return p[0] = make_block(*reads)
python
def p_read(p): """ statement : READ arguments """ gl.DATA_IS_USED = True reads = [] if p[2] is None: return for arg in p[2]: entry = arg.value if entry is None: p[0] = None return if isinstance(entry, symbols.VARARRAY): api.errmsg.syntax_error(p.lineno(1), "Cannot read '%s'. It's an array" % entry.name) p[0] = None return if isinstance(entry, symbols.VAR): if entry.class_ != CLASS.var: api.errmsg.syntax_error_cannot_assing_not_a_var(p.lineno(2), entry.name) p[0] = None return entry.accessed = True if entry.type_ == TYPE.auto: entry.type_ = _TYPE(gl.DEFAULT_TYPE) api.errmsg.warning_implicit_type(p.lineno(2), p[2], entry.type_) reads.append(make_sentence('READ', entry)) continue if isinstance(entry, symbols.ARRAYLOAD): reads.append(make_sentence('READ', symbols.ARRAYACCESS(entry.entry, entry.args, entry.lineno))) continue api.errmsg.syntax_error(p.lineno(1), "Syntax error. Can only read a variable or an array element") p[0] = None return p[0] = make_block(*reads)
[ "def", "p_read", "(", "p", ")", ":", "gl", ".", "DATA_IS_USED", "=", "True", "reads", "=", "[", "]", "if", "p", "[", "2", "]", "is", "None", ":", "return", "for", "arg", "in", "p", "[", "2", "]", ":", "entry", "=", "arg", ".", "value", "if", "entry", "is", "None", ":", "p", "[", "0", "]", "=", "None", "return", "if", "isinstance", "(", "entry", ",", "symbols", ".", "VARARRAY", ")", ":", "api", ".", "errmsg", ".", "syntax_error", "(", "p", ".", "lineno", "(", "1", ")", ",", "\"Cannot read '%s'. It's an array\"", "%", "entry", ".", "name", ")", "p", "[", "0", "]", "=", "None", "return", "if", "isinstance", "(", "entry", ",", "symbols", ".", "VAR", ")", ":", "if", "entry", ".", "class_", "!=", "CLASS", ".", "var", ":", "api", ".", "errmsg", ".", "syntax_error_cannot_assing_not_a_var", "(", "p", ".", "lineno", "(", "2", ")", ",", "entry", ".", "name", ")", "p", "[", "0", "]", "=", "None", "return", "entry", ".", "accessed", "=", "True", "if", "entry", ".", "type_", "==", "TYPE", ".", "auto", ":", "entry", ".", "type_", "=", "_TYPE", "(", "gl", ".", "DEFAULT_TYPE", ")", "api", ".", "errmsg", ".", "warning_implicit_type", "(", "p", ".", "lineno", "(", "2", ")", ",", "p", "[", "2", "]", ",", "entry", ".", "type_", ")", "reads", ".", "append", "(", "make_sentence", "(", "'READ'", ",", "entry", ")", ")", "continue", "if", "isinstance", "(", "entry", ",", "symbols", ".", "ARRAYLOAD", ")", ":", "reads", ".", "append", "(", "make_sentence", "(", "'READ'", ",", "symbols", ".", "ARRAYACCESS", "(", "entry", ".", "entry", ",", "entry", ".", "args", ",", "entry", ".", "lineno", ")", ")", ")", "continue", "api", ".", "errmsg", ".", "syntax_error", "(", "p", ".", "lineno", "(", "1", ")", ",", "\"Syntax error. Can only read a variable or an array element\"", ")", "p", "[", "0", "]", "=", "None", "return", "p", "[", "0", "]", "=", "make_block", "(", "*", "reads", ")" ]
statement : READ arguments
[ "statement", ":", "READ", "arguments" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L1632-L1674
boriel/zxbasic
zxbparser.py
p_do_loop_while
def p_do_loop_while(p): """ statement : do_start program_co label_loop WHILE expr | do_start label_loop WHILE expr | DO label_loop WHILE expr """ if len(p) == 6: q = make_block(p[2], p[3]) r = p[5] else: q = p[2] r = p[4] if p[1] == 'DO': gl.LOOPS.append(('DO',)) p[0] = make_sentence('DO_WHILE', r, q) gl.LOOPS.pop() if is_number(r): api.errmsg.warning_condition_is_always(p.lineno(3), bool(r.value)) if q is None: api.errmsg.warning_empty_loop(p.lineno(3))
python
def p_do_loop_while(p): """ statement : do_start program_co label_loop WHILE expr | do_start label_loop WHILE expr | DO label_loop WHILE expr """ if len(p) == 6: q = make_block(p[2], p[3]) r = p[5] else: q = p[2] r = p[4] if p[1] == 'DO': gl.LOOPS.append(('DO',)) p[0] = make_sentence('DO_WHILE', r, q) gl.LOOPS.pop() if is_number(r): api.errmsg.warning_condition_is_always(p.lineno(3), bool(r.value)) if q is None: api.errmsg.warning_empty_loop(p.lineno(3))
[ "def", "p_do_loop_while", "(", "p", ")", ":", "if", "len", "(", "p", ")", "==", "6", ":", "q", "=", "make_block", "(", "p", "[", "2", "]", ",", "p", "[", "3", "]", ")", "r", "=", "p", "[", "5", "]", "else", ":", "q", "=", "p", "[", "2", "]", "r", "=", "p", "[", "4", "]", "if", "p", "[", "1", "]", "==", "'DO'", ":", "gl", ".", "LOOPS", ".", "append", "(", "(", "'DO'", ",", ")", ")", "p", "[", "0", "]", "=", "make_sentence", "(", "'DO_WHILE'", ",", "r", ",", "q", ")", "gl", ".", "LOOPS", ".", "pop", "(", ")", "if", "is_number", "(", "r", ")", ":", "api", ".", "errmsg", ".", "warning_condition_is_always", "(", "p", ".", "lineno", "(", "3", ")", ",", "bool", "(", "r", ".", "value", ")", ")", "if", "q", "is", "None", ":", "api", ".", "errmsg", ".", "warning_empty_loop", "(", "p", ".", "lineno", "(", "3", ")", ")" ]
statement : do_start program_co label_loop WHILE expr | do_start label_loop WHILE expr | DO label_loop WHILE expr
[ "statement", ":", "do_start", "program_co", "label_loop", "WHILE", "expr", "|", "do_start", "label_loop", "WHILE", "expr", "|", "DO", "label_loop", "WHILE", "expr" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L1677-L1698
boriel/zxbasic
zxbparser.py
p_do_while_loop
def p_do_while_loop(p): """ statement : do_while_start program_co LOOP | do_while_start co_statements_co LOOP | do_while_start LOOP """ r = p[1] q = p[2] if q == 'LOOP': q = None p[0] = make_sentence('WHILE_DO', r, q) gl.LOOPS.pop() if is_number(r): api.errmsg.warning_condition_is_always(p.lineno(2), bool(r.value))
python
def p_do_while_loop(p): """ statement : do_while_start program_co LOOP | do_while_start co_statements_co LOOP | do_while_start LOOP """ r = p[1] q = p[2] if q == 'LOOP': q = None p[0] = make_sentence('WHILE_DO', r, q) gl.LOOPS.pop() if is_number(r): api.errmsg.warning_condition_is_always(p.lineno(2), bool(r.value))
[ "def", "p_do_while_loop", "(", "p", ")", ":", "r", "=", "p", "[", "1", "]", "q", "=", "p", "[", "2", "]", "if", "q", "==", "'LOOP'", ":", "q", "=", "None", "p", "[", "0", "]", "=", "make_sentence", "(", "'WHILE_DO'", ",", "r", ",", "q", ")", "gl", ".", "LOOPS", ".", "pop", "(", ")", "if", "is_number", "(", "r", ")", ":", "api", ".", "errmsg", ".", "warning_condition_is_always", "(", "p", ".", "lineno", "(", "2", ")", ",", "bool", "(", "r", ".", "value", ")", ")" ]
statement : do_while_start program_co LOOP | do_while_start co_statements_co LOOP | do_while_start LOOP
[ "statement", ":", "do_while_start", "program_co", "LOOP", "|", "do_while_start", "co_statements_co", "LOOP", "|", "do_while_start", "LOOP" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L1701-L1715
boriel/zxbasic
zxbparser.py
p_while_sentence
def p_while_sentence(p): """ statement : while_start co_statements_co label_end_while | while_start program_co label_end_while """ gl.LOOPS.pop() q = make_block(p[2], p[3]) if is_number(p[1]) and p[1].value: if q is None: warning(p[1].lineno, "Condition is always true and leads to an infinite loop.") else: warning(p[1].lineno, "Condition is always true and might lead to an infinite loop.") p[0] = make_sentence('WHILE', p[1], q)
python
def p_while_sentence(p): """ statement : while_start co_statements_co label_end_while | while_start program_co label_end_while """ gl.LOOPS.pop() q = make_block(p[2], p[3]) if is_number(p[1]) and p[1].value: if q is None: warning(p[1].lineno, "Condition is always true and leads to an infinite loop.") else: warning(p[1].lineno, "Condition is always true and might lead to an infinite loop.") p[0] = make_sentence('WHILE', p[1], q)
[ "def", "p_while_sentence", "(", "p", ")", ":", "gl", ".", "LOOPS", ".", "pop", "(", ")", "q", "=", "make_block", "(", "p", "[", "2", "]", ",", "p", "[", "3", "]", ")", "if", "is_number", "(", "p", "[", "1", "]", ")", "and", "p", "[", "1", "]", ".", "value", ":", "if", "q", "is", "None", ":", "warning", "(", "p", "[", "1", "]", ".", "lineno", ",", "\"Condition is always true and leads to an infinite loop.\"", ")", "else", ":", "warning", "(", "p", "[", "1", "]", ".", "lineno", ",", "\"Condition is always true and might lead to an infinite loop.\"", ")", "p", "[", "0", "]", "=", "make_sentence", "(", "'WHILE'", ",", "p", "[", "1", "]", ",", "q", ")" ]
statement : while_start co_statements_co label_end_while | while_start program_co label_end_while
[ "statement", ":", "while_start", "co_statements_co", "label_end_while", "|", "while_start", "program_co", "label_end_while" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L1768-L1781
boriel/zxbasic
zxbparser.py
p_while_start
def p_while_start(p): """ while_start : WHILE expr """ p[0] = p[2] gl.LOOPS.append(('WHILE',)) if is_number(p[2]) and not p[2].value: api.errmsg.warning_condition_is_always(p.lineno(1))
python
def p_while_start(p): """ while_start : WHILE expr """ p[0] = p[2] gl.LOOPS.append(('WHILE',)) if is_number(p[2]) and not p[2].value: api.errmsg.warning_condition_is_always(p.lineno(1))
[ "def", "p_while_start", "(", "p", ")", ":", "p", "[", "0", "]", "=", "p", "[", "2", "]", "gl", ".", "LOOPS", ".", "append", "(", "(", "'WHILE'", ",", ")", ")", "if", "is_number", "(", "p", "[", "2", "]", ")", "and", "not", "p", "[", "2", "]", ".", "value", ":", "api", ".", "errmsg", ".", "warning_condition_is_always", "(", "p", ".", "lineno", "(", "1", ")", ")" ]
while_start : WHILE expr
[ "while_start", ":", "WHILE", "expr" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L1784-L1790
boriel/zxbasic
zxbparser.py
p_exit
def p_exit(p): """ statement : EXIT WHILE | EXIT DO | EXIT FOR """ q = p[2] p[0] = make_sentence('EXIT_%s' % q) for i in gl.LOOPS: if q == i[0]: return syntax_error(p.lineno(1), 'Syntax Error: EXIT %s out of loop' % q)
python
def p_exit(p): """ statement : EXIT WHILE | EXIT DO | EXIT FOR """ q = p[2] p[0] = make_sentence('EXIT_%s' % q) for i in gl.LOOPS: if q == i[0]: return syntax_error(p.lineno(1), 'Syntax Error: EXIT %s out of loop' % q)
[ "def", "p_exit", "(", "p", ")", ":", "q", "=", "p", "[", "2", "]", "p", "[", "0", "]", "=", "make_sentence", "(", "'EXIT_%s'", "%", "q", ")", "for", "i", "in", "gl", ".", "LOOPS", ":", "if", "q", "==", "i", "[", "0", "]", ":", "return", "syntax_error", "(", "p", ".", "lineno", "(", "1", ")", ",", "'Syntax Error: EXIT %s out of loop'", "%", "q", ")" ]
statement : EXIT WHILE | EXIT DO | EXIT FOR
[ "statement", ":", "EXIT", "WHILE", "|", "EXIT", "DO", "|", "EXIT", "FOR" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L1793-L1805
boriel/zxbasic
zxbparser.py
p_print_list_expr
def p_print_list_expr(p): """ print_elem : expr | print_at | print_tab | attr | BOLD expr | ITALIC expr """ if p[1] in ('BOLD', 'ITALIC'): p[0] = make_sentence(p[1] + '_TMP', make_typecast(TYPE.ubyte, p[2], p.lineno(1))) else: p[0] = p[1]
python
def p_print_list_expr(p): """ print_elem : expr | print_at | print_tab | attr | BOLD expr | ITALIC expr """ if p[1] in ('BOLD', 'ITALIC'): p[0] = make_sentence(p[1] + '_TMP', make_typecast(TYPE.ubyte, p[2], p.lineno(1))) else: p[0] = p[1]
[ "def", "p_print_list_expr", "(", "p", ")", ":", "if", "p", "[", "1", "]", "in", "(", "'BOLD'", ",", "'ITALIC'", ")", ":", "p", "[", "0", "]", "=", "make_sentence", "(", "p", "[", "1", "]", "+", "'_TMP'", ",", "make_typecast", "(", "TYPE", ".", "ubyte", ",", "p", "[", "2", "]", ",", "p", ".", "lineno", "(", "1", ")", ")", ")", "else", ":", "p", "[", "0", "]", "=", "p", "[", "1", "]" ]
print_elem : expr | print_at | print_tab | attr | BOLD expr | ITALIC expr
[ "print_elem", ":", "expr", "|", "print_at", "|", "print_tab", "|", "attr", "|", "BOLD", "expr", "|", "ITALIC", "expr" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L1832-L1844
boriel/zxbasic
zxbparser.py
p_attr
def p_attr(p): """ attr : OVER expr | INVERSE expr | INK expr | PAPER expr | BRIGHT expr | FLASH expr """ # ATTR_LIST are used by drawing commands: PLOT, DRAW, CIRCLE # BOLD and ITALIC are ignored by them, so we put them out of the # attr definition so something like DRAW BOLD 1; .... will raise # a syntax error p[0] = make_sentence(p[1] + '_TMP', make_typecast(TYPE.ubyte, p[2], p.lineno(1)))
python
def p_attr(p): """ attr : OVER expr | INVERSE expr | INK expr | PAPER expr | BRIGHT expr | FLASH expr """ # ATTR_LIST are used by drawing commands: PLOT, DRAW, CIRCLE # BOLD and ITALIC are ignored by them, so we put them out of the # attr definition so something like DRAW BOLD 1; .... will raise # a syntax error p[0] = make_sentence(p[1] + '_TMP', make_typecast(TYPE.ubyte, p[2], p.lineno(1)))
[ "def", "p_attr", "(", "p", ")", ":", "# ATTR_LIST are used by drawing commands: PLOT, DRAW, CIRCLE", "# BOLD and ITALIC are ignored by them, so we put them out of the", "# attr definition so something like DRAW BOLD 1; .... will raise", "# a syntax error", "p", "[", "0", "]", "=", "make_sentence", "(", "p", "[", "1", "]", "+", "'_TMP'", ",", "make_typecast", "(", "TYPE", ".", "ubyte", ",", "p", "[", "2", "]", ",", "p", ".", "lineno", "(", "1", ")", ")", ")" ]
attr : OVER expr | INVERSE expr | INK expr | PAPER expr | BRIGHT expr | FLASH expr
[ "attr", ":", "OVER", "expr", "|", "INVERSE", "expr", "|", "INK", "expr", "|", "PAPER", "expr", "|", "BRIGHT", "expr", "|", "FLASH", "expr" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L1859-L1872
boriel/zxbasic
zxbparser.py
p_print_list
def p_print_list(p): """ print_list : print_list SC print_elem """ p[0] = p[1] p[0].eol = (p[3] is not None) if p[3] is not None: p[0].appendChild(p[3])
python
def p_print_list(p): """ print_list : print_list SC print_elem """ p[0] = p[1] p[0].eol = (p[3] is not None) if p[3] is not None: p[0].appendChild(p[3])
[ "def", "p_print_list", "(", "p", ")", ":", "p", "[", "0", "]", "=", "p", "[", "1", "]", "p", "[", "0", "]", ".", "eol", "=", "(", "p", "[", "3", "]", "is", "not", "None", ")", "if", "p", "[", "3", "]", "is", "not", "None", ":", "p", "[", "0", "]", ".", "appendChild", "(", "p", "[", "3", "]", ")" ]
print_list : print_list SC print_elem
[ "print_list", ":", "print_list", "SC", "print_elem" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L1888-L1895
boriel/zxbasic
zxbparser.py
p_print_list_comma
def p_print_list_comma(p): """ print_list : print_list COMMA print_elem """ p[0] = p[1] p[0].eol = (p[3] is not None) p[0].appendChild(make_sentence('PRINT_COMMA')) if p[3] is not None: p[0].appendChild(p[3])
python
def p_print_list_comma(p): """ print_list : print_list COMMA print_elem """ p[0] = p[1] p[0].eol = (p[3] is not None) p[0].appendChild(make_sentence('PRINT_COMMA')) if p[3] is not None: p[0].appendChild(p[3])
[ "def", "p_print_list_comma", "(", "p", ")", ":", "p", "[", "0", "]", "=", "p", "[", "1", "]", "p", "[", "0", "]", ".", "eol", "=", "(", "p", "[", "3", "]", "is", "not", "None", ")", "p", "[", "0", "]", ".", "appendChild", "(", "make_sentence", "(", "'PRINT_COMMA'", ")", ")", "if", "p", "[", "3", "]", "is", "not", "None", ":", "p", "[", "0", "]", ".", "appendChild", "(", "p", "[", "3", "]", ")" ]
print_list : print_list COMMA print_elem
[ "print_list", ":", "print_list", "COMMA", "print_elem" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L1898-L1906
boriel/zxbasic
zxbparser.py
p_print_list_at
def p_print_list_at(p): """ print_at : AT expr COMMA expr """ p[0] = make_sentence('PRINT_AT', make_typecast(TYPE.ubyte, p[2], p.lineno(1)), make_typecast(TYPE.ubyte, p[4], p.lineno(3)))
python
def p_print_list_at(p): """ print_at : AT expr COMMA expr """ p[0] = make_sentence('PRINT_AT', make_typecast(TYPE.ubyte, p[2], p.lineno(1)), make_typecast(TYPE.ubyte, p[4], p.lineno(3)))
[ "def", "p_print_list_at", "(", "p", ")", ":", "p", "[", "0", "]", "=", "make_sentence", "(", "'PRINT_AT'", ",", "make_typecast", "(", "TYPE", ".", "ubyte", ",", "p", "[", "2", "]", ",", "p", ".", "lineno", "(", "1", ")", ")", ",", "make_typecast", "(", "TYPE", ".", "ubyte", ",", "p", "[", "4", "]", ",", "p", ".", "lineno", "(", "3", ")", ")", ")" ]
print_at : AT expr COMMA expr
[ "print_at", ":", "AT", "expr", "COMMA", "expr" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L1909-L1914
boriel/zxbasic
zxbparser.py
p_print_list_tab
def p_print_list_tab(p): """ print_tab : TAB expr """ p[0] = make_sentence('PRINT_TAB', make_typecast(TYPE.ubyte, p[2], p.lineno(1)))
python
def p_print_list_tab(p): """ print_tab : TAB expr """ p[0] = make_sentence('PRINT_TAB', make_typecast(TYPE.ubyte, p[2], p.lineno(1)))
[ "def", "p_print_list_tab", "(", "p", ")", ":", "p", "[", "0", "]", "=", "make_sentence", "(", "'PRINT_TAB'", ",", "make_typecast", "(", "TYPE", ".", "ubyte", ",", "p", "[", "2", "]", ",", "p", ".", "lineno", "(", "1", ")", ")", ")" ]
print_tab : TAB expr
[ "print_tab", ":", "TAB", "expr" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L1917-L1921
boriel/zxbasic
zxbparser.py
p_on_goto
def p_on_goto(p): """ statement : ON expr goto label_list """ expr = make_typecast(TYPE.ubyte, p[2], p.lineno(1)) p[0] = make_sentence('ON_' + p[3], expr, *p[4])
python
def p_on_goto(p): """ statement : ON expr goto label_list """ expr = make_typecast(TYPE.ubyte, p[2], p.lineno(1)) p[0] = make_sentence('ON_' + p[3], expr, *p[4])
[ "def", "p_on_goto", "(", "p", ")", ":", "expr", "=", "make_typecast", "(", "TYPE", ".", "ubyte", ",", "p", "[", "2", "]", ",", "p", ".", "lineno", "(", "1", ")", ")", "p", "[", "0", "]", "=", "make_sentence", "(", "'ON_'", "+", "p", "[", "3", "]", ",", "expr", ",", "*", "p", "[", "4", "]", ")" ]
statement : ON expr goto label_list
[ "statement", ":", "ON", "expr", "goto", "label_list" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L1924-L1928
boriel/zxbasic
zxbparser.py
p_label_list_list
def p_label_list_list(p): """ label_list : label_list COMMA ID | label_list COMMA NUMBER """ p[0] = p[1] entry = check_and_make_label(p[3], p.lineno(3)) p[1].append(entry)
python
def p_label_list_list(p): """ label_list : label_list COMMA ID | label_list COMMA NUMBER """ p[0] = p[1] entry = check_and_make_label(p[3], p.lineno(3)) p[1].append(entry)
[ "def", "p_label_list_list", "(", "p", ")", ":", "p", "[", "0", "]", "=", "p", "[", "1", "]", "entry", "=", "check_and_make_label", "(", "p", "[", "3", "]", ",", "p", ".", "lineno", "(", "3", ")", ")", "p", "[", "1", "]", ".", "append", "(", "entry", ")" ]
label_list : label_list COMMA ID | label_list COMMA NUMBER
[ "label_list", ":", "label_list", "COMMA", "ID", "|", "label_list", "COMMA", "NUMBER" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L1939-L1945
boriel/zxbasic
zxbparser.py
p_return
def p_return(p): """ statement : RETURN """ if not FUNCTION_LEVEL: # At less one level, otherwise, this return is from a GOSUB p[0] = make_sentence('RETURN') return if FUNCTION_LEVEL[-1].kind != KIND.sub: syntax_error(p.lineno(1), 'Syntax Error: Functions must RETURN a value, or use EXIT FUNCTION instead.') p[0] = None return p[0] = make_sentence('RETURN', FUNCTION_LEVEL[-1])
python
def p_return(p): """ statement : RETURN """ if not FUNCTION_LEVEL: # At less one level, otherwise, this return is from a GOSUB p[0] = make_sentence('RETURN') return if FUNCTION_LEVEL[-1].kind != KIND.sub: syntax_error(p.lineno(1), 'Syntax Error: Functions must RETURN a value, or use EXIT FUNCTION instead.') p[0] = None return p[0] = make_sentence('RETURN', FUNCTION_LEVEL[-1])
[ "def", "p_return", "(", "p", ")", ":", "if", "not", "FUNCTION_LEVEL", ":", "# At less one level, otherwise, this return is from a GOSUB", "p", "[", "0", "]", "=", "make_sentence", "(", "'RETURN'", ")", "return", "if", "FUNCTION_LEVEL", "[", "-", "1", "]", ".", "kind", "!=", "KIND", ".", "sub", ":", "syntax_error", "(", "p", ".", "lineno", "(", "1", ")", ",", "'Syntax Error: Functions must RETURN a value, or use EXIT FUNCTION instead.'", ")", "p", "[", "0", "]", "=", "None", "return", "p", "[", "0", "]", "=", "make_sentence", "(", "'RETURN'", ",", "FUNCTION_LEVEL", "[", "-", "1", "]", ")" ]
statement : RETURN
[ "statement", ":", "RETURN" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L1948-L1960
boriel/zxbasic
zxbparser.py
p_return_expr
def p_return_expr(p): """ statement : RETURN expr """ if not FUNCTION_LEVEL: # At less one level syntax_error(p.lineno(1), 'Syntax Error: Returning value out of FUNCTION') p[0] = None return if FUNCTION_LEVEL[-1].kind is None: # This function was not correctly declared. p[0] = None return if FUNCTION_LEVEL[-1].kind != KIND.function: syntax_error(p.lineno(1), 'Syntax Error: SUBs cannot return a value') p[0] = None return if is_numeric(p[2]) and FUNCTION_LEVEL[-1].type_ == TYPE.string: syntax_error(p.lineno(2), 'Type Error: Function must return a string, not a numeric value') p[0] = None return if not is_numeric(p[2]) and FUNCTION_LEVEL[-1].type_ != TYPE.string: syntax_error(p.lineno(2), 'Type Error: Function must return a numeric value, not a string') p[0] = None return p[0] = make_sentence('RETURN', FUNCTION_LEVEL[-1], make_typecast(FUNCTION_LEVEL[-1].type_, p[2], p.lineno(1)))
python
def p_return_expr(p): """ statement : RETURN expr """ if not FUNCTION_LEVEL: # At less one level syntax_error(p.lineno(1), 'Syntax Error: Returning value out of FUNCTION') p[0] = None return if FUNCTION_LEVEL[-1].kind is None: # This function was not correctly declared. p[0] = None return if FUNCTION_LEVEL[-1].kind != KIND.function: syntax_error(p.lineno(1), 'Syntax Error: SUBs cannot return a value') p[0] = None return if is_numeric(p[2]) and FUNCTION_LEVEL[-1].type_ == TYPE.string: syntax_error(p.lineno(2), 'Type Error: Function must return a string, not a numeric value') p[0] = None return if not is_numeric(p[2]) and FUNCTION_LEVEL[-1].type_ != TYPE.string: syntax_error(p.lineno(2), 'Type Error: Function must return a numeric value, not a string') p[0] = None return p[0] = make_sentence('RETURN', FUNCTION_LEVEL[-1], make_typecast(FUNCTION_LEVEL[-1].type_, p[2], p.lineno(1)))
[ "def", "p_return_expr", "(", "p", ")", ":", "if", "not", "FUNCTION_LEVEL", ":", "# At less one level", "syntax_error", "(", "p", ".", "lineno", "(", "1", ")", ",", "'Syntax Error: Returning value out of FUNCTION'", ")", "p", "[", "0", "]", "=", "None", "return", "if", "FUNCTION_LEVEL", "[", "-", "1", "]", ".", "kind", "is", "None", ":", "# This function was not correctly declared.", "p", "[", "0", "]", "=", "None", "return", "if", "FUNCTION_LEVEL", "[", "-", "1", "]", ".", "kind", "!=", "KIND", ".", "function", ":", "syntax_error", "(", "p", ".", "lineno", "(", "1", ")", ",", "'Syntax Error: SUBs cannot return a value'", ")", "p", "[", "0", "]", "=", "None", "return", "if", "is_numeric", "(", "p", "[", "2", "]", ")", "and", "FUNCTION_LEVEL", "[", "-", "1", "]", ".", "type_", "==", "TYPE", ".", "string", ":", "syntax_error", "(", "p", ".", "lineno", "(", "2", ")", ",", "'Type Error: Function must return a string, not a numeric value'", ")", "p", "[", "0", "]", "=", "None", "return", "if", "not", "is_numeric", "(", "p", "[", "2", "]", ")", "and", "FUNCTION_LEVEL", "[", "-", "1", "]", ".", "type_", "!=", "TYPE", ".", "string", ":", "syntax_error", "(", "p", ".", "lineno", "(", "2", ")", ",", "'Type Error: Function must return a numeric value, not a string'", ")", "p", "[", "0", "]", "=", "None", "return", "p", "[", "0", "]", "=", "make_sentence", "(", "'RETURN'", ",", "FUNCTION_LEVEL", "[", "-", "1", "]", ",", "make_typecast", "(", "FUNCTION_LEVEL", "[", "-", "1", "]", ".", "type_", ",", "p", "[", "2", "]", ",", "p", ".", "lineno", "(", "1", ")", ")", ")" ]
statement : RETURN expr
[ "statement", ":", "RETURN", "expr" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L1963-L1992
boriel/zxbasic
zxbparser.py
p_pause
def p_pause(p): """ statement : PAUSE expr """ p[0] = make_sentence('PAUSE', make_typecast(TYPE.uinteger, p[2], p.lineno(1)))
python
def p_pause(p): """ statement : PAUSE expr """ p[0] = make_sentence('PAUSE', make_typecast(TYPE.uinteger, p[2], p.lineno(1)))
[ "def", "p_pause", "(", "p", ")", ":", "p", "[", "0", "]", "=", "make_sentence", "(", "'PAUSE'", ",", "make_typecast", "(", "TYPE", ".", "uinteger", ",", "p", "[", "2", "]", ",", "p", ".", "lineno", "(", "1", ")", ")", ")" ]
statement : PAUSE expr
[ "statement", ":", "PAUSE", "expr" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L1995-L1999
boriel/zxbasic
zxbparser.py
p_poke
def p_poke(p): """ statement : POKE expr COMMA expr | POKE LP expr COMMA expr RP """ i = 2 if isinstance(p[2], Symbol) or p[2] is None else 3 if p[i] is None or p[i + 2] is None: p[0] = None return p[0] = make_sentence('POKE', make_typecast(TYPE.uinteger, p[i], p.lineno(i + 1)), make_typecast(TYPE.ubyte, p[i + 2], p.lineno(i + 1)))
python
def p_poke(p): """ statement : POKE expr COMMA expr | POKE LP expr COMMA expr RP """ i = 2 if isinstance(p[2], Symbol) or p[2] is None else 3 if p[i] is None or p[i + 2] is None: p[0] = None return p[0] = make_sentence('POKE', make_typecast(TYPE.uinteger, p[i], p.lineno(i + 1)), make_typecast(TYPE.ubyte, p[i + 2], p.lineno(i + 1)))
[ "def", "p_poke", "(", "p", ")", ":", "i", "=", "2", "if", "isinstance", "(", "p", "[", "2", "]", ",", "Symbol", ")", "or", "p", "[", "2", "]", "is", "None", "else", "3", "if", "p", "[", "i", "]", "is", "None", "or", "p", "[", "i", "+", "2", "]", "is", "None", ":", "p", "[", "0", "]", "=", "None", "return", "p", "[", "0", "]", "=", "make_sentence", "(", "'POKE'", ",", "make_typecast", "(", "TYPE", ".", "uinteger", ",", "p", "[", "i", "]", ",", "p", ".", "lineno", "(", "i", "+", "1", ")", ")", ",", "make_typecast", "(", "TYPE", ".", "ubyte", ",", "p", "[", "i", "+", "2", "]", ",", "p", ".", "lineno", "(", "i", "+", "1", ")", ")", ")" ]
statement : POKE expr COMMA expr | POKE LP expr COMMA expr RP
[ "statement", ":", "POKE", "expr", "COMMA", "expr", "|", "POKE", "LP", "expr", "COMMA", "expr", "RP" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L2002-L2012
boriel/zxbasic
zxbparser.py
p_poke2
def p_poke2(p): """ statement : POKE numbertype expr COMMA expr | POKE LP numbertype expr COMMA expr RP """ i = 2 if isinstance(p[2], Symbol) or p[2] is None else 3 if p[i + 1] is None or p[i + 3] is None: p[0] = None return p[0] = make_sentence('POKE', make_typecast(TYPE.uinteger, p[i + 1], p.lineno(i + 2)), make_typecast(p[i], p[i + 3], p.lineno(i + 3)) )
python
def p_poke2(p): """ statement : POKE numbertype expr COMMA expr | POKE LP numbertype expr COMMA expr RP """ i = 2 if isinstance(p[2], Symbol) or p[2] is None else 3 if p[i + 1] is None or p[i + 3] is None: p[0] = None return p[0] = make_sentence('POKE', make_typecast(TYPE.uinteger, p[i + 1], p.lineno(i + 2)), make_typecast(p[i], p[i + 3], p.lineno(i + 3)) )
[ "def", "p_poke2", "(", "p", ")", ":", "i", "=", "2", "if", "isinstance", "(", "p", "[", "2", "]", ",", "Symbol", ")", "or", "p", "[", "2", "]", "is", "None", "else", "3", "if", "p", "[", "i", "+", "1", "]", "is", "None", "or", "p", "[", "i", "+", "3", "]", "is", "None", ":", "p", "[", "0", "]", "=", "None", "return", "p", "[", "0", "]", "=", "make_sentence", "(", "'POKE'", ",", "make_typecast", "(", "TYPE", ".", "uinteger", ",", "p", "[", "i", "+", "1", "]", ",", "p", ".", "lineno", "(", "i", "+", "2", ")", ")", ",", "make_typecast", "(", "p", "[", "i", "]", ",", "p", "[", "i", "+", "3", "]", ",", "p", ".", "lineno", "(", "i", "+", "3", ")", ")", ")" ]
statement : POKE numbertype expr COMMA expr | POKE LP numbertype expr COMMA expr RP
[ "statement", ":", "POKE", "numbertype", "expr", "COMMA", "expr", "|", "POKE", "LP", "numbertype", "expr", "COMMA", "expr", "RP" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L2015-L2026
boriel/zxbasic
zxbparser.py
p_out
def p_out(p): """ statement : OUT expr COMMA expr """ p[0] = make_sentence('OUT', make_typecast(TYPE.uinteger, p[2], p.lineno(3)), make_typecast(TYPE.ubyte, p[4], p.lineno(4)))
python
def p_out(p): """ statement : OUT expr COMMA expr """ p[0] = make_sentence('OUT', make_typecast(TYPE.uinteger, p[2], p.lineno(3)), make_typecast(TYPE.ubyte, p[4], p.lineno(4)))
[ "def", "p_out", "(", "p", ")", ":", "p", "[", "0", "]", "=", "make_sentence", "(", "'OUT'", ",", "make_typecast", "(", "TYPE", ".", "uinteger", ",", "p", "[", "2", "]", ",", "p", ".", "lineno", "(", "3", ")", ")", ",", "make_typecast", "(", "TYPE", ".", "ubyte", ",", "p", "[", "4", "]", ",", "p", ".", "lineno", "(", "4", ")", ")", ")" ]
statement : OUT expr COMMA expr
[ "statement", ":", "OUT", "expr", "COMMA", "expr" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L2043-L2048
boriel/zxbasic
zxbparser.py
p_simple_instruction
def p_simple_instruction(p): """ statement : ITALIC expr | BOLD expr | INK expr | PAPER expr | BRIGHT expr | FLASH expr | OVER expr | INVERSE expr """ p[0] = make_sentence(p[1], make_typecast(TYPE.ubyte, p[2], p.lineno(1)))
python
def p_simple_instruction(p): """ statement : ITALIC expr | BOLD expr | INK expr | PAPER expr | BRIGHT expr | FLASH expr | OVER expr | INVERSE expr """ p[0] = make_sentence(p[1], make_typecast(TYPE.ubyte, p[2], p.lineno(1)))
[ "def", "p_simple_instruction", "(", "p", ")", ":", "p", "[", "0", "]", "=", "make_sentence", "(", "p", "[", "1", "]", ",", "make_typecast", "(", "TYPE", ".", "ubyte", ",", "p", "[", "2", "]", ",", "p", ".", "lineno", "(", "1", ")", ")", ")" ]
statement : ITALIC expr | BOLD expr | INK expr | PAPER expr | BRIGHT expr | FLASH expr | OVER expr | INVERSE expr
[ "statement", ":", "ITALIC", "expr", "|", "BOLD", "expr", "|", "INK", "expr", "|", "PAPER", "expr", "|", "BRIGHT", "expr", "|", "FLASH", "expr", "|", "OVER", "expr", "|", "INVERSE", "expr" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L2051-L2061
boriel/zxbasic
zxbparser.py
p_save_code
def p_save_code(p): """ statement : SAVE expr CODE expr COMMA expr | SAVE expr ID | SAVE expr ARRAY_ID """ if p[2].type_ != TYPE.string: api.errmsg.syntax_error_expected_string(p.lineno(1), p[2].type_) if len(p) == 5: if p[3].upper() not in ('SCREEN', 'SCREEN$'): syntax_error(p.lineno(3), 'Unexpected "%s" ID. Expected "SCREEN$" instead' % p[3]) return None else: # ZX Spectrum screen start + length # This should be stored in a architecture-dependant file start = make_number(16384, lineno=p.lineno(1)) length = make_number(6912, lineno=p.lineno(1)) else: start = p[4] length = p[6] p[0] = make_sentence(p[1], p[2], start, length)
python
def p_save_code(p): """ statement : SAVE expr CODE expr COMMA expr | SAVE expr ID | SAVE expr ARRAY_ID """ if p[2].type_ != TYPE.string: api.errmsg.syntax_error_expected_string(p.lineno(1), p[2].type_) if len(p) == 5: if p[3].upper() not in ('SCREEN', 'SCREEN$'): syntax_error(p.lineno(3), 'Unexpected "%s" ID. Expected "SCREEN$" instead' % p[3]) return None else: # ZX Spectrum screen start + length # This should be stored in a architecture-dependant file start = make_number(16384, lineno=p.lineno(1)) length = make_number(6912, lineno=p.lineno(1)) else: start = p[4] length = p[6] p[0] = make_sentence(p[1], p[2], start, length)
[ "def", "p_save_code", "(", "p", ")", ":", "if", "p", "[", "2", "]", ".", "type_", "!=", "TYPE", ".", "string", ":", "api", ".", "errmsg", ".", "syntax_error_expected_string", "(", "p", ".", "lineno", "(", "1", ")", ",", "p", "[", "2", "]", ".", "type_", ")", "if", "len", "(", "p", ")", "==", "5", ":", "if", "p", "[", "3", "]", ".", "upper", "(", ")", "not", "in", "(", "'SCREEN'", ",", "'SCREEN$'", ")", ":", "syntax_error", "(", "p", ".", "lineno", "(", "3", ")", ",", "'Unexpected \"%s\" ID. Expected \"SCREEN$\" instead'", "%", "p", "[", "3", "]", ")", "return", "None", "else", ":", "# ZX Spectrum screen start + length", "# This should be stored in a architecture-dependant file", "start", "=", "make_number", "(", "16384", ",", "lineno", "=", "p", ".", "lineno", "(", "1", ")", ")", "length", "=", "make_number", "(", "6912", ",", "lineno", "=", "p", ".", "lineno", "(", "1", ")", ")", "else", ":", "start", "=", "p", "[", "4", "]", "length", "=", "p", "[", "6", "]", "p", "[", "0", "]", "=", "make_sentence", "(", "p", "[", "1", "]", ",", "p", "[", "2", "]", ",", "start", ",", "length", ")" ]
statement : SAVE expr CODE expr COMMA expr | SAVE expr ID | SAVE expr ARRAY_ID
[ "statement", ":", "SAVE", "expr", "CODE", "expr", "COMMA", "expr", "|", "SAVE", "expr", "ID", "|", "SAVE", "expr", "ARRAY_ID" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L2064-L2085
boriel/zxbasic
zxbparser.py
p_save_data
def p_save_data(p): """ statement : SAVE expr DATA | SAVE expr DATA ID | SAVE expr DATA ID LP RP """ if p[2].type_ != TYPE.string: api.errmsg.syntax_error_expected_string(p.lineno(1), p[2].type_) if len(p) != 4: entry = SYMBOL_TABLE.access_id(p[4], p.lineno(4)) if entry is None: p[0] = None return entry.accessed = True access = entry start = make_unary(p.lineno(4), 'ADDRESS', access, type_=TYPE.uinteger) if entry.class_ == CLASS.array: length = make_number(entry.memsize, lineno=p.lineno(4)) else: length = make_number(entry.type_.size, lineno=p.lineno(4)) else: access = SYMBOL_TABLE.access_id('.ZXBASIC_USER_DATA', p.lineno(3)) start = make_unary(p.lineno(3), 'ADDRESS', access, type_=TYPE.uinteger) access = SYMBOL_TABLE.access_id('.ZXBASIC_USER_DATA_LEN', p.lineno(3)) length = make_unary(p.lineno(3), 'ADDRESS', access, type_=TYPE.uinteger) p[0] = make_sentence(p[1], p[2], start, length)
python
def p_save_data(p): """ statement : SAVE expr DATA | SAVE expr DATA ID | SAVE expr DATA ID LP RP """ if p[2].type_ != TYPE.string: api.errmsg.syntax_error_expected_string(p.lineno(1), p[2].type_) if len(p) != 4: entry = SYMBOL_TABLE.access_id(p[4], p.lineno(4)) if entry is None: p[0] = None return entry.accessed = True access = entry start = make_unary(p.lineno(4), 'ADDRESS', access, type_=TYPE.uinteger) if entry.class_ == CLASS.array: length = make_number(entry.memsize, lineno=p.lineno(4)) else: length = make_number(entry.type_.size, lineno=p.lineno(4)) else: access = SYMBOL_TABLE.access_id('.ZXBASIC_USER_DATA', p.lineno(3)) start = make_unary(p.lineno(3), 'ADDRESS', access, type_=TYPE.uinteger) access = SYMBOL_TABLE.access_id('.ZXBASIC_USER_DATA_LEN', p.lineno(3)) length = make_unary(p.lineno(3), 'ADDRESS', access, type_=TYPE.uinteger) p[0] = make_sentence(p[1], p[2], start, length)
[ "def", "p_save_data", "(", "p", ")", ":", "if", "p", "[", "2", "]", ".", "type_", "!=", "TYPE", ".", "string", ":", "api", ".", "errmsg", ".", "syntax_error_expected_string", "(", "p", ".", "lineno", "(", "1", ")", ",", "p", "[", "2", "]", ".", "type_", ")", "if", "len", "(", "p", ")", "!=", "4", ":", "entry", "=", "SYMBOL_TABLE", ".", "access_id", "(", "p", "[", "4", "]", ",", "p", ".", "lineno", "(", "4", ")", ")", "if", "entry", "is", "None", ":", "p", "[", "0", "]", "=", "None", "return", "entry", ".", "accessed", "=", "True", "access", "=", "entry", "start", "=", "make_unary", "(", "p", ".", "lineno", "(", "4", ")", ",", "'ADDRESS'", ",", "access", ",", "type_", "=", "TYPE", ".", "uinteger", ")", "if", "entry", ".", "class_", "==", "CLASS", ".", "array", ":", "length", "=", "make_number", "(", "entry", ".", "memsize", ",", "lineno", "=", "p", ".", "lineno", "(", "4", ")", ")", "else", ":", "length", "=", "make_number", "(", "entry", ".", "type_", ".", "size", ",", "lineno", "=", "p", ".", "lineno", "(", "4", ")", ")", "else", ":", "access", "=", "SYMBOL_TABLE", ".", "access_id", "(", "'.ZXBASIC_USER_DATA'", ",", "p", ".", "lineno", "(", "3", ")", ")", "start", "=", "make_unary", "(", "p", ".", "lineno", "(", "3", ")", ",", "'ADDRESS'", ",", "access", ",", "type_", "=", "TYPE", ".", "uinteger", ")", "access", "=", "SYMBOL_TABLE", ".", "access_id", "(", "'.ZXBASIC_USER_DATA_LEN'", ",", "p", ".", "lineno", "(", "3", ")", ")", "length", "=", "make_unary", "(", "p", ".", "lineno", "(", "3", ")", ",", "'ADDRESS'", ",", "access", ",", "type_", "=", "TYPE", ".", "uinteger", ")", "p", "[", "0", "]", "=", "make_sentence", "(", "p", "[", "1", "]", ",", "p", "[", "2", "]", ",", "start", ",", "length", ")" ]
statement : SAVE expr DATA | SAVE expr DATA ID | SAVE expr DATA ID LP RP
[ "statement", ":", "SAVE", "expr", "DATA", "|", "SAVE", "expr", "DATA", "ID", "|", "SAVE", "expr", "DATA", "ID", "LP", "RP" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L2088-L2117
boriel/zxbasic
zxbparser.py
p_load_code
def p_load_code(p): """ statement : load_or_verify expr ID | load_or_verify expr CODE | load_or_verify expr CODE expr | load_or_verify expr CODE expr COMMA expr """ if p[2].type_ != TYPE.string: api.errmsg.syntax_error_expected_string(p.lineno(3), p[2].type_) if len(p) == 4: if p[3].upper() not in ('SCREEN', 'SCREEN$', 'CODE'): syntax_error(p.lineno(3), 'Unexpected "%s" ID. Expected "SCREEN$" instead' % p[3]) return None else: if p[3].upper() == 'CODE': # LOAD "..." CODE start = make_number(0, lineno=p.lineno(3)) length = make_number(0, lineno=p.lineno(3)) else: # SCREEN$ start = make_number(16384, lineno=p.lineno(3)) length = make_number(6912, lineno=p.lineno(3)) else: start = make_typecast(TYPE.uinteger, p[4], p.lineno(3)) if len(p) == 5: length = make_number(0, lineno=p.lineno(3)) else: length = make_typecast(TYPE.uinteger, p[6], p.lineno(5)) p[0] = make_sentence(p[1], p[2], start, length)
python
def p_load_code(p): """ statement : load_or_verify expr ID | load_or_verify expr CODE | load_or_verify expr CODE expr | load_or_verify expr CODE expr COMMA expr """ if p[2].type_ != TYPE.string: api.errmsg.syntax_error_expected_string(p.lineno(3), p[2].type_) if len(p) == 4: if p[3].upper() not in ('SCREEN', 'SCREEN$', 'CODE'): syntax_error(p.lineno(3), 'Unexpected "%s" ID. Expected "SCREEN$" instead' % p[3]) return None else: if p[3].upper() == 'CODE': # LOAD "..." CODE start = make_number(0, lineno=p.lineno(3)) length = make_number(0, lineno=p.lineno(3)) else: # SCREEN$ start = make_number(16384, lineno=p.lineno(3)) length = make_number(6912, lineno=p.lineno(3)) else: start = make_typecast(TYPE.uinteger, p[4], p.lineno(3)) if len(p) == 5: length = make_number(0, lineno=p.lineno(3)) else: length = make_typecast(TYPE.uinteger, p[6], p.lineno(5)) p[0] = make_sentence(p[1], p[2], start, length)
[ "def", "p_load_code", "(", "p", ")", ":", "if", "p", "[", "2", "]", ".", "type_", "!=", "TYPE", ".", "string", ":", "api", ".", "errmsg", ".", "syntax_error_expected_string", "(", "p", ".", "lineno", "(", "3", ")", ",", "p", "[", "2", "]", ".", "type_", ")", "if", "len", "(", "p", ")", "==", "4", ":", "if", "p", "[", "3", "]", ".", "upper", "(", ")", "not", "in", "(", "'SCREEN'", ",", "'SCREEN$'", ",", "'CODE'", ")", ":", "syntax_error", "(", "p", ".", "lineno", "(", "3", ")", ",", "'Unexpected \"%s\" ID. Expected \"SCREEN$\" instead'", "%", "p", "[", "3", "]", ")", "return", "None", "else", ":", "if", "p", "[", "3", "]", ".", "upper", "(", ")", "==", "'CODE'", ":", "# LOAD \"...\" CODE", "start", "=", "make_number", "(", "0", ",", "lineno", "=", "p", ".", "lineno", "(", "3", ")", ")", "length", "=", "make_number", "(", "0", ",", "lineno", "=", "p", ".", "lineno", "(", "3", ")", ")", "else", ":", "# SCREEN$", "start", "=", "make_number", "(", "16384", ",", "lineno", "=", "p", ".", "lineno", "(", "3", ")", ")", "length", "=", "make_number", "(", "6912", ",", "lineno", "=", "p", ".", "lineno", "(", "3", ")", ")", "else", ":", "start", "=", "make_typecast", "(", "TYPE", ".", "uinteger", ",", "p", "[", "4", "]", ",", "p", ".", "lineno", "(", "3", ")", ")", "if", "len", "(", "p", ")", "==", "5", ":", "length", "=", "make_number", "(", "0", ",", "lineno", "=", "p", ".", "lineno", "(", "3", ")", ")", "else", ":", "length", "=", "make_typecast", "(", "TYPE", ".", "uinteger", ",", "p", "[", "6", "]", ",", "p", ".", "lineno", "(", "5", ")", ")", "p", "[", "0", "]", "=", "make_sentence", "(", "p", "[", "1", "]", ",", "p", "[", "2", "]", ",", "start", ",", "length", ")" ]
statement : load_or_verify expr ID | load_or_verify expr CODE | load_or_verify expr CODE expr | load_or_verify expr CODE expr COMMA expr
[ "statement", ":", "load_or_verify", "expr", "ID", "|", "load_or_verify", "expr", "CODE", "|", "load_or_verify", "expr", "CODE", "expr", "|", "load_or_verify", "expr", "CODE", "expr", "COMMA", "expr" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L2127-L2155
boriel/zxbasic
zxbparser.py
p_expr_plus_expr
def p_expr_plus_expr(p): """ expr : expr PLUS expr """ p[0] = make_binary(p.lineno(2), 'PLUS', p[1], p[3], lambda x, y: x + y)
python
def p_expr_plus_expr(p): """ expr : expr PLUS expr """ p[0] = make_binary(p.lineno(2), 'PLUS', p[1], p[3], lambda x, y: x + y)
[ "def", "p_expr_plus_expr", "(", "p", ")", ":", "p", "[", "0", "]", "=", "make_binary", "(", "p", ".", "lineno", "(", "2", ")", ",", "'PLUS'", ",", "p", "[", "1", "]", ",", "p", "[", "3", "]", ",", "lambda", "x", ",", "y", ":", "x", "+", "y", ")" ]
expr : expr PLUS expr
[ "expr", ":", "expr", "PLUS", "expr" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L2202-L2205
boriel/zxbasic
zxbparser.py
p_expr_minus_expr
def p_expr_minus_expr(p): """ expr : expr MINUS expr """ p[0] = make_binary(p.lineno(2), 'MINUS', p[1], p[3], lambda x, y: x - y)
python
def p_expr_minus_expr(p): """ expr : expr MINUS expr """ p[0] = make_binary(p.lineno(2), 'MINUS', p[1], p[3], lambda x, y: x - y)
[ "def", "p_expr_minus_expr", "(", "p", ")", ":", "p", "[", "0", "]", "=", "make_binary", "(", "p", ".", "lineno", "(", "2", ")", ",", "'MINUS'", ",", "p", "[", "1", "]", ",", "p", "[", "3", "]", ",", "lambda", "x", ",", "y", ":", "x", "-", "y", ")" ]
expr : expr MINUS expr
[ "expr", ":", "expr", "MINUS", "expr" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L2208-L2211
boriel/zxbasic
zxbparser.py
p_expr_mul_expr
def p_expr_mul_expr(p): """ expr : expr MUL expr """ p[0] = make_binary(p.lineno(2), 'MUL', p[1], p[3], lambda x, y: x * y)
python
def p_expr_mul_expr(p): """ expr : expr MUL expr """ p[0] = make_binary(p.lineno(2), 'MUL', p[1], p[3], lambda x, y: x * y)
[ "def", "p_expr_mul_expr", "(", "p", ")", ":", "p", "[", "0", "]", "=", "make_binary", "(", "p", ".", "lineno", "(", "2", ")", ",", "'MUL'", ",", "p", "[", "1", "]", ",", "p", "[", "3", "]", ",", "lambda", "x", ",", "y", ":", "x", "*", "y", ")" ]
expr : expr MUL expr
[ "expr", ":", "expr", "MUL", "expr" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L2214-L2217
boriel/zxbasic
zxbparser.py
p_expr_div_expr
def p_expr_div_expr(p): """ expr : expr DIV expr """ p[0] = make_binary(p.lineno(2), 'DIV', p[1], p[3], lambda x, y: x / y)
python
def p_expr_div_expr(p): """ expr : expr DIV expr """ p[0] = make_binary(p.lineno(2), 'DIV', p[1], p[3], lambda x, y: x / y)
[ "def", "p_expr_div_expr", "(", "p", ")", ":", "p", "[", "0", "]", "=", "make_binary", "(", "p", ".", "lineno", "(", "2", ")", ",", "'DIV'", ",", "p", "[", "1", "]", ",", "p", "[", "3", "]", ",", "lambda", "x", ",", "y", ":", "x", "/", "y", ")" ]
expr : expr DIV expr
[ "expr", ":", "expr", "DIV", "expr" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L2220-L2223
boriel/zxbasic
zxbparser.py
p_expr_mod_expr
def p_expr_mod_expr(p): """ expr : expr MOD expr """ p[0] = make_binary(p.lineno(2), 'MOD', p[1], p[3], lambda x, y: x % y)
python
def p_expr_mod_expr(p): """ expr : expr MOD expr """ p[0] = make_binary(p.lineno(2), 'MOD', p[1], p[3], lambda x, y: x % y)
[ "def", "p_expr_mod_expr", "(", "p", ")", ":", "p", "[", "0", "]", "=", "make_binary", "(", "p", ".", "lineno", "(", "2", ")", ",", "'MOD'", ",", "p", "[", "1", "]", ",", "p", "[", "3", "]", ",", "lambda", "x", ",", "y", ":", "x", "%", "y", ")" ]
expr : expr MOD expr
[ "expr", ":", "expr", "MOD", "expr" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L2226-L2229
boriel/zxbasic
zxbparser.py
p_expr_pow_expr
def p_expr_pow_expr(p): """ expr : expr POW expr """ p[0] = make_binary(p.lineno(2), 'POW', make_typecast(TYPE.float_, p[1], p.lineno(2)), make_typecast(TYPE.float_, p[3], p.lexer.lineno), lambda x, y: x ** y)
python
def p_expr_pow_expr(p): """ expr : expr POW expr """ p[0] = make_binary(p.lineno(2), 'POW', make_typecast(TYPE.float_, p[1], p.lineno(2)), make_typecast(TYPE.float_, p[3], p.lexer.lineno), lambda x, y: x ** y)
[ "def", "p_expr_pow_expr", "(", "p", ")", ":", "p", "[", "0", "]", "=", "make_binary", "(", "p", ".", "lineno", "(", "2", ")", ",", "'POW'", ",", "make_typecast", "(", "TYPE", ".", "float_", ",", "p", "[", "1", "]", ",", "p", ".", "lineno", "(", "2", ")", ")", ",", "make_typecast", "(", "TYPE", ".", "float_", ",", "p", "[", "3", "]", ",", "p", ".", "lexer", ".", "lineno", ")", ",", "lambda", "x", ",", "y", ":", "x", "**", "y", ")" ]
expr : expr POW expr
[ "expr", ":", "expr", "POW", "expr" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L2232-L2238
boriel/zxbasic
zxbparser.py
p_expr_shl_expr
def p_expr_shl_expr(p): """ expr : expr SHL expr """ if p[1] is None or p[3] is None: p[0] = None return if p[1].type_ in (TYPE.float_, TYPE.fixed): p[1] = make_typecast(TYPE.ulong, p[1], p.lineno(2)) p[0] = make_binary(p.lineno(2), 'SHL', p[1], make_typecast(TYPE.ubyte, p[3], p.lineno(2)), lambda x, y: x << y)
python
def p_expr_shl_expr(p): """ expr : expr SHL expr """ if p[1] is None or p[3] is None: p[0] = None return if p[1].type_ in (TYPE.float_, TYPE.fixed): p[1] = make_typecast(TYPE.ulong, p[1], p.lineno(2)) p[0] = make_binary(p.lineno(2), 'SHL', p[1], make_typecast(TYPE.ubyte, p[3], p.lineno(2)), lambda x, y: x << y)
[ "def", "p_expr_shl_expr", "(", "p", ")", ":", "if", "p", "[", "1", "]", "is", "None", "or", "p", "[", "3", "]", "is", "None", ":", "p", "[", "0", "]", "=", "None", "return", "if", "p", "[", "1", "]", ".", "type_", "in", "(", "TYPE", ".", "float_", ",", "TYPE", ".", "fixed", ")", ":", "p", "[", "1", "]", "=", "make_typecast", "(", "TYPE", ".", "ulong", ",", "p", "[", "1", "]", ",", "p", ".", "lineno", "(", "2", ")", ")", "p", "[", "0", "]", "=", "make_binary", "(", "p", ".", "lineno", "(", "2", ")", ",", "'SHL'", ",", "p", "[", "1", "]", ",", "make_typecast", "(", "TYPE", ".", "ubyte", ",", "p", "[", "3", "]", ",", "p", ".", "lineno", "(", "2", ")", ")", ",", "lambda", "x", ",", "y", ":", "x", "<<", "y", ")" ]
expr : expr SHL expr
[ "expr", ":", "expr", "SHL", "expr" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L2241-L2253
boriel/zxbasic
zxbparser.py
p_expr_EQ_expr
def p_expr_EQ_expr(p): """ expr : expr EQ expr """ p[0] = make_binary(p.lineno(2), 'EQ', p[1], p[3], lambda x, y: x == y)
python
def p_expr_EQ_expr(p): """ expr : expr EQ expr """ p[0] = make_binary(p.lineno(2), 'EQ', p[1], p[3], lambda x, y: x == y)
[ "def", "p_expr_EQ_expr", "(", "p", ")", ":", "p", "[", "0", "]", "=", "make_binary", "(", "p", ".", "lineno", "(", "2", ")", ",", "'EQ'", ",", "p", "[", "1", "]", ",", "p", "[", "3", "]", ",", "lambda", "x", ",", "y", ":", "x", "==", "y", ")" ]
expr : expr EQ expr
[ "expr", ":", "expr", "EQ", "expr" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L2277-L2280
boriel/zxbasic
zxbparser.py
p_expr_LT_expr
def p_expr_LT_expr(p): """ expr : expr LT expr """ p[0] = make_binary(p.lineno(2), 'LT', p[1], p[3], lambda x, y: x < y)
python
def p_expr_LT_expr(p): """ expr : expr LT expr """ p[0] = make_binary(p.lineno(2), 'LT', p[1], p[3], lambda x, y: x < y)
[ "def", "p_expr_LT_expr", "(", "p", ")", ":", "p", "[", "0", "]", "=", "make_binary", "(", "p", ".", "lineno", "(", "2", ")", ",", "'LT'", ",", "p", "[", "1", "]", ",", "p", "[", "3", "]", ",", "lambda", "x", ",", "y", ":", "x", "<", "y", ")" ]
expr : expr LT expr
[ "expr", ":", "expr", "LT", "expr" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L2283-L2286
boriel/zxbasic
zxbparser.py
p_expr_LE_expr
def p_expr_LE_expr(p): """ expr : expr LE expr """ p[0] = make_binary(p.lineno(2), 'LE', p[1], p[3], lambda x, y: x <= y)
python
def p_expr_LE_expr(p): """ expr : expr LE expr """ p[0] = make_binary(p.lineno(2), 'LE', p[1], p[3], lambda x, y: x <= y)
[ "def", "p_expr_LE_expr", "(", "p", ")", ":", "p", "[", "0", "]", "=", "make_binary", "(", "p", ".", "lineno", "(", "2", ")", ",", "'LE'", ",", "p", "[", "1", "]", ",", "p", "[", "3", "]", ",", "lambda", "x", ",", "y", ":", "x", "<=", "y", ")" ]
expr : expr LE expr
[ "expr", ":", "expr", "LE", "expr" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L2289-L2292
boriel/zxbasic
zxbparser.py
p_expr_GT_expr
def p_expr_GT_expr(p): """ expr : expr GT expr """ p[0] = make_binary(p.lineno(2), 'GT', p[1], p[3], lambda x, y: x > y)
python
def p_expr_GT_expr(p): """ expr : expr GT expr """ p[0] = make_binary(p.lineno(2), 'GT', p[1], p[3], lambda x, y: x > y)
[ "def", "p_expr_GT_expr", "(", "p", ")", ":", "p", "[", "0", "]", "=", "make_binary", "(", "p", ".", "lineno", "(", "2", ")", ",", "'GT'", ",", "p", "[", "1", "]", ",", "p", "[", "3", "]", ",", "lambda", "x", ",", "y", ":", "x", ">", "y", ")" ]
expr : expr GT expr
[ "expr", ":", "expr", "GT", "expr" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L2295-L2298
boriel/zxbasic
zxbparser.py
p_expr_GE_expr
def p_expr_GE_expr(p): """ expr : expr GE expr """ p[0] = make_binary(p.lineno(2), 'GE', p[1], p[3], lambda x, y: x >= y)
python
def p_expr_GE_expr(p): """ expr : expr GE expr """ p[0] = make_binary(p.lineno(2), 'GE', p[1], p[3], lambda x, y: x >= y)
[ "def", "p_expr_GE_expr", "(", "p", ")", ":", "p", "[", "0", "]", "=", "make_binary", "(", "p", ".", "lineno", "(", "2", ")", ",", "'GE'", ",", "p", "[", "1", "]", ",", "p", "[", "3", "]", ",", "lambda", "x", ",", "y", ":", "x", ">=", "y", ")" ]
expr : expr GE expr
[ "expr", ":", "expr", "GE", "expr" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L2301-L2304
boriel/zxbasic
zxbparser.py
p_expr_NE_expr
def p_expr_NE_expr(p): """ expr : expr NE expr """ p[0] = make_binary(p.lineno(2), 'NE', p[1], p[3], lambda x, y: x != y)
python
def p_expr_NE_expr(p): """ expr : expr NE expr """ p[0] = make_binary(p.lineno(2), 'NE', p[1], p[3], lambda x, y: x != y)
[ "def", "p_expr_NE_expr", "(", "p", ")", ":", "p", "[", "0", "]", "=", "make_binary", "(", "p", ".", "lineno", "(", "2", ")", ",", "'NE'", ",", "p", "[", "1", "]", ",", "p", "[", "3", "]", ",", "lambda", "x", ",", "y", ":", "x", "!=", "y", ")" ]
expr : expr NE expr
[ "expr", ":", "expr", "NE", "expr" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L2307-L2310
boriel/zxbasic
zxbparser.py
p_expr_OR_expr
def p_expr_OR_expr(p): """ expr : expr OR expr """ p[0] = make_binary(p.lineno(2), 'OR', p[1], p[3], lambda x, y: x or y)
python
def p_expr_OR_expr(p): """ expr : expr OR expr """ p[0] = make_binary(p.lineno(2), 'OR', p[1], p[3], lambda x, y: x or y)
[ "def", "p_expr_OR_expr", "(", "p", ")", ":", "p", "[", "0", "]", "=", "make_binary", "(", "p", ".", "lineno", "(", "2", ")", ",", "'OR'", ",", "p", "[", "1", "]", ",", "p", "[", "3", "]", ",", "lambda", "x", ",", "y", ":", "x", "or", "y", ")" ]
expr : expr OR expr
[ "expr", ":", "expr", "OR", "expr" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L2313-L2316
boriel/zxbasic
zxbparser.py
p_expr_BOR_expr
def p_expr_BOR_expr(p): """ expr : expr BOR expr """ p[0] = make_binary(p.lineno(2), 'BOR', p[1], p[3], lambda x, y: x | y)
python
def p_expr_BOR_expr(p): """ expr : expr BOR expr """ p[0] = make_binary(p.lineno(2), 'BOR', p[1], p[3], lambda x, y: x | y)
[ "def", "p_expr_BOR_expr", "(", "p", ")", ":", "p", "[", "0", "]", "=", "make_binary", "(", "p", ".", "lineno", "(", "2", ")", ",", "'BOR'", ",", "p", "[", "1", "]", ",", "p", "[", "3", "]", ",", "lambda", "x", ",", "y", ":", "x", "|", "y", ")" ]
expr : expr BOR expr
[ "expr", ":", "expr", "BOR", "expr" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L2319-L2322
boriel/zxbasic
zxbparser.py
p_expr_XOR_expr
def p_expr_XOR_expr(p): """ expr : expr XOR expr """ p[0] = make_binary(p.lineno(2), 'XOR', p[1], p[3], lambda x, y: (x and not y) or (not x and y))
python
def p_expr_XOR_expr(p): """ expr : expr XOR expr """ p[0] = make_binary(p.lineno(2), 'XOR', p[1], p[3], lambda x, y: (x and not y) or (not x and y))
[ "def", "p_expr_XOR_expr", "(", "p", ")", ":", "p", "[", "0", "]", "=", "make_binary", "(", "p", ".", "lineno", "(", "2", ")", ",", "'XOR'", ",", "p", "[", "1", "]", ",", "p", "[", "3", "]", ",", "lambda", "x", ",", "y", ":", "(", "x", "and", "not", "y", ")", "or", "(", "not", "x", "and", "y", ")", ")" ]
expr : expr XOR expr
[ "expr", ":", "expr", "XOR", "expr" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L2325-L2328
boriel/zxbasic
zxbparser.py
p_expr_BXOR_expr
def p_expr_BXOR_expr(p): """ expr : expr BXOR expr """ p[0] = make_binary(p.lineno(2), 'BXOR', p[1], p[3], lambda x, y: x ^ y)
python
def p_expr_BXOR_expr(p): """ expr : expr BXOR expr """ p[0] = make_binary(p.lineno(2), 'BXOR', p[1], p[3], lambda x, y: x ^ y)
[ "def", "p_expr_BXOR_expr", "(", "p", ")", ":", "p", "[", "0", "]", "=", "make_binary", "(", "p", ".", "lineno", "(", "2", ")", ",", "'BXOR'", ",", "p", "[", "1", "]", ",", "p", "[", "3", "]", ",", "lambda", "x", ",", "y", ":", "x", "^", "y", ")" ]
expr : expr BXOR expr
[ "expr", ":", "expr", "BXOR", "expr" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L2331-L2334
boriel/zxbasic
zxbparser.py
p_expr_AND_expr
def p_expr_AND_expr(p): """ expr : expr AND expr """ p[0] = make_binary(p.lineno(2), 'AND', p[1], p[3], lambda x, y: x and y)
python
def p_expr_AND_expr(p): """ expr : expr AND expr """ p[0] = make_binary(p.lineno(2), 'AND', p[1], p[3], lambda x, y: x and y)
[ "def", "p_expr_AND_expr", "(", "p", ")", ":", "p", "[", "0", "]", "=", "make_binary", "(", "p", ".", "lineno", "(", "2", ")", ",", "'AND'", ",", "p", "[", "1", "]", ",", "p", "[", "3", "]", ",", "lambda", "x", ",", "y", ":", "x", "and", "y", ")" ]
expr : expr AND expr
[ "expr", ":", "expr", "AND", "expr" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L2337-L2340
boriel/zxbasic
zxbparser.py
p_expr_BAND_expr
def p_expr_BAND_expr(p): """ expr : expr BAND expr """ p[0] = make_binary(p.lineno(2), 'BAND', p[1], p[3], lambda x, y: x & y)
python
def p_expr_BAND_expr(p): """ expr : expr BAND expr """ p[0] = make_binary(p.lineno(2), 'BAND', p[1], p[3], lambda x, y: x & y)
[ "def", "p_expr_BAND_expr", "(", "p", ")", ":", "p", "[", "0", "]", "=", "make_binary", "(", "p", ".", "lineno", "(", "2", ")", ",", "'BAND'", ",", "p", "[", "1", "]", ",", "p", "[", "3", "]", ",", "lambda", "x", ",", "y", ":", "x", "&", "y", ")" ]
expr : expr BAND expr
[ "expr", ":", "expr", "BAND", "expr" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L2343-L2346
boriel/zxbasic
zxbparser.py
p_expr_PI
def p_expr_PI(p): """ bexpr : PI """ p[0] = make_number(PI, lineno=p.lineno(1), type_=TYPE.float_)
python
def p_expr_PI(p): """ bexpr : PI """ p[0] = make_number(PI, lineno=p.lineno(1), type_=TYPE.float_)
[ "def", "p_expr_PI", "(", "p", ")", ":", "p", "[", "0", "]", "=", "make_number", "(", "PI", ",", "lineno", "=", "p", ".", "lineno", "(", "1", ")", ",", "type_", "=", "TYPE", ".", "float_", ")" ]
bexpr : PI
[ "bexpr", ":", "PI" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L2379-L2382
boriel/zxbasic
zxbparser.py
p_expr_id_substr
def p_expr_id_substr(p): """ string : ID substr """ entry = SYMBOL_TABLE.access_var(p[1], p.lineno(1), default_type=TYPE.string) p[0] = None if entry is None: return entry.accessed = True p[0] = make_strslice(p.lineno(1), entry, p[2][0], p[2][1])
python
def p_expr_id_substr(p): """ string : ID substr """ entry = SYMBOL_TABLE.access_var(p[1], p.lineno(1), default_type=TYPE.string) p[0] = None if entry is None: return entry.accessed = True p[0] = make_strslice(p.lineno(1), entry, p[2][0], p[2][1])
[ "def", "p_expr_id_substr", "(", "p", ")", ":", "entry", "=", "SYMBOL_TABLE", ".", "access_var", "(", "p", "[", "1", "]", ",", "p", ".", "lineno", "(", "1", ")", ",", "default_type", "=", "TYPE", ".", "string", ")", "p", "[", "0", "]", "=", "None", "if", "entry", "is", "None", ":", "return", "entry", ".", "accessed", "=", "True", "p", "[", "0", "]", "=", "make_strslice", "(", "p", ".", "lineno", "(", "1", ")", ",", "entry", ",", "p", "[", "2", "]", "[", "0", "]", ",", "p", "[", "2", "]", "[", "1", "]", ")" ]
string : ID substr
[ "string", ":", "ID", "substr" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L2427-L2436
boriel/zxbasic
zxbparser.py
p_string_expr_lp
def p_string_expr_lp(p): """ string : LP expr RP substr """ if p[2].type_ != TYPE.string: syntax_error(p.lexer.lineno, "Expected a string type expression. " "Got %s type instead" % TYPE.to_string(p[2].type_)) p[0] = None else: p[0] = make_strslice(p.lexer.lineno, p[2], p[4][0], p[4][1])
python
def p_string_expr_lp(p): """ string : LP expr RP substr """ if p[2].type_ != TYPE.string: syntax_error(p.lexer.lineno, "Expected a string type expression. " "Got %s type instead" % TYPE.to_string(p[2].type_)) p[0] = None else: p[0] = make_strslice(p.lexer.lineno, p[2], p[4][0], p[4][1])
[ "def", "p_string_expr_lp", "(", "p", ")", ":", "if", "p", "[", "2", "]", ".", "type_", "!=", "TYPE", ".", "string", ":", "syntax_error", "(", "p", ".", "lexer", ".", "lineno", ",", "\"Expected a string type expression. \"", "\"Got %s type instead\"", "%", "TYPE", ".", "to_string", "(", "p", "[", "2", "]", ".", "type_", ")", ")", "p", "[", "0", "]", "=", "None", "else", ":", "p", "[", "0", "]", "=", "make_strslice", "(", "p", ".", "lexer", ".", "lineno", ",", "p", "[", "2", "]", ",", "p", "[", "4", "]", "[", "0", "]", ",", "p", "[", "4", "]", "[", "1", "]", ")" ]
string : LP expr RP substr
[ "string", ":", "LP", "expr", "RP", "substr" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L2445-L2454
boriel/zxbasic
zxbparser.py
p_subind_str
def p_subind_str(p): """ substr : LP expr TO expr RP """ p[0] = (make_typecast(TYPE.uinteger, p[2], p.lineno(1)), make_typecast(TYPE.uinteger, p[4], p.lineno(3)))
python
def p_subind_str(p): """ substr : LP expr TO expr RP """ p[0] = (make_typecast(TYPE.uinteger, p[2], p.lineno(1)), make_typecast(TYPE.uinteger, p[4], p.lineno(3)))
[ "def", "p_subind_str", "(", "p", ")", ":", "p", "[", "0", "]", "=", "(", "make_typecast", "(", "TYPE", ".", "uinteger", ",", "p", "[", "2", "]", ",", "p", ".", "lineno", "(", "1", ")", ")", ",", "make_typecast", "(", "TYPE", ".", "uinteger", ",", "p", "[", "4", "]", ",", "p", ".", "lineno", "(", "3", ")", ")", ")" ]
substr : LP expr TO expr RP
[ "substr", ":", "LP", "expr", "TO", "expr", "RP" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L2457-L2461
boriel/zxbasic
zxbparser.py
p_subind_strTO
def p_subind_strTO(p): """ substr : LP TO expr RP """ p[0] = (make_typecast(TYPE.uinteger, make_number(0, lineno=p.lineno(2)), p.lineno(1)), make_typecast(TYPE.uinteger, p[3], p.lineno(2)))
python
def p_subind_strTO(p): """ substr : LP TO expr RP """ p[0] = (make_typecast(TYPE.uinteger, make_number(0, lineno=p.lineno(2)), p.lineno(1)), make_typecast(TYPE.uinteger, p[3], p.lineno(2)))
[ "def", "p_subind_strTO", "(", "p", ")", ":", "p", "[", "0", "]", "=", "(", "make_typecast", "(", "TYPE", ".", "uinteger", ",", "make_number", "(", "0", ",", "lineno", "=", "p", ".", "lineno", "(", "2", ")", ")", ",", "p", ".", "lineno", "(", "1", ")", ")", ",", "make_typecast", "(", "TYPE", ".", "uinteger", ",", "p", "[", "3", "]", ",", "p", ".", "lineno", "(", "2", ")", ")", ")" ]
substr : LP TO expr RP
[ "substr", ":", "LP", "TO", "expr", "RP" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L2464-L2469
boriel/zxbasic
zxbparser.py
p_subind_TO
def p_subind_TO(p): """ substr : LP TO RP """ p[0] = (make_typecast(TYPE.uinteger, make_number(0, lineno=p.lineno(2)), p.lineno(1)), make_typecast(TYPE.uinteger, make_number(gl.MAX_STRSLICE_IDX, lineno=p.lineno(3)), p.lineno(2)))
python
def p_subind_TO(p): """ substr : LP TO RP """ p[0] = (make_typecast(TYPE.uinteger, make_number(0, lineno=p.lineno(2)), p.lineno(1)), make_typecast(TYPE.uinteger, make_number(gl.MAX_STRSLICE_IDX, lineno=p.lineno(3)), p.lineno(2)))
[ "def", "p_subind_TO", "(", "p", ")", ":", "p", "[", "0", "]", "=", "(", "make_typecast", "(", "TYPE", ".", "uinteger", ",", "make_number", "(", "0", ",", "lineno", "=", "p", ".", "lineno", "(", "2", ")", ")", ",", "p", ".", "lineno", "(", "1", ")", ")", ",", "make_typecast", "(", "TYPE", ".", "uinteger", ",", "make_number", "(", "gl", ".", "MAX_STRSLICE_IDX", ",", "lineno", "=", "p", ".", "lineno", "(", "3", ")", ")", ",", "p", ".", "lineno", "(", "2", ")", ")", ")" ]
substr : LP TO RP
[ "substr", ":", "LP", "TO", "RP" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L2482-L2490
boriel/zxbasic
zxbparser.py
p_id_expr
def p_id_expr(p): """ bexpr : ID | ARRAY_ID """ entry = SYMBOL_TABLE.access_id(p[1], p.lineno(1), default_class=CLASS.var) if entry is None: p[0] = None return entry.accessed = True if entry.type_ == TYPE.auto: entry.type_ = _TYPE(gl.DEFAULT_TYPE) api.errmsg.warning_implicit_type(p.lineno(1), p[1], entry.type_) p[0] = entry """ if entry.class_ == CLASS.var: if entry.type_ == TYPE.auto: entry.type_ = SYMBOL_TABLE.basic_types[gl.DEFAULT_TYPE] #api.errmsg.warning_implicit_type(p.lineno(1), p[1], entry.type_) """ if entry.class_ == CLASS.array: if not LET_ASSIGNMENT: syntax_error(p.lineno(1), "Variable '%s' is an array and cannot be used in this context" % p[1]) p[0] = None elif entry.kind == KIND.function: # Function call with 0 args p[0] = make_call(p[1], p.lineno(1), make_arg_list(None)) elif entry.kind == KIND.sub: # Forbidden for subs api.errmsg.syntax_error_is_a_sub_not_a_func(p.lineno(1), p[1]) p[0] = None
python
def p_id_expr(p): """ bexpr : ID | ARRAY_ID """ entry = SYMBOL_TABLE.access_id(p[1], p.lineno(1), default_class=CLASS.var) if entry is None: p[0] = None return entry.accessed = True if entry.type_ == TYPE.auto: entry.type_ = _TYPE(gl.DEFAULT_TYPE) api.errmsg.warning_implicit_type(p.lineno(1), p[1], entry.type_) p[0] = entry """ if entry.class_ == CLASS.var: if entry.type_ == TYPE.auto: entry.type_ = SYMBOL_TABLE.basic_types[gl.DEFAULT_TYPE] #api.errmsg.warning_implicit_type(p.lineno(1), p[1], entry.type_) """ if entry.class_ == CLASS.array: if not LET_ASSIGNMENT: syntax_error(p.lineno(1), "Variable '%s' is an array and cannot be used in this context" % p[1]) p[0] = None elif entry.kind == KIND.function: # Function call with 0 args p[0] = make_call(p[1], p.lineno(1), make_arg_list(None)) elif entry.kind == KIND.sub: # Forbidden for subs api.errmsg.syntax_error_is_a_sub_not_a_func(p.lineno(1), p[1]) p[0] = None
[ "def", "p_id_expr", "(", "p", ")", ":", "entry", "=", "SYMBOL_TABLE", ".", "access_id", "(", "p", "[", "1", "]", ",", "p", ".", "lineno", "(", "1", ")", ",", "default_class", "=", "CLASS", ".", "var", ")", "if", "entry", "is", "None", ":", "p", "[", "0", "]", "=", "None", "return", "entry", ".", "accessed", "=", "True", "if", "entry", ".", "type_", "==", "TYPE", ".", "auto", ":", "entry", ".", "type_", "=", "_TYPE", "(", "gl", ".", "DEFAULT_TYPE", ")", "api", ".", "errmsg", ".", "warning_implicit_type", "(", "p", ".", "lineno", "(", "1", ")", ",", "p", "[", "1", "]", ",", "entry", ".", "type_", ")", "p", "[", "0", "]", "=", "entry", "\"\"\"\n if entry.class_ == CLASS.var:\n if entry.type_ == TYPE.auto:\n entry.type_ = SYMBOL_TABLE.basic_types[gl.DEFAULT_TYPE]\n #api.errmsg.warning_implicit_type(p.lineno(1), p[1], entry.type_)\n \"\"\"", "if", "entry", ".", "class_", "==", "CLASS", ".", "array", ":", "if", "not", "LET_ASSIGNMENT", ":", "syntax_error", "(", "p", ".", "lineno", "(", "1", ")", ",", "\"Variable '%s' is an array and cannot be used in this context\"", "%", "p", "[", "1", "]", ")", "p", "[", "0", "]", "=", "None", "elif", "entry", ".", "kind", "==", "KIND", ".", "function", ":", "# Function call with 0 args", "p", "[", "0", "]", "=", "make_call", "(", "p", "[", "1", "]", ",", "p", ".", "lineno", "(", "1", ")", ",", "make_arg_list", "(", "None", ")", ")", "elif", "entry", ".", "kind", "==", "KIND", ".", "sub", ":", "# Forbidden for subs", "api", ".", "errmsg", ".", "syntax_error_is_a_sub_not_a_func", "(", "p", ".", "lineno", "(", "1", ")", ",", "p", "[", "1", "]", ")", "p", "[", "0", "]", "=", "None" ]
bexpr : ID | ARRAY_ID
[ "bexpr", ":", "ID", "|", "ARRAY_ID" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L2499-L2529
boriel/zxbasic
zxbparser.py
p_addr_of_id
def p_addr_of_id(p): """ bexpr : ADDRESSOF ID | ADDRESSOF ARRAY_ID """ entry = SYMBOL_TABLE.access_id(p[2], p.lineno(2)) if entry is None: p[0] = None return entry.accessed = True result = make_unary(p.lineno(1), 'ADDRESS', entry, type_=_TYPE(gl.PTR_TYPE)) if is_dynamic(entry): p[0] = result else: p[0] = make_constexpr(p.lineno(1), result)
python
def p_addr_of_id(p): """ bexpr : ADDRESSOF ID | ADDRESSOF ARRAY_ID """ entry = SYMBOL_TABLE.access_id(p[2], p.lineno(2)) if entry is None: p[0] = None return entry.accessed = True result = make_unary(p.lineno(1), 'ADDRESS', entry, type_=_TYPE(gl.PTR_TYPE)) if is_dynamic(entry): p[0] = result else: p[0] = make_constexpr(p.lineno(1), result)
[ "def", "p_addr_of_id", "(", "p", ")", ":", "entry", "=", "SYMBOL_TABLE", ".", "access_id", "(", "p", "[", "2", "]", ",", "p", ".", "lineno", "(", "2", ")", ")", "if", "entry", "is", "None", ":", "p", "[", "0", "]", "=", "None", "return", "entry", ".", "accessed", "=", "True", "result", "=", "make_unary", "(", "p", ".", "lineno", "(", "1", ")", ",", "'ADDRESS'", ",", "entry", ",", "type_", "=", "_TYPE", "(", "gl", ".", "PTR_TYPE", ")", ")", "if", "is_dynamic", "(", "entry", ")", ":", "p", "[", "0", "]", "=", "result", "else", ":", "p", "[", "0", "]", "=", "make_constexpr", "(", "p", ".", "lineno", "(", "1", ")", ",", "result", ")" ]
bexpr : ADDRESSOF ID | ADDRESSOF ARRAY_ID
[ "bexpr", ":", "ADDRESSOF", "ID", "|", "ADDRESSOF", "ARRAY_ID" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L2532-L2547
boriel/zxbasic
zxbparser.py
p_idcall_expr
def p_idcall_expr(p): """ func_call : ID arg_list %prec UMINUS """ # This can be a function call or a string index p[0] = make_call(p[1], p.lineno(1), p[2]) if p[0] is None: return if p[0].token in ('STRSLICE', 'VAR', 'STRING'): entry = SYMBOL_TABLE.access_call(p[1], p.lineno(1)) entry.accessed = True return # TODO: Check that arrays really needs kind=function to be set # Both array accesses and functions are tagged as functions # functions also has the class_ attribute set to 'function' p[0].entry.set_kind(KIND.function, p.lineno(1)) p[0].entry.accessed = True
python
def p_idcall_expr(p): """ func_call : ID arg_list %prec UMINUS """ # This can be a function call or a string index p[0] = make_call(p[1], p.lineno(1), p[2]) if p[0] is None: return if p[0].token in ('STRSLICE', 'VAR', 'STRING'): entry = SYMBOL_TABLE.access_call(p[1], p.lineno(1)) entry.accessed = True return # TODO: Check that arrays really needs kind=function to be set # Both array accesses and functions are tagged as functions # functions also has the class_ attribute set to 'function' p[0].entry.set_kind(KIND.function, p.lineno(1)) p[0].entry.accessed = True
[ "def", "p_idcall_expr", "(", "p", ")", ":", "# This can be a function call or a string index", "p", "[", "0", "]", "=", "make_call", "(", "p", "[", "1", "]", ",", "p", ".", "lineno", "(", "1", ")", ",", "p", "[", "2", "]", ")", "if", "p", "[", "0", "]", "is", "None", ":", "return", "if", "p", "[", "0", "]", ".", "token", "in", "(", "'STRSLICE'", ",", "'VAR'", ",", "'STRING'", ")", ":", "entry", "=", "SYMBOL_TABLE", ".", "access_call", "(", "p", "[", "1", "]", ",", "p", ".", "lineno", "(", "1", ")", ")", "entry", ".", "accessed", "=", "True", "return", "# TODO: Check that arrays really needs kind=function to be set", "# Both array accesses and functions are tagged as functions", "# functions also has the class_ attribute set to 'function'", "p", "[", "0", "]", ".", "entry", ".", "set_kind", "(", "KIND", ".", "function", ",", "p", ".", "lineno", "(", "1", ")", ")", "p", "[", "0", "]", ".", "entry", ".", "accessed", "=", "True" ]
func_call : ID arg_list %prec UMINUS
[ "func_call", ":", "ID", "arg_list", "%prec", "UMINUS" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L2562-L2578
boriel/zxbasic
zxbparser.py
p_arr_access_expr
def p_arr_access_expr(p): """ func_call : ARRAY_ID arg_list """ # This is an array access p[0] = make_call(p[1], p.lineno(1), p[2]) if p[0] is None: return entry = SYMBOL_TABLE.access_call(p[1], p.lineno(1)) entry.accessed = True
python
def p_arr_access_expr(p): """ func_call : ARRAY_ID arg_list """ # This is an array access p[0] = make_call(p[1], p.lineno(1), p[2]) if p[0] is None: return entry = SYMBOL_TABLE.access_call(p[1], p.lineno(1)) entry.accessed = True
[ "def", "p_arr_access_expr", "(", "p", ")", ":", "# This is an array access", "p", "[", "0", "]", "=", "make_call", "(", "p", "[", "1", "]", ",", "p", ".", "lineno", "(", "1", ")", ",", "p", "[", "2", "]", ")", "if", "p", "[", "0", "]", "is", "None", ":", "return", "entry", "=", "SYMBOL_TABLE", ".", "access_call", "(", "p", "[", "1", "]", ",", "p", ".", "lineno", "(", "1", ")", ")", "entry", ".", "accessed", "=", "True" ]
func_call : ARRAY_ID arg_list
[ "func_call", ":", "ARRAY_ID", "arg_list" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L2581-L2589
boriel/zxbasic
zxbparser.py
p_let_arr_substr
def p_let_arr_substr(p): """ statement : LET ARRAY_ID arg_list substr EQ expr | ARRAY_ID arg_list substr EQ expr """ i = 2 if p[1].upper() == 'LET' else 1 id_ = p[i] arg_list = p[i + 1] substr = p[i + 2] expr_ = p[i + 4] p[0] = make_array_substr_assign(p.lineno(i), id_, arg_list, substr, expr_)
python
def p_let_arr_substr(p): """ statement : LET ARRAY_ID arg_list substr EQ expr | ARRAY_ID arg_list substr EQ expr """ i = 2 if p[1].upper() == 'LET' else 1 id_ = p[i] arg_list = p[i + 1] substr = p[i + 2] expr_ = p[i + 4] p[0] = make_array_substr_assign(p.lineno(i), id_, arg_list, substr, expr_)
[ "def", "p_let_arr_substr", "(", "p", ")", ":", "i", "=", "2", "if", "p", "[", "1", "]", ".", "upper", "(", ")", "==", "'LET'", "else", "1", "id_", "=", "p", "[", "i", "]", "arg_list", "=", "p", "[", "i", "+", "1", "]", "substr", "=", "p", "[", "i", "+", "2", "]", "expr_", "=", "p", "[", "i", "+", "4", "]", "p", "[", "0", "]", "=", "make_array_substr_assign", "(", "p", ".", "lineno", "(", "i", ")", ",", "id_", ",", "arg_list", ",", "substr", ",", "expr_", ")" ]
statement : LET ARRAY_ID arg_list substr EQ expr | ARRAY_ID arg_list substr EQ expr
[ "statement", ":", "LET", "ARRAY_ID", "arg_list", "substr", "EQ", "expr", "|", "ARRAY_ID", "arg_list", "substr", "EQ", "expr" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L2592-L2602
boriel/zxbasic
zxbparser.py
p_let_arr_substr_in_args
def p_let_arr_substr_in_args(p): """ statement : LET ARRAY_ID LP arguments TO RP EQ expr | ARRAY_ID LP arguments TO RP EQ expr """ i = 2 if p[1].upper() == 'LET' else 1 id_ = p[i] arg_list = p[i + 2] substr = (arg_list.children.pop().value, make_number(gl.MAX_STRSLICE_IDX, lineno=p.lineno(i + 3))) expr_ = p[i + 6] p[0] = make_array_substr_assign(p.lineno(i), id_, arg_list, substr, expr_)
python
def p_let_arr_substr_in_args(p): """ statement : LET ARRAY_ID LP arguments TO RP EQ expr | ARRAY_ID LP arguments TO RP EQ expr """ i = 2 if p[1].upper() == 'LET' else 1 id_ = p[i] arg_list = p[i + 2] substr = (arg_list.children.pop().value, make_number(gl.MAX_STRSLICE_IDX, lineno=p.lineno(i + 3))) expr_ = p[i + 6] p[0] = make_array_substr_assign(p.lineno(i), id_, arg_list, substr, expr_)
[ "def", "p_let_arr_substr_in_args", "(", "p", ")", ":", "i", "=", "2", "if", "p", "[", "1", "]", ".", "upper", "(", ")", "==", "'LET'", "else", "1", "id_", "=", "p", "[", "i", "]", "arg_list", "=", "p", "[", "i", "+", "2", "]", "substr", "=", "(", "arg_list", ".", "children", ".", "pop", "(", ")", ".", "value", ",", "make_number", "(", "gl", ".", "MAX_STRSLICE_IDX", ",", "lineno", "=", "p", ".", "lineno", "(", "i", "+", "3", ")", ")", ")", "expr_", "=", "p", "[", "i", "+", "6", "]", "p", "[", "0", "]", "=", "make_array_substr_assign", "(", "p", ".", "lineno", "(", "i", ")", ",", "id_", ",", "arg_list", ",", "substr", ",", "expr_", ")" ]
statement : LET ARRAY_ID LP arguments TO RP EQ expr | ARRAY_ID LP arguments TO RP EQ expr
[ "statement", ":", "LET", "ARRAY_ID", "LP", "arguments", "TO", "RP", "EQ", "expr", "|", "ARRAY_ID", "LP", "arguments", "TO", "RP", "EQ", "expr" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L2618-L2629
boriel/zxbasic
zxbparser.py
p_let_arr_substr_in_args2
def p_let_arr_substr_in_args2(p): """ statement : LET ARRAY_ID LP arguments COMMA TO expr RP EQ expr | ARRAY_ID LP arguments COMMA TO expr RP EQ expr """ i = 2 if p[1].upper() == 'LET' else 1 id_ = p[i] arg_list = p[i + 2] top_ = p[i + 5] substr = (make_number(0, lineno=p.lineno(i + 4)), top_) expr_ = p[i + 8] p[0] = make_array_substr_assign(p.lineno(i), id_, arg_list, substr, expr_)
python
def p_let_arr_substr_in_args2(p): """ statement : LET ARRAY_ID LP arguments COMMA TO expr RP EQ expr | ARRAY_ID LP arguments COMMA TO expr RP EQ expr """ i = 2 if p[1].upper() == 'LET' else 1 id_ = p[i] arg_list = p[i + 2] top_ = p[i + 5] substr = (make_number(0, lineno=p.lineno(i + 4)), top_) expr_ = p[i + 8] p[0] = make_array_substr_assign(p.lineno(i), id_, arg_list, substr, expr_)
[ "def", "p_let_arr_substr_in_args2", "(", "p", ")", ":", "i", "=", "2", "if", "p", "[", "1", "]", ".", "upper", "(", ")", "==", "'LET'", "else", "1", "id_", "=", "p", "[", "i", "]", "arg_list", "=", "p", "[", "i", "+", "2", "]", "top_", "=", "p", "[", "i", "+", "5", "]", "substr", "=", "(", "make_number", "(", "0", ",", "lineno", "=", "p", ".", "lineno", "(", "i", "+", "4", ")", ")", ",", "top_", ")", "expr_", "=", "p", "[", "i", "+", "8", "]", "p", "[", "0", "]", "=", "make_array_substr_assign", "(", "p", ".", "lineno", "(", "i", ")", ",", "id_", ",", "arg_list", ",", "substr", ",", "expr_", ")" ]
statement : LET ARRAY_ID LP arguments COMMA TO expr RP EQ expr | ARRAY_ID LP arguments COMMA TO expr RP EQ expr
[ "statement", ":", "LET", "ARRAY_ID", "LP", "arguments", "COMMA", "TO", "expr", "RP", "EQ", "expr", "|", "ARRAY_ID", "LP", "arguments", "COMMA", "TO", "expr", "RP", "EQ", "expr" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L2632-L2643
boriel/zxbasic
zxbparser.py
p_let_arr_substr_in_args3
def p_let_arr_substr_in_args3(p): """ statement : LET ARRAY_ID LP arguments COMMA TO RP EQ expr | ARRAY_ID LP arguments COMMA TO RP EQ expr """ i = 2 if p[1].upper() == 'LET' else 1 id_ = p[i] arg_list = p[i + 2] substr = (make_number(0, lineno=p.lineno(i + 4)), make_number(gl.MAX_STRSLICE_IDX, lineno=p.lineno(i + 3))) expr_ = p[i + 7] p[0] = make_array_substr_assign(p.lineno(i), id_, arg_list, substr, expr_)
python
def p_let_arr_substr_in_args3(p): """ statement : LET ARRAY_ID LP arguments COMMA TO RP EQ expr | ARRAY_ID LP arguments COMMA TO RP EQ expr """ i = 2 if p[1].upper() == 'LET' else 1 id_ = p[i] arg_list = p[i + 2] substr = (make_number(0, lineno=p.lineno(i + 4)), make_number(gl.MAX_STRSLICE_IDX, lineno=p.lineno(i + 3))) expr_ = p[i + 7] p[0] = make_array_substr_assign(p.lineno(i), id_, arg_list, substr, expr_)
[ "def", "p_let_arr_substr_in_args3", "(", "p", ")", ":", "i", "=", "2", "if", "p", "[", "1", "]", ".", "upper", "(", ")", "==", "'LET'", "else", "1", "id_", "=", "p", "[", "i", "]", "arg_list", "=", "p", "[", "i", "+", "2", "]", "substr", "=", "(", "make_number", "(", "0", ",", "lineno", "=", "p", ".", "lineno", "(", "i", "+", "4", ")", ")", ",", "make_number", "(", "gl", ".", "MAX_STRSLICE_IDX", ",", "lineno", "=", "p", ".", "lineno", "(", "i", "+", "3", ")", ")", ")", "expr_", "=", "p", "[", "i", "+", "7", "]", "p", "[", "0", "]", "=", "make_array_substr_assign", "(", "p", ".", "lineno", "(", "i", ")", ",", "id_", ",", "arg_list", ",", "substr", ",", "expr_", ")" ]
statement : LET ARRAY_ID LP arguments COMMA TO RP EQ expr | ARRAY_ID LP arguments COMMA TO RP EQ expr
[ "statement", ":", "LET", "ARRAY_ID", "LP", "arguments", "COMMA", "TO", "RP", "EQ", "expr", "|", "ARRAY_ID", "LP", "arguments", "COMMA", "TO", "RP", "EQ", "expr" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L2646-L2657
boriel/zxbasic
zxbparser.py
p_let_arr_substr_in_args4
def p_let_arr_substr_in_args4(p): """ statement : LET ARRAY_ID LP arguments TO expr RP EQ expr | ARRAY_ID LP arguments TO expr RP EQ expr """ i = 2 if p[1].upper() == 'LET' else 1 id_ = p[i] arg_list = p[i + 2] substr = (arg_list.children.pop().value, p[i + 4]) expr_ = p[i + 7] p[0] = make_array_substr_assign(p.lineno(i), id_, arg_list, substr, expr_)
python
def p_let_arr_substr_in_args4(p): """ statement : LET ARRAY_ID LP arguments TO expr RP EQ expr | ARRAY_ID LP arguments TO expr RP EQ expr """ i = 2 if p[1].upper() == 'LET' else 1 id_ = p[i] arg_list = p[i + 2] substr = (arg_list.children.pop().value, p[i + 4]) expr_ = p[i + 7] p[0] = make_array_substr_assign(p.lineno(i), id_, arg_list, substr, expr_)
[ "def", "p_let_arr_substr_in_args4", "(", "p", ")", ":", "i", "=", "2", "if", "p", "[", "1", "]", ".", "upper", "(", ")", "==", "'LET'", "else", "1", "id_", "=", "p", "[", "i", "]", "arg_list", "=", "p", "[", "i", "+", "2", "]", "substr", "=", "(", "arg_list", ".", "children", ".", "pop", "(", ")", ".", "value", ",", "p", "[", "i", "+", "4", "]", ")", "expr_", "=", "p", "[", "i", "+", "7", "]", "p", "[", "0", "]", "=", "make_array_substr_assign", "(", "p", ".", "lineno", "(", "i", ")", ",", "id_", ",", "arg_list", ",", "substr", ",", "expr_", ")" ]
statement : LET ARRAY_ID LP arguments TO expr RP EQ expr | ARRAY_ID LP arguments TO expr RP EQ expr
[ "statement", ":", "LET", "ARRAY_ID", "LP", "arguments", "TO", "expr", "RP", "EQ", "expr", "|", "ARRAY_ID", "LP", "arguments", "TO", "expr", "RP", "EQ", "expr" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L2660-L2670
boriel/zxbasic
zxbparser.py
p_addr_of_array_element
def p_addr_of_array_element(p): """ bexpr : ADDRESSOF ARRAY_ID arg_list """ p[0] = None if p[3] is None: return result = make_array_access(p[2], p.lineno(2), p[3]) if result is None: return result.entry.accessed = True p[0] = make_unary(p.lineno(1), 'ADDRESS', result, type_=_TYPE(gl.PTR_TYPE))
python
def p_addr_of_array_element(p): """ bexpr : ADDRESSOF ARRAY_ID arg_list """ p[0] = None if p[3] is None: return result = make_array_access(p[2], p.lineno(2), p[3]) if result is None: return result.entry.accessed = True p[0] = make_unary(p.lineno(1), 'ADDRESS', result, type_=_TYPE(gl.PTR_TYPE))
[ "def", "p_addr_of_array_element", "(", "p", ")", ":", "p", "[", "0", "]", "=", "None", "if", "p", "[", "3", "]", "is", "None", ":", "return", "result", "=", "make_array_access", "(", "p", "[", "2", "]", ",", "p", ".", "lineno", "(", "2", ")", ",", "p", "[", "3", "]", ")", "if", "result", "is", "None", ":", "return", "result", ".", "entry", ".", "accessed", "=", "True", "p", "[", "0", "]", "=", "make_unary", "(", "p", ".", "lineno", "(", "1", ")", ",", "'ADDRESS'", ",", "result", ",", "type_", "=", "_TYPE", "(", "gl", ".", "PTR_TYPE", ")", ")" ]
bexpr : ADDRESSOF ARRAY_ID arg_list
[ "bexpr", ":", "ADDRESSOF", "ARRAY_ID", "arg_list" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L2673-L2686
boriel/zxbasic
zxbparser.py
p_bexpr_func
def p_bexpr_func(p): """ bexpr : ID bexpr """ args = make_arg_list(make_argument(p[2], p.lineno(2))) p[0] = make_call(p[1], p.lineno(1), args) if p[0] is None: return if p[0].token in ('STRSLICE', 'VAR', 'STRING'): entry = SYMBOL_TABLE.access_call(p[1], p.lineno(1)) entry.accessed = True return # TODO: Check that arrays really needs kind=function to be set # Both array accesses and functions are tagged as functions # functions also has the class_ attribute set to 'function' p[0].entry.set_kind(KIND.function, p.lineno(1)) p[0].entry.accessed = True
python
def p_bexpr_func(p): """ bexpr : ID bexpr """ args = make_arg_list(make_argument(p[2], p.lineno(2))) p[0] = make_call(p[1], p.lineno(1), args) if p[0] is None: return if p[0].token in ('STRSLICE', 'VAR', 'STRING'): entry = SYMBOL_TABLE.access_call(p[1], p.lineno(1)) entry.accessed = True return # TODO: Check that arrays really needs kind=function to be set # Both array accesses and functions are tagged as functions # functions also has the class_ attribute set to 'function' p[0].entry.set_kind(KIND.function, p.lineno(1)) p[0].entry.accessed = True
[ "def", "p_bexpr_func", "(", "p", ")", ":", "args", "=", "make_arg_list", "(", "make_argument", "(", "p", "[", "2", "]", ",", "p", ".", "lineno", "(", "2", ")", ")", ")", "p", "[", "0", "]", "=", "make_call", "(", "p", "[", "1", "]", ",", "p", ".", "lineno", "(", "1", ")", ",", "args", ")", "if", "p", "[", "0", "]", "is", "None", ":", "return", "if", "p", "[", "0", "]", ".", "token", "in", "(", "'STRSLICE'", ",", "'VAR'", ",", "'STRING'", ")", ":", "entry", "=", "SYMBOL_TABLE", ".", "access_call", "(", "p", "[", "1", "]", ",", "p", ".", "lineno", "(", "1", ")", ")", "entry", ".", "accessed", "=", "True", "return", "# TODO: Check that arrays really needs kind=function to be set", "# Both array accesses and functions are tagged as functions", "# functions also has the class_ attribute set to 'function'", "p", "[", "0", "]", ".", "entry", ".", "set_kind", "(", "KIND", ".", "function", ",", "p", ".", "lineno", "(", "1", ")", ")", "p", "[", "0", "]", ".", "entry", ".", "accessed", "=", "True" ]
bexpr : ID bexpr
[ "bexpr", ":", "ID", "bexpr" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L2696-L2713
boriel/zxbasic
zxbparser.py
p_arguments
def p_arguments(p): """ arguments : arguments COMMA expr """ if p[1] is None or p[3] is None: p[0] = None else: p[0] = make_arg_list(p[1], make_argument(p[3], p.lineno(2)))
python
def p_arguments(p): """ arguments : arguments COMMA expr """ if p[1] is None or p[3] is None: p[0] = None else: p[0] = make_arg_list(p[1], make_argument(p[3], p.lineno(2)))
[ "def", "p_arguments", "(", "p", ")", ":", "if", "p", "[", "1", "]", "is", "None", "or", "p", "[", "3", "]", "is", "None", ":", "p", "[", "0", "]", "=", "None", "else", ":", "p", "[", "0", "]", "=", "make_arg_list", "(", "p", "[", "1", "]", ",", "make_argument", "(", "p", "[", "3", "]", ",", "p", ".", "lineno", "(", "2", ")", ")", ")" ]
arguments : arguments COMMA expr
[ "arguments", ":", "arguments", "COMMA", "expr" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L2728-L2734
boriel/zxbasic
zxbparser.py
p_funcdecl
def p_funcdecl(p): """ function_declaration : function_header function_body """ if p[1] is None: p[0] = None return p[0] = p[1] p[0].local_symbol_table = SYMBOL_TABLE.table[SYMBOL_TABLE.current_scope] p[0].locals_size = SYMBOL_TABLE.leave_scope() FUNCTION_LEVEL.pop() p[0].entry.body = p[2] entry = p[0].entry entry.forwarded = False
python
def p_funcdecl(p): """ function_declaration : function_header function_body """ if p[1] is None: p[0] = None return p[0] = p[1] p[0].local_symbol_table = SYMBOL_TABLE.table[SYMBOL_TABLE.current_scope] p[0].locals_size = SYMBOL_TABLE.leave_scope() FUNCTION_LEVEL.pop() p[0].entry.body = p[2] entry = p[0].entry entry.forwarded = False
[ "def", "p_funcdecl", "(", "p", ")", ":", "if", "p", "[", "1", "]", "is", "None", ":", "p", "[", "0", "]", "=", "None", "return", "p", "[", "0", "]", "=", "p", "[", "1", "]", "p", "[", "0", "]", ".", "local_symbol_table", "=", "SYMBOL_TABLE", ".", "table", "[", "SYMBOL_TABLE", ".", "current_scope", "]", "p", "[", "0", "]", ".", "locals_size", "=", "SYMBOL_TABLE", ".", "leave_scope", "(", ")", "FUNCTION_LEVEL", ".", "pop", "(", ")", "p", "[", "0", "]", ".", "entry", ".", "body", "=", "p", "[", "2", "]", "entry", "=", "p", "[", "0", "]", ".", "entry", "entry", ".", "forwarded", "=", "False" ]
function_declaration : function_header function_body
[ "function_declaration", ":", "function_header", "function_body" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L2743-L2757
boriel/zxbasic
zxbparser.py
p_funcdeclforward
def p_funcdeclforward(p): """ function_declaration : DECLARE function_header_pre """ if p[2] is None: if FUNCTION_LEVEL: FUNCTION_LEVEL.pop() return if p[2].entry.forwarded: syntax_error(p.lineno(1), "duplicated declaration for function '%s'" % p[2].name) p[2].entry.forwarded = True SYMBOL_TABLE.leave_scope() FUNCTION_LEVEL.pop()
python
def p_funcdeclforward(p): """ function_declaration : DECLARE function_header_pre """ if p[2] is None: if FUNCTION_LEVEL: FUNCTION_LEVEL.pop() return if p[2].entry.forwarded: syntax_error(p.lineno(1), "duplicated declaration for function '%s'" % p[2].name) p[2].entry.forwarded = True SYMBOL_TABLE.leave_scope() FUNCTION_LEVEL.pop()
[ "def", "p_funcdeclforward", "(", "p", ")", ":", "if", "p", "[", "2", "]", "is", "None", ":", "if", "FUNCTION_LEVEL", ":", "FUNCTION_LEVEL", ".", "pop", "(", ")", "return", "if", "p", "[", "2", "]", ".", "entry", ".", "forwarded", ":", "syntax_error", "(", "p", ".", "lineno", "(", "1", ")", ",", "\"duplicated declaration for function '%s'\"", "%", "p", "[", "2", "]", ".", "name", ")", "p", "[", "2", "]", ".", "entry", ".", "forwarded", "=", "True", "SYMBOL_TABLE", ".", "leave_scope", "(", ")", "FUNCTION_LEVEL", ".", "pop", "(", ")" ]
function_declaration : DECLARE function_header_pre
[ "function_declaration", ":", "DECLARE", "function_header_pre" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L2760-L2773
boriel/zxbasic
zxbparser.py
p_function_header_pre
def p_function_header_pre(p): """ function_header_pre : function_def param_decl typedef """ if p[1] is None or p[2] is None: p[0] = None return forwarded = p[1].entry.forwarded p[0] = p[1] p[0].appendChild(p[2]) p[0].params_size = p[2].size lineno = p.lineno(3) previoustype_ = p[0].type_ if not p[3].implicit or p[0].entry.type_ is None or p[0].entry.type_ == TYPE.unknown: p[0].type_ = p[3] if p[3].implicit and p[0].entry.kind == KIND.function: api.errmsg.warning_implicit_type(p[3].lineno, p[0].entry.name, p[0].type_) if forwarded and previoustype_ != p[0].type_: api.errmsg.syntax_error_func_type_mismatch(lineno, p[0].entry) p[0] = None return if forwarded: # Was predeclared, check parameters match p1 = p[0].entry.params # Param list previously declared p2 = p[2].children if len(p1) != len(p2): api.errmsg.syntax_error_parameter_mismatch(lineno, p[0].entry) p[0] = None return for a, b in zip(p1, p2): if a.name != b.name: warning(lineno, "Parameter '%s' in function '%s' has been renamed to '%s'" % (a.name, p[0].name, b.name)) if a.type_ != b.type_ or a.byref != b.byref: api.errmsg.syntax_error_parameter_mismatch(lineno, p[0].entry) p[0] = None return p[0].entry.params = p[2] if FUNCTION_LEVEL[-1].kind == KIND.sub and not p[3].implicit: syntax_error(lineno, 'SUBs cannot have a return type definition') p[0] = None return if FUNCTION_LEVEL[-1].kind == KIND.function: api.check.check_type_is_explicit(p[0].lineno, p[0].entry.name, p[3]) if p[0].entry.convention == CONVENTION.fastcall and len(p[2]) > 1: kind = 'SUB' if FUNCTION_LEVEL[-1].kind == KIND.sub else 'FUNCTION' warning(lineno, "%s '%s' declared as FASTCALL with %i parameters" % (kind, p[0].entry.name, len(p[2])))
python
def p_function_header_pre(p): """ function_header_pre : function_def param_decl typedef """ if p[1] is None or p[2] is None: p[0] = None return forwarded = p[1].entry.forwarded p[0] = p[1] p[0].appendChild(p[2]) p[0].params_size = p[2].size lineno = p.lineno(3) previoustype_ = p[0].type_ if not p[3].implicit or p[0].entry.type_ is None or p[0].entry.type_ == TYPE.unknown: p[0].type_ = p[3] if p[3].implicit and p[0].entry.kind == KIND.function: api.errmsg.warning_implicit_type(p[3].lineno, p[0].entry.name, p[0].type_) if forwarded and previoustype_ != p[0].type_: api.errmsg.syntax_error_func_type_mismatch(lineno, p[0].entry) p[0] = None return if forwarded: # Was predeclared, check parameters match p1 = p[0].entry.params # Param list previously declared p2 = p[2].children if len(p1) != len(p2): api.errmsg.syntax_error_parameter_mismatch(lineno, p[0].entry) p[0] = None return for a, b in zip(p1, p2): if a.name != b.name: warning(lineno, "Parameter '%s' in function '%s' has been renamed to '%s'" % (a.name, p[0].name, b.name)) if a.type_ != b.type_ or a.byref != b.byref: api.errmsg.syntax_error_parameter_mismatch(lineno, p[0].entry) p[0] = None return p[0].entry.params = p[2] if FUNCTION_LEVEL[-1].kind == KIND.sub and not p[3].implicit: syntax_error(lineno, 'SUBs cannot have a return type definition') p[0] = None return if FUNCTION_LEVEL[-1].kind == KIND.function: api.check.check_type_is_explicit(p[0].lineno, p[0].entry.name, p[3]) if p[0].entry.convention == CONVENTION.fastcall and len(p[2]) > 1: kind = 'SUB' if FUNCTION_LEVEL[-1].kind == KIND.sub else 'FUNCTION' warning(lineno, "%s '%s' declared as FASTCALL with %i parameters" % (kind, p[0].entry.name, len(p[2])))
[ "def", "p_function_header_pre", "(", "p", ")", ":", "if", "p", "[", "1", "]", "is", "None", "or", "p", "[", "2", "]", "is", "None", ":", "p", "[", "0", "]", "=", "None", "return", "forwarded", "=", "p", "[", "1", "]", ".", "entry", ".", "forwarded", "p", "[", "0", "]", "=", "p", "[", "1", "]", "p", "[", "0", "]", ".", "appendChild", "(", "p", "[", "2", "]", ")", "p", "[", "0", "]", ".", "params_size", "=", "p", "[", "2", "]", ".", "size", "lineno", "=", "p", ".", "lineno", "(", "3", ")", "previoustype_", "=", "p", "[", "0", "]", ".", "type_", "if", "not", "p", "[", "3", "]", ".", "implicit", "or", "p", "[", "0", "]", ".", "entry", ".", "type_", "is", "None", "or", "p", "[", "0", "]", ".", "entry", ".", "type_", "==", "TYPE", ".", "unknown", ":", "p", "[", "0", "]", ".", "type_", "=", "p", "[", "3", "]", "if", "p", "[", "3", "]", ".", "implicit", "and", "p", "[", "0", "]", ".", "entry", ".", "kind", "==", "KIND", ".", "function", ":", "api", ".", "errmsg", ".", "warning_implicit_type", "(", "p", "[", "3", "]", ".", "lineno", ",", "p", "[", "0", "]", ".", "entry", ".", "name", ",", "p", "[", "0", "]", ".", "type_", ")", "if", "forwarded", "and", "previoustype_", "!=", "p", "[", "0", "]", ".", "type_", ":", "api", ".", "errmsg", ".", "syntax_error_func_type_mismatch", "(", "lineno", ",", "p", "[", "0", "]", ".", "entry", ")", "p", "[", "0", "]", "=", "None", "return", "if", "forwarded", ":", "# Was predeclared, check parameters match", "p1", "=", "p", "[", "0", "]", ".", "entry", ".", "params", "# Param list previously declared", "p2", "=", "p", "[", "2", "]", ".", "children", "if", "len", "(", "p1", ")", "!=", "len", "(", "p2", ")", ":", "api", ".", "errmsg", ".", "syntax_error_parameter_mismatch", "(", "lineno", ",", "p", "[", "0", "]", ".", "entry", ")", "p", "[", "0", "]", "=", "None", "return", "for", "a", ",", "b", "in", "zip", "(", "p1", ",", "p2", ")", ":", "if", "a", ".", "name", "!=", "b", ".", "name", ":", "warning", "(", "lineno", ",", "\"Parameter '%s' in function '%s' has been renamed to '%s'\"", "%", "(", "a", ".", "name", ",", "p", "[", "0", "]", ".", "name", ",", "b", ".", "name", ")", ")", "if", "a", ".", "type_", "!=", "b", ".", "type_", "or", "a", ".", "byref", "!=", "b", ".", "byref", ":", "api", ".", "errmsg", ".", "syntax_error_parameter_mismatch", "(", "lineno", ",", "p", "[", "0", "]", ".", "entry", ")", "p", "[", "0", "]", "=", "None", "return", "p", "[", "0", "]", ".", "entry", ".", "params", "=", "p", "[", "2", "]", "if", "FUNCTION_LEVEL", "[", "-", "1", "]", ".", "kind", "==", "KIND", ".", "sub", "and", "not", "p", "[", "3", "]", ".", "implicit", ":", "syntax_error", "(", "lineno", ",", "'SUBs cannot have a return type definition'", ")", "p", "[", "0", "]", "=", "None", "return", "if", "FUNCTION_LEVEL", "[", "-", "1", "]", ".", "kind", "==", "KIND", ".", "function", ":", "api", ".", "check", ".", "check_type_is_explicit", "(", "p", "[", "0", "]", ".", "lineno", ",", "p", "[", "0", "]", ".", "entry", ".", "name", ",", "p", "[", "3", "]", ")", "if", "p", "[", "0", "]", ".", "entry", ".", "convention", "==", "CONVENTION", ".", "fastcall", "and", "len", "(", "p", "[", "2", "]", ")", ">", "1", ":", "kind", "=", "'SUB'", "if", "FUNCTION_LEVEL", "[", "-", "1", "]", ".", "kind", "==", "KIND", ".", "sub", "else", "'FUNCTION'", "warning", "(", "lineno", ",", "\"%s '%s' declared as FASTCALL with %i parameters\"", "%", "(", "kind", ",", "p", "[", "0", "]", ".", "entry", ".", "name", ",", "len", "(", "p", "[", "2", "]", ")", ")", ")" ]
function_header_pre : function_def param_decl typedef
[ "function_header_pre", ":", "function_def", "param_decl", "typedef" ]
train
https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L2783-L2840