summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorAkim Demaille <akim.demaille@gmail.com>2021-01-31 21:28:58 +0100
committerAkim Demaille <akim.demaille@gmail.com>2021-02-09 06:48:00 +0100
commit96b881094b114685413c63774117e5186627263a (patch)
tree57eac02fa6cead5806f7ffae9e332dc7b9ca151c /examples
parentfdba54a961a01595f5461d38af6ff6426c74e165 (diff)
downloadbison-96b881094b114685413c63774117e5186627263a.tar.gz
examples: do not rely on YY_LOCATION_PRINT
* examples/c/bistromathic/parse.y (location_print): New. Use it.
Diffstat (limited to 'examples')
-rw-r--r--examples/c/bistromathic/parse.y24
1 files changed, 24 insertions, 0 deletions
diff --git a/examples/c/bistromathic/parse.y b/examples/c/bistromathic/parse.y
index b772f1ba..ad025e66 100644
--- a/examples/c/bistromathic/parse.y
+++ b/examples/c/bistromathic/parse.y
@@ -94,6 +94,10 @@
// Emitted in the implementation file.
%code {
+ // Print *LOC on OUT.
+ static void location_print (FILE *out, YYLTYPE const * const loc);
+ #define YY_LOCATION_PRINT(Out, Loc) location_print(Out, &(Loc))
+
#if defined ENABLE_NLS && ENABLE_NLS
# define _(Msgid) gettext (Msgid)
#else
@@ -269,6 +273,26 @@ symbol_count (void)
}
+
+/*------------.
+| Locations. |
+`------------*/
+
+// Print *LOC on OUT. Do it in a compact way, that avoids redundancy.
+
+static void
+location_print (FILE *out, YYLTYPE const * const loc)
+{
+ fprintf (out, "%d.%d", loc->first_line, loc->first_column);
+
+ int end_col = 0 != loc->last_column ? loc->last_column - 1 : 0;
+ if (loc->first_line < loc->last_line)
+ fprintf (out, "-%d.%d", loc->last_line, end_col);
+ else if (loc->first_column < end_col)
+ fprintf (out, "-%d", end_col);
+}
+
+
/*----------.
| Scanner. |
`----------*/