Advertisement
Guest User

Untitled

a guest
Nov 28th, 2014
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. {
  2. type token = ECHO | QUOTED of string | UNQUOTED of string | COMMENT
  3. exception Eof
  4. }
  5.  
  6. let alphanum = [ 'A'-'Z' 'a'-'z' '0'-'9' '_' ]
  7. let comment_line = "//"([^ 'n' ]+)'n'
  8. let space = [ ' ' 't' 'n' ]
  9. let quoted = '"'([^ '"' ]+)'"'
  10. let unquoted = alphanum('/'?alphanum+)+
  11.  
  12. rule lexer = parse
  13. space+ { lexer lexbuf }
  14. | comment_line { print_endline "got comment"; COMMENT }
  15. | "echo" { ECHO }
  16. | quoted { print_endline "got quoted"; QUOTED (Lexing.lexeme lexbuf) }
  17. | unquoted { print_endline "got unquoted"; UNQUOTED (Lexing.lexeme lexbuf) }
  18. | eof { raise Eof }
  19.  
  20. {
  21.  
  22. let _ =
  23. try
  24. let lexbuf = Lexing.from_channel stdin in
  25. while true do
  26. match lexer lexbuf with
  27. ECHO -> print_endline "echo"
  28. | QUOTED _ -> print_endline "quoted"
  29. | UNQUOTED _ -> print_endline "unquoted"
  30. | COMMENT -> print_endline "comment"
  31. done
  32. with Eof -> exit 0
  33.  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement