返回假条,今天要写编译原理,来不及更新啦(1 / 1)神子晶首页

关灯 护眼     字体:

上一章 目录 下一章

// ConsoleApplication14.cpp:

//

#include“stdafx.h“

#include<iostream>

#include<fstream>

#include<string>

#include<stdlib.h>

#include<iomanip>

#include<windows.h>

#include<cmath>

using namespace std;

#define MAXSIZE 0xffff

int ip = 0;

int N = 0;

int n = 0;//stack number

bool flag=1;

int top = 0;//变量存储

struct node {

node *index;

node *bro=NULL;

node *child=NULL;

int id;

string text;

bool hasval=true;

double val;

}S, A, B, C, D, E, F, G, H, I, J,*sheet,*p,*start;

struct variable{

string name;

double val;

}var[20];

int find_var(string a){

for (int i = 0; i <top; i++)

if (var[i].name == a)

return i;

return -1;

}

template<class type>

class my_stack

{

int top;

type* my_s;

int maxsize;

public:

my_stack():top(-1), maxsize(MAXSIZE)

{

my_s = new type[maxsize];

if (my_s == NULL)

{

cerr <<“动态存储分配失败!“<< endl;

exit(1);

}

}

my_stack(int size):top(-1), maxsize(size)

{

my_s = new type[maxsize];

if (my_s == NULL)

{

cerr <<“动态存储分配失败!“<< endl;

exit(1);

}

}

~my_stack()

{

delete[] my_s;

}

//是否为空

bool Empty();

//压栈

node* Push(type tp);

//返回栈顶元素

type Top();

//返回第n个栈顶元素

type Top(int n);

//出栈

void Pop();

//栈大小

int Size();

string Show();

string show();

int Num();

};

template<class type>

bool my_stack<type>::Empty()

{

if (top ==-1){

return true;

}

else

return false;

}

template<class type>

type my_stack<type>::Top()

{

if (top !=-1)

{

return my_s[top];

}

else

{

cout <<“栈空\n“;

exit(1);

}

}

template<class type>

type my_stack<type>::Top(int n)

{

if ((top - n)>-1)

{

return my_s[top - n];

}

else

{

cout <<“栈空\n“;

exit(1);

}

}

node* my_stack<node>::Push(node tp)

{

node *temp = new node;

*temp = tp;

temp->index = temp;

n++;

if (top + 1<maxsize)

{

my_s[++top]=*temp;

}

else

{

cout <<“栈满\n“;

exit(1);

}

return temp;

}

template<class type>

int my_stack<type>::Num(){

return top;

}

template<class type>

void my_stack<type>::Pop()

{

if (top >= 0)

{

top--;

}

else

{

cout <<“栈空\n“;

exit(1);

}

}

template<class type>

int my_stack<type>::Size()

{

return top + 1;

}

template<class type>

string my_stack<type>::Show(){

string s;

for (int i = 0; i <= top; i++)

s += my_s[i].text;

return s;

}

string my_stack<node>::show(){

string s;

for (int i = 0; i <= top; i++)

s+=(my_s[i].index->text)+““;

return s;

}

void S_P(node *sheet, node *a, my_stack<node>&stack){

cout <<“pop(S),“;

node t10 = sheet[10];

node t9 = sheet[9];

switch (a[ip].id){

case 10:

stack.Push(t9);

stack.Push(B);

stack.Push(t10);

stack.Push(A);

cout <<“push(A?B;)“;

break;

case 17:

stack.Push(t9);

stack.Push(B);

stack.Push(t10);

stack.Push(A);

cout <<“push(A?B;)“;

break;

case 21:

break;

default:

cout <<“error : NO PATTERN FOR S!\n“;

flag = 0;

break;

}

}

void A_P(node *sheet, node *a, my_stack<node>&stack){

cout <<“pop(A),“;

node t9 = sheet[9];

switch (a[ip].id){

case 10:

break;

case 17:

stack.Push(A);

stack.Push(t9);

stack.Push(C);

cout <<“push(C;A)“;

break;

default:

cout <<“error : NO PATTERN FOR A!\n“;

flag = 0;

break;

}

}

