[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Lex & Yacc error question

Posted on 2004-04-03
3
Medium Priority
?
1,150 Views
Last Modified: 2011-09-20
Hi, I'm currently using yacc..  But i've come across an error message that I can't seem to fix, and was wondering if any of you guys can help me on this...  Well, i have a ambiguious grammer, and to fix the shift reduce i do the following:

exp : exp '+' exp {$$ = $1 + $3}
      | exp '*' exp {$$ = $1 + $3}
...

and so on..  But i get this error:
$$ of 'exp' has no declared type
$1 of 'exp' has no declared type
$3 of 'exp' has no declared type

Am i doing something wrong?  I don't understand what they mean by the declared type.  Thanks guys~
0
Comment
Question by:iamnamja
3 Comments
 
LVL 5

Accepted Solution

by:
jerry_jeremiah earned 100 total points
ID: 10750606

yacc internally uses YYSTYPE for the stack items.
But it won't compile unless you have told the compiler
what kind of type YYSTYPE actually is.  Maybe do this:

#define YYSTYPE int

Take a look at this for more info:

http://ds9a.nl/lex-yacc/cvs/lex-yacc-howto.html
0
 
LVL 11

Assisted Solution

by:avizit
avizit earned 100 total points
ID: 10755297
or you have to define what type exp belongs too

if you think its an integer , adding the following lines should( hopefully :P) solve the prob


%{


%}

%union{
   int yyint;
}


%token <yyint> exp

%%
...... your grammar here

%%




-- abhijit
0
 

Author Comment

by:iamnamja
ID: 10755477
thanks guys~ I was finally able to figure it out...  Since both of you guys helped, i'll split the points~  Thanks again!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question