+]])
+
+AT_DATA_GRAMMAR([calc.y],
+[[/* Infix notation calculator--calc */
+]$4
+AT_SKEL_CC_IF(
+[%define global_tokens_and_yystype])[
+%code requires
+{
+]AT_LOCATION_TYPE_IF([[
+# include <iostream>
+ struct Point
+ {
+ int l;
+ int c;
+ };
+
+ struct Span
+ {
+ Point first;
+ Point last;
+ };
+
+# define YYLLOC_DEFAULT(Current, Rhs, N) \
+ do \
+ if (N) \
+ { \
+ (Current).first = YYRHSLOC (Rhs, 1).first; \
+ (Current).last = YYRHSLOC (Rhs, N).last; \
+ } \
+ else \
+ { \
+ (Current).first = (Current).last = YYRHSLOC (Rhs, 0).last; \
+ } \
+ while (false)
+
+]])[
+ /* Exercise pre-prologue dependency to %union. */
+ typedef int semantic_value;
+}
+
+/* Exercise %union. */
+%union
+{
+ semantic_value ival;
+};
+
+%code provides
+{
+ #include <stdio.h>
+ /* The input. */
+ extern FILE *input;
+ extern semantic_value global_result;
+ extern int global_count;
+}
+
+%code
+{
+#include <assert.h>
+#include <string.h>
+#define USE(Var)
+
+FILE *input;
+static int power (int base, int exponent);
+
+]AT_YYERROR_DECLARE[
+]AT_YYLEX_DECLARE_EXTERN[
+}
+
+/* Bison Declarations */
+%token CALC_EOF 0 "end of input"
+%token <ival> NUM "number"
+%type <ival> exp
+
+%nonassoc '=' /* comparison */
+%left '-' '+'
+%left '*' '/'
+%left NEG /* negation--unary minus */
+%right '^' /* exponentiation */
+
+/* Grammar follows */
+%%
+input:
+ line
+| input line { ]AT_PARAM_IF([++*count; ++global_count;])[ }
+;
+
+line:
+ '\n'
+| exp '\n' { ]AT_PARAM_IF([*result = global_result = $1], [USE ($1)])[; }
+;
+
+exp:
+ NUM { $$ = $1; }
+| exp '=' exp
+ {
+ if ($1 != $3)
+ fprintf (stderr, "calc: error: %d != %d\n", $1, $3);
+ $$ = $1;
+ }
+| exp '+' exp { $$ = $1 + $3; }
+| exp '-' exp { $$ = $1 - $3; }
+| exp '*' exp { $$ = $1 * $3; }
+| exp '/' exp { $$ = $1 / $3; }
+| '-' exp %prec NEG { $$ = -$2; }
+| exp '^' exp { $$ = power ($1, $3); }
+| '(' exp ')' { $$ = $2; }
+| '(' error ')' { $$ = 1111; yyerrok; }
+| '!' { $$ = 0; YYERROR; }
+| '-' error { $$ = 0; YYERROR; }
+;
+%%