fixed parser ignoring tokens and flipped associativity the right way round

This commit is contained in:
William Ball 2024-08-13 16:08:08 -07:00
parent 55a1a9ce0a
commit 607b9f1d7d
3 changed files with 16 additions and 6 deletions

View file

@ -24,10 +24,10 @@ struct
open Scanner open Scanner
val prec = val prec =
fn AND => (6, 7) fn AND => (7, 6)
| OR => (4, 5) | OR => (5, 4)
| RARROW => (3, 2) | RARROW => (2, 3)
| LRARROW => (1, 2) | LRARROW => (1, 1)
| _ => (~1, ~1) | _ => (~1, ~1)
exception NotOperator exception NotOperator
@ -122,8 +122,13 @@ struct
val (lprec, rprec) = prec t val (lprec, rprec) = prec t
val comb = comb_func t val comb = comb_func t
in in
if lprec < mprec then OK (v, r1, ts) if lprec < mprec then
else ((comb_p rprec) oo (fn res => comb (v, res))) rest if connective t then
((comb_p 0) oo (fn res => comb (v, res))) rest
else
OK (v, r1, ts)
else
((comb_p rprec) oo (fn res => comb (v, res))) rest
end end
in in
comb_p 0 comb_p 0

View file

@ -18,4 +18,6 @@ sig
val scan: {srcname: string, input: string} -> (token * Region.reg) list val scan: {srcname: string, input: string} -> (token * Region.reg) list
val pp_token: token -> string val pp_token: token -> string
val connective: token -> bool
end end

View file

@ -61,4 +61,7 @@ struct
| ERR => "unk" | ERR => "unk"
| HASH => "#" | HASH => "#"
| IDENT s => s | IDENT s => s
val connective =
fn AND => true | OR => true | RARROW => true | LRARROW => true | _ => false
end end