help-bison
[Top][All Lists]
Advanced

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

Newbie question - yyval problems


From: Boris Köster
Subject: Newbie question - yyval problems
Date: Sun, 19 May 2002 20:21:34 +0200

Hello,

I have a problem with bison, and I don´t know what I am doing
wrong.

The errors are: "flex scanner jammed" on exit and I have no values in
"yyval", only "NULL".

Using FreeBSD 4.5 stable, 2 bottles of milk and a lot of fish´n chips
since 2 days now.


------------- lexer.l ---------------

%{
#include <stdio.h>
#include "bison.tab.h"
extern YYSTYPE yylval;

%}
%s paramscan assopscan valuescan eolscan
PARAMETER       [a-zA-Z0-9]*

%option noyywrap
%option nodefault

%%

<INITIAL,paramscan>Tante|Geschlecht|Sexy  {
                        yyval=strdup(yytext);
                        printf("P: %s\n",yyval);
                        BEGIN(assopscan);
                        printf("X\n");
                        return KEYWORD;
                       }

<assopscan>"="                  {
                        yyval=strdup("=");
                        BEGIN(valuescan);
                        return ASSOP;
                        }

<eolscan,valuescan>\"   {yyval=strdup("\"");
                        return ANF; }


<valuescan>{PARAMETER}          {
                        {
                        yyval=strdup(yytext);
                        BEGIN(eolscan);
                        return PARAM;
                        }


                        }
<eolscan>"\n"|";\n"             {
                        BEGIN(INITIAL);
                        return EOL;
                        }

[ \t]+                  {} /* Leerzeichen / Tabs ignorieren */

.                       return (int) yytext[0];

%%

--------------------------------------------------------------


---------------- bison.y -------------------------------------

%{
        #include <stdio.h>

%}
%token KEYWORD ASSOP ANF PARAM EOL UNKNOWN
%%

start:
        start ausdruck
        |
        ;

ausdruck:
        KEYWORD ASSOP ANF PARAM ANF EOL
        {
        printf("Variable: %s Inhalt: %s\n",$1,$4);
        }
        |

;

%%
YYSTYPE yyval;
int yyerror (char *msg) { printf("Fehler: %s",msg);return 0; }


#include "lex.yy.c"

     main( argc, argv )
                {
extern int yydebug;
yydebug=1;
                        yyparse();
                }

----------------------------------------------------------------

----------- a silly but working makefile ---------------------------

xyz:    main
        make clean
        make main

main:   main.o

main.o:
        make clean
        flex lexer.l
        bison --defines --verbose -t -d bison.y
        cp bison.tab.c main.c
        cc -c main.c
        cc -o main main.o
        ./main < test.cfg

clean:
        -rm main
        -rm *.o
        -rm *.tab*
        -rm lex.yy.c
        -rm main.c
        -rm bison.output

----------------------------------------------------------

--------- the configuration file to read from stdin ---------

Tante="Uschi";
Geschlecht="weiblich";
Sexy="Nein";

-------------------------------------------------------------

Problem description: yyval is not working and I have no results in
bison. After parsing I get a "jammed" lexer.


-- 
Best regards,
 Boris Köster                         mailto:address@hidden
 X-ITEC IT-Consulting
 http://www.x-itec.net




reply via email to

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