473,910 Members | 4,173 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.strin g[yyleng-2] !='"')
warning("Undete rminated 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 6343

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
4911
by: Rodrick Brown | last post by:
This might be off topic but can someone give me a quick run down on why tools like lexx/yacc/bison are usefull ? I know what there used for but not sure when they should be used and where ? Thanks. -- Rodrick R. Brown
6
15500
by: Volker Hetzer | last post by:
Hi! We are finding ourselves in a situation where we have to parse several more or less free format text files. In the past, on linux, we had flex and bison for generating very fast parsers for these files. Is there any equivalent in the visual studio world? Lots of Greetings! Volker --
1
4290
by: deepusrp | last post by:
Helo everyone, i am doing a project on some graphic tool using qt as the front end. i am using lex and yacc as parser. now i am facing a problem since yacc generates only c code as i want to bring c++ features. so my request is " is there any way that we can create parser in qt itself or is there any method by which i can make a c++ (yacc) Parser... "
13
5039
by: Berk Birand | last post by:
Hi, I am working on a school project where we use lex/yacc to write a compiler for a fictional (Java-like) language. I have handled all the details about the yacc and lex files, but I still have a question regarding the dynamic memory allocation for strings. When the lex file encounters a variable name, I want it to pass this to yacc through yylval, and then retrieve it to add to a syntax tree. For this purpose, I wrote the following...
2
7535
by: max.giacometti | last post by:
Hi everybody! I am using lex and yacc to write a vhdl to systemc converter. Lex simply reads the input file and yacc implements grammar and translation. I'd like to be able to make yacc able to command lex to stop reading the current file and starting reading another file, when the inclusion syntax is reached.
2
1961
by: Mohitz | last post by:
Hi Guys, I am facing a peculiar problem with my yacc script. Following is the snippet of the yacc script that i am using. I am using lex as the lexical analyzer. Sample Input :
1
1920
by: neena.usenet | last post by:
I have a gui that reads in a file using C++/yacc. If the file has a parsing error, yacc throws the error to my program and I report it. The problem is at that point, I would like to try to open a different file, one that has no syntax errors. When I try to open this second file, yacc throws me another error which I believe is leftover from parsing the first file. How do I clear the yacc "error stack"?
5
2188
by: thomas | last post by:
hello I m writing a simple parser using bison. I just used someone's else c++ grammar, to produce a code beutifier. The thing is , most of the actions for productions would have form {$$ = $1 + $2 + $3} and so forth depending on number of terminals in production. Is it possible to set default action for all the productions like the one above ? It is something strange to type this formula for over 200 productions.
1
2036
by: Robert | last post by:
If the goal is to take a 1-dimensional package of text and produce a tree data structure that is easy to understand and manipulate, and then write C/C++ code that works with that tree - does lex/yacc suit that purpose - i.e. kind of like a tree-manufacturing C library? Or is it for producing a compiler/interpreter the internals of which a new C/ C++ program cannot so easily work with?
0
10037
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9879
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10541
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9727
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8099
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7250
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5939
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6142
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3360
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.