Directive
#line changes the position of the report for the compiler and is used by code generation software to help the programmer identify the problem at the source. It can be used by anyone to help redirect the error report to be more informative.
So, for example, your parser generates a CSSGrammar.cpp file that is compiled by the C ++ compiler and has C ++ fragments in it, the directive #line 25 "CSSGrammar.y" tells the C ++ compiler to process this specific point in the file, as if it's line number 25 from CSSGrammar.y
The compiler will continue to analyze subsequent lines and report errors in the initial conditions of this directive.
So, if an error occurs 3 lines later, it will report that the error occurred on line 28 in CSSGrammar.y
Please note that in one source file there may be sources coming from several parts; and that this directive can be used efficiently enough to indicate error conditions.
You will usually see that there are several #line directives in the #line ; they just have to consider the different injections on the way (before resetting the reporting carriages if you want).
Please note that the #line directive can be used by the ANY generator, including your own, and is not limited to them in parsers.
Ahmed masud
source share