void B_P(node *sheet, node *a, my_stack<node>&stack){

cout <<“pop(B),“;

switch (a[ip].id){

case 0:

stack.Push(E);

stack.Push(D);

cout <<“push(DE)“;

break;

case 1:

stack.Push(E);

stack.Push(D);

cout <<“push(DE)“;

break;

case 2:

stack.Push(E);

stack.Push(D);

cout <<“push(DE)“;

break;

case 3:

stack.Push(E);

stack.Push(D);

cout <<“push(DE)“;

break;

case 4:

stack.Push(E);

stack.Push(D);

cout <<“push(DE)“;

break;

case 5:

stack.Push(E);

stack.Push(D);

cout <<“push(DE)“;

break;

case 6:

stack.Push(E);

stack.Push(D);

cout <<“push(DE)“;

break;

case 7:

stack.Push(E);

stack.Push(D);

cout <<“push(DE)“;

break;

case 12:

stack.Push(E);

stack.Push(D);

cout <<“push(DE)“;

break;

case 17:

stack.Push(E);

stack.Push(D);

cout <<“push(DE)“;

break;

case 18:

stack.Push(E);

stack.Push(D);

cout <<“push(DE)“;

break;

case 19:

stack.Push(E);

stack.Push(D);

cout <<“push(DE)“;

break;

case 20:

stack.Push(E);

stack.Push(D);

cout <<“push(DE)“;

break;

default:

cout <<“error : NO PATTERN FOR B!\n“;

flag = 0;

break;

}

}

void C_P(node *sheet, node *a, my_stack<node>&stack)

{

cout <<“pop(C),“;

node t17 = sheet[17];

node t15 = sheet[15];

switch (a[ip].id){

case 17:

stack.Push(B);

stack.Push(t15);

stack.Push(t17);

cout <<“push(var=B)“;

break;

default:

cout <<“error : NO PATTERN FOR C!\n“;

flag = 0;

break;

}

}

void D_P(node *sheet, node *a, my_stack<node>&stack){

cout <<“pop(D),“;

switch (a[ip].id){

case 0:

stack.Push(G);

stack.Push(F);

cout <<“push(FG)“;

break;

case 1:

stack.Push(G);

stack.Push(F);

cout <<“push(FG)“;

break;

case 2:

stack.Push(G);

stack.Push(F);

cout <<“push(FG)“;

break;

case 3:

stack.Push(G);

stack.Push(F);

cout <<“push(FG)“;

break;

case 4:

stack.Push(G);

stack.Push(F);

cout <<“push(FG)“;

case 5:

stack.Push(G);

stack.Push(F);

cout <<“push(FG)“;

break;

case 6:

stack.Push(G);

stack.Push(F);

cout <<“push(FG)“;

break;

case 7:

stack.Push(G);

stack.Push(F);

cout <<“push(FG)“;

break;

case 12:

stack.Push(G);

stack.Push(F);

cout <<“push(FG)“;

break;

case 17:

stack.Push(G);

stack.Push(F);

cout <<“push(FG)“;

break;

case 18:

stack.Push(G);

stack.Push(F);

cout <<“push(FG)“;

break;

case 19:

stack.Push(G);

stack.Push(F);

cout <<“push(FG)“;

case 20:

stack.Push(G);

stack.Push(F);

break;

cout <<“push(FG)“;

break;

break;

default:

flag = 0;

cout <<“error : NO PATTERN FOR D!\n“;

break;

}

}

void E_P(node *sheet, node *a, my_stack<node>&stack){

cout <<“pop(E),“;

node t11 = sheet[11], t12 = sheet[12];

switch (a[ip].id){

case 8:

break;

case 9:

break;

case 11:

stack.Push(E);

stack.Push(D);

stack.Push(sheet[11]);

cout <<“push(+DE)“;

break;

case 12:

stack.Push(E);

stack.Push(D);

stack.Push(sheet[12]);

cout <<“push(-DE)“;

break;

default:

flag = 0;

cout <<“error : NO PATTERN FOR E!\n“;

break;

}

}

