nand2tetris/projects/06/assembler/lib/Lexer.mll

25 lines
554 B
OCaml
Raw Normal View History

2022-07-18 19:16:54 +00:00
{
open Parser
}
let white = [' ' '\t']+
let comment = "//" _*
let newline = '\n' | '\r'
let digit = ['0'-'9']
let letter = ['a'-'z' 'A'-'Z']
let special = ['.' '$' '_' '-' '+' '&' '!' '|']
let id = (digit | letter | special)+
rule read =
parse
| white { read lexbuf }
| "@" { AT }
| "(" { LPAREN }
| ")" { RPAREN }
| ";" { SCOLON }
| "=" { EQUALS }
| comment as c { COMMENT (c) }
| id as id { ID (id) }
| eof { EOF }