58 lines
1.1 KiB
OCaml
58 lines
1.1 KiB
OCaml
|
{
|
||
|
open Be_parser
|
||
|
}
|
||
|
|
||
|
let address = ['0'-'9']+
|
||
|
|
||
|
(* let ADD = "add"
|
||
|
let SUB = "sub"
|
||
|
let NEG = "neg"
|
||
|
let EQ = "eq"
|
||
|
let GT = "gt"
|
||
|
let LT = "lt"
|
||
|
let AND = "and"
|
||
|
let OR = "or"
|
||
|
let NOT = "not"
|
||
|
let POP = "pop"
|
||
|
let PUSH = "push" *)
|
||
|
|
||
|
let command = "add"
|
||
|
| "sub"
|
||
|
| "neg"
|
||
|
| "eq"
|
||
|
| "gt"
|
||
|
| "lt"
|
||
|
| "and"
|
||
|
| "or"
|
||
|
| "not"
|
||
|
| "pop"
|
||
|
| "push"
|
||
|
|
||
|
let segment = "argument"
|
||
|
| "local"
|
||
|
| "static"
|
||
|
| "this"
|
||
|
| "that"
|
||
|
| "pointer"
|
||
|
| "temp"
|
||
|
| "constant"
|
||
|
|
||
|
let white = [' ' '\t']+
|
||
|
let comment = "//" _*
|
||
|
|
||
|
(*
|
||
|
let digit = ['0'-'9']
|
||
|
let letter = ['a'-'z' 'A'-'Z']
|
||
|
let special = ['.' '$' '_' '-' '+' '&' '!' '|']
|
||
|
let id = (digit | letter | special)+
|
||
|
*)
|
||
|
|
||
|
rule read =
|
||
|
parse
|
||
|
| white { read lexbuf }
|
||
|
| address as a { ADDRESS (a) }
|
||
|
| command as c { COMMAND (c) }
|
||
|
| segment as s { SEGMENT (s) }
|
||
|
| comment as c { COMMENT (c) }
|
||
|
| eof { EOF }
|