Lex / Yacc problem

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
 
D

dj3vande

[Subject line: "Lex/Yacc problem"]
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.

Code generators like lex and yacc are not defined by the C language and
are therefore beyond the scope of comp.lang.c.

comp.compilers might be a better place to ask.


dave

--
Dave Vandervies dj3vande at eskimo dot com
Yes, P.J. Plauger is more or less a regular.
Less, I think. More of a sporadic than a regular.
--Keith Thompson and Richard Heathfield in comp.lang.c
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top