nand2tetris/assembler/lib/lexer.mll

25 lines
554 B
OCaml

{
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 }