11{
2- exception IllegalCharacter of char
3- exception UnterminatedComment
2+ exception Unterminated_comment
3+ exception Unterminated_string
44
55let next_line lexbuf =
66let pos= lexbuf.Lexing. lex_curr_pin
@@ -24,7 +24,11 @@ rule top = parse
2424| newline { next_line lexbuf;Parser. NL }
2525| " print" {Parser. PRINT }
2626| " '" [^ '\' ']" '" as s {Parser. CHAR s.[1 ] }
27- | " \" " [^ '"' ]* " \" " as s {Parser. STRING s }(* FIXME*)
27+ | " '\\ n'" {Parser. CHAR '\n' }
28+ | " '\\ t'" {Parser. CHAR '\t' }
29+ | " '\\\\ '" {Parser. CHAR '\\' }
30+ | " '\\ ''" {Parser. CHAR '\' ' }
31+ | " \" " {Parser. STRING (string lexbuf) }
2832| " broadcast" | " bc" {Parser. BROADCAST }
2933| lidas l {Parser. LOWER_ID l }
3034| " =" {Parser. EQUAL }
@@ -47,5 +51,15 @@ and comment = parse
4751 ) }
4852|newline { next_line lexbuf; comment lexbuf }
4953|"(*" { incr inner_comments_number; comment lexbuf }
50- |eof { raiseUnterminatedComment }
54+ |eof { raiseUnterminated_comment }
5155|_ { comment lexbuf }
56+
57+ (* FIXME inefficient but easy to read*)
58+ and string = parse
59+ |"\\ n" { "\n" ^ string lexbuf }
60+ |"\\ t" { "\t" ^ string lexbuf }
61+ |"\\\\ " { "\\" ^ string lexbuf }
62+ |"\\\" " { "\"" ^ string lexbuf }
63+ |"\" " { "" }
64+ |eof { raise Unterminated_string }
65+ |_ as c {String. make 1 c ^ string lexbuf }