/*******************************************************************************
Title(c++): LR语法分析器.cpp
Author: volantfish num:10211xxx Class:2010211309 Date: 2012.11 (volantfish)
Introduction:
Version:
*******************************************************************************/
#include
using namespace std;
//#define DEBUG_
//枚举常量:用来表示LR分析表中表项的状态
enumformStyle{SHIFT, REDUCE, ACCEPT, GOTO, ERROR};
//the element of result of lexical analysis classWordEle { public: WordEle():style(-1), real(\ WordEle(intst, string re):style(st), real(re){} int style; //the string real; // };
//the element of the form classformEle {
public: formStyle style; //enum intnum; //the number of production. };
//the element of stack classstackEle { public: stackEle():state(-1), ch(-1){} stackEle(intst, int c):state(st), ch(c){} int state; //the number of state. intch; //the number of character. };
/*Global variable*/
map
* Description: 打印此刻的分析动作
* Arguments: 输入此刻分析表的一个元素 * Returns: 用string表示的分析动作 */
stringPrintOption(constformEle&formTemp) { string output;
char charTemp[100]; //装门用于atoi()函数的参数,没有其他作用
if(formTemp.style == SHIFT) { output += \ output += itoa(formTemp.num, charTemp, 10); } else { if(formTemp.style == REDUCE) { output += \
output += numChar.at(proListL.at(formTemp.num)); output += \ vector
* Description: 打印未处理的输入串
* Arguments: 输入字符串的迭代器,指向正在处理的字符 * Returns: 未处理的输入串 */
stringPrintInput(vector
* Description: 打印栈的全部元素 ~ * Arguments: 栈
* Returns: 储存栈元素的string
*/
stringPrintStack(const list
* Description: LR语法分析主程序 * Arguments: * Returns: */
voidGramAna() { vector
else { if(formTemp.style == REDUCE) // 归约 { printf(\ %-15s\\n\ PrintInput(iterWord).c_str(), PrintOption(formTemp).c_str()); for(vector
* Description: 词法分析程序
* Arguments: 未经处理的输入符号串 * Returns: */
voidLexiAna(const string inputStr) { string::const_iteratoriter = inputStr.begin();
百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库LR语法分析器 北邮 编译原理 实验在线全文阅读。
相关推荐: