| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2005 人关注过本帖
标题:【C++编译】几乎全是【语法错误 : 缺少“;”(在“}”的前面)】 怎么改?
只看楼主 加入收藏
my19891115
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2010-6-15
结帖率:50%
收藏
 问题点数:0 回复次数:2 
【C++编译】几乎全是【语法错误 : 缺少“;”(在“}”的前面)】 怎么改?

#include<iostream>
using namespace std;




const int maxstack=30;
int count;
int Error_code;
const int MAX_SIZE = 1000;

double a;
double b;
char op;





//表达式基本正确。进行计算(但也有可能会出现“输入错误”提示) [部分]


char ex;
int z;
int i;
int j;
int temp[10];



template<class T,int maxstack> class Stack
{
public:
    Stack();
    bool empty() const;
    bool full() const;
    int pop();                           
    int top(T &item) const;
    int push(const T &item);
private:
    int count;
    T entry[maxstack];
    T item;
};





//以下为Stack类定义


template<class T,int maxstack> void class Stack<class T,int maxstack>::Stack()                                    //constructor
{count=0;}

template<class T,int maxstack> bool class Stack<class T,int maxstack>::empty() const
{
 bool outcome=true;
 if(count>0)outcome=false;
 return outcome;
}


template<class T,int maxstack> bool class Stack<class T,int maxstack>::full() const
{
 bool outcome=false;
 if(count=maxstack-1) outcome=true;
 return outcome;
}


template<class T,int maxstack> int class Stack<class T,int maxstack>::pop()                        
{
 Error_code outcome=0;
 if(count=0)
    outcome=-1;
 else --count;
 return outcome;
}



template<class T,int maxstack> int class Stack<class T,int maxstack>::top(T &item) const            //取操作数栈顶元素item
{
 Error_code outcome=0;
 if(count=0)
    outcome=-1;
 else item=entry[count-1];
 return outcome;
}



template<class T,int maxstack> int class Stack<class T,maxstack>::push(const T &item)      //将数据item压入操作数栈
{
 Error_code outcome=0;
 if(count>=maxtrack)
    outcome=1;
 else entry[count++]=item;
 return outcome;
}











char zh;
int judge(char zh)                                          //判断函数:判断ch(数组元素)是运算符号还是运算数据
{if((zh>='0'&&zh<='9')||zh='.')
    return 1;                                                //是运算数据
 if(zh='('||zh=')'||zh='+'||zh='-'||zh='*'||zh='/'||zh='#')
    return 0;                                            //是运算符号
}



int qiumi(int a,int b);                                  //求幂函数:a的b次幂(既10的b次幂)(目的:将数组转化为十进制数后压栈)
{int a;
 int b;
 int i;
 int temp=1;
 for(int i=0;i<b;i++)
 {temp*=a;}
return temp;
}


double deci_sim(int t)                                      //求值:将数组转化为十进制数后压栈回运算数据
{int mi[10];
 int t;
 double operand=0;
 for(q=0;t=0;q++,t--)
 {
    int q;
    mi[q]=qiumi(10,q)
    operand=operand+temp[t]*mi[q];
 }
    return operand;
}




double deci_comp(int n)
{int n
 double sum;
 
 double mi[10];
 double operand_xs;                                     //小数点后面转化成十进制数
 for(p=-1;j+1=i;p--)
 {
     double temp[10];
     int p;
     mi[p]=qiumi(10,p);
     operand_xs=operand_xs+temp[j+1]*mi[p];
     j=j+1;
 }

 sum=deci_sim(n)+operand_xs;
 return sum;
}



char ch;         
char compare(fuhao.top,char ch)                                   //判断函数:判断运算符栈运算符号的优先级      
{int fuhaojudge=2;
if((fuhao.top=='+'&&ch=='+') || (fuhao.top=='+'&&ch=='-') || (fuhao.top=='-'&&ch=='+') || (fuhao.top=='-'&&ch=='-')  
|| (fuhao.top=='*'&&ch=='*') || (fuhao.top=='/'&&ch=='/') || (fuhao.top=='*'&&ch=='/') || (fuhao.top=='/'&&ch=='*')  
|| (fuhao.top=='*'&&ch=='+') || (fuhao.top=='*'&&ch=='-') || (fuhao.top=='/'&&ch=='+') || (fuhao.top=='/'&&ch=='-')  
|| (fuhao.top=='+'&&ch==')') || (fuhao.top=='+'&&ch=='#') || (fuhao.top=='-'&&ch==')') || (fuhao.top=='-'&&ch=='#')  
|| (fuhao.top=='*'&&ch==')') || (fuhao.top=='*'&&ch=='#') || (fuhao.top=='/'&&ch==')') || (fuhao.top=='/'&&ch=='#')  
|| (fuhao.top==')'&&ch=='+') || (fuhao.top==')'&&ch=='-') || (fuhao.top==')'&&ch=='*') || (fuhao.top==')'&&ch=='/')  
|| (fuhao.top==')'&&ch=='(') || (fuhao.top==')'&&ch=='#')  )
{fuhaojudge=1
return '>';}


if((fuhao.top=='+'&&ch=='*') || (fuhao.top=='+'&&ch=='/') || (fuhao.top=='+'&&ch=='(') || (fuhao.top=='-'&&ch=='*')  
|| (fuhao.top=='-'&&ch=='/') || (fuhao.top=='-'&&ch=='(') || (fuhao.top=='*'&&ch=='(') || (fuhao.top=='/'&&ch=='(')  
|| (fuhao.top=='('&&ch=='+') || (fuhao.top=='('&&ch=='-') || (fuhao.top=='('&&ch=='*') || (fuhao.top=='('&&ch=='/')  
|| (fuhao.top=='('&&ch=='(') || (fuhao.top=='#'&&ch=='+') || (fuhao.top=='#'&&ch=='-') || (fuhao.top=='#'&&ch=='*')  
|| (fuhao.top=='#'&&ch=='/') || (fuhao.top=='#'&&ch=='(') )
{fuhaojudge=-1;
return '<';}

if((fuhao.top=='('&&ch==')') || (fuhao.top=='#'&&ch=='#')  )
{fuhaojudge=0;
return '=';}
}




