[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Lex & Yacc error question

Posted on 2004-04-03
3
Medium Priority
?
1,148 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
Suggested Courses

656 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