Solved

Lex & Yacc error question

Posted on 2004-04-03
3
1,136 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 25 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 25 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

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

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…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

914 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now