void F_P(node *sheet, node *a, my_stack<node>&stack){

cout <<“pop(F),“;

switch (a[ip].id){

case 0:

stack.Push(sheet[8]);

stack.Push(H);

stack.Push(sheet[7]);

stack.Push(sheet[0]);

cout <<“push(sin(H))“;

break;

case 1:

stack.Push(sheet[8]);

stack.Push(H);

stack.Push(sheet[7]);

stack.Push(sheet[1]);

cout <<“push(cos(H))“;

break;

case 2:

stack.Push(sheet[8]);

stack.Push(H);

stack.Push(sheet[7]);

stack.Push(sheet[2]);

cout <<“push(tg(H))“;

break;

case 3:

stack.Push(sheet[8]);

stack.Push(H);

stack.Push(sheet[7]);

stack.Push(sheet[3]);

cout <<“push(ctg(H))“;

break;

case 4:

stack.Push(sheet[8]);

stack.Push(H);

stack.Push(sheet[7]);

stack.Push(sheet[4]);

cout <<“push(log(H))“;

break;

case 5:

stack.Push(sheet[8]);

stack.Push(H);

stack.Push(sheet[7]);

stack.Push(sheet[5]);

cout <<“push(lg(H))“;

break;

case 6:

stack.Push(sheet[8]);

stack.Push(H);

stack.Push(sheet[7]);

stack.Push(sheet[6]);

cout <<“push(ln(H))“;

break;

case 7:

stack.Push(I);

stack.Push(H);

cout <<“push(HI)“;

break;

case 12:

stack.Push(I);

stack.Push(H);

cout <<“push(HI)“;

break;

case 17:

stack.Push(I);

stack.Push(H);

cout <<“push(HI)“;

break;

case 18:

stack.Push(I);

stack.Push(H);

cout <<“push(HI)“;

break;

case 19:

stack.Push(I);

stack.Push(H);

cout <<“push(HI)“;

break;

case 20:

stack.Push(I);

stack.Push(H);

cout <<“push(HI)“;

break;

default:

cout <<“error : NO PATTERN FOR F!\n“;

flag = 0;

break;

}

}

void G_P(node *sheet, node *a, my_stack<node>&stack){

cout <<“pop(G),“;

switch (a[ip].id){

case 8:

break;

case 9:

break;

case 11:

break;

case 12:

break;

case 13:

stack.Push(G);

stack.Push(F);

stack.Push(sheet[13]);

cout <<“push(*FG)“;

break;

case 14:

stack.Push(G);

stack.Push(F);

stack.Push(sheet[14]);

cout <<“push(/FG)“;

break;

default:

cout <<“error : NO PATTERN FOR G!\n“;

flag = 0;

break;

}

}

void H_P(node *sheet, node *a, my_stack<node>&stack){

cout <<“pop(H),“;

switch (a[ip].id){

case 7:

stack.Push(sheet[8]);

stack.Push(B);

stack.Push(sheet[7]);

cout <<“push((B))“;

break;

case 12:

stack.Push(H);

stack.Push(sheet[12]);

cout <<“push(-H)“;

break;

case 17:

stack.Push(sheet[17]);

cout <<“push(var)“;

break;

case 18:

stack.Push(sheet[18]);

cout <<“push(con)“;

break;

case 19:

stack.Push(sheet[18]);

cout <<“push(con)“;

break;

case 20:

stack.Push(sheet[18]);

cout <<“push(con)“;

break;

default:

cout <<“error : NO PATTERN FOR H!\n“;

flag = 0;

break;

}

}

void I_P(node *sheet, node *a, my_stack<node>&stack){

cout <<“pop(I),“;

switch (a[ip].id){

case 8:

break;

case 9:

break;

case 11:

break;

case 12:

break;

case 13:

break;

case 14:

break;

case 16:

stack.Push(H);

stack.Push(sheet[16]);

cout <<“push(^H)“;

break;

default:

cout <<“error : NO PATTERN FOR I!\n“;

flag = 0;

break;

}

}

void J_P(node *sheet, node *a, my_stack<node>&stack){

cout <<“pop(J),“;

switch (a[ip].id){

case 8:

stack.Push(sheet[8]);

cout <<“push())“;

break;

case 22:

stack.Push(sheet[8]);

stack.Push(H);

stack.Push(sheet[22]);

cout <<“push(,H))“;

default:

cout <<“error : NO PATTERN FOR J!\n“;

flag = 0;

break;

}

}

string show(node *a){

string s;

for (int i = ip; i < N; i++)

{

s += a[i].text;

}

return s;

}

