pro-fondement/Rendu0/lexer.mll

40 lines
1.3 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 }
| "fun" { FUN }
| "->" { MAPSTO }
| "_" { UNDERSCORE }
| ";;" { PVPV }
| (['a'-'z'])(['a'-'z' 'A'-'Z' '0'-'9' '_'])* as v { VAR (v) }
| eof { raise Eof } (* fin du fichier *)