双手 *** 作分析,是指以 *** 作人员双手为研究对象,发现笨拙、无效动作,改善工具、物料、设备的布局,以达到平衡左右手的负荷、减轻疲劳、提高作业效率的一种方法。双手 *** 作分析工具是双手 *** 作分析图,它是通过程序分析的符号记录工作人员双手的动作及其相互关系。[1]
手 *** 作分析时常采用“双手 *** 作程序图”。双手 *** 作程序图以双手为对象,记录其动作,表示其关系,并可指导 *** 作者如何有效地动用双手,对从事生产性的工作,提供一种新的动作观念,找出一种新的改善途径。
#include <iostream>
#include <ctypeh>
#include <fstream>
#include <stringh>
#include <malloch>
using namespace std;
ifstream fp("sourcetxt",ios::in);
char cbuffer;
char key[13]={"if","else","for","while","do","return","break","continue","int","void"
,"main","const","printf"}; //关键字
char border[7]={ "," , ";" , "{" , "}" , "(" , ")" ,"//"}; //分界符
char arithmetic[6]={"+" , "-" , "" , "/" , "++" , "--"}; //运算符
char relation[7]={"<" , "<=" , "=" , ">" , ">=" , "==" ,"!="}; //关系运算符
char lableconst[80]; //标识符
int constnum=40;
int lableconstnum=0;
int linenum=1; //统计常数和标识符数量
int search(char searchchar[],int wordtype)
{
int i=0,t=0;
switch (wordtype)
{
case 1:
{ for (i=0;i<=12;i++) //关键字
{
if (strcmp(key[i],searchchar)==0)
return(i+1);
}
return(0);}
case 2:
{
for (i=0;i<=6;i++) //分界符
{
if (strcmp(border[i],searchchar)==0)
return(i+1);
}
return(0);
}
case 3:
{
for (i=0;i<=5;i++) //运算符
{
if (strcmp(arithmetic[i],searchchar)==0)
return(i+1);
}
return(0);
}
case 4:
{
for (i=0;i<=6;i++) //关系运算符
{
if (strcmp(relation[i],searchchar)==0)
return(i+1);
}
return(0);
}
case 5:
{
for (t=40;t<=constnum;t++) //常数
{
if (strcmp(searchchar,lableconst[t])==0)//判断该常数是否已出现过
return(t+1);
}
lableconst[t-1]=(char )malloc(sizeof(searchchar));//为新的元素分配内存空间
strcpy(lableconst[t-1],searchchar);//为数组赋值lableconst指针数组名
constnum++; //常数个数自加
return(t);
}
case 6:
{
for (i=0;i<=lableconstnum;i++)
{
if (strcmp(searchchar,lableconst[i])==0) //判断标识符是否已出现过
return(i+1);
}
lableconst[i-1]=(char )malloc(sizeof(searchchar));
strcpy(lableconst[i-1],searchchar);
lableconstnum++; //标识符个数自加
return(i);
}
default:cout<<"错误!";
}
}
char alphaprocess(char buffer) //字符处理过程
{
int atype;
int i=-1;
char alphatp[20];
while ((isalpha(buffer))||(isdigit(buffer)))
//这两个函数分别是判字符和判数字函数位于ctypeh中
{
alphatp[++i]=buffer;
fpget(buffer);
}
alphatp[i+1]='\0';//在末尾添加字符串结束标志
if (atype=search(alphatp,1))
cout<<"linenum: "<<linenum<<" String= "<<alphatp<<"\t\t\t"<<"关键字"<<endl;
else
{
atype=search(alphatp,6); //标识符
cout<<"linenum: "<<linenum<<" String= "<<alphatp<<"\t\t\t"<<"标识符"<<endl;
}
return(buffer);
}
char digitprocess(char buffer) //数字处理过程
{
int i=-1;
char digittp[20];
int dtype;
while ((isdigit(buffer)))
{
digittp[++i]=buffer;
fpget(buffer);
}
digittp[i+1]='\0';
dtype=search(digittp,5);
cout<<"linenum: "<<linenum<<" String= "<<digittp<<"\t\t\t"<<"数据"<<endl;
return(buffer);
}
char otherprocess(char buffer) //分界符、运算符、逻辑运算符、等
{
int i=-1;
char othertp[20];
int otype,otypetp;
othertp[0]=buffer;
othertp[1]='\0';
if (otype=search(othertp,3))
{
fpget(buffer);
othertp[1]=buffer;
othertp[2]='\0';
if (otypetp=search(othertp,3)) //判断该运算符是否是
//由连续的两个字符组成的
{
cout<<"linenum: "<<linenum<<" String= "<<othertp<<"\t\t\t"<<"运算符"<<endl;
fpget(buffer);
goto out;
}
else //单字符逻辑运算符
{
othertp[1]='\0';
cout<<"linenum: "<<linenum<<" String= "<<othertp<<"\t\t\t"<<"逻辑运算符"<<endl;
goto out;
}
}
if (otype=search(othertp,4)) //关系运算符
{
fpget(buffer);
othertp[1]=buffer;
othertp[2]='\0';
if (otypetp=search(othertp,4)) //判断该关系运算符是否是
//由连续的两个字符组成的
{
cout<<"linenum: "<<linenum<<" String= "<<othertp<<"\t\t\t"<<"关系运算符"<<endl;
fpget(buffer);
goto out;
}
else //单字符逻辑运算符
{
othertp[1]='\0';
cout<<"linenum: "<<linenum<<" String= "<<othertp<<"\t\t\t"<<"逻辑运算"<<endl;
goto out;
}
}
if (buffer=='!') //"=="的判断
{
fpget(buffer);
if (buffer=='=')
//cout<<"!= (2,2)\n";
fpget(buffer);
goto out;
}
else
{
if (otype=search(othertp,2)) //分界符
{
cout<<"linenum: "<<linenum<<" String= "<<othertp<<"\t\t\t"<<"分界符"<<endl;
fpget(buffer);
goto out;
}
}
if ((buffer!='\n')&&(buffer!=' '))
cout<<"错误!,字符非法"<<"\t\t\t"<<buffer<<endl;
fpget(buffer);
out: return(buffer);
}
void main()
{
int i;
for (i=0;i<=50;i++)
{
lableconst[i]=" ";//用于保存标识符
}
if (!fp)
cout<<"文件打开错误!!"<<endl;
else
{
fpget (cbuffer);
while (!fpeof())
{
if(cbuffer=='\n')
{
linenum++;
fpget(cbuffer);
}
else if (isalpha(cbuffer))
{
cbuffer=alphaprocess(cbuffer);
}
else if (isdigit(cbuffer))
{
cbuffer=digitprocess(cbuffer);
}
else
cbuffer=otherprocess(cbuffer);
}
}
cout<<"标识符个数是:"<<lableconstnum<<"分别是"<<endl;
i=0;
while(i<lableconstnum)
{
cout<<lableconst[i++]<<" ";
}
cout<<endl;
cout<<"完成\n";
getchar();
}
以上就是关于两手 *** 作是什么意思全部的内容,包括:两手 *** 作是什么意思、编译原理词法分析程序、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)