void ana(my_stack<node>&stack, node *a){

int i = 0;

while (flag){

p = stack.Top().index;//当前指针

i++;

cout << right << setw(3)<< i <<“)|“;

cout << left << setw(20)<< stack.Show();

cout << left << setw(60)<< show(a);

switch (stack.Top().id){

case 23:

stack.Pop();

S_P(sheet, a, stack);

break;

case 24:

stack.Pop();

A_P(sheet, a, stack);

break;

case 25:

stack.Pop();

B_P(sheet, a, stack);

break;

case 26:

stack.Pop();

C_P(sheet, a, stack);

break;

case 27:

stack.Pop();

D_P(sheet, a, stack);

break;

case 28:

stack.Pop();

E_P(sheet, a, stack);

break;

case 29:

stack.Pop();

F_P(sheet, a, stack);

break;

case 30:

stack.Pop();

G_P(sheet, a, stack);

break;

case 31:

stack.Pop();

H_P(sheet, a, stack);

break;

case 32:

stack.Pop();

I_P(sheet, a, stack);

break;

case 33:

stack.Pop();

J_P(sheet, a, stack);

break;

default:

if (stack.Top().id == a[ip].id){

if (stack.Top().id == 17)

stack.Top().index->text = a[ip].text;

else if (stack.Top().id == 18)

{

if (a[ip].text ==“PI“)

{

stack.Top().index->text = a[ip].text;

stack.Top().index->val = 3.141592;

}

else if (a[ip].text ==“E“)

{

stack.Top().index->text = a[ip].text;

stack.Top().index->val = 2.718281;

}

else {

stack.Top().index->text = a[ip].text;

stack.Top().index->val = stod(a[ip].text);

}

}

ip++;

if(stack.Top().id<23&& stack.Top().id>=0)

cout <<“pop(“<< sheet[stack.Top().id].text <<“),“;

else

cout <<“pop(“<< stack.Top().text <<“),“;

stack.Pop();

cout <<“next(ip)“;

if (stack.Empty()) cout <<“\nSuccess\n“;

}

else {

cout <<“\nerror: Fail!\n“;

flag = 0;

break;

}

}

cout << endl;

if (stack.Empty()) break;

if (n>0)

{p->child = stack.Top(0).index;

node *temp = p->child->index;

for (int i = 1; i < n; i++)

{

temp->bro = stack.Top(i).index;

temp = temp->bro;

}

}

n = 0;

}

}

/********************************************************************/

/*语义分析*/

void semanti_ana(my_stack<node>&stack, node *s)//主体部分,对后序遍历得到的后缀树进行栈操作,得出最后结果,放在后序遍历循环体中

