天津理工大学编译原理实验3:语义分析与中间代码生成

2026/4/29 13:22:08

} }; std::vector source; std::string sourceCode; private:

Lexical.cpp #include \#include #include using namespace ccyg; Lexical::Lexical() { } Lexical::Lexical(std::string s) { } Lexical::~Lexical() { } bool Lexical::analysis() { if (sourceCode.size() == 0) { } source.clear(); identifier.clear(); int number = NULL; for (int i = 0; i <= sourceCode.size(); i++) { if (i == sourceCode.size()) { if (number != NULL) { } source.push_back(sha); return true; 第5页 共15页

sourceCode = s; std::cout << \ << std::endl; return false; source.push_back(ide); identifier.push_back(number); number = 0; } } else if (sourceCode[i] >= '0'&& sourceCode[i] <= '9') { } else { } if (number != NULL) { } switch (sourceCode[i]) { case '+': } source.push_back(add); break; source.push_back(sub); break; source.push_back(mul); break; source.push_back(div); break; source.push_back(pow); break; source.push_back(lef); break; source.push_back(rig); break; std::cout << \ << sourceCode[i] << return false; break; source.push_back(ide); identifier.push_back(number); number = 0; number = number * 10 + sourceCode[i] - 48; case '-': case '*': case '/': case '^': case '(': case ')': default: std::endl; source.push_back(sha); 第6页 共15页

} return true; void Lexical::printSource() { } char Lexical::toChar(int a) { } void Lexical::setSourceCode(std::string source) { } sourceCode = source; switch (a) { case add: } return 0; return '+'; return '-'; return '*'; return '/'; return '^'; return 'i'; return '('; return ')'; return '#'; break; case sub: case mul: case div: case pow: case ide: case lef: case rig: case sha: default: for (int i = 0; i < source.size(); i++) { } std::cout << \; std::cout << toChar(source[i]);

第7页 共15页

Syntax.h #pragma once #include \namespace ccyg { std::vector symbolStack;// 定义符号栈 std::vector inputStack; // 定义输入栈 std::vector semStack; //定义语义栈 bool isSuccess; bool isInitNext; 第8页 共15页

class Syntax : public ccyg::Lexical { public: enum Relation //定义优先关系枚举 { }; enum Symbol { }; Syntax(std::string = 0); ~Syntax(); bool reduced();//定义归约方法 void movein();//定义移进方法 int findOperator();//查找最近运算符 char toChar(int); bool nextStep(); void initNext(); void printSymbol(); void printSemantic(); bool getSuccess(); E = 9, T = 10, F = 11, P = 12 equal = 0, less = 1, greater = 2, //错误 i_i = 3, i_left = 4, left_sharp = 5, right_i = 6, right_left = 7, sharp_right = 8


天津理工大学编译原理实验3:语义分析与中间代码生成.doc 将本文的Word文档下载到电脑
搜索更多关于: 天津理工大学编译原理实验3:语义分析与中间代码生成 的文档
相关推荐
相关阅读
× 游客快捷下载通道(下载后可以自由复制和排版)

下载本文档需要支付 10

支付方式:

开通VIP包月会员 特价:29元/月

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:xuecool-com QQ:370150219