LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
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.

Notices

Reply
 
LinkBack Search this Thread
Old 04-06-2010, 06:12 AM   #1
saurav.nith
LQ Newbie
 
Registered: Apr 2010
Posts: 1

Rep: Reputation: 0
flex and bison


i have written two files which are given below.
ex1.l
%{
#include"y.tab.h"
#include<stdio.h>
%}
extern int yylval;
%%

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

________________________________________________________________________

ex2.y


%{

#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 y.tab.c 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
devnull10
Member
 
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: http://ds9a.nl/lex-yacc/cvs/lex-yacc-howto.html
 
  


Reply


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
Trackbacks are Off
Pingbacks are On
Refbacks are 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 10:28 AM.

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