help-bison
[Top][All Lists]
Advanced

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

Help Deciphering an Example


From: Jason Ki
Subject: Help Deciphering an Example
Date: Tue, 04 Oct 2005 13:48:36 -0700

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.

Please do correct me, but isn't a token a unit of word. Like for the
following sentence:

"I am 3"

If I define that an acceptable token type is of string and integer
format then the following is parsed

"I" <-- with this being of string format
"am"<-- with this being of string format
"3" <-- with this being of integer format

The more I think about this the more I get confused over the role the
defining of a token and the role of yylex(). 

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.

thanks,
~Jason Ki






reply via email to

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