⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 1.txt

📁 这是我用VC写 的一个小程序希望对大家有用
💻 TXT
字号:
//code.txt为内码对照表
//get.txt为Pascal程序设计语言
//put.txt为词法分析后输出。格式为(内码 行 列)
#include<iostream.h>
#include<fstream.h>
#include<string.h>
#include<stdlib.h>

struct code{//存放内码对照表
char word[10];
};
void getch(int & x,int & y,char z)
{
   if(z=='\n')
   {y=0;x++;}
   else y++;
}

void main()
{int i,n,m,val;
int row=1;//行
int column=1;//列
int x;//存放单词的行
int y;//存放单词的列
char str[3];//存放双字符
struct code count[36];
ifstream inn;
ifstream in;
ofstream out;
inn.open("code.txt");//内部码输入
for(n=1;n<36;n++)
inn>>count[n].word;
inn.close();

in.open("get.txt");//打开输入文件
out.open("put.txt");//打开输出存储文件

char putword[20];//存放输出字母和标识符
char inword;
in.get(inword);

//out<<inword;
while(inword!=EOF)
{m=0;
    if((inword!='\n')&&(inword!=' '))// 判断是否空格类字符
	{   
		if((inword>='A')&&(inword<='Z')||(inword>='a')&&(inword<='z'))
		{x=row;y=column;
			while((m<20)&&(((inword>='A')&&(inword<='Z')||(inword>='a')&&(inword<='z')||(inword>='0')&&(inword<='9'))))
			{
			 putword[m]=inword;
		   m++;
		   in.get(inword);
          getch(row,column,inword);
			}//while
			putword[m]='\0';
		   for(int i=1;i<16;i++)
		   {
          	  	if(!strcmp(count[i].word,putword))
                {out<<count[i].word<<" "<<i<<" "<<x<<" "<<y<<endl;//输出内码和行列信息
				 break;//找到则跳出
				}
				if(i==15)
					out<<putword<<" "<<x<<" "<<y<<endl;//输出保留字
		   }//for
		   
		}//if



		else if((inword>='0')&&(inword<='9'))//输入为数字
		{val=0;x=row;y=column;
		  while((inword>='0')&&(inword<='9'))
		  {
		     val=val*10+inword-'0';
		      in.get(inword);
			  getch(row,column,inword);
		  }
          out<<val<<" "<<x<<" "<<y<<endl;
		}
           else
		   {
		      if((inword=='<')||(inword=='>')||(inword==':'))
			  {  str[0]=inword;
		         in.get(inword);
				 if(inword=='=')//为双字符
				 {   str[1]=inword;
				     str[2]='\0';
					 for(i=23;i<=30;i++)
					 {
					    if(!strcmp(count[i].word,str))
							out<<count[i].word<<" "<<i<<" "<<row<<" "<<column<<endl;
					 }
				 getch(row,column,inword);
				 }
                 else//单字符
                 {str[1]='\0';
				   for(i=22;i<=29;i++)
					 {
					    if(!strcmp(count[i].word,str))
							out<<count[i].word<<" "<<i<<" "<<row<<" "<<column<<endl;
					 }
				 }//else
			  } 
			  else//单字符
			  {str[0]=inword;
			   str[1]='\0';
			    for(i=1;i<=35;i++)
					 {
					    if(!strcmp(count[i].word,str))
							out<<count[i].word<<" "<<i<<" "<<row<<" "<<column<<endl;
					 }
			  }
		   in.get(inword);//完成一个取单词后继续读入字符
	       getch(row,column,inword);
		   }
	
	}
	else {
    
	in.get(inword);//非空格类字符时继续读取下一个字符
	getch(row,column,inword);
	}
	          
}
in.close();//关闭文件
out.close();


}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -