Advertisement
Guest User

Untitled

a guest
Oct 1st, 2012
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 1.11 KB | None | 0 0
  1.  
  2. open Lexing
  3.  
  4. let lb_chan = from_channel stdin
  5.  
  6. let lb_str = from_string "\nEND OF INPUT\n"
  7.  
  8. let lexbuf =
  9.   { lb_chan with refill_buff =
  10.     let in_string = ref false in
  11.     fun lb ->
  12.       if !in_string then lb_str.refill_buff lb
  13.       else begin
  14.     lb_chan.refill_buff lb;
  15.     if lb.lex_eof_reached
  16.     then begin
  17.       in_string := true;
  18.       lb.lex_buffer      <- lb_str.lex_buffer;
  19.       lb.lex_buffer_len  <- lb_str.lex_buffer_len;
  20.       lb.lex_abs_pos     <- lb_str.lex_abs_pos;
  21.       lb.lex_start_pos   <- lb_str.lex_start_pos;
  22.       lb.lex_curr_pos    <- lb_str.lex_curr_pos;
  23.       lb.lex_last_pos    <- lb_str.lex_last_pos;
  24.       lb.lex_last_action <- lb_str.lex_last_action;
  25.       lb.lex_eof_reached <- lb_str.lex_eof_reached;
  26.       lb.lex_mem         <- lb_str.lex_mem;
  27.       lb.lex_start_p     <- lb_str.lex_start_p;
  28.       lb.lex_curr_p      <- lb_str.lex_curr_p;
  29.       lb_str.refill_buff lb
  30.     end
  31.       end
  32.   }
  33.  
  34. let rec read () =
  35.   lexbuf.refill_buff lexbuf;
  36.   print_string lexbuf.lex_buffer;
  37.   if lexbuf.lex_eof_reached then print_string "\nDone reading.\n"
  38.   else read ()
  39.  
  40. let () = read ()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement