diff options
-rw-r--r-- | miscutils/bc.c | 312 |
1 files changed, 155 insertions, 157 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c index 35778ff1c..5cd80c1e5 100644 --- a/miscutils/bc.c +++ b/miscutils/bc.c | |||
@@ -714,12 +714,10 @@ typedef struct BcLex { | |||
714 | size_t i; | 714 | size_t i; |
715 | size_t line; | 715 | size_t line; |
716 | size_t len; | 716 | size_t len; |
717 | bool newline; | 717 | bool newline; |
718 | struct { | 718 | smallint lex; // was BcLexType |
719 | BcLexType t; | 719 | smallint lex_last; // was BcLexType |
720 | BcLexType last; | 720 | BcVec lex_buf; |
721 | BcVec v; | ||
722 | } t; | ||
723 | } BcLex; | 721 | } BcLex; |
724 | 722 | ||
725 | #define BC_PARSE_STREND (0xff) | 723 | #define BC_PARSE_STREND (0xff) |
@@ -2753,7 +2751,7 @@ static void bc_lex_lineComment(BcLex *l) | |||
2753 | { | 2751 | { |
2754 | // Try: echo -n '#foo' | bc | 2752 | // Try: echo -n '#foo' | bc |
2755 | size_t i; | 2753 | size_t i; |
2756 | l->t.t = XC_LEX_WHITESPACE; | 2754 | l->lex = XC_LEX_WHITESPACE; |
2757 | i = l->i; | 2755 | i = l->i; |
2758 | while (i < l->len && l->buf[i] != '\n') | 2756 | while (i < l->len && l->buf[i] != '\n') |
2759 | i++; | 2757 | i++; |
@@ -2762,7 +2760,7 @@ static void bc_lex_lineComment(BcLex *l) | |||
2762 | 2760 | ||
2763 | static void bc_lex_whitespace(BcLex *l) | 2761 | static void bc_lex_whitespace(BcLex *l) |
2764 | { | 2762 | { |
2765 | l->t.t = XC_LEX_WHITESPACE; | 2763 | l->lex = XC_LEX_WHITESPACE; |
2766 | for (;;) { | 2764 | for (;;) { |
2767 | char c = l->buf[l->i]; | 2765 | char c = l->buf[l->i]; |
2768 | if (c == '\n') // this is XC_LEX_NLINE, not XC_LEX_WHITESPACE | 2766 | if (c == '\n') // this is XC_LEX_NLINE, not XC_LEX_WHITESPACE |
@@ -2780,7 +2778,7 @@ static BC_STATUS zbc_lex_number(BcLex *l, char start) | |||
2780 | bool pt; | 2778 | bool pt; |
2781 | 2779 | ||
2782 | pt = (start == '.'); | 2780 | pt = (start == '.'); |
2783 | l->t.t = XC_LEX_NUMBER; | 2781 | l->lex = XC_LEX_NUMBER; |
2784 | ccnt = i = 0; | 2782 | ccnt = i = 0; |
2785 | for (;;) { | 2783 | for (;;) { |
2786 | char c = buf[i]; | 2784 | char c = buf[i]; |
@@ -2820,9 +2818,9 @@ static BC_STATUS zbc_lex_number(BcLex *l, char start) | |||
2820 | RETURN_STATUS(bc_error("number too long: must be [1,"BC_MAX_NUM_STR"]")); | 2818 | RETURN_STATUS(bc_error("number too long: must be [1,"BC_MAX_NUM_STR"]")); |
2821 | } | 2819 | } |
2822 | 2820 | ||
2823 | bc_vec_pop_all(&l->t.v); | 2821 | bc_vec_pop_all(&l->lex_buf); |
2824 | bc_vec_expand(&l->t.v, 1 + len); | 2822 | bc_vec_expand(&l->lex_buf, 1 + len); |
2825 | bc_vec_push(&l->t.v, &start); | 2823 | bc_vec_push(&l->lex_buf, &start); |
2826 | 2824 | ||
2827 | while (ccnt != 0) { | 2825 | while (ccnt != 0) { |
2828 | // If we have hit a backslash, skip it. We don't have | 2826 | // If we have hit a backslash, skip it. We don't have |
@@ -2832,12 +2830,12 @@ static BC_STATUS zbc_lex_number(BcLex *l, char start) | |||
2832 | ccnt -= 2; | 2830 | ccnt -= 2; |
2833 | continue; | 2831 | continue; |
2834 | } | 2832 | } |
2835 | bc_vec_push(&l->t.v, buf); | 2833 | bc_vec_push(&l->lex_buf, buf); |
2836 | buf++; | 2834 | buf++; |
2837 | ccnt--; | 2835 | ccnt--; |
2838 | } | 2836 | } |
2839 | 2837 | ||
2840 | bc_vec_pushZeroByte(&l->t.v); | 2838 | bc_vec_pushZeroByte(&l->lex_buf); |
2841 | 2839 | ||
2842 | RETURN_STATUS(BC_STATUS_SUCCESS); | 2840 | RETURN_STATUS(BC_STATUS_SUCCESS); |
2843 | } | 2841 | } |
@@ -2848,7 +2846,7 @@ static void bc_lex_name(BcLex *l) | |||
2848 | size_t i; | 2846 | size_t i; |
2849 | const char *buf; | 2847 | const char *buf; |
2850 | 2848 | ||
2851 | l->t.t = XC_LEX_NAME; | 2849 | l->lex = XC_LEX_NAME; |
2852 | 2850 | ||
2853 | i = 0; | 2851 | i = 0; |
2854 | buf = l->buf + l->i - 1; | 2852 | buf = l->buf + l->i - 1; |
@@ -2865,7 +2863,7 @@ static void bc_lex_name(BcLex *l) | |||
2865 | return bc_error("name too long: must be [1,"BC_MAX_STRING_STR"]"); | 2863 | return bc_error("name too long: must be [1,"BC_MAX_STRING_STR"]"); |
2866 | } | 2864 | } |
2867 | #endif | 2865 | #endif |
2868 | bc_vec_string(&l->t.v, i, buf); | 2866 | bc_vec_string(&l->lex_buf, i, buf); |
2869 | 2867 | ||
2870 | // Increment the index. We minus 1 because it has already been incremented. | 2868 | // Increment the index. We minus 1 because it has already been incremented. |
2871 | l->i += i - 1; | 2869 | l->i += i - 1; |
@@ -2875,12 +2873,12 @@ static void bc_lex_name(BcLex *l) | |||
2875 | 2873 | ||
2876 | static void bc_lex_init(BcLex *l) | 2874 | static void bc_lex_init(BcLex *l) |
2877 | { | 2875 | { |
2878 | bc_char_vec_init(&l->t.v); | 2876 | bc_char_vec_init(&l->lex_buf); |
2879 | } | 2877 | } |
2880 | 2878 | ||
2881 | static void bc_lex_free(BcLex *l) | 2879 | static void bc_lex_free(BcLex *l) |
2882 | { | 2880 | { |
2883 | bc_vec_free(&l->t.v); | 2881 | bc_vec_free(&l->lex_buf); |
2884 | } | 2882 | } |
2885 | 2883 | ||
2886 | static void bc_lex_file(BcLex *l) | 2884 | static void bc_lex_file(BcLex *l) |
@@ -2970,8 +2968,8 @@ static BC_STATUS zbc_lex_next(BcLex *l) | |||
2970 | { | 2968 | { |
2971 | BcStatus s; | 2969 | BcStatus s; |
2972 | 2970 | ||
2973 | l->t.last = l->t.t; | 2971 | l->lex_last = l->lex; |
2974 | if (l->t.last == XC_LEX_EOF) RETURN_STATUS(bc_error("end of file")); | 2972 | if (l->lex_last == XC_LEX_EOF) RETURN_STATUS(bc_error("end of file")); |
2975 | 2973 | ||
2976 | l->line += l->newline; | 2974 | l->line += l->newline; |
2977 | G.err_line = l->line; | 2975 | G.err_line = l->line; |
@@ -2983,7 +2981,7 @@ static BC_STATUS zbc_lex_next(BcLex *l) | |||
2983 | s = BC_STATUS_SUCCESS; | 2981 | s = BC_STATUS_SUCCESS; |
2984 | do { | 2982 | do { |
2985 | if (l->i == l->len) { | 2983 | if (l->i == l->len) { |
2986 | l->t.t = XC_LEX_EOF; | 2984 | l->lex = XC_LEX_EOF; |
2987 | if (!G.input_fp) | 2985 | if (!G.input_fp) |
2988 | RETURN_STATUS(BC_STATUS_SUCCESS); | 2986 | RETURN_STATUS(BC_STATUS_SUCCESS); |
2989 | if (!bc_lex_more_input(l)) { | 2987 | if (!bc_lex_more_input(l)) { |
@@ -3000,8 +2998,8 @@ static BC_STATUS zbc_lex_next(BcLex *l) | |||
3000 | } else { | 2998 | } else { |
3001 | IF_DC(s = zdc_lex_token(l)); | 2999 | IF_DC(s = zdc_lex_token(l)); |
3002 | } | 3000 | } |
3003 | } while (!s && l->t.t == XC_LEX_WHITESPACE); | 3001 | } while (!s && l->lex == XC_LEX_WHITESPACE); |
3004 | dbg_lex("l->t.t from string:%d", l->t.t); | 3002 | dbg_lex("l->lex from string:%d", l->lex); |
3005 | 3003 | ||
3006 | RETURN_STATUS(s); | 3004 | RETURN_STATUS(s); |
3007 | } | 3005 | } |
@@ -3010,7 +3008,7 @@ static BC_STATUS zbc_lex_next(BcLex *l) | |||
3010 | #if ENABLE_BC | 3008 | #if ENABLE_BC |
3011 | static BC_STATUS zbc_lex_skip_if_at_NLINE(BcLex *l) | 3009 | static BC_STATUS zbc_lex_skip_if_at_NLINE(BcLex *l) |
3012 | { | 3010 | { |
3013 | if (l->t.t == XC_LEX_NLINE) | 3011 | if (l->lex == XC_LEX_NLINE) |
3014 | RETURN_STATUS(zbc_lex_next(l)); | 3012 | RETURN_STATUS(zbc_lex_next(l)); |
3015 | RETURN_STATUS(BC_STATUS_SUCCESS); | 3013 | RETURN_STATUS(BC_STATUS_SUCCESS); |
3016 | } | 3014 | } |
@@ -3033,7 +3031,7 @@ static BC_STATUS zbc_lex_text_init(BcLex *l, const char *text) | |||
3033 | l->buf = text; | 3031 | l->buf = text; |
3034 | l->i = 0; | 3032 | l->i = 0; |
3035 | l->len = strlen(text); | 3033 | l->len = strlen(text); |
3036 | l->t.t = l->t.last = XC_LEX_INVALID; | 3034 | l->lex = l->lex_last = XC_LEX_INVALID; |
3037 | RETURN_STATUS(zbc_lex_next(l)); | 3035 | RETURN_STATUS(zbc_lex_next(l)); |
3038 | } | 3036 | } |
3039 | #define zbc_lex_text_init(...) (zbc_lex_text_init(__VA_ARGS__) COMMA_SUCCESS) | 3037 | #define zbc_lex_text_init(...) (zbc_lex_text_init(__VA_ARGS__) COMMA_SUCCESS) |
@@ -3058,7 +3056,7 @@ static BC_STATUS zbc_lex_identifier(BcLex *l) | |||
3058 | // buf starts with keyword bc_lex_kws[i] | 3056 | // buf starts with keyword bc_lex_kws[i] |
3059 | if (isalnum(buf[j]) || buf[j]=='_') | 3057 | if (isalnum(buf[j]) || buf[j]=='_') |
3060 | continue; // "ifz" does not match "if" keyword, "if." does | 3058 | continue; // "ifz" does not match "if" keyword, "if." does |
3061 | l->t.t = BC_LEX_KEY_1st_keyword + i; | 3059 | l->lex = BC_LEX_KEY_1st_keyword + i; |
3062 | if (!bc_lex_kws_POSIX(i)) { | 3060 | if (!bc_lex_kws_POSIX(i)) { |
3063 | s = zbc_posix_error_fmt("%sthe '%.8s' keyword", "POSIX does not allow ", bc_lex_kws[i].name8); | 3061 | s = zbc_posix_error_fmt("%sthe '%.8s' keyword", "POSIX does not allow ", bc_lex_kws[i].name8); |
3064 | if (s) RETURN_STATUS(s); | 3062 | if (s) RETURN_STATUS(s); |
@@ -3072,7 +3070,7 @@ static BC_STATUS zbc_lex_identifier(BcLex *l) | |||
3072 | bc_lex_name(l); | 3070 | bc_lex_name(l); |
3073 | s = BC_STATUS_SUCCESS; | 3071 | s = BC_STATUS_SUCCESS; |
3074 | 3072 | ||
3075 | if (l->t.v.len > 2) { | 3073 | if (l->lex_buf.len > 2) { |
3076 | // Prevent this: | 3074 | // Prevent this: |
3077 | // >>> qwe=1 | 3075 | // >>> qwe=1 |
3078 | // bc: POSIX only allows one character names; the following is bad: 'qwe=1 | 3076 | // bc: POSIX only allows one character names; the following is bad: 'qwe=1 |
@@ -3089,7 +3087,7 @@ static BC_STATUS zbc_lex_string(BcLex *l) | |||
3089 | { | 3087 | { |
3090 | size_t len, nls, i; | 3088 | size_t len, nls, i; |
3091 | 3089 | ||
3092 | l->t.t = XC_LEX_STR; | 3090 | l->lex = XC_LEX_STR; |
3093 | 3091 | ||
3094 | nls = 0; | 3092 | nls = 0; |
3095 | i = l->i; | 3093 | i = l->i; |
@@ -3111,7 +3109,7 @@ static BC_STATUS zbc_lex_string(BcLex *l) | |||
3111 | if (len > BC_MAX_STRING) | 3109 | if (len > BC_MAX_STRING) |
3112 | RETURN_STATUS(bc_error("string too long: must be [1,"BC_MAX_STRING_STR"]")); | 3110 | RETURN_STATUS(bc_error("string too long: must be [1,"BC_MAX_STRING_STR"]")); |
3113 | } | 3111 | } |
3114 | bc_vec_string(&l->t.v, len, l->buf + l->i); | 3112 | bc_vec_string(&l->lex_buf, len, l->buf + l->i); |
3115 | 3113 | ||
3116 | l->i = i + 1; | 3114 | l->i = i + 1; |
3117 | l->line += nls; | 3115 | l->line += nls; |
@@ -3127,7 +3125,7 @@ static void bc_lex_assign(BcLex *l, unsigned with_and_without) | |||
3127 | ++l->i; | 3125 | ++l->i; |
3128 | with_and_without >>= 8; // store "with" value | 3126 | with_and_without >>= 8; // store "with" value |
3129 | } // else store "without" value | 3127 | } // else store "without" value |
3130 | l->t.t = (with_and_without & 0xff); | 3128 | l->lex = (with_and_without & 0xff); |
3131 | } | 3129 | } |
3132 | #define bc_lex_assign(l, with, without) \ | 3130 | #define bc_lex_assign(l, with, without) \ |
3133 | bc_lex_assign(l, ((with)<<8)|(without)) | 3131 | bc_lex_assign(l, ((with)<<8)|(without)) |
@@ -3137,7 +3135,7 @@ static BC_STATUS zbc_lex_comment(BcLex *l) | |||
3137 | size_t i, nls = 0; | 3135 | size_t i, nls = 0; |
3138 | const char *buf = l->buf; | 3136 | const char *buf = l->buf; |
3139 | 3137 | ||
3140 | l->t.t = XC_LEX_WHITESPACE; | 3138 | l->lex = XC_LEX_WHITESPACE; |
3141 | i = l->i; /* here buf[l->i] is the '*' of opening comment delimiter */ | 3139 | i = l->i; /* here buf[l->i] is the '*' of opening comment delimiter */ |
3142 | for (;;) { | 3140 | for (;;) { |
3143 | char c = buf[++i]; | 3141 | char c = buf[++i]; |
@@ -3173,11 +3171,11 @@ static BC_STATUS zbc_lex_token(BcLex *l) | |||
3173 | switch (c) { | 3171 | switch (c) { |
3174 | // case '\0': // probably never reached | 3172 | // case '\0': // probably never reached |
3175 | // l->i--; | 3173 | // l->i--; |
3176 | // l->t.t = XC_LEX_EOF; | 3174 | // l->lex = XC_LEX_EOF; |
3177 | // l->newline = true; | 3175 | // l->newline = true; |
3178 | // break; | 3176 | // break; |
3179 | case '\n': | 3177 | case '\n': |
3180 | l->t.t = XC_LEX_NLINE; | 3178 | l->lex = XC_LEX_NLINE; |
3181 | l->newline = true; | 3179 | l->newline = true; |
3182 | break; | 3180 | break; |
3183 | case '\t': | 3181 | case '\t': |
@@ -3189,7 +3187,7 @@ static BC_STATUS zbc_lex_token(BcLex *l) | |||
3189 | break; | 3187 | break; |
3190 | case '!': | 3188 | case '!': |
3191 | bc_lex_assign(l, XC_LEX_OP_REL_NE, BC_LEX_OP_BOOL_NOT); | 3189 | bc_lex_assign(l, XC_LEX_OP_REL_NE, BC_LEX_OP_BOOL_NOT); |
3192 | if (l->t.t == BC_LEX_OP_BOOL_NOT) { | 3190 | if (l->lex == BC_LEX_OP_BOOL_NOT) { |
3193 | s = zbc_POSIX_does_not_allow_bool_ops_this_is_bad("!"); | 3191 | s = zbc_POSIX_does_not_allow_bool_ops_this_is_bad("!"); |
3194 | if (s) RETURN_STATUS(s); | 3192 | if (s) RETURN_STATUS(s); |
3195 | } | 3193 | } |
@@ -3211,15 +3209,15 @@ static BC_STATUS zbc_lex_token(BcLex *l) | |||
3211 | s = zbc_POSIX_does_not_allow_bool_ops_this_is_bad("&&"); | 3209 | s = zbc_POSIX_does_not_allow_bool_ops_this_is_bad("&&"); |
3212 | if (s) RETURN_STATUS(s); | 3210 | if (s) RETURN_STATUS(s); |
3213 | ++l->i; | 3211 | ++l->i; |
3214 | l->t.t = BC_LEX_OP_BOOL_AND; | 3212 | l->lex = BC_LEX_OP_BOOL_AND; |
3215 | } else { | 3213 | } else { |
3216 | l->t.t = XC_LEX_INVALID; | 3214 | l->lex = XC_LEX_INVALID; |
3217 | s = bc_error_bad_character('&'); | 3215 | s = bc_error_bad_character('&'); |
3218 | } | 3216 | } |
3219 | break; | 3217 | break; |
3220 | case '(': | 3218 | case '(': |
3221 | case ')': | 3219 | case ')': |
3222 | l->t.t = (BcLexType)(c - '(' + BC_LEX_LPAREN); | 3220 | l->lex = (BcLexType)(c - '(' + BC_LEX_LPAREN); |
3223 | break; | 3221 | break; |
3224 | case '*': | 3222 | case '*': |
3225 | bc_lex_assign(l, BC_LEX_OP_ASSIGN_MULTIPLY, XC_LEX_OP_MULTIPLY); | 3223 | bc_lex_assign(l, BC_LEX_OP_ASSIGN_MULTIPLY, XC_LEX_OP_MULTIPLY); |
@@ -3228,18 +3226,18 @@ static BC_STATUS zbc_lex_token(BcLex *l) | |||
3228 | c2 = l->buf[l->i]; | 3226 | c2 = l->buf[l->i]; |
3229 | if (c2 == '+') { | 3227 | if (c2 == '+') { |
3230 | ++l->i; | 3228 | ++l->i; |
3231 | l->t.t = BC_LEX_OP_INC; | 3229 | l->lex = BC_LEX_OP_INC; |
3232 | } else | 3230 | } else |
3233 | bc_lex_assign(l, BC_LEX_OP_ASSIGN_PLUS, XC_LEX_OP_PLUS); | 3231 | bc_lex_assign(l, BC_LEX_OP_ASSIGN_PLUS, XC_LEX_OP_PLUS); |
3234 | break; | 3232 | break; |
3235 | case ',': | 3233 | case ',': |
3236 | l->t.t = BC_LEX_COMMA; | 3234 | l->lex = BC_LEX_COMMA; |
3237 | break; | 3235 | break; |
3238 | case '-': | 3236 | case '-': |
3239 | c2 = l->buf[l->i]; | 3237 | c2 = l->buf[l->i]; |
3240 | if (c2 == '-') { | 3238 | if (c2 == '-') { |
3241 | ++l->i; | 3239 | ++l->i; |
3242 | l->t.t = BC_LEX_OP_DEC; | 3240 | l->lex = BC_LEX_OP_DEC; |
3243 | } else | 3241 | } else |
3244 | bc_lex_assign(l, BC_LEX_OP_ASSIGN_MINUS, XC_LEX_OP_MINUS); | 3242 | bc_lex_assign(l, BC_LEX_OP_ASSIGN_MINUS, XC_LEX_OP_MINUS); |
3245 | break; | 3243 | break; |
@@ -3247,7 +3245,7 @@ static BC_STATUS zbc_lex_token(BcLex *l) | |||
3247 | if (isdigit(l->buf[l->i])) | 3245 | if (isdigit(l->buf[l->i])) |
3248 | s = zbc_lex_number(l, c); | 3246 | s = zbc_lex_number(l, c); |
3249 | else { | 3247 | else { |
3250 | l->t.t = BC_LEX_KEY_LAST; | 3248 | l->lex = BC_LEX_KEY_LAST; |
3251 | s = zbc_POSIX_does_not_allow("a period ('.') as a shortcut for the last result"); | 3249 | s = zbc_POSIX_does_not_allow("a period ('.') as a shortcut for the last result"); |
3252 | } | 3250 | } |
3253 | break; | 3251 | break; |
@@ -3277,7 +3275,7 @@ static BC_STATUS zbc_lex_token(BcLex *l) | |||
3277 | s = zbc_lex_number(l, c); | 3275 | s = zbc_lex_number(l, c); |
3278 | break; | 3276 | break; |
3279 | case ';': | 3277 | case ';': |
3280 | l->t.t = BC_LEX_SCOLON; | 3278 | l->lex = BC_LEX_SCOLON; |
3281 | break; | 3279 | break; |
3282 | case '<': | 3280 | case '<': |
3283 | bc_lex_assign(l, XC_LEX_OP_REL_LE, XC_LEX_OP_REL_LT); | 3281 | bc_lex_assign(l, XC_LEX_OP_REL_LE, XC_LEX_OP_REL_LT); |
@@ -3290,11 +3288,11 @@ static BC_STATUS zbc_lex_token(BcLex *l) | |||
3290 | break; | 3288 | break; |
3291 | case '[': | 3289 | case '[': |
3292 | case ']': | 3290 | case ']': |
3293 | l->t.t = (BcLexType)(c - '[' + BC_LEX_LBRACKET); | 3291 | l->lex = (BcLexType)(c - '[' + BC_LEX_LBRACKET); |
3294 | break; | 3292 | break; |
3295 | case '\\': | 3293 | case '\\': |
3296 | if (l->buf[l->i] == '\n') { | 3294 | if (l->buf[l->i] == '\n') { |
3297 | l->t.t = XC_LEX_WHITESPACE; | 3295 | l->lex = XC_LEX_WHITESPACE; |
3298 | ++l->i; | 3296 | ++l->i; |
3299 | } else | 3297 | } else |
3300 | s = bc_error_bad_character(c); | 3298 | s = bc_error_bad_character(c); |
@@ -3332,7 +3330,7 @@ static BC_STATUS zbc_lex_token(BcLex *l) | |||
3332 | break; | 3330 | break; |
3333 | case '{': | 3331 | case '{': |
3334 | case '}': | 3332 | case '}': |
3335 | l->t.t = (BcLexType)(c - '{' + BC_LEX_LBRACE); | 3333 | l->lex = (BcLexType)(c - '{' + BC_LEX_LBRACE); |
3336 | break; | 3334 | break; |
3337 | case '|': | 3335 | case '|': |
3338 | c2 = l->buf[l->i]; | 3336 | c2 = l->buf[l->i]; |
@@ -3340,14 +3338,14 @@ static BC_STATUS zbc_lex_token(BcLex *l) | |||
3340 | s = zbc_POSIX_does_not_allow_bool_ops_this_is_bad("||"); | 3338 | s = zbc_POSIX_does_not_allow_bool_ops_this_is_bad("||"); |
3341 | if (s) RETURN_STATUS(s); | 3339 | if (s) RETURN_STATUS(s); |
3342 | ++l->i; | 3340 | ++l->i; |
3343 | l->t.t = BC_LEX_OP_BOOL_OR; | 3341 | l->lex = BC_LEX_OP_BOOL_OR; |
3344 | } else { | 3342 | } else { |
3345 | l->t.t = XC_LEX_INVALID; | 3343 | l->lex = XC_LEX_INVALID; |
3346 | s = bc_error_bad_character(c); | 3344 | s = bc_error_bad_character(c); |
3347 | } | 3345 | } |
3348 | break; | 3346 | break; |
3349 | default: | 3347 | default: |
3350 | l->t.t = XC_LEX_INVALID; | 3348 | l->lex = XC_LEX_INVALID; |
3351 | s = bc_error_bad_character(c); | 3349 | s = bc_error_bad_character(c); |
3352 | break; | 3350 | break; |
3353 | } | 3351 | } |
@@ -3365,10 +3363,10 @@ static BC_STATUS zdc_lex_register(BcLex *l) | |||
3365 | l->i++; // bc_lex_name() expects this | 3363 | l->i++; // bc_lex_name() expects this |
3366 | bc_lex_name(l); | 3364 | bc_lex_name(l); |
3367 | } else { | 3365 | } else { |
3368 | bc_vec_pop_all(&l->t.v); | 3366 | bc_vec_pop_all(&l->lex_buf); |
3369 | bc_vec_push(&l->t.v, &l->buf[l->i++]); | 3367 | bc_vec_push(&l->lex_buf, &l->buf[l->i++]); |
3370 | bc_vec_pushZeroByte(&l->t.v); | 3368 | bc_vec_pushZeroByte(&l->lex_buf); |
3371 | l->t.t = XC_LEX_NAME; | 3369 | l->lex = XC_LEX_NAME; |
3372 | } | 3370 | } |
3373 | 3371 | ||
3374 | RETURN_STATUS(BC_STATUS_SUCCESS); | 3372 | RETURN_STATUS(BC_STATUS_SUCCESS); |
@@ -3379,8 +3377,8 @@ static BC_STATUS zdc_lex_string(BcLex *l) | |||
3379 | { | 3377 | { |
3380 | size_t depth, nls, i; | 3378 | size_t depth, nls, i; |
3381 | 3379 | ||
3382 | l->t.t = XC_LEX_STR; | 3380 | l->lex = XC_LEX_STR; |
3383 | bc_vec_pop_all(&l->t.v); | 3381 | bc_vec_pop_all(&l->lex_buf); |
3384 | 3382 | ||
3385 | nls = 0; | 3383 | nls = 0; |
3386 | depth = 1; | 3384 | depth = 1; |
@@ -3398,12 +3396,12 @@ static BC_STATUS zdc_lex_string(BcLex *l) | |||
3398 | if (--depth == 0) | 3396 | if (--depth == 0) |
3399 | break; | 3397 | break; |
3400 | } | 3398 | } |
3401 | bc_vec_push(&l->t.v, &l->buf[i]); | 3399 | bc_vec_push(&l->lex_buf, &l->buf[i]); |
3402 | i++; | 3400 | i++; |
3403 | } | 3401 | } |
3404 | i++; | 3402 | i++; |
3405 | 3403 | ||
3406 | bc_vec_pushZeroByte(&l->t.v); | 3404 | bc_vec_pushZeroByte(&l->lex_buf); |
3407 | // This check makes sense only if size_t is (much) larger than BC_MAX_STRING. | 3405 | // This check makes sense only if size_t is (much) larger than BC_MAX_STRING. |
3408 | if (SIZE_MAX > (BC_MAX_STRING | 0xff)) { | 3406 | if (SIZE_MAX > (BC_MAX_STRING | 0xff)) { |
3409 | if (i - l->i > BC_MAX_STRING) | 3407 | if (i - l->i > BC_MAX_STRING) |
@@ -3435,14 +3433,14 @@ static BC_STATUS zdc_lex_token(BcLex *l) | |||
3435 | size_t i; | 3433 | size_t i; |
3436 | 3434 | ||
3437 | for (i = 0; i < ARRAY_SIZE(dc_lex_regs); ++i) { | 3435 | for (i = 0; i < ARRAY_SIZE(dc_lex_regs); ++i) { |
3438 | if (l->t.last == dc_lex_regs[i]) | 3436 | if (l->lex_last == dc_lex_regs[i]) |
3439 | RETURN_STATUS(zdc_lex_register(l)); | 3437 | RETURN_STATUS(zdc_lex_register(l)); |
3440 | } | 3438 | } |
3441 | 3439 | ||
3442 | s = BC_STATUS_SUCCESS; | 3440 | s = BC_STATUS_SUCCESS; |
3443 | c = l->buf[l->i++]; | 3441 | c = l->buf[l->i++]; |
3444 | if (c >= '%' && c <= '~' | 3442 | if (c >= '%' && c <= '~' |
3445 | && (l->t.t = dc_char_to_LEX[c - '%']) != XC_LEX_INVALID | 3443 | && (l->lex = dc_char_to_LEX[c - '%']) != XC_LEX_INVALID |
3446 | ) { | 3444 | ) { |
3447 | RETURN_STATUS(s); | 3445 | RETURN_STATUS(s); |
3448 | } | 3446 | } |
@@ -3450,7 +3448,7 @@ static BC_STATUS zdc_lex_token(BcLex *l) | |||
3450 | // This is the workhorse of the lexer. | 3448 | // This is the workhorse of the lexer. |
3451 | switch (c) { | 3449 | switch (c) { |
3452 | // case '\0': // probably never reached | 3450 | // case '\0': // probably never reached |
3453 | // l->t.t = XC_LEX_EOF; | 3451 | // l->lex = XC_LEX_EOF; |
3454 | // break; | 3452 | // break; |
3455 | case '\n': | 3453 | case '\n': |
3456 | // '\n' is XC_LEX_NLINE, not XC_LEX_WHITESPACE | 3454 | // '\n' is XC_LEX_NLINE, not XC_LEX_WHITESPACE |
@@ -3461,7 +3459,7 @@ static BC_STATUS zdc_lex_token(BcLex *l) | |||
3461 | // commands are not executed on pressing <enter>). | 3459 | // commands are not executed on pressing <enter>). |
3462 | // IOW: typing "1p<enter>" should print "1" _at once_, | 3460 | // IOW: typing "1p<enter>" should print "1" _at once_, |
3463 | // not after some more input. | 3461 | // not after some more input. |
3464 | l->t.t = XC_LEX_NLINE; | 3462 | l->lex = XC_LEX_NLINE; |
3465 | l->newline = true; | 3463 | l->newline = true; |
3466 | break; | 3464 | break; |
3467 | case '\t': | 3465 | case '\t': |
@@ -3475,11 +3473,11 @@ static BC_STATUS zdc_lex_token(BcLex *l) | |||
3475 | case '!': | 3473 | case '!': |
3476 | c2 = l->buf[l->i]; | 3474 | c2 = l->buf[l->i]; |
3477 | if (c2 == '=') | 3475 | if (c2 == '=') |
3478 | l->t.t = XC_LEX_OP_REL_NE; | 3476 | l->lex = XC_LEX_OP_REL_NE; |
3479 | else if (c2 == '<') | 3477 | else if (c2 == '<') |
3480 | l->t.t = XC_LEX_OP_REL_LE; | 3478 | l->lex = XC_LEX_OP_REL_LE; |
3481 | else if (c2 == '>') | 3479 | else if (c2 == '>') |
3482 | l->t.t = XC_LEX_OP_REL_GE; | 3480 | l->lex = XC_LEX_OP_REL_GE; |
3483 | else | 3481 | else |
3484 | RETURN_STATUS(bc_error_bad_character(c)); | 3482 | RETURN_STATUS(bc_error_bad_character(c)); |
3485 | ++l->i; | 3483 | ++l->i; |
@@ -3515,7 +3513,7 @@ static BC_STATUS zdc_lex_token(BcLex *l) | |||
3515 | s = zdc_lex_string(l); | 3513 | s = zdc_lex_string(l); |
3516 | break; | 3514 | break; |
3517 | default: | 3515 | default: |
3518 | l->t.t = XC_LEX_INVALID; | 3516 | l->lex = XC_LEX_INVALID; |
3519 | s = bc_error_bad_character(c); | 3517 | s = bc_error_bad_character(c); |
3520 | break; | 3518 | break; |
3521 | } | 3519 | } |
@@ -3575,7 +3573,7 @@ static void bc_parse_pushJUMP_ZERO(BcParse *p, size_t idx) | |||
3575 | 3573 | ||
3576 | static BC_STATUS zbc_parse_pushSTR(BcParse *p) | 3574 | static BC_STATUS zbc_parse_pushSTR(BcParse *p) |
3577 | { | 3575 | { |
3578 | char *str = xstrdup(p->l.t.v.v); | 3576 | char *str = xstrdup(p->l.lex_buf.v); |
3579 | 3577 | ||
3580 | bc_parse_push(p, XC_INST_STR); | 3578 | bc_parse_push(p, XC_INST_STR); |
3581 | bc_parse_pushIndex(p, p->func->strs.len); | 3579 | bc_parse_pushIndex(p, p->func->strs.len); |
@@ -3588,7 +3586,7 @@ static BC_STATUS zbc_parse_pushSTR(BcParse *p) | |||
3588 | 3586 | ||
3589 | static void bc_parse_pushNUM(BcParse *p) | 3587 | static void bc_parse_pushNUM(BcParse *p) |
3590 | { | 3588 | { |
3591 | char *num = xstrdup(p->l.t.v.v); | 3589 | char *num = xstrdup(p->l.lex_buf.v); |
3592 | #if ENABLE_BC && ENABLE_DC | 3590 | #if ENABLE_BC && ENABLE_DC |
3593 | size_t idx = bc_vec_push(IS_BC ? &p->func->consts : &G.prog.consts, &num); | 3591 | size_t idx = bc_vec_push(IS_BC ? &p->func->consts : &G.prog.consts, &num); |
3594 | #elif ENABLE_BC | 3592 | #elif ENABLE_BC |
@@ -3636,7 +3634,7 @@ static void bc_parse_reset(BcParse *p) | |||
3636 | } | 3634 | } |
3637 | 3635 | ||
3638 | p->l.i = p->l.len; | 3636 | p->l.i = p->l.len; |
3639 | p->l.t.t = XC_LEX_EOF; | 3637 | p->l.lex = XC_LEX_EOF; |
3640 | 3638 | ||
3641 | IF_BC(bc_vec_pop_all(&p->exits);) | 3639 | IF_BC(bc_vec_pop_all(&p->exits);) |
3642 | IF_BC(bc_vec_pop_all(&p->conds);) | 3640 | IF_BC(bc_vec_pop_all(&p->conds);) |
@@ -3745,7 +3743,7 @@ static BC_STATUS zbc_parse_stmt_allow_NLINE_before(BcParse *p, const char *after | |||
3745 | // Same for "else", "while()", "for()". | 3743 | // Same for "else", "while()", "for()". |
3746 | BcStatus s = zbc_lex_next_and_skip_NLINE(&p->l); | 3744 | BcStatus s = zbc_lex_next_and_skip_NLINE(&p->l); |
3747 | if (s) RETURN_STATUS(s); | 3745 | if (s) RETURN_STATUS(s); |
3748 | if (p->l.t.t == XC_LEX_NLINE) | 3746 | if (p->l.lex == XC_LEX_NLINE) |
3749 | RETURN_STATUS(bc_error_fmt("no statement after '%s'", after_X)); | 3747 | RETURN_STATUS(bc_error_fmt("no statement after '%s'", after_X)); |
3750 | 3748 | ||
3751 | RETURN_STATUS(zbc_parse_stmt(p)); | 3749 | RETURN_STATUS(zbc_parse_stmt(p)); |
@@ -3803,20 +3801,20 @@ static BC_STATUS zbc_parse_params(BcParse *p, uint8_t flags) | |||
3803 | BcStatus s; | 3801 | BcStatus s; |
3804 | size_t nparams; | 3802 | size_t nparams; |
3805 | 3803 | ||
3806 | dbg_lex("%s:%d p->l.t.t:%d", __func__, __LINE__, p->l.t.t); | 3804 | dbg_lex("%s:%d p->l.lex:%d", __func__, __LINE__, p->l.lex); |
3807 | flags = (flags & ~(BC_PARSE_PRINT | BC_PARSE_REL)) | BC_PARSE_ARRAY; | 3805 | flags = (flags & ~(BC_PARSE_PRINT | BC_PARSE_REL)) | BC_PARSE_ARRAY; |
3808 | 3806 | ||
3809 | s = zbc_lex_next(&p->l); | 3807 | s = zbc_lex_next(&p->l); |
3810 | if (s) RETURN_STATUS(s); | 3808 | if (s) RETURN_STATUS(s); |
3811 | 3809 | ||
3812 | nparams = 0; | 3810 | nparams = 0; |
3813 | if (p->l.t.t != BC_LEX_RPAREN) { | 3811 | if (p->l.lex != BC_LEX_RPAREN) { |
3814 | for (;;) { | 3812 | for (;;) { |
3815 | s = zbc_parse_expr(p, flags); | 3813 | s = zbc_parse_expr(p, flags); |
3816 | if (s) RETURN_STATUS(s); | 3814 | if (s) RETURN_STATUS(s); |
3817 | nparams++; | 3815 | nparams++; |
3818 | if (p->l.t.t != BC_LEX_COMMA) { | 3816 | if (p->l.lex != BC_LEX_COMMA) { |
3819 | if (p->l.t.t == BC_LEX_RPAREN) | 3817 | if (p->l.lex == BC_LEX_RPAREN) |
3820 | break; | 3818 | break; |
3821 | RETURN_STATUS(bc_error_bad_token()); | 3819 | RETURN_STATUS(bc_error_bad_token()); |
3822 | } | 3820 | } |
@@ -3844,7 +3842,7 @@ static BC_STATUS zbc_parse_call(BcParse *p, char *name, uint8_t flags) | |||
3844 | s = zbc_parse_params(p, flags); | 3842 | s = zbc_parse_params(p, flags); |
3845 | if (s) goto err; | 3843 | if (s) goto err; |
3846 | 3844 | ||
3847 | if (p->l.t.t != BC_LEX_RPAREN) { | 3845 | if (p->l.lex != BC_LEX_RPAREN) { |
3848 | s = bc_error_bad_token(); | 3846 | s = bc_error_bad_token(); |
3849 | goto err; | 3847 | goto err; |
3850 | } | 3848 | } |
@@ -3873,15 +3871,15 @@ static BC_STATUS zbc_parse_name(BcParse *p, BcInst *type, uint8_t flags) | |||
3873 | BcStatus s; | 3871 | BcStatus s; |
3874 | char *name; | 3872 | char *name; |
3875 | 3873 | ||
3876 | name = xstrdup(p->l.t.v.v); | 3874 | name = xstrdup(p->l.lex_buf.v); |
3877 | s = zbc_lex_next(&p->l); | 3875 | s = zbc_lex_next(&p->l); |
3878 | if (s) goto err; | 3876 | if (s) goto err; |
3879 | 3877 | ||
3880 | if (p->l.t.t == BC_LEX_LBRACKET) { | 3878 | if (p->l.lex == BC_LEX_LBRACKET) { |
3881 | s = zbc_lex_next(&p->l); | 3879 | s = zbc_lex_next(&p->l); |
3882 | if (s) goto err; | 3880 | if (s) goto err; |
3883 | 3881 | ||
3884 | if (p->l.t.t == BC_LEX_RBRACKET) { | 3882 | if (p->l.lex == BC_LEX_RBRACKET) { |
3885 | if (!(flags & BC_PARSE_ARRAY)) { | 3883 | if (!(flags & BC_PARSE_ARRAY)) { |
3886 | s = bc_error_bad_expression(); | 3884 | s = bc_error_bad_expression(); |
3887 | goto err; | 3885 | goto err; |
@@ -3898,7 +3896,7 @@ static BC_STATUS zbc_parse_name(BcParse *p, BcInst *type, uint8_t flags) | |||
3898 | bc_parse_push(p, *type); | 3896 | bc_parse_push(p, *type); |
3899 | bc_parse_pushName(p, name); | 3897 | bc_parse_pushName(p, name); |
3900 | free(name); | 3898 | free(name); |
3901 | } else if (p->l.t.t == BC_LEX_LPAREN) { | 3899 | } else if (p->l.lex == BC_LEX_LPAREN) { |
3902 | if (flags & BC_PARSE_NOCALL) { | 3900 | if (flags & BC_PARSE_NOCALL) { |
3903 | s = bc_error_bad_token(); | 3901 | s = bc_error_bad_token(); |
3904 | goto err; | 3902 | goto err; |
@@ -3925,11 +3923,11 @@ static BC_STATUS zbc_parse_read(BcParse *p) | |||
3925 | 3923 | ||
3926 | s = zbc_lex_next(&p->l); | 3924 | s = zbc_lex_next(&p->l); |
3927 | if (s) RETURN_STATUS(s); | 3925 | if (s) RETURN_STATUS(s); |
3928 | if (p->l.t.t != BC_LEX_LPAREN) RETURN_STATUS(bc_error_bad_token()); | 3926 | if (p->l.lex != BC_LEX_LPAREN) RETURN_STATUS(bc_error_bad_token()); |
3929 | 3927 | ||
3930 | s = zbc_lex_next(&p->l); | 3928 | s = zbc_lex_next(&p->l); |
3931 | if (s) RETURN_STATUS(s); | 3929 | if (s) RETURN_STATUS(s); |
3932 | if (p->l.t.t != BC_LEX_RPAREN) RETURN_STATUS(bc_error_bad_token()); | 3930 | if (p->l.lex != BC_LEX_RPAREN) RETURN_STATUS(bc_error_bad_token()); |
3933 | 3931 | ||
3934 | bc_parse_push(p, XC_INST_READ); | 3932 | bc_parse_push(p, XC_INST_READ); |
3935 | 3933 | ||
@@ -3944,7 +3942,7 @@ static BC_STATUS zbc_parse_builtin(BcParse *p, BcLexType type, uint8_t flags, | |||
3944 | 3942 | ||
3945 | s = zbc_lex_next(&p->l); | 3943 | s = zbc_lex_next(&p->l); |
3946 | if (s) RETURN_STATUS(s); | 3944 | if (s) RETURN_STATUS(s); |
3947 | if (p->l.t.t != BC_LEX_LPAREN) RETURN_STATUS(bc_error_bad_token()); | 3945 | if (p->l.lex != BC_LEX_LPAREN) RETURN_STATUS(bc_error_bad_token()); |
3948 | 3946 | ||
3949 | flags = (flags & ~(BC_PARSE_PRINT | BC_PARSE_REL)) | BC_PARSE_ARRAY; | 3947 | flags = (flags & ~(BC_PARSE_PRINT | BC_PARSE_REL)) | BC_PARSE_ARRAY; |
3950 | 3948 | ||
@@ -3954,7 +3952,7 @@ static BC_STATUS zbc_parse_builtin(BcParse *p, BcLexType type, uint8_t flags, | |||
3954 | s = zbc_parse_expr(p, flags); | 3952 | s = zbc_parse_expr(p, flags); |
3955 | if (s) RETURN_STATUS(s); | 3953 | if (s) RETURN_STATUS(s); |
3956 | 3954 | ||
3957 | if (p->l.t.t != BC_LEX_RPAREN) RETURN_STATUS(bc_error_bad_token()); | 3955 | if (p->l.lex != BC_LEX_RPAREN) RETURN_STATUS(bc_error_bad_token()); |
3958 | 3956 | ||
3959 | *prev = (type == BC_LEX_KEY_LENGTH) ? XC_INST_LENGTH : XC_INST_SQRT; | 3957 | *prev = (type == BC_LEX_KEY_LENGTH) ? XC_INST_LENGTH : XC_INST_SQRT; |
3960 | bc_parse_push(p, *prev); | 3958 | bc_parse_push(p, *prev); |
@@ -3970,7 +3968,7 @@ static BC_STATUS zbc_parse_scale(BcParse *p, BcInst *type, uint8_t flags) | |||
3970 | s = zbc_lex_next(&p->l); | 3968 | s = zbc_lex_next(&p->l); |
3971 | if (s) RETURN_STATUS(s); | 3969 | if (s) RETURN_STATUS(s); |
3972 | 3970 | ||
3973 | if (p->l.t.t != BC_LEX_LPAREN) { | 3971 | if (p->l.lex != BC_LEX_LPAREN) { |
3974 | *type = XC_INST_SCALE; | 3972 | *type = XC_INST_SCALE; |
3975 | bc_parse_push(p, XC_INST_SCALE); | 3973 | bc_parse_push(p, XC_INST_SCALE); |
3976 | RETURN_STATUS(BC_STATUS_SUCCESS); | 3974 | RETURN_STATUS(BC_STATUS_SUCCESS); |
@@ -3984,7 +3982,7 @@ static BC_STATUS zbc_parse_scale(BcParse *p, BcInst *type, uint8_t flags) | |||
3984 | 3982 | ||
3985 | s = zbc_parse_expr(p, flags); | 3983 | s = zbc_parse_expr(p, flags); |
3986 | if (s) RETURN_STATUS(s); | 3984 | if (s) RETURN_STATUS(s); |
3987 | if (p->l.t.t != BC_LEX_RPAREN) | 3985 | if (p->l.lex != BC_LEX_RPAREN) |
3988 | RETURN_STATUS(bc_error_bad_token()); | 3986 | RETURN_STATUS(bc_error_bad_token()); |
3989 | bc_parse_push(p, XC_INST_SCALE_FUNC); | 3987 | bc_parse_push(p, XC_INST_SCALE_FUNC); |
3990 | 3988 | ||
@@ -4004,16 +4002,16 @@ static BC_STATUS zbc_parse_incdec(BcParse *p, BcInst *prev, bool *paren_expr, | |||
4004 | || etype == XC_INST_SCALE || etype == BC_INST_LAST | 4002 | || etype == XC_INST_SCALE || etype == BC_INST_LAST |
4005 | || etype == XC_INST_IBASE || etype == XC_INST_OBASE | 4003 | || etype == XC_INST_IBASE || etype == XC_INST_OBASE |
4006 | ) { | 4004 | ) { |
4007 | *prev = inst = BC_INST_INC_POST + (p->l.t.t != BC_LEX_OP_INC); | 4005 | *prev = inst = BC_INST_INC_POST + (p->l.lex != BC_LEX_OP_INC); |
4008 | bc_parse_push(p, inst); | 4006 | bc_parse_push(p, inst); |
4009 | s = zbc_lex_next(&p->l); | 4007 | s = zbc_lex_next(&p->l); |
4010 | } else { | 4008 | } else { |
4011 | *prev = inst = BC_INST_INC_PRE + (p->l.t.t != BC_LEX_OP_INC); | 4009 | *prev = inst = BC_INST_INC_PRE + (p->l.lex != BC_LEX_OP_INC); |
4012 | *paren_expr = true; | 4010 | *paren_expr = true; |
4013 | 4011 | ||
4014 | s = zbc_lex_next(&p->l); | 4012 | s = zbc_lex_next(&p->l); |
4015 | if (s) RETURN_STATUS(s); | 4013 | if (s) RETURN_STATUS(s); |
4016 | type = p->l.t.t; | 4014 | type = p->l.lex; |
4017 | 4015 | ||
4018 | // Because we parse the next part of the expression | 4016 | // Because we parse the next part of the expression |
4019 | // right here, we need to increment this. | 4017 | // right here, we need to increment this. |
@@ -4032,7 +4030,7 @@ static BC_STATUS zbc_parse_incdec(BcParse *p, BcInst *prev, bool *paren_expr, | |||
4032 | case BC_LEX_KEY_SCALE: | 4030 | case BC_LEX_KEY_SCALE: |
4033 | s = zbc_lex_next(&p->l); | 4031 | s = zbc_lex_next(&p->l); |
4034 | if (s) RETURN_STATUS(s); | 4032 | if (s) RETURN_STATUS(s); |
4035 | if (p->l.t.t == BC_LEX_LPAREN) | 4033 | if (p->l.lex == BC_LEX_LPAREN) |
4036 | s = bc_error_bad_token(); | 4034 | s = bc_error_bad_token(); |
4037 | else | 4035 | else |
4038 | bc_parse_push(p, XC_INST_SCALE); | 4036 | bc_parse_push(p, XC_INST_SCALE); |
@@ -4084,7 +4082,7 @@ static BC_STATUS zbc_parse_print(BcParse *p) | |||
4084 | for (;;) { | 4082 | for (;;) { |
4085 | s = zbc_lex_next(&p->l); | 4083 | s = zbc_lex_next(&p->l); |
4086 | if (s) RETURN_STATUS(s); | 4084 | if (s) RETURN_STATUS(s); |
4087 | type = p->l.t.t; | 4085 | type = p->l.lex; |
4088 | if (type == XC_LEX_STR) { | 4086 | if (type == XC_LEX_STR) { |
4089 | s = zbc_parse_pushSTR(p); | 4087 | s = zbc_parse_pushSTR(p); |
4090 | } else { | 4088 | } else { |
@@ -4092,7 +4090,7 @@ static BC_STATUS zbc_parse_print(BcParse *p) | |||
4092 | } | 4090 | } |
4093 | if (s) RETURN_STATUS(s); | 4091 | if (s) RETURN_STATUS(s); |
4094 | bc_parse_push(p, XC_INST_PRINT_POP); | 4092 | bc_parse_push(p, XC_INST_PRINT_POP); |
4095 | if (p->l.t.t != BC_LEX_COMMA) | 4093 | if (p->l.lex != BC_LEX_COMMA) |
4096 | break; | 4094 | break; |
4097 | } | 4095 | } |
4098 | 4096 | ||
@@ -4109,7 +4107,7 @@ static BC_STATUS zbc_parse_return(BcParse *p) | |||
4109 | s = zbc_lex_next(&p->l); | 4107 | s = zbc_lex_next(&p->l); |
4110 | if (s) RETURN_STATUS(s); | 4108 | if (s) RETURN_STATUS(s); |
4111 | 4109 | ||
4112 | t = p->l.t.t; | 4110 | t = p->l.lex; |
4113 | if (t == XC_LEX_NLINE || t == BC_LEX_SCOLON) | 4111 | if (t == XC_LEX_NLINE || t == BC_LEX_SCOLON) |
4114 | bc_parse_push(p, BC_INST_RET0); | 4112 | bc_parse_push(p, BC_INST_RET0); |
4115 | else { | 4113 | else { |
@@ -4121,7 +4119,7 @@ static BC_STATUS zbc_parse_return(BcParse *p) | |||
4121 | } | 4119 | } |
4122 | if (s) RETURN_STATUS(s); | 4120 | if (s) RETURN_STATUS(s); |
4123 | 4121 | ||
4124 | if (!paren || p->l.t.last != BC_LEX_RPAREN) { | 4122 | if (!paren || p->l.lex_last != BC_LEX_RPAREN) { |
4125 | s = zbc_POSIX_requires("parentheses around return expressions"); | 4123 | s = zbc_POSIX_requires("parentheses around return expressions"); |
4126 | if (s) RETURN_STATUS(s); | 4124 | if (s) RETURN_STATUS(s); |
4127 | } | 4125 | } |
@@ -4148,13 +4146,13 @@ static BC_STATUS zbc_parse_if(BcParse *p) | |||
4148 | dbg_lex_enter("%s:%d entered", __func__, __LINE__); | 4146 | dbg_lex_enter("%s:%d entered", __func__, __LINE__); |
4149 | s = zbc_lex_next(&p->l); | 4147 | s = zbc_lex_next(&p->l); |
4150 | if (s) RETURN_STATUS(s); | 4148 | if (s) RETURN_STATUS(s); |
4151 | if (p->l.t.t != BC_LEX_LPAREN) RETURN_STATUS(bc_error_bad_token()); | 4149 | if (p->l.lex != BC_LEX_LPAREN) RETURN_STATUS(bc_error_bad_token()); |
4152 | 4150 | ||
4153 | s = zbc_lex_next(&p->l); | 4151 | s = zbc_lex_next(&p->l); |
4154 | if (s) RETURN_STATUS(s); | 4152 | if (s) RETURN_STATUS(s); |
4155 | s = zbc_parse_expr(p, BC_PARSE_REL); | 4153 | s = zbc_parse_expr(p, BC_PARSE_REL); |
4156 | if (s) RETURN_STATUS(s); | 4154 | if (s) RETURN_STATUS(s); |
4157 | if (p->l.t.t != BC_LEX_RPAREN) RETURN_STATUS(bc_error_bad_token()); | 4155 | if (p->l.lex != BC_LEX_RPAREN) RETURN_STATUS(bc_error_bad_token()); |
4158 | 4156 | ||
4159 | // Encode "if zero, jump to ..." | 4157 | // Encode "if zero, jump to ..." |
4160 | // Pushed value (destination of the jump) is uninitialized, | 4158 | // Pushed value (destination of the jump) is uninitialized, |
@@ -4165,8 +4163,8 @@ static BC_STATUS zbc_parse_if(BcParse *p) | |||
4165 | s = zbc_parse_stmt_allow_NLINE_before(p, STRING_if); | 4163 | s = zbc_parse_stmt_allow_NLINE_before(p, STRING_if); |
4166 | if (s) RETURN_STATUS(s); | 4164 | if (s) RETURN_STATUS(s); |
4167 | 4165 | ||
4168 | dbg_lex("%s:%d in if after stmt: p->l.t.t:%d", __func__, __LINE__, p->l.t.t); | 4166 | dbg_lex("%s:%d in if after stmt: p->l.lex:%d", __func__, __LINE__, p->l.lex); |
4169 | if (p->l.t.t == BC_LEX_KEY_ELSE) { | 4167 | if (p->l.lex == BC_LEX_KEY_ELSE) { |
4170 | size_t ip2_idx; | 4168 | size_t ip2_idx; |
4171 | 4169 | ||
4172 | // Encode "after then_stmt, jump to end of if()" | 4170 | // Encode "after then_stmt, jump to end of if()" |
@@ -4199,7 +4197,7 @@ static BC_STATUS zbc_parse_while(BcParse *p) | |||
4199 | 4197 | ||
4200 | s = zbc_lex_next(&p->l); | 4198 | s = zbc_lex_next(&p->l); |
4201 | if (s) RETURN_STATUS(s); | 4199 | if (s) RETURN_STATUS(s); |
4202 | if (p->l.t.t != BC_LEX_LPAREN) RETURN_STATUS(bc_error_bad_token()); | 4200 | if (p->l.lex != BC_LEX_LPAREN) RETURN_STATUS(bc_error_bad_token()); |
4203 | s = zbc_lex_next(&p->l); | 4201 | s = zbc_lex_next(&p->l); |
4204 | if (s) RETURN_STATUS(s); | 4202 | if (s) RETURN_STATUS(s); |
4205 | 4203 | ||
@@ -4212,7 +4210,7 @@ static BC_STATUS zbc_parse_while(BcParse *p) | |||
4212 | 4210 | ||
4213 | s = zbc_parse_expr(p, BC_PARSE_REL); | 4211 | s = zbc_parse_expr(p, BC_PARSE_REL); |
4214 | if (s) RETURN_STATUS(s); | 4212 | if (s) RETURN_STATUS(s); |
4215 | if (p->l.t.t != BC_LEX_RPAREN) RETURN_STATUS(bc_error_bad_token()); | 4213 | if (p->l.lex != BC_LEX_RPAREN) RETURN_STATUS(bc_error_bad_token()); |
4216 | 4214 | ||
4217 | bc_parse_pushJUMP_ZERO(p, ip_idx); | 4215 | bc_parse_pushJUMP_ZERO(p, ip_idx); |
4218 | 4216 | ||
@@ -4237,14 +4235,14 @@ static BC_STATUS zbc_parse_for(BcParse *p) | |||
4237 | BcStatus s; | 4235 | BcStatus s; |
4238 | size_t cond_idx, exit_idx, body_idx, update_idx; | 4236 | size_t cond_idx, exit_idx, body_idx, update_idx; |
4239 | 4237 | ||
4240 | dbg_lex("%s:%d p->l.t.t:%d", __func__, __LINE__, p->l.t.t); | 4238 | dbg_lex("%s:%d p->l.lex:%d", __func__, __LINE__, p->l.lex); |
4241 | s = zbc_lex_next(&p->l); | 4239 | s = zbc_lex_next(&p->l); |
4242 | if (s) RETURN_STATUS(s); | 4240 | if (s) RETURN_STATUS(s); |
4243 | if (p->l.t.t != BC_LEX_LPAREN) RETURN_STATUS(bc_error_bad_token()); | 4241 | if (p->l.lex != BC_LEX_LPAREN) RETURN_STATUS(bc_error_bad_token()); |
4244 | s = zbc_lex_next(&p->l); | 4242 | s = zbc_lex_next(&p->l); |
4245 | if (s) RETURN_STATUS(s); | 4243 | if (s) RETURN_STATUS(s); |
4246 | 4244 | ||
4247 | if (p->l.t.t != BC_LEX_SCOLON) { | 4245 | if (p->l.lex != BC_LEX_SCOLON) { |
4248 | s = zbc_parse_expr(p, 0); | 4246 | s = zbc_parse_expr(p, 0); |
4249 | bc_parse_push(p, XC_INST_POP); | 4247 | bc_parse_push(p, XC_INST_POP); |
4250 | if (s) RETURN_STATUS(s); | 4248 | if (s) RETURN_STATUS(s); |
@@ -4253,7 +4251,7 @@ static BC_STATUS zbc_parse_for(BcParse *p) | |||
4253 | if (s) RETURN_STATUS(s); | 4251 | if (s) RETURN_STATUS(s); |
4254 | } | 4252 | } |
4255 | 4253 | ||
4256 | if (p->l.t.t != BC_LEX_SCOLON) RETURN_STATUS(bc_error_bad_token()); | 4254 | if (p->l.lex != BC_LEX_SCOLON) RETURN_STATUS(bc_error_bad_token()); |
4257 | s = zbc_lex_next(&p->l); | 4255 | s = zbc_lex_next(&p->l); |
4258 | if (s) RETURN_STATUS(s); | 4256 | if (s) RETURN_STATUS(s); |
4259 | 4257 | ||
@@ -4262,19 +4260,19 @@ static BC_STATUS zbc_parse_for(BcParse *p) | |||
4262 | body_idx = update_idx + 1; | 4260 | body_idx = update_idx + 1; |
4263 | exit_idx = body_idx + 1; | 4261 | exit_idx = body_idx + 1; |
4264 | 4262 | ||
4265 | if (p->l.t.t != BC_LEX_SCOLON) | 4263 | if (p->l.lex != BC_LEX_SCOLON) |
4266 | s = zbc_parse_expr(p, BC_PARSE_REL); | 4264 | s = zbc_parse_expr(p, BC_PARSE_REL); |
4267 | else { | 4265 | else { |
4268 | // Set this for the next call to bc_parse_pushNUM(). | 4266 | // Set this for the next call to bc_parse_pushNUM(). |
4269 | // This is safe to set because the current token is a semicolon, | 4267 | // This is safe to set because the current token is a semicolon, |
4270 | // which has no string requirement. | 4268 | // which has no string requirement. |
4271 | bc_vec_string(&p->l.t.v, 1, "1"); | 4269 | bc_vec_string(&p->l.lex_buf, 1, "1"); |
4272 | bc_parse_pushNUM(p); | 4270 | bc_parse_pushNUM(p); |
4273 | s = zbc_POSIX_does_not_allow_empty_X_expression_in_for("condition"); | 4271 | s = zbc_POSIX_does_not_allow_empty_X_expression_in_for("condition"); |
4274 | } | 4272 | } |
4275 | if (s) RETURN_STATUS(s); | 4273 | if (s) RETURN_STATUS(s); |
4276 | 4274 | ||
4277 | if (p->l.t.t != BC_LEX_SCOLON) RETURN_STATUS(bc_error_bad_token()); | 4275 | if (p->l.lex != BC_LEX_SCOLON) RETURN_STATUS(bc_error_bad_token()); |
4278 | 4276 | ||
4279 | s = zbc_lex_next(&p->l); | 4277 | s = zbc_lex_next(&p->l); |
4280 | if (s) RETURN_STATUS(s); | 4278 | if (s) RETURN_STATUS(s); |
@@ -4285,10 +4283,10 @@ static BC_STATUS zbc_parse_for(BcParse *p) | |||
4285 | bc_vec_push(&p->conds, &update_idx); | 4283 | bc_vec_push(&p->conds, &update_idx); |
4286 | bc_vec_push(&p->func->labels, &p->func->code.len); | 4284 | bc_vec_push(&p->func->labels, &p->func->code.len); |
4287 | 4285 | ||
4288 | if (p->l.t.t != BC_LEX_RPAREN) { | 4286 | if (p->l.lex != BC_LEX_RPAREN) { |
4289 | s = zbc_parse_expr(p, 0); | 4287 | s = zbc_parse_expr(p, 0); |
4290 | if (s) RETURN_STATUS(s); | 4288 | if (s) RETURN_STATUS(s); |
4291 | if (p->l.t.t != BC_LEX_RPAREN) RETURN_STATUS(bc_error_bad_token()); | 4289 | if (p->l.lex != BC_LEX_RPAREN) RETURN_STATUS(bc_error_bad_token()); |
4292 | bc_parse_push(p, XC_INST_POP); | 4290 | bc_parse_push(p, XC_INST_POP); |
4293 | } else { | 4291 | } else { |
4294 | s = zbc_POSIX_does_not_allow_empty_X_expression_in_for("update"); | 4292 | s = zbc_POSIX_does_not_allow_empty_X_expression_in_for("update"); |
@@ -4335,7 +4333,7 @@ static BC_STATUS zbc_parse_break_or_continue(BcParse *p, BcLexType type) | |||
4335 | s = zbc_lex_next(&p->l); | 4333 | s = zbc_lex_next(&p->l); |
4336 | if (s) RETURN_STATUS(s); | 4334 | if (s) RETURN_STATUS(s); |
4337 | 4335 | ||
4338 | if (p->l.t.t != BC_LEX_SCOLON && p->l.t.t != XC_LEX_NLINE) | 4336 | if (p->l.lex != BC_LEX_SCOLON && p->l.lex != XC_LEX_NLINE) |
4339 | RETURN_STATUS(bc_error_bad_token()); | 4337 | RETURN_STATUS(bc_error_bad_token()); |
4340 | 4338 | ||
4341 | RETURN_STATUS(zbc_lex_next(&p->l)); | 4339 | RETURN_STATUS(zbc_lex_next(&p->l)); |
@@ -4372,37 +4370,37 @@ static BC_STATUS zbc_parse_funcdef(BcParse *p) | |||
4372 | dbg_lex_enter("%s:%d entered", __func__, __LINE__); | 4370 | dbg_lex_enter("%s:%d entered", __func__, __LINE__); |
4373 | s = zbc_lex_next(&p->l); | 4371 | s = zbc_lex_next(&p->l); |
4374 | if (s) RETURN_STATUS(s); | 4372 | if (s) RETURN_STATUS(s); |
4375 | if (p->l.t.t != XC_LEX_NAME) | 4373 | if (p->l.lex != XC_LEX_NAME) |
4376 | RETURN_STATUS(bc_error("bad function definition")); | 4374 | RETURN_STATUS(bc_error("bad function definition")); |
4377 | 4375 | ||
4378 | name = xstrdup(p->l.t.v.v); | 4376 | name = xstrdup(p->l.lex_buf.v); |
4379 | p->fidx = bc_program_addFunc(name); | 4377 | p->fidx = bc_program_addFunc(name); |
4380 | p->func = bc_program_func(p->fidx); | 4378 | p->func = bc_program_func(p->fidx); |
4381 | 4379 | ||
4382 | s = zbc_lex_next(&p->l); | 4380 | s = zbc_lex_next(&p->l); |
4383 | if (s) RETURN_STATUS(s); | 4381 | if (s) RETURN_STATUS(s); |
4384 | if (p->l.t.t != BC_LEX_LPAREN) | 4382 | if (p->l.lex != BC_LEX_LPAREN) |
4385 | RETURN_STATUS(bc_error("bad function definition")); | 4383 | RETURN_STATUS(bc_error("bad function definition")); |
4386 | s = zbc_lex_next(&p->l); | 4384 | s = zbc_lex_next(&p->l); |
4387 | if (s) RETURN_STATUS(s); | 4385 | if (s) RETURN_STATUS(s); |
4388 | 4386 | ||
4389 | while (p->l.t.t != BC_LEX_RPAREN) { | 4387 | while (p->l.lex != BC_LEX_RPAREN) { |
4390 | if (p->l.t.t != XC_LEX_NAME) | 4388 | if (p->l.lex != XC_LEX_NAME) |
4391 | RETURN_STATUS(bc_error("bad function definition")); | 4389 | RETURN_STATUS(bc_error("bad function definition")); |
4392 | 4390 | ||
4393 | ++p->func->nparams; | 4391 | ++p->func->nparams; |
4394 | 4392 | ||
4395 | name = xstrdup(p->l.t.v.v); | 4393 | name = xstrdup(p->l.lex_buf.v); |
4396 | s = zbc_lex_next(&p->l); | 4394 | s = zbc_lex_next(&p->l); |
4397 | if (s) goto err; | 4395 | if (s) goto err; |
4398 | 4396 | ||
4399 | var = p->l.t.t != BC_LEX_LBRACKET; | 4397 | var = p->l.lex != BC_LEX_LBRACKET; |
4400 | 4398 | ||
4401 | if (!var) { | 4399 | if (!var) { |
4402 | s = zbc_lex_next(&p->l); | 4400 | s = zbc_lex_next(&p->l); |
4403 | if (s) goto err; | 4401 | if (s) goto err; |
4404 | 4402 | ||
4405 | if (p->l.t.t != BC_LEX_RBRACKET) { | 4403 | if (p->l.lex != BC_LEX_RBRACKET) { |
4406 | s = bc_error("bad function definition"); | 4404 | s = bc_error("bad function definition"); |
4407 | goto err; | 4405 | goto err; |
4408 | } | 4406 | } |
@@ -4411,7 +4409,7 @@ static BC_STATUS zbc_parse_funcdef(BcParse *p) | |||
4411 | if (s) goto err; | 4409 | if (s) goto err; |
4412 | } | 4410 | } |
4413 | 4411 | ||
4414 | comma = p->l.t.t == BC_LEX_COMMA; | 4412 | comma = p->l.lex == BC_LEX_COMMA; |
4415 | if (comma) { | 4413 | if (comma) { |
4416 | s = zbc_lex_next(&p->l); | 4414 | s = zbc_lex_next(&p->l); |
4417 | if (s) goto err; | 4415 | if (s) goto err; |
@@ -4426,7 +4424,7 @@ static BC_STATUS zbc_parse_funcdef(BcParse *p) | |||
4426 | s = zbc_lex_next(&p->l); | 4424 | s = zbc_lex_next(&p->l); |
4427 | if (s) RETURN_STATUS(s); | 4425 | if (s) RETURN_STATUS(s); |
4428 | 4426 | ||
4429 | if (p->l.t.t != BC_LEX_LBRACE) { | 4427 | if (p->l.lex != BC_LEX_LBRACE) { |
4430 | s = zbc_POSIX_requires("the left brace be on the same line as the function header"); | 4428 | s = zbc_POSIX_requires("the left brace be on the same line as the function header"); |
4431 | if (s) RETURN_STATUS(s); | 4429 | if (s) RETURN_STATUS(s); |
4432 | } | 4430 | } |
@@ -4435,7 +4433,7 @@ static BC_STATUS zbc_parse_funcdef(BcParse *p) | |||
4435 | s = zbc_lex_skip_if_at_NLINE(&p->l); | 4433 | s = zbc_lex_skip_if_at_NLINE(&p->l); |
4436 | if (s) RETURN_STATUS(s); | 4434 | if (s) RETURN_STATUS(s); |
4437 | //GNU bc requires a {} block even if function body has single stmt, enforce this? | 4435 | //GNU bc requires a {} block even if function body has single stmt, enforce this? |
4438 | if (p->l.t.t != BC_LEX_LBRACE) | 4436 | if (p->l.lex != BC_LEX_LBRACE) |
4439 | RETURN_STATUS(bc_error("function { body } expected")); | 4437 | RETURN_STATUS(bc_error("function { body } expected")); |
4440 | 4438 | ||
4441 | p->in_funcdef++; // to determine whether "return" stmt is allowed, and such | 4439 | p->in_funcdef++; // to determine whether "return" stmt is allowed, and such |
@@ -4469,19 +4467,19 @@ static BC_STATUS zbc_parse_auto(BcParse *p) | |||
4469 | if (s) RETURN_STATUS(s); | 4467 | if (s) RETURN_STATUS(s); |
4470 | 4468 | ||
4471 | comma = false; | 4469 | comma = false; |
4472 | one = p->l.t.t == XC_LEX_NAME; | 4470 | one = p->l.lex == XC_LEX_NAME; |
4473 | 4471 | ||
4474 | while (p->l.t.t == XC_LEX_NAME) { | 4472 | while (p->l.lex == XC_LEX_NAME) { |
4475 | name = xstrdup(p->l.t.v.v); | 4473 | name = xstrdup(p->l.lex_buf.v); |
4476 | s = zbc_lex_next(&p->l); | 4474 | s = zbc_lex_next(&p->l); |
4477 | if (s) goto err; | 4475 | if (s) goto err; |
4478 | 4476 | ||
4479 | var = p->l.t.t != BC_LEX_LBRACKET; | 4477 | var = p->l.lex != BC_LEX_LBRACKET; |
4480 | if (!var) { | 4478 | if (!var) { |
4481 | s = zbc_lex_next(&p->l); | 4479 | s = zbc_lex_next(&p->l); |
4482 | if (s) goto err; | 4480 | if (s) goto err; |
4483 | 4481 | ||
4484 | if (p->l.t.t != BC_LEX_RBRACKET) { | 4482 | if (p->l.lex != BC_LEX_RBRACKET) { |
4485 | s = bc_error("bad function definition"); | 4483 | s = bc_error("bad function definition"); |
4486 | goto err; | 4484 | goto err; |
4487 | } | 4485 | } |
@@ -4490,7 +4488,7 @@ static BC_STATUS zbc_parse_auto(BcParse *p) | |||
4490 | if (s) goto err; | 4488 | if (s) goto err; |
4491 | } | 4489 | } |
4492 | 4490 | ||
4493 | comma = p->l.t.t == BC_LEX_COMMA; | 4491 | comma = p->l.lex == BC_LEX_COMMA; |
4494 | if (comma) { | 4492 | if (comma) { |
4495 | s = zbc_lex_next(&p->l); | 4493 | s = zbc_lex_next(&p->l); |
4496 | if (s) goto err; | 4494 | if (s) goto err; |
@@ -4503,7 +4501,7 @@ static BC_STATUS zbc_parse_auto(BcParse *p) | |||
4503 | if (comma) RETURN_STATUS(bc_error("bad function definition")); | 4501 | if (comma) RETURN_STATUS(bc_error("bad function definition")); |
4504 | if (!one) RETURN_STATUS(bc_error("no auto variable found")); | 4502 | if (!one) RETURN_STATUS(bc_error("no auto variable found")); |
4505 | 4503 | ||
4506 | if (p->l.t.t != XC_LEX_NLINE && p->l.t.t != BC_LEX_SCOLON) | 4504 | if (p->l.lex != XC_LEX_NLINE && p->l.lex != BC_LEX_SCOLON) |
4507 | RETURN_STATUS(bc_error_bad_token()); | 4505 | RETURN_STATUS(bc_error_bad_token()); |
4508 | 4506 | ||
4509 | dbg_lex_done("%s:%d done", __func__, __LINE__); | 4507 | dbg_lex_done("%s:%d done", __func__, __LINE__); |
@@ -4520,29 +4518,29 @@ static BC_STATUS zbc_parse_stmt_possibly_auto(BcParse *p, bool auto_allowed) | |||
4520 | { | 4518 | { |
4521 | BcStatus s = BC_STATUS_SUCCESS; | 4519 | BcStatus s = BC_STATUS_SUCCESS; |
4522 | 4520 | ||
4523 | dbg_lex_enter("%s:%d entered, p->l.t.t:%d", __func__, __LINE__, p->l.t.t); | 4521 | dbg_lex_enter("%s:%d entered, p->l.lex:%d", __func__, __LINE__, p->l.lex); |
4524 | 4522 | ||
4525 | if (p->l.t.t == XC_LEX_NLINE) { | 4523 | if (p->l.lex == XC_LEX_NLINE) { |
4526 | dbg_lex_done("%s:%d done (seen XC_LEX_NLINE)", __func__, __LINE__); | 4524 | dbg_lex_done("%s:%d done (seen XC_LEX_NLINE)", __func__, __LINE__); |
4527 | RETURN_STATUS(zbc_lex_next(&p->l)); | 4525 | RETURN_STATUS(zbc_lex_next(&p->l)); |
4528 | } | 4526 | } |
4529 | if (p->l.t.t == BC_LEX_SCOLON) { | 4527 | if (p->l.lex == BC_LEX_SCOLON) { |
4530 | dbg_lex_done("%s:%d done (seen BC_LEX_SCOLON)", __func__, __LINE__); | 4528 | dbg_lex_done("%s:%d done (seen BC_LEX_SCOLON)", __func__, __LINE__); |
4531 | RETURN_STATUS(zbc_lex_next(&p->l)); | 4529 | RETURN_STATUS(zbc_lex_next(&p->l)); |
4532 | } | 4530 | } |
4533 | 4531 | ||
4534 | if (p->l.t.t == BC_LEX_LBRACE) { | 4532 | if (p->l.lex == BC_LEX_LBRACE) { |
4535 | dbg_lex("%s:%d BC_LEX_LBRACE: (auto_allowed:%d)", __func__, __LINE__, auto_allowed); | 4533 | dbg_lex("%s:%d BC_LEX_LBRACE: (auto_allowed:%d)", __func__, __LINE__, auto_allowed); |
4536 | do { | 4534 | do { |
4537 | s = zbc_lex_next(&p->l); | 4535 | s = zbc_lex_next(&p->l); |
4538 | if (s) RETURN_STATUS(s); | 4536 | if (s) RETURN_STATUS(s); |
4539 | } while (p->l.t.t == XC_LEX_NLINE); | 4537 | } while (p->l.lex == XC_LEX_NLINE); |
4540 | if (auto_allowed && p->l.t.t == BC_LEX_KEY_AUTO) { | 4538 | if (auto_allowed && p->l.lex == BC_LEX_KEY_AUTO) { |
4541 | dbg_lex("%s:%d calling zbc_parse_auto()", __func__, __LINE__); | 4539 | dbg_lex("%s:%d calling zbc_parse_auto()", __func__, __LINE__); |
4542 | s = zbc_parse_auto(p); | 4540 | s = zbc_parse_auto(p); |
4543 | if (s) RETURN_STATUS(s); | 4541 | if (s) RETURN_STATUS(s); |
4544 | } | 4542 | } |
4545 | while (p->l.t.t != BC_LEX_RBRACE) { | 4543 | while (p->l.lex != BC_LEX_RBRACE) { |
4546 | dbg_lex("%s:%d block parsing loop", __func__, __LINE__); | 4544 | dbg_lex("%s:%d block parsing loop", __func__, __LINE__); |
4547 | s = zbc_parse_stmt(p); | 4545 | s = zbc_parse_stmt(p); |
4548 | if (s) RETURN_STATUS(s); | 4546 | if (s) RETURN_STATUS(s); |
@@ -4552,8 +4550,8 @@ static BC_STATUS zbc_parse_stmt_possibly_auto(BcParse *p, bool auto_allowed) | |||
4552 | RETURN_STATUS(s); | 4550 | RETURN_STATUS(s); |
4553 | } | 4551 | } |
4554 | 4552 | ||
4555 | dbg_lex("%s:%d p->l.t.t:%d", __func__, __LINE__, p->l.t.t); | 4553 | dbg_lex("%s:%d p->l.lex:%d", __func__, __LINE__, p->l.lex); |
4556 | switch (p->l.t.t) { | 4554 | switch (p->l.lex) { |
4557 | case XC_LEX_OP_MINUS: | 4555 | case XC_LEX_OP_MINUS: |
4558 | case BC_LEX_OP_INC: | 4556 | case BC_LEX_OP_INC: |
4559 | case BC_LEX_OP_DEC: | 4557 | case BC_LEX_OP_DEC: |
@@ -4576,7 +4574,7 @@ static BC_STATUS zbc_parse_stmt_possibly_auto(BcParse *p, bool auto_allowed) | |||
4576 | break; | 4574 | break; |
4577 | case BC_LEX_KEY_BREAK: | 4575 | case BC_LEX_KEY_BREAK: |
4578 | case BC_LEX_KEY_CONTINUE: | 4576 | case BC_LEX_KEY_CONTINUE: |
4579 | s = zbc_parse_break_or_continue(p, p->l.t.t); | 4577 | s = zbc_parse_break_or_continue(p, p->l.lex); |
4580 | break; | 4578 | break; |
4581 | case BC_LEX_KEY_FOR: | 4579 | case BC_LEX_KEY_FOR: |
4582 | s = zbc_parse_for(p); | 4580 | s = zbc_parse_for(p); |
@@ -4634,13 +4632,13 @@ static BC_STATUS zbc_parse_stmt_or_funcdef(BcParse *p) | |||
4634 | BcStatus s; | 4632 | BcStatus s; |
4635 | 4633 | ||
4636 | dbg_lex_enter("%s:%d entered", __func__, __LINE__); | 4634 | dbg_lex_enter("%s:%d entered", __func__, __LINE__); |
4637 | if (p->l.t.t == XC_LEX_EOF) | 4635 | if (p->l.lex == XC_LEX_EOF) |
4638 | s = bc_error("end of file"); | 4636 | s = bc_error("end of file"); |
4639 | else if (p->l.t.t == BC_LEX_KEY_DEFINE) { | 4637 | else if (p->l.lex == BC_LEX_KEY_DEFINE) { |
4640 | dbg_lex("%s:%d p->l.t.t:BC_LEX_KEY_DEFINE", __func__, __LINE__); | 4638 | dbg_lex("%s:%d p->l.lex:BC_LEX_KEY_DEFINE", __func__, __LINE__); |
4641 | s = zbc_parse_funcdef(p); | 4639 | s = zbc_parse_funcdef(p); |
4642 | } else { | 4640 | } else { |
4643 | dbg_lex("%s:%d p->l.t.t:%d (not BC_LEX_KEY_DEFINE)", __func__, __LINE__, p->l.t.t); | 4641 | dbg_lex("%s:%d p->l.lex:%d (not BC_LEX_KEY_DEFINE)", __func__, __LINE__, p->l.lex); |
4644 | s = zbc_parse_stmt(p); | 4642 | s = zbc_parse_stmt(p); |
4645 | } | 4643 | } |
4646 | 4644 | ||
@@ -4654,18 +4652,18 @@ static BcStatus bc_parse_expr_empty_ok(BcParse *p, uint8_t flags) | |||
4654 | { | 4652 | { |
4655 | BcStatus s = BC_STATUS_SUCCESS; | 4653 | BcStatus s = BC_STATUS_SUCCESS; |
4656 | BcInst prev = XC_INST_PRINT; | 4654 | BcInst prev = XC_INST_PRINT; |
4657 | BcLexType top, t = p->l.t.t; | 4655 | BcLexType top, t = p->l.lex; |
4658 | size_t nexprs = 0, ops_bgn = p->ops.len; | 4656 | size_t nexprs = 0, ops_bgn = p->ops.len; |
4659 | unsigned nparens, nrelops; | 4657 | unsigned nparens, nrelops; |
4660 | bool paren_first, paren_expr, rprn, done, get_token, assign, bin_last; | 4658 | bool paren_first, paren_expr, rprn, done, get_token, assign, bin_last; |
4661 | 4659 | ||
4662 | dbg_lex_enter("%s:%d entered", __func__, __LINE__); | 4660 | dbg_lex_enter("%s:%d entered", __func__, __LINE__); |
4663 | paren_first = (p->l.t.t == BC_LEX_LPAREN); | 4661 | paren_first = (p->l.lex == BC_LEX_LPAREN); |
4664 | nparens = nrelops = 0; | 4662 | nparens = nrelops = 0; |
4665 | paren_expr = rprn = done = get_token = assign = false; | 4663 | paren_expr = rprn = done = get_token = assign = false; |
4666 | bin_last = true; | 4664 | bin_last = true; |
4667 | 4665 | ||
4668 | for (; !G_interrupt && !s && !done && bc_parse_exprs(t); t = p->l.t.t) { | 4666 | for (; !G_interrupt && !s && !done && bc_parse_exprs(t); t = p->l.lex) { |
4669 | dbg_lex("%s:%d t:%d", __func__, __LINE__, t); | 4667 | dbg_lex("%s:%d t:%d", __func__, __LINE__, t); |
4670 | switch (t) { | 4668 | switch (t) { |
4671 | case BC_LEX_OP_INC: | 4669 | case BC_LEX_OP_INC: |
@@ -4858,9 +4856,9 @@ static BC_STATUS zdc_parse_register(BcParse *p) | |||
4858 | 4856 | ||
4859 | s = zbc_lex_next(&p->l); | 4857 | s = zbc_lex_next(&p->l); |
4860 | if (s) RETURN_STATUS(s); | 4858 | if (s) RETURN_STATUS(s); |
4861 | if (p->l.t.t != XC_LEX_NAME) RETURN_STATUS(bc_error_bad_token()); | 4859 | if (p->l.lex != XC_LEX_NAME) RETURN_STATUS(bc_error_bad_token()); |
4862 | 4860 | ||
4863 | bc_parse_pushName(p, p->l.t.v.v); | 4861 | bc_parse_pushName(p, p->l.lex_buf.v); |
4864 | 4862 | ||
4865 | RETURN_STATUS(s); | 4863 | RETURN_STATUS(s); |
4866 | } | 4864 | } |
@@ -4873,7 +4871,7 @@ static void dc_parse_string(BcParse *p) | |||
4873 | 4871 | ||
4874 | dbg_lex_enter("%s:%d entered", __func__, __LINE__); | 4872 | dbg_lex_enter("%s:%d entered", __func__, __LINE__); |
4875 | 4873 | ||
4876 | str = xstrdup(p->l.t.v.v); | 4874 | str = xstrdup(p->l.lex_buf.v); |
4877 | bc_parse_push(p, XC_INST_STR); | 4875 | bc_parse_push(p, XC_INST_STR); |
4878 | bc_parse_pushIndex(p, len); | 4876 | bc_parse_pushIndex(p, len); |
4879 | bc_vec_push(&G.prog.strs, &str); | 4877 | bc_vec_push(&G.prog.strs, &str); |
@@ -4921,7 +4919,7 @@ static BC_STATUS zdc_parse_cond(BcParse *p, uint8_t inst) | |||
4921 | // Note that 'else' part can not be on the next line: | 4919 | // Note that 'else' part can not be on the next line: |
4922 | // echo -e '[1p]sa [2p]sb 2 1>a eb' | dc - OK, prints "2" | 4920 | // echo -e '[1p]sa [2p]sb 2 1>a eb' | dc - OK, prints "2" |
4923 | // echo -e '[1p]sa [2p]sb 2 1>a\neb' | dc - parse error | 4921 | // echo -e '[1p]sa [2p]sb 2 1>a\neb' | dc - parse error |
4924 | if (p->l.t.t == DC_LEX_ELSE) { | 4922 | if (p->l.lex == DC_LEX_ELSE) { |
4925 | s = zdc_parse_register(p); | 4923 | s = zdc_parse_register(p); |
4926 | if (s) RETURN_STATUS(s); | 4924 | if (s) RETURN_STATUS(s); |
4927 | s = zbc_lex_next(&p->l); | 4925 | s = zbc_lex_next(&p->l); |
@@ -4966,7 +4964,7 @@ static BC_STATUS zdc_parse_token(BcParse *p, BcLexType t) | |||
4966 | dbg_lex("%s:%d LEX_NEG", __func__, __LINE__); | 4964 | dbg_lex("%s:%d LEX_NEG", __func__, __LINE__); |
4967 | s = zbc_lex_next(&p->l); | 4965 | s = zbc_lex_next(&p->l); |
4968 | if (s) RETURN_STATUS(s); | 4966 | if (s) RETURN_STATUS(s); |
4969 | if (p->l.t.t != XC_LEX_NUMBER) | 4967 | if (p->l.lex != XC_LEX_NUMBER) |
4970 | RETURN_STATUS(bc_error_bad_token()); | 4968 | RETURN_STATUS(bc_error_bad_token()); |
4971 | bc_parse_pushNUM(p); | 4969 | bc_parse_pushNUM(p); |
4972 | bc_parse_push(p, XC_INST_NEG); | 4970 | bc_parse_push(p, XC_INST_NEG); |
@@ -5015,7 +5013,7 @@ static BC_STATUS zdc_parse_expr(BcParse *p) | |||
5015 | { | 5013 | { |
5016 | int i; | 5014 | int i; |
5017 | 5015 | ||
5018 | i = (int)p->l.t.t - (int)XC_LEX_OP_POWER; | 5016 | i = (int)p->l.lex - (int)XC_LEX_OP_POWER; |
5019 | if (i >= 0) { | 5017 | if (i >= 0) { |
5020 | BcInst inst = dc_LEX_to_INST[i]; | 5018 | BcInst inst = dc_LEX_to_INST[i]; |
5021 | if (inst != DC_INST_INVALID) { | 5019 | if (inst != DC_INST_INVALID) { |
@@ -5023,14 +5021,14 @@ static BC_STATUS zdc_parse_expr(BcParse *p) | |||
5023 | RETURN_STATUS(zbc_lex_next(&p->l)); | 5021 | RETURN_STATUS(zbc_lex_next(&p->l)); |
5024 | } | 5022 | } |
5025 | } | 5023 | } |
5026 | RETURN_STATUS(zdc_parse_token(p, p->l.t.t)); | 5024 | RETURN_STATUS(zdc_parse_token(p, p->l.lex)); |
5027 | } | 5025 | } |
5028 | #define zdc_parse_expr(...) (zdc_parse_expr(__VA_ARGS__) COMMA_SUCCESS) | 5026 | #define zdc_parse_expr(...) (zdc_parse_expr(__VA_ARGS__) COMMA_SUCCESS) |
5029 | 5027 | ||
5030 | static BC_STATUS zdc_parse_exprs_until_eof(BcParse *p) | 5028 | static BC_STATUS zdc_parse_exprs_until_eof(BcParse *p) |
5031 | { | 5029 | { |
5032 | dbg_lex_enter("%s:%d entered, p->l.t.t:%d", __func__, __LINE__, p->l.t.t); | 5030 | dbg_lex_enter("%s:%d entered, p->l.lex:%d", __func__, __LINE__, p->l.lex); |
5033 | while (p->l.t.t != XC_LEX_EOF) { | 5031 | while (p->l.lex != XC_LEX_EOF) { |
5034 | BcStatus s = zdc_parse_expr(p); | 5032 | BcStatus s = zdc_parse_expr(p); |
5035 | if (s) RETURN_STATUS(s); | 5033 | if (s) RETURN_STATUS(s); |
5036 | } | 5034 | } |
@@ -5263,7 +5261,7 @@ static BC_STATUS zbc_program_read(void) | |||
5263 | } | 5261 | } |
5264 | if (s) goto exec_err; | 5262 | if (s) goto exec_err; |
5265 | 5263 | ||
5266 | if (parse.l.t.t != XC_LEX_NLINE && parse.l.t.t != XC_LEX_EOF) { | 5264 | if (parse.l.lex != XC_LEX_NLINE && parse.l.lex != XC_LEX_EOF) { |
5267 | s = bc_error("bad read() expression"); | 5265 | s = bc_error("bad read() expression"); |
5268 | goto exec_err; | 5266 | goto exec_err; |
5269 | } | 5267 | } |
@@ -6396,7 +6394,7 @@ static BC_STATUS zdc_program_execStr(char *code, size_t *bgn, bool cond) | |||
6396 | G.input_fp = sv_input_fp; | 6394 | G.input_fp = sv_input_fp; |
6397 | 6395 | ||
6398 | if (s) goto err; | 6396 | if (s) goto err; |
6399 | if (prs.l.t.t != XC_LEX_EOF) { | 6397 | if (prs.l.lex != XC_LEX_EOF) { |
6400 | s = bc_error_bad_expression(); | 6398 | s = bc_error_bad_expression(); |
6401 | err: | 6399 | err: |
6402 | bc_parse_free(&prs); | 6400 | bc_parse_free(&prs); |
@@ -6732,11 +6730,11 @@ static BC_STATUS zbc_vm_process(const char *text) | |||
6732 | s = zbc_parse_text_init(&G.prs, text); // does the first zbc_lex_next() | 6730 | s = zbc_parse_text_init(&G.prs, text); // does the first zbc_lex_next() |
6733 | if (s) RETURN_STATUS(s); | 6731 | if (s) RETURN_STATUS(s); |
6734 | 6732 | ||
6735 | while (G.prs.l.t.t != XC_LEX_EOF) { | 6733 | while (G.prs.l.lex != XC_LEX_EOF) { |
6736 | BcInstPtr *ip; | 6734 | BcInstPtr *ip; |
6737 | BcFunc *f; | 6735 | BcFunc *f; |
6738 | 6736 | ||
6739 | dbg_lex("%s:%d G.prs.l.t.t:%d, parsing...", __func__, __LINE__, G.prs.l.t.t); | 6737 | dbg_lex("%s:%d G.prs.l.lex:%d, parsing...", __func__, __LINE__, G.prs.l.lex); |
6740 | if (IS_BC) { | 6738 | if (IS_BC) { |
6741 | // FIXME: "eating" of stmt delimiters is coded inconsistently | 6739 | // FIXME: "eating" of stmt delimiters is coded inconsistently |
6742 | // (sometimes zbc_parse_stmt() eats the delimiter, sometimes don't), | 6740 | // (sometimes zbc_parse_stmt() eats the delimiter, sometimes don't), |
@@ -6747,10 +6745,10 @@ static BC_STATUS zbc_vm_process(const char *text) | |||
6747 | } else { | 6745 | } else { |
6748 | // Most of dc parsing assumes all whitespace, | 6746 | // Most of dc parsing assumes all whitespace, |
6749 | // including '\n', is eaten. | 6747 | // including '\n', is eaten. |
6750 | while (G.prs.l.t.t == XC_LEX_NLINE) { | 6748 | while (G.prs.l.lex == XC_LEX_NLINE) { |
6751 | s = zbc_lex_next(&G.prs.l); | 6749 | s = zbc_lex_next(&G.prs.l); |
6752 | if (s) goto err; | 6750 | if (s) goto err; |
6753 | if (G.prs.l.t.t == XC_LEX_EOF) | 6751 | if (G.prs.l.lex == XC_LEX_EOF) |
6754 | goto done; | 6752 | goto done; |
6755 | } | 6753 | } |
6756 | IF_DC(s = zdc_parse_expr(&G.prs)); | 6754 | IF_DC(s = zdc_parse_expr(&G.prs)); |