On 4 Oct 2005, at 22:48, Jason Ki wrote:
This is in regards to the thread "token value return in custom yylex
()"
posted by Bernd Prager on Tuesday December 3rd, 2002.
http://lists.gnu.org/archive/html/help-bison/2002-12/msg00002.html
His grammar code shows the following:
----- start of example -----
%{
#include <stdio.h>
#include <string.h>
#include "parser.tab.h"
#define TESTSTRING "word1 word2" // testpattern
char *data, buffer[1024];
%}
%union {
int id;
char *str;
}
%type <str> object token list
%token <id> WORD
----- end of example -----
I am unsure what the previous coding really means. At first I thought
that a token could either be a string or an integer. However, on a
closer inspection I noticed that the it was "%type" and not "%
token". So
does this mean that a token can only be of type integer? If this is
wrong, which I'm positively sure it is, then I believe I still have
yet
to grasp what a token is.
Bison has a static typing system, which is turned on when %union is
invoked, and at the same time the stuff in the %union clause is
implemented as a C-union. One then has to figure out how to select
the right union field, which is done with the %type and %token
declarations above. Each grammar symbol can only have one type value,
and that is written down above. It says that the token WORD has the
type <id>, the grammar variables object, token, list, have type <str>.
Additionally, is yacc similar to BISON? The website below:
http://epaperpress.com/lexandyacc/index.html
implies that yacc is the same as BISON in regards that both are
software
used to generate grammar rules for building a syntax tree.
There is a POSIX specification for what a Yacc-like program should
fulfill, and Bison has a mode where it aims to compliant with that
POSIX specification.
Hans Aberg
_______________________________________________
[email protected] http://lists.gnu.org/mailman/listinfo/help-bison