2

There are single and multi-line comments available, like in C.

How to describe the rules for the lexer to ignore all the comments, even nested, such as these:

// comment /* nested comment /* and nested again? */ */

or like these:

/* comment // one more comment /* and more... */ */

UPD:

Here is the valid code to parse nested comments(thanks Sam):

rule token = parse
  | "/*"        { comments 0 lexbuf }
  | [' ' '\t' '\n'] { token lexbuf }
  | eof         { raise End_of_file }

and comments level = parse
  | "*/"    {
          if level = 0 then token lexbuf
          else comments (level-1) lexbuf
        }
  | "/*"    { comments (level+1) lexbuf }
  | _       { comments level lexbuf }
Community
  • 1
  • 1
Evgeny Gavrin
  • 7,627
  • 1
  • 22
  • 27

1 Answers1

1

When I was playing around with FsLex I found the Ocamllex Tutorial a great help, in particular the nested comments section was easy to change into F#.

Samuel
  • 2,516
  • 2
  • 24
  • 26