parsing fixes
This commit is contained in:
parent
e3547b76b1
commit
b79c3e0f5a
4 changed files with 18 additions and 5 deletions
|
@ -167,7 +167,7 @@ function main
|
||||||
|
|
||||||
tokens = malloc(16000000)
|
tokens = malloc(16000000)
|
||||||
p = tokenize(pptokens, tokens, input_filename, 1)
|
p = tokenize(pptokens, tokens, input_filename, 1)
|
||||||
print_tokens(tokens)
|
print_tokens(tokens, p)
|
||||||
; NOTE: do NOT free pptokens as identifiers still reference them.
|
; NOTE: do NOT free pptokens as identifiers still reference them.
|
||||||
|
|
||||||
ast = malloc(56000000)
|
ast = malloc(56000000)
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
"hi"[33]
|
"hi"[33] << 8
|
||||||
|
|
17
05/parse.b
17
05/parse.b
|
@ -16,6 +16,8 @@ function parse_expression
|
||||||
local value
|
local value
|
||||||
:parse_expression_top
|
:parse_expression_top
|
||||||
|
|
||||||
|
;print_tokens(tokens, tokens_end)
|
||||||
|
|
||||||
type = out + 4
|
type = out + 4
|
||||||
|
|
||||||
if tokens == tokens_end goto empty_expression
|
if tokens == tokens_end goto empty_expression
|
||||||
|
@ -64,7 +66,7 @@ function parse_expression
|
||||||
if p >= tokens_end goto expr_find_operator_loop_end
|
if p >= tokens_end goto expr_find_operator_loop_end
|
||||||
c = *1p
|
c = *1p
|
||||||
p += 16
|
p += 16
|
||||||
if depth > 0 goto expr_find_operator_loop
|
if depth > 0 goto expr_findop_not_new_best
|
||||||
if depth < 0 goto expr_too_many_closing_brackets
|
if depth < 0 goto expr_too_many_closing_brackets
|
||||||
n = p - 16
|
n = p - 16
|
||||||
a = operator_precedence(n, b)
|
a = operator_precedence(n, b)
|
||||||
|
@ -74,7 +76,6 @@ function parse_expression
|
||||||
; new best!
|
; new best!
|
||||||
best = p - 16
|
best = p - 16
|
||||||
best_precedence = a
|
best_precedence = a
|
||||||
goto expr_find_operator_loop
|
|
||||||
:expr_findop_not_new_best
|
:expr_findop_not_new_best
|
||||||
if c == SYMBOL_LPAREN goto expr_findop_incdepth
|
if c == SYMBOL_LPAREN goto expr_findop_incdepth
|
||||||
if c == SYMBOL_RPAREN goto expr_findop_decdepth
|
if c == SYMBOL_RPAREN goto expr_findop_decdepth
|
||||||
|
@ -117,6 +118,12 @@ function parse_expression
|
||||||
if c == SYMBOL_LSHIFT goto type_binary_left_promote
|
if c == SYMBOL_LSHIFT goto type_binary_left_promote
|
||||||
if c == SYMBOL_RSHIFT goto type_binary_left_promote
|
if c == SYMBOL_RSHIFT goto type_binary_left_promote
|
||||||
if c == SYMBOL_LSQUARE goto type_subscript
|
if c == SYMBOL_LSQUARE goto type_subscript
|
||||||
|
if c == SYMBOL_EQ_EQ goto type_binary_comparison
|
||||||
|
if c == SYMBOL_NOT_EQ goto type_binary_comparison
|
||||||
|
if c == SYMBOL_LT_EQ goto type_binary_comparison
|
||||||
|
if c == SYMBOL_GT_EQ goto type_binary_comparison
|
||||||
|
if c == SYMBOL_LT goto type_binary_comparison
|
||||||
|
if c == SYMBOL_GT goto type_binary_comparison
|
||||||
if c < SYMBOL_EQ goto type_binary_usual
|
if c < SYMBOL_EQ goto type_binary_usual
|
||||||
if c > SYMBOL_OR_EQ goto type_binary_usual
|
if c > SYMBOL_OR_EQ goto type_binary_usual
|
||||||
goto type_binary_left
|
goto type_binary_left
|
||||||
|
@ -139,6 +146,9 @@ function parse_expression
|
||||||
:type_binary_usual
|
:type_binary_usual
|
||||||
*4type = expr_binary_type_usual_conversions(tokens, *4a, *4b)
|
*4type = expr_binary_type_usual_conversions(tokens, *4a, *4b)
|
||||||
return out
|
return out
|
||||||
|
:type_binary_comparison
|
||||||
|
*4type = TYPE_INT
|
||||||
|
return out
|
||||||
:type_binary_left
|
:type_binary_left
|
||||||
*4type = *4a
|
*4type = *4a
|
||||||
return out
|
return out
|
||||||
|
@ -355,7 +365,8 @@ function expr_binary_type_usual_conversions
|
||||||
|
|
||||||
function type_promotion
|
function type_promotion
|
||||||
argument type
|
argument type
|
||||||
if type < TYPE_INT goto return_type_int
|
type = types + type
|
||||||
|
if *1type < TYPE_INT goto return_type_int
|
||||||
return type
|
return type
|
||||||
|
|
||||||
; return precedence of given operator token, or 0xffff if not an operator
|
; return precedence of given operator token, or 0xffff if not an operator
|
||||||
|
|
|
@ -588,10 +588,12 @@ function read_number_suffix
|
||||||
|
|
||||||
function print_tokens
|
function print_tokens
|
||||||
argument tokens
|
argument tokens
|
||||||
|
argument tokens_end
|
||||||
local p
|
local p
|
||||||
local s
|
local s
|
||||||
p = tokens
|
p = tokens
|
||||||
:print_tokens_loop
|
:print_tokens_loop
|
||||||
|
if p ]= tokens_end goto print_tokens_loop_end
|
||||||
if *1p == 0 goto print_tokens_loop_end
|
if *1p == 0 goto print_tokens_loop_end
|
||||||
if *1p > 20 goto print_token_keyword
|
if *1p > 20 goto print_token_keyword
|
||||||
if *1p == TOKEN_CONSTANT_INT goto print_token_int
|
if *1p == TOKEN_CONSTANT_INT goto print_token_int
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue