Reputation: 639
How does one make a comment in Lex and Yacc?
So far I haven't tried Yacc, but in Lex I have tried /* comment */
and // comment
, but neither of these compile. I am on a Mac, using the builtin Lex and Yacc compilers, (or maybe the X-Code ones, I don't know). What is the correct syntax for comments in Lex or Yacc, or preferably both?
Upvotes: 9
Views: 19600
Reputation: 310860
From info flex:
In the definitions and rules sections, any indented text or text enclosed in %{ and %} is copied verbatim to the output (with the %{}'s removed). The %{}'s must appear unindented on lines by themselves.
In this case the text concerned can be a comment in the target language.
In the definitions section (but not in the rules section), an unindented comment (i.e., a line beginning with
/*
) is also copied verbatim to the output up to the next*/
.
Any valid C comment is a comment in a code block.
A comment in yacc is /* ... */
.
Upvotes: 5
Reputation: 639
Any C comment is acceptable as a comment anywhere in a program in both Yacc and Lex, BUT:
/* comment */
written into your program touching the LHS of your text will NOT WORK!
// comment
comments, Lex and Yacc are not nice. these comments, while will work in a C program, will NOT WORK!Upvotes: 7