help-bison
[Top][All Lists]
Advanced

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

Re: Can't get Bison to work


From: Davy Durham
Subject: Re: Can't get Bison to work
Date: Wed, 13 Dec 2000 10:34:38 -0600

Ah..... you're here too... I'll post my message here also
 

In spite of your response:

    This is probably better left to the bison-help mailing list, but since
your original post is here I post it here...
    You have to specify the type (from the union) you want each
rule/production to be if you're going to use them as $1, $2, $3...

For instance,
    Here is some bison code that will read consecutive quoted strings and make
a long string out of them or consecutive ints and add them together...  I
didn't include the lexer.. it should just parse an integer and return
LITERAL_INT or a quoted string and return LITERAL_STRING... However, the lexer
would also need to set yylval.intValue to the integer value of an integer read
and also set yylval.stringValue to a pointer to the string upon reading a
quoted string...

...
%union
{
    char * stringValue;
    int intValue;
    ...
}

%token <stringValue>    LITERAL_STRING    // saying that a LITERAL_STRING has
a "char *" type
%token <intValue>    LITERAL_INT    // saying that a LITERAL_INT has an "int"
type

%type <stringValue> long_string    // saying that the production, long_string,
has a "char *" type
%type <intValue> added_int    // saying that the production, added_int, has an
"int" type
 

%start start // the starting point will be the production called "start"

%%

start
    : start long_string
    {
        printf("long_string found: %s\n",$2);  // long_string is the second
thing listed above so it's $2.. and it has the type "char *"
    }
    | start added_int
    {
        printf(added_int found: %d\n",$2); // like-wise
    }
    ;

long_string
    : LITERAL_STRING
    {
        $$=$1;  // to say $$ means the production's value and we say above
that long_string and LITERAL_STRING have a type of "char *"
    }
    | long_string LITERAL_STRING
    {
        // append $2 to $1 and make that result the production's value
        $$=$1;
        $$=(char *)realloc($$,strlen($$)+strlen($2)+1);
        strcat($$,$1);
    }
    ;

added_int
    : LITERAL_INT
    {
        $$=$1;
    }
    | added_int LITERAL_INT
    {
        // add the two ints together and make the result the productions value

        $$=$1+$2;
    }

...
 

Keep in mind above, that all the while we used $1, $2... those were the rules'
parts and they're in the order that they're listed.. On top of that, we had to
say what their types are to make it valid to say $$=$1+$2;  which really
translates into  int=int+int;

I hope this helps....   I didn't actually compile this... I just wrote it off
the top of my head... But the main point you're asking about should be
explained here...

And BTW- Profanity isn't a myth... it's called that because people (today)
socially categorize certain words that way..... and social unacceptedness
DO exist  and alway will...   They may change, but this particular one has not
yet for all of society...

--Davy
 
 

JB wrote:

> ----- Original Message -----
> From: "Robert Dewar" <address@hidden>
> To: <address@hidden>
> Sent: Wednesday, December 13, 2000 9:54 PM
> Subject: Re: Bison broken?
>
> > Suggestion: when you are asking for people to volunteer to give you
> > free help, it is a good idea to avoid unnecessary profanity,
>
> Then they certainly are precious, aren't they?! Jesus christ, I've never
> come across such a precious bunch of wankers in my life. If you are correct
> and apparantly intelligent people act like this, then I don't want anything
> to do with these religious pricks, and they can choose to ignore my posts.
>
> If they are worried about "profanity" then I am worried about adults who
> believe in such mythology. I wonder if these insane, dangerous bastards
> still believe in fairies at the bottom of the garden.
>
> > since it simply will annoy some people who might otherwise be willing to
> help.
> Shame. Don't want to know them.
 
 

JB wrote:

Hello again Bison users, Hope you're all gonna have a merry Christmas! I won't be if I can't figure out my Bison woes :( AND YES I'VE READ THE F*ING MANUAL. ;-P My problem is several. One is with Bison on cygwin: Bison complains that $$, $1, $2. $n do not have types and refuses to make me a parser. I cannot get this to work at all: %union {    int ival;    char cval;    char *sval;    float fval;} And I cannot get Bison to link with bison.simple (or bison.hairy) with GCC 2.96 xxxxxx on Red Hat Linux either. The GCC manual is very unhelpful, I've scoured it for hours. And then I get error messages from GCC saying that YYSTYPE is nowhere to be found and all sorts of weird and wondrful error messages, like "request for member {whatever}val in yylval is of non-aggregate type int". This is very confusing. I have never had these error messages before. Hope you can help. (By the way, please give a command line for gcc that may work, this is the command line I have been using: gcc -o myprog myprog.tab.c lex.yy.c -lbison.simple -lfl). Thankee, James

reply via email to

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