Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 04-06-2010, 06:12 AM   #1
LQ Newbie
Registered: Apr 2010
Posts: 1

Rep: Reputation: 0
flex and bison

i have written two files which are given below.
extern int yylval;

[0-9]+ {yylval=atoi(yytext); return NUMBER;}
[ /t] ;
\n return 0;
. return yytext[0];




#include <stdio.h>


%left '+' '−'

%left '∗'

%token NUMBER


input :

| input expr '\n' { printf(”result=%d\n”,$2); }


expr : NUMBER

| expr '+' expr { $$ = $1 + $3;}

| expr '−' expr { $$ = $1 − $3;}

| expr '∗' expr { $$ = $1 ∗ $3;}



int main(){yyparse();}

this is what i am doing at terminal and errors are generated

root@sandy:/home/sandy/lexyacc# bison -d -y ex1.y
root@sandy:/home/sandy/lexyacc# flex ex2.l
root@sandy:/home/sandy/lexyacc# gcc -o calc lex.yy.c -lm -lfl
ex2.l:2:10: error: #include expects "FILENAME" or <FILENAME>
ex2.l: In function ‘yylex’:
ex2.l:5: error: ‘yylval’ undeclared (first use in this function)
ex2.l:5: error: (Each undeclared identifier is reported only once
ex2.l:5: error: for each function it appears in.)
ex2.l:5: error: ‘NUMBER’ undeclared (first use in this function)

So please help me out in solving these errors
Old 04-06-2010, 06:38 AM   #2
Registered: Jan 2010
Location: Lancashire
Distribution: Slackware Stable
Posts: 547

Rep: Reputation: 115Reputation: 115
First thing - running as root!?!?!?!?!

Second - do you need the -y flag passed to bison? Also there is no need for linking to the flex lib in your compilation as you have defined your own main() function.

This article may help you:


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Do flex and bison support C++? ankit4u1 Programming 7 08-08-2011 04:56 PM
installing bison and flex rameshsena Linux - Software 10 06-21-2010 11:33 AM
flex/bison -> parse error but why? vargadanis Programming 3 08-03-2008 07:44 PM
bison / flex zaman Programming 1 08-16-2005 10:19 AM
bison, flex and make problem ChimpFace9000 Programming 4 05-19-2002 07:49 PM

All times are GMT -5. The time now is 12:06 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration