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

View file

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

View file

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