?? rec_parse.cpp
字號:
//Rec_Parse.cpp
#include "stdafx.h"
#include "Rec_Parse.h"
//整個思想和LL1驅動器一樣,把壓棧改成調用,把彈棧改成返回.
//把查找LL1分析表改成查找PREDICT集(其實改不改都一樣.)
void Rec_Parse::Parse(symbol X)
{
terminal a;
int pnum;
vector<symbol>::reverse_iterator v_it;
a=pos->value;
if( g->is_nonterminal(X) )
{
if(a.first == Id || a.first == Intc) a=make_pair(a.first,-1);
for (pnum=0; pnum < Predict.size(); pnum++) //查找PREDICT集
{
if( (g->productions[pnum].lhs == X) && ( Predict[pnum].find(a) != Predict[pnum].end() ) )
{
cout<<"Production "<<pnum+1<<endl;
for (int n=0; n < g->productions[pnum].rhs.size(); n++)
Parse(g->productions[pnum].rhs[n]); //遞歸調用點.
return;
}
else
{
if ( pnum == Predict.size() - 1 ) error(pos,X);
else continue;
}
}
}
else if (g->is_terminal(X) && (g->match(X,a) || X.first == $) )
{
token_pos = pos;
if (X.first != $)
{
cout<<"Match: "<<g->GetStr(X)<<" , "<<g->GetStr(a)<<endl;
pos++;
}
return;
}
else if ( g->is_action_symbol(X) )
{
cout<<"Call: "<<g->GetStr(X)<<endl;
//Call Semantic Routine corresponding to X;
act.call_action(X,token_pos);
return;
}
else error(pos,X);
}
//出錯處理和LL1驅動器是一樣的.
void Rec_Parse::error(list<TOKEN>::iterator pos,nonterminal X)
{
if(pos == tlist->end())
cerr<<"Maybe lose "<<g->GetStr(X)<<endl;
else
cerr<<"There's an error here: ("<<pos->line<<") "<<g->GetStr(pos->value)<<' '<<g->GetStr(X)<<endl;
exit(1);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -