[parser] parses and dumps content (without expressions)

This commit is contained in:
dsac
2022-12-07 16:45:55 +01:00
parent 4d304d8e9a
commit e9e5cdcf4d
8 changed files with 245 additions and 0 deletions

38
src/lexer.mll Normal file
View File

@@ -0,0 +1,38 @@
{
open Lexing
open Ast
open Parser (* The type token is defined in parser.mli *)
exception Lexing_error of string
let id_or_keywork =
let h = Hashtbl.create 100 in
List.iter (fun (s,k) -> Hashtbl.add h s k)
[ ("let", LET);
("tel", TEL);
("node", NODE);
("returns", RETURNS);
("var", VAR);
("int", INT);
("bool", BOOL);
];
fun s ->
try Hashtbl.find h s with Not_found -> IDENT s
}
let alpha = ['a'-'z' 'A'-'Z']
let digit = ['0'-'9']
let ident = alpha (alpha | digit | '_')*
rule token = parse
['\n' ' ' '\t'] { token lexbuf } (* skip blanks and newlines *)
| ident { id_or_keywork (lexeme lexbuf) }
| ',' { COMMA }
| '=' { EQUAL }
| '(' { LPAREN }
| ')' { RPAREN }
| ';' { SEMICOL }
| ':' { COLON }
| eof { EOF }
| _ { raise (Lexing_error (Format.sprintf "Erruer à la vue de %s" (lexeme lexbuf)))}