Search code examples
commentsbisonflex-lexer

How can we add comments in flex/bison source code?


Like in other languages, we can add comments using either //, /---/, #, % etc. So similarly if I want to add comments in flex/bison source code for better understanding of code. Can I do the same? If yes then how? Whenever I tried to search about same on the internet, answers usually come for defining comment in flex/bison and not about how to add comments in flex/bison source code.


Solution

  • (F)lex: Indent the comment, and use a comment style appropriate to the generated code. (/*...*/ is recommended.) You must indent every line of the comment. Indented text is copied verbatim to the generated file, but a comment is a comment.

    Yacc/Bison: Use /* ... */ anywhere in the grammar. In bison, but possibly not other yacc derivatives, you can also use // comments.