471,067 Members | 1,539 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,067 software developers and data experts.

yacc

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

Nov 14 '05 #1
4 6063

"Profetas" <xu*****@yahoo.com> wrote in message

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.
Nov 14 '05 #2
>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 seeif 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.

Nov 14 '05 #3
Profetas wrote:

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
--
..O. Cesar A. K. Grossmann ICQ UIN: 35659423
...O http://www.LinuxByGrossmann.cjb.net/
OOO Quidquid Latine dictum sit, altum viditur
Nov 14 '05 #4
>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.
Nov 14 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Rodrick Brown | last post: by
6 posts views Thread by Volker Hetzer | last post: by
13 posts views Thread by Berk Birand | last post: by
2 posts views Thread by max.giacometti | last post: by
2 posts views Thread by Mohitz | last post: by
1 post views Thread by neena.usenet | last post: by
5 posts views Thread by thomas | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.