pro-fondement/Rendu0/lexer.mll
2022-01-24 18:18:27 +01:00

36 lines
1.1 KiB
OCaml

{
open Parser
exception Eof
}
rule token = parse (* la "fonction" aussi s'appelle token .. *)
| [' ' '\t'] { token lexbuf } (* on saute les blancs et les tabulations *)
(* token: appel récursif *)
(* lexbuf: argument implicite
associé au tampon où sont
lus les caractères *)
| '\n' { EOL }
| '+' { PLUS }
| '*' { TIMES }
| '-' { MINUS }
| '(' { LPAREN }
| ')' { RPAREN }
| ['0'-'9']+ as s { INT (int_of_string s) }
| "true" { TRUE }
| "false" { FALSE }
| '>' { GT }
| '<' { LT }
| ">=" { GTE }
| ">=" { LTE }
| '=' { EQ }
| "&&" { BAND }
| "||" { BOR }
| "if" { IF }
| "then" { THEN }
| "else" { ELSE }
| "prInt" { PRINT }
| "let" { LET }
| "in" { IN }
| ['a'-'z']+ as v { VAR (v) }
| eof { raise Eof } (* fin du fichier *)