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 :
create template {
with attributes :
attr1 ;
attr2 ;
attr3 ;
}
tpl_name
Output that i get should be ideally
Attribute name is attr1
Attribute name is attr2
Attribute name is attr3
But what i get is
Attribute name is attr1 ;
Attribute name is attr2 ;
Attribute name is attr3 ;
The semicolon appears at the end. Does someone know why this
happens? Would be glad to furnish more information if needed.
The lex seems to be passing the correct token.
Thanks in advance
Mohit
----------------------------------------------------------------------------------------------------------------------
The Yacc Script Snippet
----------------------------------------------------------------------------------------------------------------------
start : CREATE TEMPLATE '{' create_template _body '}'
IDENTIFIER
{
parsedTemplate =
appendTemplateN ame(strdup($6), $4);
}
;
create_template _body : define_attribut es
{
$$ = createTemplate( $1);
}
;
define_attribut es : WITH ATTRIBUTES ':' attribute_list
{
$$ = $4;
}
;
attribute_list : attribute_list attribute
{
$$ = appendAttribute ($1,$2);
// Append attribute to Attribute List
}
| attribute
{
$$ = createAttribute List($1);
}
;
attribute : IDENTIFIER ';'
{
printf("Attribu te Name is %s\n",
strdup($1));
$$ = createAttribute (strdup($1));
}
---------------------------------------------------------------------------------------------------------------------
The Lex Script Snippet
---------------------------------------------------------------------------------------------------------------------
PS: There are some other tokens here which might not make sense
because i pasted only the relevant parts of the yacc file.
digit [0-9]
letter [a-zA-Z_.]
word {letter}({lette r}|{digit})*
ws [ \n\t]
string \"[^"\n]*["\n]
number {digit}+
%%
"," { showToken(",",y ytext); return ','; }
":" { showToken(":",y ytext); return ':'; }
"{" { showToken("{",y ytext); return '{'; }
"}" { showToken("}",y ytext); return '}'; }
";" { showToken(";",y ytext); return ';'; }
{string} { yylval.str = strdup(yytext+1 );
if (yylval.str[yyleng-2] != '"')
reportError("im properly terminated string");
else {
yylval.str[yyleng-2] = 0;
showToken("STRI NG", yytext);
return STRING;
}
}
{word} {
if (isIdentifier(y ytext) == IDENTIFIER)
{
yylval.str = yytext;
showToken("IDEN TIFIER",yytext) ;
return isIdentifier(yy text);
}
else
{
yylval.str = yytext;
showToken("RESE RVED", yytext);
return isIdentifier(yy text);
}
}
{number} {
yylval.num = atoi(yytext);
showToken("NUMB ER",yytext);
return NUMBER;
}
{ws} ; /* ignore */
{comment} ; /* ignore */
.. {
printf("bad char: '%c'\n", yytext[0]);
showToken("**** **************" ,yytext);
}
%% 2 1953
Mohitz <co********@gma il.comwrites:
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 :
create template {
with attributes :
attr1 ;
attr2 ;
attr3 ;
}
tpl_name
Output that i get should be ideally
Attribute name is attr1
Attribute name is attr2
Attribute name is attr3
But what i get is
Attribute name is attr1 ;
Attribute name is attr2 ;
Attribute name is attr3 ;
The semicolon appears at the end. Does someone know why this
happens? Would be glad to furnish more information if needed.
The lex seems to be passing the correct token.
[snip]
This isn't a question about C. You might try comp.compilers.
--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
ok thanks i will..
On Jun 4, 11:47 am, Keith Thompson <k...@mib.orgwr ote:
Mohitz <coolmoh...@gma il.comwrites:
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 :
create template {
with attributes :
attr1 ;
attr2 ;
attr3 ;
}
tpl_name
Output that i get should be ideally
Attribute name is attr1
Attribute name is attr2
Attribute name is attr3
But what i get is
Attribute name is attr1 ;
Attribute name is attr2 ;
Attribute name is attr3 ;
The semicolon appears at the end. Does someone know why this
happens? Would be glad to furnish more information if needed.
The lex seems to be passing the correct token.
[snip]
This isn't a question about C. You might try comp.compilers.
--
Keith Thompson (The_Other_Keit h) k...@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"- Hide quoted text -
- Show quoted text -
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: Gvs |
last post by:
Hi,
i'm trying to implement a few things in lex and yacc though i'm having
trouble.
What i want to do is be able to parse a term and an expression.
in EBNF my term is defined as: term ::= factor { '*' | '\' } .
factor is defined as: factor ::= ident | '(' expression ')' | number .
expression is defined as: expression ::= '+' | '-' term { '+' '-' term } .
|
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
|
by: John Sasso |
last post by:
In my Yacc .y file I defined:
%union {
int value;
struct Symbol Sym;
}
The Symbol struct I defined in a header file I #included in the Prologue
section of the .y file as:
|
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
--
| |
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: 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?
|
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: 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: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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: 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();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |