X
Xose Lois Castro
Hi, mates:
I'm trying to write a grammar to read files with the following structure,
for example:
text
...
more text
'text' => 'another text',
...
'more text' => 'some more text',
text
...
Text can contain any kind of characters and symbols: a-z, 0-9, ?, *, ], (, {...
When applying this file to the parser, I only want things in the right
side of the "=>" to be in the output.
I paste here some parts of my grammar:
lex)
[\n] { return 0; }
' { return SYMBOL; }
=> { return ARROW; }
, { return COMMA; }
" "+ { return SPACE; }
.+ { yylval = strdup(yytext); return TEXT; }
yacc)
line: SYMBOL TEXT SYMBOL SPACE ARROW SPACE SYMBOL TEXT SYMBOL COMMA
{ printf("%s\n", $8); }
;
With YYSTYPE defined as "char *"
My code compiles perfectly but when I run it I get a lot of syntax errors,
and nothing is in the output.
I'd be very pleased if somebody gives my some advice in how to build a
correct grammar for my purpose.
Best regards
I'm trying to write a grammar to read files with the following structure,
for example:
text
...
more text
'text' => 'another text',
...
'more text' => 'some more text',
text
...
Text can contain any kind of characters and symbols: a-z, 0-9, ?, *, ], (, {...
When applying this file to the parser, I only want things in the right
side of the "=>" to be in the output.
I paste here some parts of my grammar:
lex)
[\n] { return 0; }
' { return SYMBOL; }
=> { return ARROW; }
, { return COMMA; }
" "+ { return SPACE; }
.+ { yylval = strdup(yytext); return TEXT; }
yacc)
line: SYMBOL TEXT SYMBOL SPACE ARROW SPACE SYMBOL TEXT SYMBOL COMMA
{ printf("%s\n", $8); }
;
With YYSTYPE defined as "char *"
My code compiles perfectly but when I run it I get a lot of syntax errors,
and nothing is in the output.
I'd be very pleased if somebody gives my some advice in how to build a
correct grammar for my purpose.
Best regards