Shells in OCaml
at main 48 lines 900 B view raw
1{ 2 open Arith_parser 3} 4 5let digit = ['0'-'9'] 6let oct_digit = ['0'-'7'] 7let hex_digit = ['0'-'9' 'a'-'f' 'A'-'F'] 8let alpha = ['a'-'z' 'A'-'Z' '_'] 9let ident = alpha (alpha | digit)* 10let var = 11 ident 12| '$' ident 13 14rule read = parse 15 | [' ' '\t' '\n'] { read lexbuf } 16 17 | "+=" { PLUSEQ } 18 | "-=" { MINUSEQ } 19 | "/=" { DIVEQ } 20 | "*=" { MULEQ } 21 | "%=" { MODEQ } 22 | "==" { EQEQ } 23 | '=' { EQ } 24 25 | '+' { PLUS } 26 | '-' { MINUS } 27 | '*' { MUL } 28 | '/' { DIV } 29 | '?' { QUESTION } 30 | ':' { COLON } 31 | '>' { GT } 32 | '<' { LT } 33 34 | '(' { LPAREN } 35 | ')' { RPAREN } 36 37 | "0x" hex_digit+ as s { INT (int_of_string s) } 38 | "0X" hex_digit+ as s { INT (int_of_string s) } 39 | "0" oct_digit+ as s { INT (int_of_string ("0o" ^ s)) } 40 | digit+ as i { INT (int_of_string i) } 41 42 | var as v { VAR v } 43 44 | eof { EOF } 45 46 | _ as c 47 { failwith ("Unexpected character: " ^ Char.escaped c) } 48