当前位置:网站首页>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;
}
边栏推荐
- J'aimerais dire quelques mots de plus sur ce problème de communication...
- Jerry's setting currently uses the dial. Switch the dial through this function [chapter]
- 二分(整数二分、实数二分)
- There is a gap in traditional home decoration. VR panoramic home decoration allows you to experience the completion effect of your new house
- UDP协议:因性善而简单,难免碰到“城会玩”
- 【Swoole系列2.1】先把Swoole跑起来
- The latest financial report release + tmall 618 double top, Nike energy leads the next 50 years
- sql语句优化,order by desc速度优化
- MSF横向之MSF端口转发+路由表+SOCKS5+proxychains
- 第三季百度网盘AI大赛盛夏来袭,寻找热爱AI的你!
猜你喜欢
Summary of Android interview questions of Dachang in 2022 (I) (including answers)
推荐好用的后台管理脚手架,人人开源
Appium automated test scroll and drag_ and_ Drop slides according to element position
scratch疫情隔离和核酸检测模拟 电子学会图形化编程scratch等级考试三级真题和答案解析2022年6月
Open source and safe "song of ice and fire"
Interview assault 63: how to remove duplication in MySQL?
Easy introduction to SQL (1): addition, deletion, modification and simple query
一体化实时 HTAP 数据库 StoneDB,如何替换 MySQL 并实现近百倍性能提升
EasyCVR授权到期页面无法登录,该如何解决?
UDP协议:因性善而简单,难免碰到“城会玩”
随机推荐
Redis的五种数据结构
Scratch epidemic isolation and nucleic acid detection Analog Electronics Society graphical programming scratch grade examination level 3 true questions and answers analysis June 2022
C语言通过指针交换两个数
酷雷曼多种AI数字人形象,打造科技感VR虚拟展厅
Summary of Android interview questions of Dachang in 2022 (I) (including answers)
Stealing others' vulnerability reports and selling them into sidelines, and the vulnerability reward platform gives rise to "insiders"
EasyCVR授权到期页面无法登录,该如何解决?
Jerry's setting currently uses the dial. Switch the dial through this function [chapter]
趣-关于undefined的问题
After entering Alibaba for the interview and returning with a salary of 35K, I summarized an interview question of Alibaba test engineer
中移动、蚂蚁、顺丰、兴盛优选技术专家,带你了解架构稳定性保障
EasyCVR平台通过接口编辑通道出现报错“ID不能为空”,是什么原因?
VR panoramic wedding helps couples record romantic and beautiful scenes
78 岁华科教授逐梦 40 载,国产数据库达梦冲刺 IPO
Pytest learning ----- pytest confitest of interface automation test Py file details
Open source and safe "song of ice and fire"
第三季百度网盘AI大赛盛夏来袭,寻找热爱AI的你!
【Android】Kotlin代码编写规范化文档
How to output special symbols in shell
The easycvr authorization expiration page cannot be logged in. How to solve it?