{

string out=““;

bool hasundefine=false;

if (s->id >= 0 && s->id < 19)

{

if (s->id == 10)

{

cout << left << setw(40)<<“?“;

cout <<“Return Top[0].val“;

cout << endl;

cout <<“结果:“;

if (hasundefine)

cout << s;

else

cout<<setw(40)<<stack.show();

}

else if (s->id == 0)

{

if (s->index->hasval)

stack.Top().index->val = sin(stack.Top().index->val);

else

{

out+=“sin(“+ stack.Top().index->text +“)“;

stack.Top().index->text = out;

stack.Top().index->hasval = false;

}

cout << setw(40)<< stack.show();

cout <<“Top[0].text =“<< stack.Top().index->text;

cout <<“,Top[0].val=sin(Top[0].val)“;

}

else if (s->id == 1)

{

if (s->index->hasval)

stack.Top().index->val = cos(stack.Top().index->val);

else

{

out =“cos(“+ stack.Top().index->text +“)“;

stack.Top().index->text = out;

stack.Top().index->hasval = false;

}

cout<<setw(40)<<stack.show();

cout <<“Top[0].text =“<< stack.Top().index->text;

cout <<“,Top[0].val=cos(Top[0].val)“;

}

else if (s->id == 2)

{

if (s->index->hasval)

stack.Top().index->val = tan(stack.Top().index->val);

else

{

out =“tan(“+ stack.Top().index->text +“)“;

stack.Top().index->text = out;

stack.Top().index->hasval = false;

}

cout<<setw(40)<<stack.show();

cout <<“Top[0].text =“<< stack.Top().index->text;

cout <<“,Top[0].val=tg(Top[0].val)“;

}

else if (s->id == 3)

{

if (s->index->hasval)

stack.Top().index->val = tan(1.57-stack.Top().index->val);

else

{

out =“cot(“+ stack.Top().index->text +“)“;

stack.Top().index->text = out;

stack.Top().index->hasval = false;

}

cout<<setw(40)<<stack.show();

cout <<“Top[0].text =“<< stack.Top().index->text;

cout <<“,Top[0].val=ctg(Top[0].val)“;

}

else if (s->id == 4)

{

if (s->index->hasval)

stack.Top().index->val = log(stack.Top().index->val);

else

{

out =“log(“+ stack.Top().index->text +“)“;

stack.Top().index->text = out;

stack.Top().index->hasval = false;

}

cout<<setw(40)<<stack.show();

cout <<“Top[0].text =“<< stack.Top().index->text;

cout <<“,Top[0].val=log(Top[0].val)“;

}

else if (s->id == 5)

{

if (s->index->hasval)

stack.Top().index->val = log10(stack.Top().index->val);

else

{

out =“lg(“+ stack.Top().index->text +“)“;

stack.Top().index->text = out;

stack.Top().index->hasval = false;

}

cout<<setw(40)<<stack.show();

cout <<“Top[0].text =“<< stack.Top().index->text;

cout <<“,Top[0].val=lg(Top[0].val)“;

}

else if (s->id == 6)

{

if (s->index->hasval)

stack.Top().index->val = log(stack.Top().index->val);

else

{

out =“ln(“+ stack.Top().index->text +“)“;

stack.Top().index->text = out;

stack.Top().index->hasval = false;

}

cout<<setw(40)<<stack.show();

cout <<“Top[0].text =“<< stack.Top().index->text;

cout <<“,Top[0].val=ln(Top[0].val)“;

}

else if (s->id == 11)

{

if (stack.Top(0).index->hasval&&stack.Top(1).index->hasval)

{

double temp = stack.Top().index->val;

stack.Pop();

stack.Top().index->val += temp;

stack.Top().index->text = to_string(stack.Top().index->val);

}

else {

out =“(“+ stack.Top(1).index->text +“+“+stack.Top(0).index->text +“)“;

stack.Top(1).index->text = out;

stack.Top(1).index->hasval = false;

stack.Pop();

}

cout<<setw(40)<<stack.show();

cout <<“Top[1].val+=Top[0].val , Pop()“;

}

else if (s->id == 12)

{

if (stack.Top(0).index->hasval&&stack.Top(1).index->hasval)

{

double temp = stack.Top().index->val;

stack.Pop();

stack.Top().index->val -= temp;

stack.Top().index->text = to_string(stack.Top().index->val);

}

else {

out =“(“+ stack.Top(1).index->text +“-“+ stack.Top(0).index->text +“)“;

stack.Top(1).index->text = out;

stack.Top(1).index->hasval = false;

stack.Pop();

}

cout<<setw(40)<<stack.show();

cout <<“Top[1].val-=Top[0].val , Pop()“;

}

else if (s->id == 13)

{

if (stack.Top(0).index->hasval&&stack.Top(1).index->hasval)

{

double temp = stack.Top().index->val;

stack.Pop();

stack.Top().index->val *= temp;

stack.Top().index->text = to_string(stack.Top().index->val);

}

else {

out = stack.Top(1).index->text +“*“+ stack.Top(0).index->text ;

stack.Top(1).index->text = out;

stack.Top(1).index->hasval = false;

stack.Pop();

}

cout<<setw(40)<<stack.show();

cout <<“Top[1].val*=Top[0].val , Pop()“;

}

else if (s->id == 14)

{

if (stack.Top(0).index->hasval&&stack.Top(1).index->hasval)

{

double temp = stack.Top().index->val;

stack.Pop();

stack.Top().index->val /= temp;

stack.Top().index->text = to_string(stack.Top().index->val);

}

else {

out = stack.Top(1).index->text +“/“+ stack.Top(0).index->text;

stack.Top(1).index->text = out;

stack.Top(1).index->hasval = false;

stack.Pop();

}

cout<<setw(40)<<stack.show();

cout <<“Top[1].val/=Top[0].val , Pop()“;

}

else if (s->id == 15)

{

var[top].val = stack.Top().index->val;

stack.Push(*s);

cout<<setw(40)<<stack.show();

stack.Pop();

cout <<“Variable[top].val =“<< stack.Top().index->val;

stack.Pop();

top++;

}

else if (s->id == 16)

{

if (stack.Top(0).index->hasval&&stack.Top(1).index->hasval){

double temp = stack.Top().index->val;

stack.Pop();

stack.Top().index->val = pow(stack.Top().index->val, temp);

stack.Top().index->text = to_string(stack.Top().index->val);

}

else {

out = stack.Top(1).index->text +“^“+ stack.Top(0).index->text;

stack.Top(1).index->text = out;

stack.Top(1).index->hasval = false;

stack.Pop();

}

cout<<setw(40)<<stack.show();

cout <<“Top[1].val=Top[1].val^Top[0].val , Pop()“;

}

else if (s->id == 18)

{

stack.Push(*s);

cout<<setw(40)<<stack.show();

cout<<“Push(“<<stack.Top().index->val<<“)“;

}

else if (s->id == 17)

{

if (var[top - 1].name ==““)

{

var[top - 1].name = s->index->text;

string temp= to_string(var[top - 1].val)+“=“+ s->index->text ;

cout << setw(40)<< temp;

cout <<“Variable[Top].text =“<< s->index->text<<“,Pop(3)“;

}

else

{

if (find_var(s->index->text)>= 0)

{

s->index->val = var[find_var(s->index->text)].val;

stack.Push(*s);

cout << setw(40)<< stack.show();

cout <<“Find(“<< s->index->text <<“)=“<< s->index->val;

}

else

{

s->index->hasval = false;

hasundefine = true;

stack.Push(*s);

cout << setw(40)<< stack.show();

cout <<“No Define “<<s->index->text;

}

}

}

}

}

