Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- type token = ECHO | QUOTED of string | UNQUOTED of string | COMMENT
- exception Eof
- }
- let alphanum = [ 'A'-'Z' 'a'-'z' '0'-'9' '_' ]
- let comment_line = "//"([^ 'n' ]+)'n'
- let space = [ ' ' 't' 'n' ]
- let quoted = '"'([^ '"' ]+)'"'
- let unquoted = alphanum('/'?alphanum+)+
- rule lexer = parse
- space+ { lexer lexbuf }
- | comment_line { print_endline "got comment"; COMMENT }
- | "echo" { ECHO }
- | quoted { print_endline "got quoted"; QUOTED (Lexing.lexeme lexbuf) }
- | unquoted { print_endline "got unquoted"; UNQUOTED (Lexing.lexeme lexbuf) }
- | eof { raise Eof }
- {
- let _ =
- try
- let lexbuf = Lexing.from_channel stdin in
- while true do
- match lexer lexbuf with
- ECHO -> print_endline "echo"
- | QUOTED _ -> print_endline "quoted"
- | UNQUOTED _ -> print_endline "unquoted"
- | COMMENT -> print_endline "comment"
- done
- with Eof -> exit 0
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement