Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 10-26-2011, 11:00 PM   #1
LQ Newbie
Registered: Oct 2011
Posts: 10

Rep: Reputation: Disabled
implementing calculator program in lex and yacc but getting syntax error

I am implementing calculator program in lex and yacc.I have created calci.y file. Also y_tab.c and lexyy.c have been created.But whenever i enter the expression(eg:2+3) it gives me "syntax error"

int intval;
float floatval;
%token <intval> D1
%token <floatval> D2
%token NAME
%type <floatval> exp
%left '+' '-'
%left '*' '/'
%start s
s: NAME'='exp {printf("\nresult: %d\n",$3);}
|exp {printf("\nresult:%d\n",$1);}
exp:exp'+'exp {$$=$1+$3;}
|exp'-'exp {$$=$1-$3;}
|exp'*'exp {$$=$1*$3;}
|exp'/'exp {$$=$1/$3;}
char ch;
printf("\nenter exression:");
printf("\ndo u want to continue:");
void yyerror(char *ch)
printf("%s: error\n",ch);
Old 10-27-2011, 10:27 AM   #2
Senior Member
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: CentOS 6 & 7
Posts: 3,209

Rep: Reputation: 871Reputation: 871Reputation: 871Reputation: 871Reputation: 871Reputation: 871Reputation: 871
Need two things:
1) edit your post and add code tags
2) Show that you have done at least minimal debugging: check and print results of all calls


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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
lex and yacc aarsh Linux - Software 3 01-03-2011 08:58 AM
[SOLVED] YACC syntax error MTK358 Programming 5 02-05-2010 04:54 PM
LEX and YACC with C gr33ndata Programming 4 11-18-2007 05:12 PM
Implementing yacc/lex Millenniumman Programming 2 10-07-2006 10:49 AM
Error in Makefile for Lex and Yacc oulevon Programming 2 10-24-2005 12:52 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:47 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