int count_p = 0;

void post(node *s)//对树的后序遍历

{

if (s != NULL){

post( s->child);

post( s->bro);

if(s->id < 23 && s->id != 7 && s->id != 8 && s->id != 9)cout << s->text;

}

}

void post(my_stack<node>&stack,node *s)//对树的后序遍历

{

if (s != NULL ){

post(stack,s->child);

post(stack,s->bro);

if (s->id < 23&&s->id!=7&&s->id!=8&&s->id!=9)

{

cout <<setw(10)<< left<< count_p <<““;

count_p++;

semanti_ana(stack, s);

cout << endl;

}

}

}

int main()

{

node *start =&S;

sheet = new node[23];

sheet[0].text =“sin“;

sheet[1].text =“cos“;

sheet[2].text =“tg“;

sheet[3].text =“ctg“;

sheet[4].text =“log“;

sheet[5].text =“lg“;

sheet[6].text =“ln“;

sheet[7].text =“(“;

sheet[8].text =“)“;

sheet[9].text =“;“;

sheet[10].text =“?“;

sheet[11].text =“+“;

sheet[12].text =“-“;

sheet[13].text =“*“;

sheet[14].text =“/“;

sheet[15].text =“=“;

sheet[16].text =“^“;

sheet[17].text =“var“;

sheet[18].text =“con“;

sheet[19].text =“PI“;

sheet[20].text =“E“;

sheet[21].text =“#“;

sheet[22].text =“,“;

S.id = 23; S.text =“S“;

A.id = 24; A.text =“A“;

B.id = 25; B.text =“B“;

C.id = 26; C.text =“C“;

D.id = 27; D.text =“D“;

E.id = 28; E.text =“E“;

F.id = 29; F.text =“F“;

G.id = 30; G.text =“G“;

H.id = 31; H.text =“H“;

I.id = 32; I.text =“I“;

J.id = 33; J.text =“J“;

for (int i = 0; i < 23; i++)

sheet[i].id = i;

ifstream in;

in.open(“D:\\词法.txt“);

node *a = new node[MAXSIZE];//当前输入

char buffer[256];

while (in.getline(buffer, 100))//读取输入内容,既词法分析结果

{

a[N].text = buffer;

int c1 = a[N].text.find(“<“);

int c2 = a[N].text.find(“,“);

int c3 = a[N].text.find(“>“);

a[N].id = stoi(a[N].text.substr(c2 + 1, c3 - 1).data());

if (a[N].id == 19 || a[N].id == 20) a[N].id = 18;

a[N].text = a[N].text.substr(c1 + 1, c2 - 1);

N++;

}

a[N].text =“#“;

a[N].id =-1;

a[N].child = NULL;

a[N].bro = NULL;

in.close();

N++;

my_stack<node> stack;

stack.Push(a[N - 1]);

stack.Push(S);

start = stack.Top().index;

n -= 2;

cout <<“**************************************************语法分析***************************************************\n“;

cout <<“步骤栈内容当前输入操作\n“;

string c =“--------------------------------------------------------------------------------------------------------------\n“;

cout << c << c;

ana(stack, a);

cout <<“**************************************************语法分析***************************************************\n\n\n“;

cout <<“**************************************************语义分析***************************************************\n“;

my_stack<node> lexme;//语义分析栈

cout << endl;

cout<<“后缀式:“;

post(start);

cout << endl;

cout << endl;

cout <<“步骤栈内容操作\n“;

cout << c << c;

post(lexme,start);

cout <<“**************************************************语义分析***************************************************\n\n\n“;

return 0;

}

『加入书签,方便阅读』

上一章 目录 下一章