0
votes

did anybody worked on flex and bison??

i have an example of them.i run it but it shows without bison,

for example: in flex in .l file i defined id and put printf{"id"} for it.

and in bison i defined something like this:

  id_list       :   ID          {printf("id-list::=id\n");}
    |   id_list   ','   ID      {printf("id-list::=<id-list>,id\n");}

but when i run main.exe when i entered id it just show id(shouldnt it print id-list::=id????) i know i didnt explain well,if im missing something please say me or say me to put codes.

1
I retagged this from Adobe Flex to gnu-flex; as I do not believe this question relates to Adobe Flex Development.JeffryHouser
adobe flex was not correct,thanksArash

1 Answers

1
votes

Theres a few things that could be wrong. First which is wrong is the printf. Printf is missing %s so it will only print your text. Heres how i'd do it

id_list:
                  ID        { $$ = id_list( 0, $1); }
    | id_list ',' ID        { $$ = id_list($1, $2); }

in your C file

IdList* id_list(IdList*p, ID*pp) {
    //pp == yylval in this case a c-string from strdup
    printf("id_list: %X %s", p, pp); //i rather set a breakpoint instead
    if(p==0) p=new IdList;
    p->deque.push_back(pp);
    return p;
}

in the lex file

//makes a copy bc yytext will be reused for other things
....        { yylval=strdup(yytext); return ID; }