grammars-v4 icon indicating copy to clipboard operation
grammars-v4 copied to clipboard

[C] Implement line marker rule

Open atirut-w opened this issue 1 year ago • 1 comments

This will be very useful for writing compilers, since line markers is the standard way to convey information where a line is from after a file has been preprocessed, and they can be used as "offsets" for proper error reporting.

atirut-w avatar Jul 06 '24 09:07 atirut-w

The c grammar does not implement preprocessor directives, including #line. We don't implement a preprocessor.

But, let's assume that you generated the post-processed input via cpp or gcc -E. This would contain #line directives. For a concrete example, let's take the source file hw.c-pre.txt and the post-processed generated file hw.c-post.txt

I assume that you'd want a lexer that creates a new token type that contains the additional information that computes the line/column back to the original source. However, in the example I provide, some #line directives don't follow the ISO spec. (The current draft is https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3096.pdf. We don't have a grammar for the newest spec.)

It's possible to do something, but I don't have time at the moment to understand the #line directives that aren't ISO 9899 compliant, and to implement this.

kaby76 avatar Jul 06 '24 11:07 kaby76