Solved

Lex & Yacc error question

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

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. 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

Suggested Solutions

Title # Comments Views Activity
Estimate porting issues. 9 120
cURL: stopping a http transaction before it's finished 3 126
Why does module make constant click noise ? 9 135
An API detour question 7 93
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…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
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.

856 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