double execute(double a,char op,double b)                                    
{
 switch
 {case'op='+'':return (b+a);break;
  case'op='-'':return (b-a);break;
  case'op='*'':return (b*a);break;
  case'op='/'':return (b/a);break;
 }
}



















int main()
{



Stack<char,int> fuhao;        //定义运算符栈
Stack<double,int> shu;        //定义操作数栈



//函数声明
char zh;
int judge(char zh);

int qiumi(int a,int b);

double deci_sim(int t);

double deci_comp(int n);

char ch;         
char compare(fuhao.top,char ch);


double a
double b;
char op;
double execute(a,op,b);



fuhao.push('#');                 //将#压入运算符栈栈底



//输入表达式

char array[MAX_SIZE];
char arr[] = "exit";

cout<<"Please input an expression(Ending with #)"<<endl;      
cin.getline(array,MAX_SIZE,'\n');
int length=strlen(array);


//判断表达式是否输入正确。若错误,输出“输入有误”
if (array[0]=='+'||array[0]=='-'||array[0]=='*'||array[0]=='/'||array[0]==')'||array[0]=='#')
   cout<<"输入有误"<<endl;

int z;
bool judge=false;
for (z=0;z<=length;z++)
{if (((array[z]=='+'||array[z]=='-'||array[z]=='*'||array[z]=='/')&&(array[z+1]=='+'||array[z+1]=='-'||array[z+1]=='*'||array[z+1]=='/'))
   ||((array[z]=='+'||array[z]=='-'||array[z]=='*'||array[z]=='/'||array[z]=='(')&&(array[z+1]=='#'))
   ||((array[z]=='+'||array[z]=='-'||array[z]=='*'||array[z]=='/'||array[z]=='(')&&(array[z+1]==')')))
judge=true;
}

for(z=1;z<=length;z++)
if((array[z]=='#')&&(array[z+1]!=NULL))
judge=true;

if(judge)
cout<<"输入有误"<<endl;





//表达式基本正确。进行计算(但也有可能会出现“输入错误”提示)


char ex;
int z;
int i;
int j;
int temp[10];


for (z=0;z<=length;z++)
{
ex=expre[z];
if(judge(ex))                                                        //判断数组元素是运算数据
        {
         int make=1;
         for(i=0;(i<=9)&&(make=1);i++)
            {temp[i]=ex;
             ex=expre[z+1];
             if(judge(ex))
                {make=1;z--;};
             else
                {make=-1;i--;}
            }

        }
   

        double sum_m;
        if {
        {for(j=0;j<t;j++)
        {if(temp[j]=='.')                                            //判断数组temp中是否有小数点
        {{j=j-1;
             sum_m=deci_comp(j-1);                                   //有小数点,进入函数deci_comp,进行十进制转换
             }                                                  
            {double deci_sim(i);                                        //无小数点,进入函数deci_sim,进行十进制转换
              int t=i;
              sum_m=deci_sim(i);
            }
            shu.push(sum_m);}
        else{}
        }



else{
    if(judge(ex)==0)
    {char jisuan;
        jisuan=compare(fuhao.top,ex);
        switch(jisuan)
            {case'<':fuhao.push(ex);
                     break;  
             case'=':fuhao.pop();
                     break;
             case'>':double a,b;
                     char op;
                     shu.top(a);
                     shu.top(b);
                     fuhao.top(op);
                     double v;
            
                     v=execute(a,op,b);
                     shu.push(v);
                     break;
             default:cout<<"输入有误"<<endl
        }}
    else{}
   
}
}



double sum_f;

sum_f=shu.top();                                                    //若运算符栈是两个#,则直接输出操作数栈栈顶
cout<<sum_f<<endl;
return 0;
}

我看了很多说是include 顺序不对 还请高手解答
搜索更多相关主题的帖子: 语法 编译 
2010-06-19 23:25
debroa723
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:23
帖 子:862
专家分:1954
注 册:2008-10-12
收藏
得分:0 
错误太多,先把书写规范了再来,许多错误都是不规范的书写造成的不必要的笔误。
2010-06-20 14:40
小破鱼
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2010-6-20
收藏
得分:0 
我初学的没有看懂

我新手
大家多多指教
2010-06-20 16:16
快速回复:【C++编译】几乎全是【语法错误 : 缺少“;”(在“}”的前面)】 怎么改 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019033 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved