diff options
Diffstat (limited to 'src/dc_parse.c')
-rw-r--r-- | src/dc_parse.c | 66 |
1 files changed, 42 insertions, 24 deletions
diff --git a/src/dc_parse.c b/src/dc_parse.c index 26aad6796d88..d45f951bad4f 100644 --- a/src/dc_parse.c +++ b/src/dc_parse.c @@ -50,8 +50,9 @@ * @param p The parser. * @param var True if the parser is for a variable, false otherwise. */ -static void dc_parse_register(BcParse *p, bool var) { - +static void +dc_parse_register(BcParse* p, bool var) +{ bc_lex_next(&p->l); if (p->l.t != BC_LEX_NAME) bc_parse_err(p, BC_ERR_PARSE_TOKEN); @@ -62,7 +63,9 @@ static void dc_parse_register(BcParse *p, bool var) { * Parses a dc string. * @param p The parser. */ -static inline void dc_parse_string(BcParse *p) { +static inline void +dc_parse_string(BcParse* p) +{ bc_parse_addString(p); bc_lex_next(&p->l); } @@ -75,8 +78,9 @@ static inline void dc_parse_string(BcParse *p) { * a global. * @param store True if the operation is a store, false otherwise. */ -static void dc_parse_mem(BcParse *p, uchar inst, bool name, bool store) { - +static void +dc_parse_mem(BcParse* p, uchar inst, bool name, bool store) +{ // Push the instruction. bc_parse_push(p, inst); @@ -85,7 +89,8 @@ static void dc_parse_mem(BcParse *p, uchar inst, bool name, bool store) { // Stores use the bc assign infrastructure, but they need to do a swap // first. - if (store) { + if (store) + { bc_parse_push(p, BC_INST_SWAP); bc_parse_push(p, BC_INST_ASSIGN_NO_VAL); } @@ -98,8 +103,9 @@ static void dc_parse_mem(BcParse *p, uchar inst, bool name, bool store) { * @param p The parser. * @param inst The instruction for the condition. */ -static void dc_parse_cond(BcParse *p, uchar inst) { - +static void +dc_parse_cond(BcParse* p, uchar inst) +{ // Push the instruction for the condition and the conditional execution. bc_parse_push(p, inst); bc_parse_push(p, BC_INST_EXEC_COND); @@ -110,7 +116,8 @@ static void dc_parse_cond(BcParse *p, uchar inst) { bc_lex_next(&p->l); // If the next token is an else, parse the else. - if (p->l.t == BC_LEX_KW_ELSE) { + if (p->l.t == BC_LEX_KW_ELSE) + { dc_parse_register(p, true); bc_lex_next(&p->l); } @@ -124,13 +131,14 @@ static void dc_parse_cond(BcParse *p, uchar inst) { * @param t The token to parse. * @param flags The flags that say what is allowed or not. */ -static void dc_parse_token(BcParse *p, BcLexType t, uint8_t flags) { - +static void +dc_parse_token(BcParse* p, BcLexType t, uint8_t flags) +{ uchar inst; bool assign, get_token = false; - switch (t) { - + switch (t) + { case BC_LEX_OP_REL_EQ: case BC_LEX_OP_REL_LE: case BC_LEX_OP_REL_GE: @@ -161,16 +169,18 @@ static void dc_parse_token(BcParse *p, BcLexType t, uint8_t flags) { // This tells us whether or not the neg is for a command or at the // beginning of a number. If it's a command, push it. Otherwise, // fallthrough and parse the number. - if (dc_lex_negCommand(&p->l)) { + if (dc_lex_negCommand(&p->l)) + { bc_parse_push(p, BC_INST_NEG); get_token = true; break; } bc_lex_next(&p->l); + + // Fallthrough. + BC_FALLTHROUGH } - // Fallthrough. - BC_FALLTHROUGH case BC_LEX_NUMBER: { @@ -187,7 +197,9 @@ static void dc_parse_token(BcParse *p, BcLexType t, uint8_t flags) { { // Make sure the read is not recursive. if (BC_ERR(flags & BC_PARSE_NOREAD)) + { bc_parse_err(p, BC_ERR_EXEC_REC_READ); + } else bc_parse_push(p, BC_INST_READ); get_token = true; @@ -254,8 +266,9 @@ static void dc_parse_token(BcParse *p, BcLexType t, uint8_t flags) { if (get_token) bc_lex_next(&p->l); } -void dc_parse_expr(BcParse *p, uint8_t flags) { - +void +dc_parse_expr(BcParse* p, uint8_t flags) +{ BcInst inst; BcLexType t; bool need_expr, have_expr = false; @@ -267,10 +280,11 @@ void dc_parse_expr(BcParse *p, uint8_t flags) { // designed. // While we don't have EOF... - while ((t = p->l.t) != BC_LEX_EOF) { - + while ((t = p->l.t) != BC_LEX_EOF) + { // Eat newline. - if (t == BC_LEX_NLINE) { + if (t == BC_LEX_NLINE) + { bc_lex_next(&p->l); continue; } @@ -281,7 +295,8 @@ void dc_parse_expr(BcParse *p, uint8_t flags) { // If the instruction is invalid, that means we have to do some harder // parsing. So if not invalid, just push the instruction; otherwise, // parse the token. - if (inst != BC_INST_INVALID) { + if (inst != BC_INST_INVALID) + { bc_parse_push(p, inst); bc_lex_next(&p->l); } @@ -295,11 +310,14 @@ void dc_parse_expr(BcParse *p, uint8_t flags) { // indicate that it is executing a string. if (BC_ERR(need_expr && !have_expr)) bc_err(BC_ERR_EXEC_READ_EXPR); else if (p->l.t == BC_LEX_EOF && (flags & BC_PARSE_NOCALL)) + { bc_parse_push(p, BC_INST_POP_EXEC); + } } -void dc_parse_parse(BcParse *p) { - +void +dc_parse_parse(BcParse* p) +{ assert(p != NULL); BC_SETJMP_LOCKED(exit); |