Search code examples
jflex

How to comment code in jflex


Unlike in flex, /* */ and \\

don't seem to work in jlex. They give the error, "Missing brace at start of lexical action."


Solution

  • You can include comments in the first and third sections of your JLex specification (which are the definition and java code sections), but not in the second (rules) part, because JLex will think they are part of a pattern.

    Write %state DUMMY

    in the declaration section and then writing comments in the rules section like this:

    <DUMMY>. { /* this is my comment */ }