From ac1eea42e9fb99fb69240e421177d67601dcd454 Mon Sep 17 00:00:00 2001 From: Benjamin Loison Date: Sat, 10 Dec 2022 19:24:34 +0100 Subject: [PATCH] Make `<=`, `>=` and `<>` work --- src/ast_to_c.ml | 3 +-- src/lexer.mll | 8 +++----- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/ast_to_c.ml b/src/ast_to_c.ml index 9978e22..094c424 100644 --- a/src/ast_to_c.ml +++ b/src/ast_to_c.ml @@ -125,8 +125,7 @@ let pp_expression = begin let s = match cop with | COp_eq -> " == " - | COp_neq -> " ≠ " - (* TODO: check <= and >= *) + | COp_neq -> " != " | COp_le -> " <= " | COp_lt -> " < " | COp_ge -> " >= " | COp_gt -> " > " in Format.fprintf fmt "%s%a%s%a" prefix diff --git a/src/lexer.mll b/src/lexer.mll index 4b28de5..5802800 100644 --- a/src/lexer.mll +++ b/src/lexer.mll @@ -16,15 +16,10 @@ ("int", TYP(Ast.TInt)); ("real", TYP(Ast.TReal)); ("bool", TYP(Ast.TBool)); - ("<=", CMP_le); - (">=", CMP_ge); ("not", MO_not); ("mod", BO_mod); - ("&&", BO_and); ("and", BO_and); - ("||", BO_or); ("or", BO_or); - ("<>", CMP_neq); ("if", IF); ("then", THEN); ("else", ELSE); @@ -56,7 +51,10 @@ rule token = parse | ';' { SEMICOL } | ':' { COLON } | '<' { CMP_lt } + | "<=" { CMP_le } | '>' { CMP_gt } + | ">=" { CMP_ge } + | "<>" { CMP_neq } | '+' { PLUS } | '-' { MINUS } | '*' { BO_mul }