当前位置:网站首页>Compilation Principle -- C language implementation of prediction table
Compilation Principle -- C language implementation of prediction table
2022-07-06 18:06:00 【The way of growth of Peng】



#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
/* Guangxi Normal University School of computer science and engineering GuangXi Normal University College of Computer Science and Engineering Student STZ */
string map[6][7]={
{
"", "i", "+", "*", "(",")","#"},
{
"E", "TD", "", "", "TD", "", ""},
{
"D", "","+TD", "", "","e","e"},
{
"T", "FS", "", "", "FS", "", ""},
{
"S", "", "e","*FS", "","e","e"},
{
"F", "i", "", "","(E)", "", ""},
};
char input[] = "i+i*i#";
char start[] = "#E";
void match(int l,int c){
// int len = map[l][c].length();// The length of the replacement string
int i = 0;
int isfirst = 0;
cout<<start[strlen(start)-1]<<"->"<<map[l][c]<<endl;
for(string::reverse_iterator iter=map[l][c].rbegin();iter!=map[l][c].rend();iter++){
// Reverse iteration
if(isfirst==0){
start[strlen(start)-1] = *iter;
isfirst=1;
}else{
start[strlen(start)] = *iter;
}
for(int j=0;j<6;j++){
printf("%c",start[j]);
}cout<<endl;
}
int analysis(char l,char c){
int flag = 1;
int i,j;
string L = "";
L += l;
string C = "";
C +=c;
//cout<<l<<endl;
for(i=1;i<6;++i){
if(L.compare(map[i][0])==0){
// Match to line
break;
}
}
// cout<<i<<endl;
// i--;
for(j=1;j<7;++j){
if(C.compare(map[0][j])==0){
// Match to column
break;
}
}
// cout<<j<<endl;
// j--;
if(map[0][j].compare("")!=0){
match(i,j);//
return 1;
}else{
cout<<l<<" Mismatch "<<map[0][j]<<" map by :"<<map[i][j]<<endl;
return 0;
}
}
int main(){
int flag = 1;
while(flag){
cout<<endl<<" At present start state :";
for(int j=0;j<6;j++){
printf("%c",start[j]);
}cout<<endl;
cout<<" At present input state :"<<input<<endl;
if(start[strlen(start)-1] == input[0]){
// If the tail of the stack is the same as the head of the remaining string, eliminate it first ;
start[strlen(start)-1]='\0';
for(int i=0;i<strlen(input)-1;i++){
input[i] = input[i+1];
}
input[strlen(input)-1]='\0';
cout<<endl<<" Elimination success !\n At present start state :"<<start<<"\n At present input state :"<<input<<endl;
}
else if(start[strlen(start)-1]=='e'){
// If the last one is empty , Automatically remove
start[strlen(start)-1]='\0';
}
else
flag = analysis(start[strlen(start)-1],input[0]);// If the tail of the stack is different from the head of the remaining string ;
if(flag==0){
cout<<" Compilation error !!"<<endl;
break;
}
if(strlen(input)==0){
cout<<"END!!"<<endl;
break;
}
}
return 0;
}
边栏推荐
- 容器里用systemctl运行服务报错:Failed to get D-Bus connection: Operation not permitted(解决方法)
- Kill -9 system call used by PID to kill process
- 第三季百度网盘AI大赛盛夏来袭,寻找热爱AI的你!
- Jerry's updated equipment resource document [chapter]
- J'aimerais dire quelques mots de plus sur ce problème de communication...
- Solution qui ne peut pas être retournée après la mise à jour du navigateur Web flutter
- Running the service with systemctl in the container reports an error: failed to get D-Bus connection: operation not permitted (solution)
- scratch疫情隔离和核酸检测模拟 电子学会图形化编程scratch等级考试三级真题和答案解析2022年6月
- 8位MCU跑RTOS有没有意义?
- Interview shock 62: what are the precautions for group by?
猜你喜欢
![Jerry's updated equipment resource document [chapter]](/img/6c/17bd69b34c7b1bae32604977f6bc48.jpg)
Jerry's updated equipment resource document [chapter]

IP, subnet mask, gateway, default gateway

OliveTin能在网页上安全运行shell命令(上)

Selected technical experts from China Mobile, ant, SF, and Xingsheng will show you the guarantee of architecture stability

基本磁盘与动态磁盘 RAID磁盘冗余阵列区分

How to solve the error "press any to exit" when deploying multiple easycvr on one server?

Declval (example of return value of guidance function)

开源与安全的“冰与火之歌”

F200——搭载基于模型设计的国产开源飞控系统无人机

FMT开源自驾仪 | FMT中间件:一种高实时的分布式日志模块Mlog
随机推荐
微信小程序中给event对象传递数据
Jerry's access to additional information on the dial [article]
MSF横向之MSF端口转发+路由表+SOCKS5+proxychains
Markdown grammar - better blogging
MarkDown语法——更好地写博客
DNS hijacking
《ASP.NET Core 6框架揭秘》样章发布[200页/5章]
RB157-ASEMI整流桥RB157
Fleet tutorial 13 basic introduction to listview's most commonly used scroll controls (tutorial includes source code)
ASEMI整流桥DB207的导通时间与参数选择
Take you through ancient Rome, the meta universe bus is coming # Invisible Cities
[introduction to MySQL] the first sentence · first time in the "database" Mainland
Solution qui ne peut pas être retournée après la mise à jour du navigateur Web flutter
面试突击62:group by 有哪些注意事项?
编译原理——预测表C语言实现
Interview shock 62: what are the precautions for group by?
Principle and usage of extern
The easycvr platform reports an error "ID cannot be empty" through the interface editing channel. What is the reason?
Scratch epidemic isolation and nucleic acid detection Analog Electronics Society graphical programming scratch grade examination level 3 true questions and answers analysis June 2022
开源与安全的“冰与火之歌”