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
--
Xose Lois 2 1737
In article <pa************ *************** *@yahoo.com>,
Xose Lois Castro <gt************ *****@yahoo.com wrote:
[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
Xose Lois Castro wrote, On 10/01/08 22:25:
Hi, mates:
As far as I am aware you are not my mate.
<snip>
I paste here some parts of my grammar:
lex)
<snip>
yacc)
<snip>
I see no C, only lex and yacc neither of which are C. I suggest you find
a group or mailing list where they are topical. It might be worth
checking out comp.compilers, but check there FAQ and at least a weeks
worth of posts before posting there. Alternatively comp.programmin g,
comp.unix.progr ammer or comp.lang.misc might be worth a try.
--
Flash Gordon This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Profetas |
last post by:
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 !='"')
warning("Undeterminated Character strig",(char
*)0);
else
|
by: Antoon Pardon |
last post by:
I have the following little piece of code:
class Cfg:pass
#config = Cfg()
def assign():
setattr(config, 'Start' , )
def foo():
config = Cfg()
|
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... "
|
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...
|
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.
| |
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 :
|
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"?
|
by: Laszlo Nagy |
last post by:
This is a fragment from my yacc file:
import ply.yacc as yacc
from lex import tokens
from ast import *
def p_msd(p):
r"""msd : SCHEMA WORD LBRACE defs RBRACE """
p = MSDSchema(p)
|
by: betterking |
last post by:
I want to write a tiny sql parser with lex and yacc. At first I just
write sql.l sql.y with simple CREATE TABLE funciton.
sql.l
%{
#include "y.tab.h" //<>
#include <stdlib.h>
#include <string.h>
void yyerror(char *);
|
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...
|
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,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |