yacc

P

Profetas

Hi.
I was wondering how can I access the yacc functions?
because when use a normal yacc function such as

qstring {
yylval.string = strdup(yytext+1);
if(yylval.string[yyleng-2] !='"')
warning("Undeterminated Character strig",(char
*)0);
else
yylval.string[yyleng-2]='\0';
return qstring;}

I won't be able to compile it gives me
example.l: In function `yylex':
example.l:14: `yylval' undeclared (first use in this function)
example.l:14: (Each undeclared identifier is reported only once
example.l:14: for each function it appears in.)

as if the yacc library weren't been used.

How do I include then?

Thanks Profetas
 
M

Malcolm

Profetas said:
I was wondering how can I access the yacc functions?
because when use a normal yacc function such as

example.l: In function `yylex':
example.l:14: `yylval' undeclared (first use in this function)
Yacc takes a parser specification and spits out compileable C source. yylval
is if I remember rightly a global variable inserted into the source, whilst
yylex() is the name of the function it generates for the lexical analyser.

You can add fragments of C to the yacc file and they will be incorporated
into the output. Somehow you must have got yacc into a state where yylval
isn't visble to yylex(). Remember to the C compiler this is just source.

How you've done this I couldn't say. You don't want to edit the yacc C
output. You need to look at your specification file to see what has gone
wrong, maybe making a toy parser that accesses in yylval in yylex() to see
if the same problem crops up.
 
P

Profetas

How you've done this I couldn't say. You don't want to edit the yacc C
output. You need to look at your specification file to see what has gone
wrong, maybe making a toy parser that accesses in yylval in yylex() to see
if the same problem crops up.

I am using a example given in a book, I think the problem is when I
compile the flexer using flex or lex it won't find its own library in the
book example they don't use any pre-process or something like that.
I guessed that the flex/lex would automatically identify its own library
but it may be my system that has wrong path thing like that.
 
C

Cesar A. K. Grossmann

Profetas said:
I guessed that the flex/lex would automatically identify its own library
but it may be my system that has wrong path thing like that.

IIRC, you need to link with the correct lib, libl for lex, and libfl for
flex:

cc file.c -o output -lfl

A good RTFM (man flex) helps.

[]s
 
P

Profetas

IIRC, you need to link with the correct lib, libl for lex, and libfl for
flex:
cc file.c -o output -lfl
A good RTFM (man flex) helps.

NO I found the problem, you probably don't know lex well
as yylval is a local union which I hadn't deffined.
 

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

Members online

Forum statistics

Threads
473,982
Messages
2,570,189
Members
46,734
Latest member
manin

Latest Threads

Top