Solved

Lex & Yacc error question

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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…
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.

746 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

13 Experts available now in Live!

Get 1:1 Help Now