help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

location tracking with empty RHS.


From: Tanaka Akira
Subject: location tracking with empty RHS.
Date: Sat, 05 Apr 2003 15:18:16 +0900
User-agent: T-gnus/6.15.7 (based on Oort Gnus v0.08) SEMI/1.14.4 (Hosorogi) FLIM/1.14.4 (Kashiharajingū-mae) APEL/10.4 Emacs/21.2 (i386-debian-linux-gnu) MULE/5.0 (SAKAKI)

Hi.  I have a question about location tracking with empty RHS.

Bison uses YYLLOC_DEFAULT to track locations.
By default, it is defined as follows.

     #define YYLLOC_DEFAULT(Current, Rhs, N)          \
       Current.first_line   = Rhs[1].first_line;      \
       Current.first_column = Rhs[1].first_column;    \
       Current.last_line    = Rhs[N].last_line;       \
       Current.last_column  = Rhs[N].last_column;

But what's happen when N = 0 which is caused by empty RHS?

For example, following grammar has empty RHS: the RHS of start is
empty. 

  start :

In this extreme simple case, when YYLLOC_DEFAULT is evaluated, they
are zero as:

% cat empty.y
%locations

%{
#include <stdio.h>

int yylex(void);
void yyerror(char const *s);

#define YYLLOC_DEFAULT(Current, Rhs, N)          \
  Current.first_line   = Rhs[1].first_line;      \
  Current.first_column = Rhs[1].first_column;    \
  Current.last_line    = Rhs[N].last_line;       \
  Current.last_column  = Rhs[N].last_column;     \
  fprintf(stderr, "loc(%d) [l%d,c%d l%d,c%d] [l%d,c%d l%d,c%d]\n", N, \
    Rhs[1].first_line, Rhs[1].first_column, \
    Rhs[1].last_line, Rhs[1].last_column, \
    Rhs[N].first_line, Rhs[N].first_column, \
    Rhs[N].last_line, Rhs[N].last_column);

%}

%%
start : 
%%

int yylex(void) { return 0; }
void yyerror(char const *s) { fprintf(stderr, "%s\n", s); }
int main(int argc, char **argv)
{
  yyparse();
  return 0;
}
% bison empty.y  
% gcc empty.tab.c
% ./a.out        
loc(0) [l0,c0 l0,c0] [l0,c0 l0,c0]
% 

But what's happen in general case?

I use bison-1.875a come from Debian.

% bison --version
bison (GNU Bison) 1.875a
Written by Robert Corbett and Richard Stallman.

Copyright (C) 2003 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-- 
Tanaka Akira




reply via email to

[Prev in Thread] Current Thread [Next in Thread]