I am using Lex and Yacc to design a parser and encounter some issue about comment.
I use the following Lex rule.
'#'[^('\r'|'\n')]* { /* do nothing */ }
It works, but at the end of execution all the comments are printed to the standard output. Is there way to clear that? Thank you for the suggestion.
The characters
',|,(, and)have no special meaning in[], so you’re only matching (and discarding) comments that don’t contain them. In addition, in most versions of lex'has no special meaning at all — only"can be used to quote literal strings. What you probably want is:In addition,
#has no special meaning either, so there’s no real need to quote it.In general, if you’re using lex (or flex) as the input to a parser, you NEVER want the default echoing behavior, so its best to add a ‘catch-all’ rule at the very end: