Next: , Up: Location Tracking Calculator: ltcalc   [Contents][Index]


2.4.1 Declarations for ltcalc

The C and Bison declarations for the location tracking calculator are the same as the declarations for the infix notation calculator.

/* Location tracking calculator. */

%{
  #include <math.h>
  int yylex (void);
  void yyerror (char const *);
%}

/* Bison declarations. */
%define api.value.type {int}
%token NUM

%left '-' '+'
%left '*' '/'
%precedence NEG
%right '^'

%% /* The grammar follows. */

Note there are no declarations specific to locations. Defining a data type for storing locations is not needed: we will use the type provided by default (see Data Type of Locations), which is a four member structure with the following integer fields: first_line, first_column, last_line and last_column. By conventions, and in accordance with the GNU Coding Standards and common practice, the line and column count both start at 1.