Hello,
My name is Tejas. I am trying to use Flex and Bison to parse (and convert)
one file to another format. Currently, I am not bothered about conversion,
just the parsing.
I have never used either tools, and what my problem is, may be trivial.
(Worth laughing)
Here is my problem:
I am going to attach my .l and .y files and .txt file which is my input.
Here I will just include the tokenIZING part of .l and grammar of .y.
This is part of my flex which returns tokens to yyparse:-
"graph" { return GRAPH; }
"{" { return '{'; }
"}" { return '}'; }
"init" { yylval= yytext;
return INIT; }
{id} { yylval = yytext;
return ID; }
where id = [a-zA-Z_][a-zA-z_0-9]*
This is my bison grammar:-
%%
input: /* empty */
| GRAPH '{' graphitemset '}' { printf("GRAPH
FOUND"); }
| error
graphitemset: responsivestate { printf("RESPONSIVE
STATE"); }
responsivestate: INIT statename '{' '}' { printf("INIT %s",$2);
}
statename: /* empty */
| ID
%%
After running it,
C:\>gnu\bin\flex -olex.yy.c -i s.l
C:\>gnu\bin\bison -d s.y
C:\>gcc -ose s.tab.c lex.yy.c -ly -lfl
C:\>se < s.txt
Now if my s.txt = *graph{init{}}*
then I get output *INIT (null)RESPONSIVE STATEGRAPH FOUND.*
However, if I change s.txt to *graph{initnabc{}}*
then I get *se: syntax error line 0*
i.e., it only recognizes state names which are empty, otherwise, there is
some problem with ID.
I want it to recognoze graph, init as well as the state name.
I think ID definition conflicts with "graph", or "init".
It also generates a warning: No new line at end of file for .l file.
Please help me with this problem.
__________________________________________________________________________
Also, simlar kind of problem, but with very simple files:
"graph" { return GRAPH; }
{id} { yylval = yytext;
return ID; }
for tokens
input: GRAPH { printf("GRAPH FOUND"); }
| GRAPH ID { printf("GRAPH + ID"); }
the grammar
with input graph, its executes to* GRAPH FOUND;*
with input graphgraph, it gives syntax error; and not GRAPH FOUND twice.,
nor GRAPH + ID for something like graphbhg.
Do we have to run the tokenizing routing in some loop like while not EOF,
etc.?
I have no idea what to do to get the desired output.
This may sound very funny, but as I said, I have no experience with these
two tools.
I will really appreciate your help.
The actual input will be quite large, I am just experimenting with
graph{init{}}, and having problems with that
Also, sorry for the long email.
thanking you in advance,
tejasSK
graph{init{}}
s.y
Description: Binary data
s.l
Description: Binary data
ex.l
Description: Binary data
ex.y
Description: Binary data
_______________________________________________ [email protected] http://lists.gnu.org/mailman/listinfo/help-bison
