forked from NUDT-compiler/nudt-compiler-cpp
@ -1,30 +1,178 @@
|
||||
// 基于语法树的语义检查与名称绑定。
|
||||
#pragma once
|
||||
#ifndef SEMANTIC_ANALYSIS_H
|
||||
#define SEMANTIC_ANALYSIS_H
|
||||
|
||||
#include "SymbolTable.h"
|
||||
#include "../../generated/src/antlr4/SysYBaseVisitor.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <unordered_map>
|
||||
#include <any>
|
||||
#include <memory>
|
||||
|
||||
#include "SysYParser.h"
|
||||
|
||||
class SemanticContext {
|
||||
public:
|
||||
void BindVarUse(SysYParser::VarContext* use,
|
||||
SysYParser::VarDefContext* decl) {
|
||||
var_uses_[use] = decl;
|
||||
}
|
||||
|
||||
SysYParser::VarDefContext* ResolveVarUse(
|
||||
const SysYParser::VarContext* use) const {
|
||||
auto it = var_uses_.find(use);
|
||||
return it == var_uses_.end() ? nullptr : it->second;
|
||||
}
|
||||
|
||||
private:
|
||||
std::unordered_map<const SysYParser::VarContext*,
|
||||
SysYParser::VarDefContext*>
|
||||
var_uses_;
|
||||
// 错误信息结构体
|
||||
struct ErrorMsg {
|
||||
std::string msg;
|
||||
int line;
|
||||
int column;
|
||||
ErrorMsg(std::string m, int l, int c) : msg(std::move(m)), line(l), column(c) {}
|
||||
};
|
||||
|
||||
// 目前仅检查:
|
||||
// - 变量先声明后使用
|
||||
// - 局部变量不允许重复定义
|
||||
SemanticContext RunSema(SysYParser::CompUnitContext& comp_unit);
|
||||
// 前向声明
|
||||
namespace antlr4 {
|
||||
class ParserRuleContext;
|
||||
namespace tree {
|
||||
class ParseTree;
|
||||
}
|
||||
}
|
||||
|
||||
// 语义/IR生成上下文核心类
|
||||
class IRGenContext {
|
||||
public:
|
||||
// 错误管理
|
||||
void RecordError(const ErrorMsg& err) { errors_.push_back(err); }
|
||||
const std::vector<ErrorMsg>& GetErrors() const { return errors_; }
|
||||
bool HasError() const { return !errors_.empty(); }
|
||||
void ClearErrors() { errors_.clear(); }
|
||||
|
||||
// 类型绑定/查询 - 使用 void* 以兼容测试代码
|
||||
void SetType(void* ctx, SymbolType type) {
|
||||
node_type_map_[ctx] = type;
|
||||
}
|
||||
|
||||
SymbolType GetType(void* ctx) const {
|
||||
auto it = node_type_map_.find(ctx);
|
||||
return it == node_type_map_.end() ? SymbolType::TYPE_UNKNOWN : it->second;
|
||||
}
|
||||
|
||||
// 常量值绑定/查询 - 使用 void* 以兼容测试代码
|
||||
void SetConstVal(void* ctx, const std::any& val) {
|
||||
const_val_map_[ctx] = val;
|
||||
}
|
||||
|
||||
std::any GetConstVal(void* ctx) const {
|
||||
auto it = const_val_map_.find(ctx);
|
||||
return it == const_val_map_.end() ? std::any() : it->second;
|
||||
}
|
||||
|
||||
// 循环状态管理
|
||||
void EnterLoop() { sym_table_.EnterLoop(); }
|
||||
void ExitLoop() { sym_table_.ExitLoop(); }
|
||||
bool InLoop() const { return sym_table_.InLoop(); }
|
||||
|
||||
// 类型判断工具函数
|
||||
bool IsIntType(const std::any& val) const {
|
||||
return val.type() == typeid(long) || val.type() == typeid(int);
|
||||
}
|
||||
|
||||
bool IsFloatType(const std::any& val) const {
|
||||
return val.type() == typeid(double) || val.type() == typeid(float);
|
||||
}
|
||||
|
||||
// 当前函数返回类型
|
||||
SymbolType GetCurrentFuncReturnType() const {
|
||||
return current_func_ret_type_;
|
||||
}
|
||||
|
||||
void SetCurrentFuncReturnType(SymbolType type) {
|
||||
current_func_ret_type_ = type;
|
||||
}
|
||||
|
||||
// 符号表访问
|
||||
SymbolTable& GetSymbolTable() { return sym_table_; }
|
||||
const SymbolTable& GetSymbolTable() const { return sym_table_; }
|
||||
|
||||
// 作用域管理
|
||||
void EnterScope() { sym_table_.EnterScope(); }
|
||||
void LeaveScope() { sym_table_.LeaveScope(); }
|
||||
size_t GetScopeDepth() const { return sym_table_.GetScopeDepth(); }
|
||||
|
||||
private:
|
||||
SymbolTable sym_table_;
|
||||
std::unordered_map<void*, SymbolType> node_type_map_;
|
||||
std::unordered_map<void*, std::any> const_val_map_;
|
||||
std::vector<ErrorMsg> errors_;
|
||||
SymbolType current_func_ret_type_ = SymbolType::TYPE_UNKNOWN;
|
||||
};
|
||||
|
||||
// 错误信息格式化工具函数
|
||||
inline std::string FormatErrMsg(const std::string& msg, int line, int col) {
|
||||
std::ostringstream oss;
|
||||
oss << "[行:" << line << ",列:" << col << "] " << msg;
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
// 语义分析访问器 - 继承自生成的基类
|
||||
class SemaVisitor : public SysYBaseVisitor {
|
||||
public:
|
||||
explicit SemaVisitor(IRGenContext& ctx) : ir_ctx_(ctx) {}
|
||||
|
||||
// 必须实现的 ANTLR4 接口
|
||||
std::any visit(antlr4::tree::ParseTree* tree) override {
|
||||
if (tree) {
|
||||
return tree->accept(this);
|
||||
}
|
||||
return std::any();
|
||||
}
|
||||
|
||||
std::any visitTerminal(antlr4::tree::TerminalNode* node) override {
|
||||
return std::any();
|
||||
}
|
||||
|
||||
std::any visitErrorNode(antlr4::tree::ErrorNode* node) override {
|
||||
if (node) {
|
||||
int line = node->getSymbol()->getLine();
|
||||
int col = node->getSymbol()->getCharPositionInLine() + 1;
|
||||
ir_ctx_.RecordError(ErrorMsg("语法错误节点", line, col));
|
||||
}
|
||||
return std::any();
|
||||
}
|
||||
|
||||
// 核心访问方法
|
||||
std::any visitCompUnit(SysYParser::CompUnitContext* ctx) override;
|
||||
std::any visitFuncDef(SysYParser::FuncDefContext* ctx) override;
|
||||
std::any visitDecl(SysYParser::DeclContext* ctx) override;
|
||||
std::any visitConstDecl(SysYParser::ConstDeclContext* ctx) override;
|
||||
std::any visitVarDecl(SysYParser::VarDeclContext* ctx) override;
|
||||
std::any visitBlock(SysYParser::BlockContext* ctx) override;
|
||||
std::any visitStmt(SysYParser::StmtContext* ctx) override;
|
||||
std::any visitLVal(SysYParser::LValContext* ctx) override;
|
||||
std::any visitExp(SysYParser::ExpContext* ctx) override;
|
||||
std::any visitCond(SysYParser::CondContext* ctx) override;
|
||||
std::any visitPrimaryExp(SysYParser::PrimaryExpContext* ctx) override;
|
||||
std::any visitUnaryExp(SysYParser::UnaryExpContext* ctx) override;
|
||||
std::any visitMulExp(SysYParser::MulExpContext* ctx) override;
|
||||
std::any visitAddExp(SysYParser::AddExpContext* ctx) override;
|
||||
std::any visitRelExp(SysYParser::RelExpContext* ctx) override;
|
||||
std::any visitEqExp(SysYParser::EqExpContext* ctx) override;
|
||||
std::any visitLAndExp(SysYParser::LAndExpContext* ctx) override;
|
||||
std::any visitLOrExp(SysYParser::LOrExpContext* ctx) override;
|
||||
std::any visitConstExp(SysYParser::ConstExpContext* ctx) override;
|
||||
std::any visitNumber(SysYParser::NumberContext* ctx) override;
|
||||
std::any visitFuncRParams(SysYParser::FuncRParamsContext* ctx) override;
|
||||
|
||||
// 通用子节点访问
|
||||
std::any visitChildren(antlr4::tree::ParseTree* node) override {
|
||||
std::any result;
|
||||
if (node) {
|
||||
for (auto* child : node->children) {
|
||||
if (child) {
|
||||
result = child->accept(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// 获取上下文引用
|
||||
IRGenContext& GetContext() { return ir_ctx_; }
|
||||
const IRGenContext& GetContext() const { return ir_ctx_; }
|
||||
|
||||
private:
|
||||
IRGenContext& ir_ctx_;
|
||||
};
|
||||
|
||||
// 语义分析入口函数
|
||||
void RunSemanticAnalysis(SysYParser::CompUnitContext* ctx, IRGenContext& ir_ctx);
|
||||
|
||||
#endif // SEMANTIC_ANALYSIS_H
|
||||
@ -1,17 +1,201 @@
|
||||
// 极简符号表:记录局部变量定义点。
|
||||
#pragma once
|
||||
#ifndef SYMBOL_TABLE_H
|
||||
#define SYMBOL_TABLE_H
|
||||
|
||||
#include <any>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
#include <stack>
|
||||
#include <utility>
|
||||
|
||||
#include "SysYParser.h"
|
||||
// 核心类型枚举
|
||||
enum class SymbolType {
|
||||
TYPE_UNKNOWN, // 未知类型
|
||||
TYPE_INT, // 整型
|
||||
TYPE_FLOAT, // 浮点型
|
||||
TYPE_VOID, // 空类型
|
||||
TYPE_ARRAY, // 数组类型
|
||||
TYPE_FUNCTION // 函数类型
|
||||
};
|
||||
|
||||
// 获取类型名称字符串
|
||||
inline const char* SymbolTypeToString(SymbolType type) {
|
||||
switch (type) {
|
||||
case SymbolType::TYPE_INT: return "int";
|
||||
case SymbolType::TYPE_FLOAT: return "float";
|
||||
case SymbolType::TYPE_VOID: return "void";
|
||||
case SymbolType::TYPE_ARRAY: return "array";
|
||||
case SymbolType::TYPE_FUNCTION: return "function";
|
||||
default: return "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
// 变量信息结构体
|
||||
struct VarInfo {
|
||||
SymbolType type = SymbolType::TYPE_UNKNOWN;
|
||||
bool is_const = false;
|
||||
std::any const_val;
|
||||
std::vector<int> array_dims; // 数组维度,空表示非数组
|
||||
void* decl_ctx = nullptr; // 关联的语法节点
|
||||
|
||||
// 检查是否为数组类型
|
||||
bool IsArray() const { return !array_dims.empty(); }
|
||||
|
||||
// 获取数组元素总数
|
||||
int GetArrayElementCount() const {
|
||||
int count = 1;
|
||||
for (int dim : array_dims) {
|
||||
count *= dim;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
};
|
||||
|
||||
// 函数信息结构体
|
||||
struct FuncInfo {
|
||||
SymbolType ret_type = SymbolType::TYPE_UNKNOWN;
|
||||
std::string name;
|
||||
std::vector<SymbolType> param_types; // 参数类型列表
|
||||
void* decl_ctx = nullptr; // 关联的语法节点
|
||||
|
||||
// 检查参数匹配
|
||||
bool CheckParams(const std::vector<SymbolType>& actual_params) const {
|
||||
if (actual_params.size() != param_types.size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < param_types.size(); ++i) {
|
||||
if (param_types[i] != actual_params[i] &&
|
||||
param_types[i] != SymbolType::TYPE_UNKNOWN &&
|
||||
actual_params[i] != SymbolType::TYPE_UNKNOWN) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
// 作用域条目结构体
|
||||
struct ScopeEntry {
|
||||
// 变量符号表:符号名 -> (符号信息, 声明节点)
|
||||
std::unordered_map<std::string, std::pair<VarInfo, void*>> var_symbols;
|
||||
|
||||
// 函数符号表:符号名 -> (函数信息, 声明节点)
|
||||
std::unordered_map<std::string, std::pair<FuncInfo, void*>> func_symbols;
|
||||
|
||||
// 清空作用域
|
||||
void Clear() {
|
||||
var_symbols.clear();
|
||||
func_symbols.clear();
|
||||
}
|
||||
};
|
||||
|
||||
// 符号表核心类
|
||||
class SymbolTable {
|
||||
public:
|
||||
void Add(const std::string& name, SysYParser::VarDefContext* decl);
|
||||
bool Contains(const std::string& name) const;
|
||||
SysYParser::VarDefContext* Lookup(const std::string& name) const;
|
||||
public:
|
||||
// ========== 作用域管理 ==========
|
||||
|
||||
// 进入新作用域
|
||||
void EnterScope();
|
||||
|
||||
// 离开当前作用域
|
||||
void LeaveScope();
|
||||
|
||||
// 获取当前作用域深度
|
||||
size_t GetScopeDepth() const { return scopes_.size(); }
|
||||
|
||||
// 检查作用域栈是否为空
|
||||
bool IsEmpty() const { return scopes_.empty(); }
|
||||
|
||||
// ========== 变量符号管理 ==========
|
||||
|
||||
// 检查当前作用域是否包含指定变量
|
||||
bool CurrentScopeHasVar(const std::string& name) const;
|
||||
|
||||
// 绑定变量到当前作用域
|
||||
void BindVar(const std::string& name, const VarInfo& info, void* decl_ctx);
|
||||
|
||||
// 查找变量(从当前作用域向上遍历)
|
||||
bool LookupVar(const std::string& name, VarInfo& out_info, void*& out_decl_ctx) const;
|
||||
|
||||
// 快速查找变量(不获取详细信息)
|
||||
bool HasVar(const std::string& name) const {
|
||||
VarInfo info;
|
||||
void* ctx;
|
||||
return LookupVar(name, info, ctx);
|
||||
}
|
||||
|
||||
// ========== 函数符号管理 ==========
|
||||
|
||||
// 检查当前作用域是否包含指定函数
|
||||
bool CurrentScopeHasFunc(const std::string& name) const;
|
||||
|
||||
// 绑定函数到当前作用域
|
||||
void BindFunc(const std::string& name, const FuncInfo& info, void* decl_ctx);
|
||||
|
||||
// 查找函数(从当前作用域向上遍历)
|
||||
bool LookupFunc(const std::string& name, FuncInfo& out_info, void*& out_decl_ctx) const;
|
||||
|
||||
// 快速查找函数(不获取详细信息)
|
||||
bool HasFunc(const std::string& name) const {
|
||||
FuncInfo info;
|
||||
void* ctx;
|
||||
return LookupFunc(name, info, ctx);
|
||||
}
|
||||
|
||||
// ========== 循环状态管理 ==========
|
||||
|
||||
// 进入循环
|
||||
void EnterLoop();
|
||||
|
||||
// 离开循环
|
||||
void ExitLoop();
|
||||
|
||||
// 检查是否在循环内
|
||||
bool InLoop() const;
|
||||
|
||||
// 获取循环嵌套深度
|
||||
int GetLoopDepth() const { return loop_depth_; }
|
||||
|
||||
// ========== 辅助功能 ==========
|
||||
|
||||
// 清空所有作用域和状态
|
||||
void Clear();
|
||||
|
||||
// 获取当前作用域中所有变量名
|
||||
std::vector<std::string> GetCurrentScopeVarNames() const;
|
||||
|
||||
// 获取当前作用域中所有函数名
|
||||
std::vector<std::string> GetCurrentScopeFuncNames() const;
|
||||
|
||||
// 调试:打印符号表内容
|
||||
void Dump() const;
|
||||
|
||||
private:
|
||||
std::unordered_map<std::string, SysYParser::VarDefContext*> table_;
|
||||
private:
|
||||
// 作用域栈
|
||||
std::stack<ScopeEntry> scopes_;
|
||||
|
||||
// 循环嵌套深度
|
||||
int loop_depth_ = 0;
|
||||
};
|
||||
|
||||
// 类型兼容性检查函数
|
||||
inline bool IsTypeCompatible(SymbolType expected, SymbolType actual) {
|
||||
if (expected == SymbolType::TYPE_UNKNOWN || actual == SymbolType::TYPE_UNKNOWN) {
|
||||
return true; // 未知类型视为兼容
|
||||
}
|
||||
|
||||
// 基本类型兼容规则
|
||||
if (expected == actual) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// int 可以隐式转换为 float
|
||||
if (expected == SymbolType::TYPE_FLOAT && actual == SymbolType::TYPE_INT) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif // SYMBOL_TABLE_H
|
||||
@ -0,0 +1,7 @@
|
||||
|
||||
// Generated from SysY.g4 by ANTLR 4.7.2
|
||||
|
||||
|
||||
#include "SysYBaseVisitor.h"
|
||||
|
||||
|
||||
@ -0,0 +1,144 @@
|
||||
|
||||
// Generated from SysY.g4 by ANTLR 4.7.2
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "antlr4-runtime.h"
|
||||
#include "SysYVisitor.h"
|
||||
|
||||
|
||||
/**
|
||||
* This class provides an empty implementation of SysYVisitor, which can be
|
||||
* extended to create a visitor which only needs to handle a subset of the available methods.
|
||||
*/
|
||||
class SysYBaseVisitor : public SysYVisitor {
|
||||
public:
|
||||
|
||||
virtual antlrcpp::Any visitCompUnit(SysYParser::CompUnitContext *ctx) override {
|
||||
return visitChildren(ctx);
|
||||
}
|
||||
|
||||
virtual antlrcpp::Any visitDecl(SysYParser::DeclContext *ctx) override {
|
||||
return visitChildren(ctx);
|
||||
}
|
||||
|
||||
virtual antlrcpp::Any visitConstDecl(SysYParser::ConstDeclContext *ctx) override {
|
||||
return visitChildren(ctx);
|
||||
}
|
||||
|
||||
virtual antlrcpp::Any visitBType(SysYParser::BTypeContext *ctx) override {
|
||||
return visitChildren(ctx);
|
||||
}
|
||||
|
||||
virtual antlrcpp::Any visitConstDef(SysYParser::ConstDefContext *ctx) override {
|
||||
return visitChildren(ctx);
|
||||
}
|
||||
|
||||
virtual antlrcpp::Any visitConstInitVal(SysYParser::ConstInitValContext *ctx) override {
|
||||
return visitChildren(ctx);
|
||||
}
|
||||
|
||||
virtual antlrcpp::Any visitVarDecl(SysYParser::VarDeclContext *ctx) override {
|
||||
return visitChildren(ctx);
|
||||
}
|
||||
|
||||
virtual antlrcpp::Any visitVarDef(SysYParser::VarDefContext *ctx) override {
|
||||
return visitChildren(ctx);
|
||||
}
|
||||
|
||||
virtual antlrcpp::Any visitInitVal(SysYParser::InitValContext *ctx) override {
|
||||
return visitChildren(ctx);
|
||||
}
|
||||
|
||||
virtual antlrcpp::Any visitFuncDef(SysYParser::FuncDefContext *ctx) override {
|
||||
return visitChildren(ctx);
|
||||
}
|
||||
|
||||
virtual antlrcpp::Any visitFuncType(SysYParser::FuncTypeContext *ctx) override {
|
||||
return visitChildren(ctx);
|
||||
}
|
||||
|
||||
virtual antlrcpp::Any visitFuncFParams(SysYParser::FuncFParamsContext *ctx) override {
|
||||
return visitChildren(ctx);
|
||||
}
|
||||
|
||||
virtual antlrcpp::Any visitFuncFParam(SysYParser::FuncFParamContext *ctx) override {
|
||||
return visitChildren(ctx);
|
||||
}
|
||||
|
||||
virtual antlrcpp::Any visitBlock(SysYParser::BlockContext *ctx) override {
|
||||
return visitChildren(ctx);
|
||||
}
|
||||
|
||||
virtual antlrcpp::Any visitBlockItem(SysYParser::BlockItemContext *ctx) override {
|
||||
return visitChildren(ctx);
|
||||
}
|
||||
|
||||
virtual antlrcpp::Any visitStmt(SysYParser::StmtContext *ctx) override {
|
||||
return visitChildren(ctx);
|
||||
}
|
||||
|
||||
virtual antlrcpp::Any visitExp(SysYParser::ExpContext *ctx) override {
|
||||
return visitChildren(ctx);
|
||||
}
|
||||
|
||||
virtual antlrcpp::Any visitCond(SysYParser::CondContext *ctx) override {
|
||||
return visitChildren(ctx);
|
||||
}
|
||||
|
||||
virtual antlrcpp::Any visitLVal(SysYParser::LValContext *ctx) override {
|
||||
return visitChildren(ctx);
|
||||
}
|
||||
|
||||
virtual antlrcpp::Any visitPrimaryExp(SysYParser::PrimaryExpContext *ctx) override {
|
||||
return visitChildren(ctx);
|
||||
}
|
||||
|
||||
virtual antlrcpp::Any visitNumber(SysYParser::NumberContext *ctx) override {
|
||||
return visitChildren(ctx);
|
||||
}
|
||||
|
||||
virtual antlrcpp::Any visitUnaryExp(SysYParser::UnaryExpContext *ctx) override {
|
||||
return visitChildren(ctx);
|
||||
}
|
||||
|
||||
virtual antlrcpp::Any visitUnaryOp(SysYParser::UnaryOpContext *ctx) override {
|
||||
return visitChildren(ctx);
|
||||
}
|
||||
|
||||
virtual antlrcpp::Any visitFuncRParams(SysYParser::FuncRParamsContext *ctx) override {
|
||||
return visitChildren(ctx);
|
||||
}
|
||||
|
||||
virtual antlrcpp::Any visitMulExp(SysYParser::MulExpContext *ctx) override {
|
||||
return visitChildren(ctx);
|
||||
}
|
||||
|
||||
virtual antlrcpp::Any visitAddExp(SysYParser::AddExpContext *ctx) override {
|
||||
return visitChildren(ctx);
|
||||
}
|
||||
|
||||
virtual antlrcpp::Any visitRelExp(SysYParser::RelExpContext *ctx) override {
|
||||
return visitChildren(ctx);
|
||||
}
|
||||
|
||||
virtual antlrcpp::Any visitEqExp(SysYParser::EqExpContext *ctx) override {
|
||||
return visitChildren(ctx);
|
||||
}
|
||||
|
||||
virtual antlrcpp::Any visitLAndExp(SysYParser::LAndExpContext *ctx) override {
|
||||
return visitChildren(ctx);
|
||||
}
|
||||
|
||||
virtual antlrcpp::Any visitLOrExp(SysYParser::LOrExpContext *ctx) override {
|
||||
return visitChildren(ctx);
|
||||
}
|
||||
|
||||
virtual antlrcpp::Any visitConstExp(SysYParser::ConstExpContext *ctx) override {
|
||||
return visitChildren(ctx);
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
@ -0,0 +1,377 @@
|
||||
|
||||
// Generated from SysY.g4 by ANTLR 4.7.2
|
||||
|
||||
|
||||
#include "SysYLexer.h"
|
||||
|
||||
|
||||
using namespace antlr4;
|
||||
|
||||
|
||||
SysYLexer::SysYLexer(CharStream *input) : Lexer(input) {
|
||||
_interpreter = new atn::LexerATNSimulator(this, _atn, _decisionToDFA, _sharedContextCache);
|
||||
}
|
||||
|
||||
SysYLexer::~SysYLexer() {
|
||||
delete _interpreter;
|
||||
}
|
||||
|
||||
std::string SysYLexer::getGrammarFileName() const {
|
||||
return "SysY.g4";
|
||||
}
|
||||
|
||||
const std::vector<std::string>& SysYLexer::getRuleNames() const {
|
||||
return _ruleNames;
|
||||
}
|
||||
|
||||
const std::vector<std::string>& SysYLexer::getChannelNames() const {
|
||||
return _channelNames;
|
||||
}
|
||||
|
||||
const std::vector<std::string>& SysYLexer::getModeNames() const {
|
||||
return _modeNames;
|
||||
}
|
||||
|
||||
const std::vector<std::string>& SysYLexer::getTokenNames() const {
|
||||
return _tokenNames;
|
||||
}
|
||||
|
||||
dfa::Vocabulary& SysYLexer::getVocabulary() const {
|
||||
return _vocabulary;
|
||||
}
|
||||
|
||||
const std::vector<uint16_t> SysYLexer::getSerializedATN() const {
|
||||
return _serializedATN;
|
||||
}
|
||||
|
||||
const atn::ATN& SysYLexer::getATN() const {
|
||||
return _atn;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Static vars and initialization.
|
||||
std::vector<dfa::DFA> SysYLexer::_decisionToDFA;
|
||||
atn::PredictionContextCache SysYLexer::_sharedContextCache;
|
||||
|
||||
// We own the ATN which in turn owns the ATN states.
|
||||
atn::ATN SysYLexer::_atn;
|
||||
std::vector<uint16_t> SysYLexer::_serializedATN;
|
||||
|
||||
std::vector<std::string> SysYLexer::_ruleNames = {
|
||||
u8"T__0", u8"T__1", u8"T__2", u8"T__3", u8"T__4", u8"T__5", u8"T__6",
|
||||
u8"T__7", u8"T__8", u8"T__9", u8"T__10", u8"T__11", u8"T__12", u8"T__13",
|
||||
u8"T__14", u8"T__15", u8"T__16", u8"T__17", u8"T__18", u8"T__19", u8"T__20",
|
||||
u8"T__21", u8"T__22", u8"T__23", u8"T__24", u8"T__25", u8"T__26", u8"T__27",
|
||||
u8"T__28", u8"T__29", u8"T__30", u8"T__31", u8"T__32", u8"DIGIT", u8"HEXDIGIT",
|
||||
u8"EXP", u8"PEXP", u8"FloatConst", u8"IntConst", u8"Ident", u8"WS", u8"LINE_COMMENT",
|
||||
u8"BLOCK_COMMENT"
|
||||
};
|
||||
|
||||
std::vector<std::string> SysYLexer::_channelNames = {
|
||||
"DEFAULT_TOKEN_CHANNEL", "HIDDEN"
|
||||
};
|
||||
|
||||
std::vector<std::string> SysYLexer::_modeNames = {
|
||||
u8"DEFAULT_MODE"
|
||||
};
|
||||
|
||||
std::vector<std::string> SysYLexer::_literalNames = {
|
||||
"", u8"'const'", u8"','", u8"';'", u8"'int'", u8"'float'", u8"'['", u8"']'",
|
||||
u8"'='", u8"'{'", u8"'}'", u8"'('", u8"')'", u8"'void'", u8"'if'", u8"'else'",
|
||||
u8"'while'", u8"'break'", u8"'continue'", u8"'return'", u8"'+'", u8"'-'",
|
||||
u8"'!'", u8"'*'", u8"'/'", u8"'%'", u8"'<'", u8"'>'", u8"'<='", u8"'>='",
|
||||
u8"'=='", u8"'!='", u8"'&&'", u8"'||'"
|
||||
};
|
||||
|
||||
std::vector<std::string> SysYLexer::_symbolicNames = {
|
||||
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
|
||||
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", u8"FloatConst",
|
||||
u8"IntConst", u8"Ident", u8"WS", u8"LINE_COMMENT", u8"BLOCK_COMMENT"
|
||||
};
|
||||
|
||||
dfa::Vocabulary SysYLexer::_vocabulary(_literalNames, _symbolicNames);
|
||||
|
||||
std::vector<std::string> SysYLexer::_tokenNames;
|
||||
|
||||
SysYLexer::Initializer::Initializer() {
|
||||
// This code could be in a static initializer lambda, but VS doesn't allow access to private class members from there.
|
||||
for (size_t i = 0; i < _symbolicNames.size(); ++i) {
|
||||
std::string name = _vocabulary.getLiteralName(i);
|
||||
if (name.empty()) {
|
||||
name = _vocabulary.getSymbolicName(i);
|
||||
}
|
||||
|
||||
if (name.empty()) {
|
||||
_tokenNames.push_back("<INVALID>");
|
||||
} else {
|
||||
_tokenNames.push_back(name);
|
||||
}
|
||||
}
|
||||
|
||||
_serializedATN = {
|
||||
0x3, 0x608b, 0xa72a, 0x8133, 0xb9ed, 0x417c, 0x3be7, 0x7786, 0x5964,
|
||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 0x3, 0x1f, 0x3, 0x20, 0x3, 0x20, 0x3, 0x20, 0x3, 0x21,
|
||||
0x3, 0x21, 0x3, 0x21, 0x3, 0x22, 0x3, 0x22, 0x3, 0x22, 0x3, 0x23, 0x3,
|
||||
0x23, 0x3, 0x24, 0x3, 0x24, 0x3, 0x25, 0x3, 0x25, 0x5, 0x25, 0xcd, 0xa,
|
||||
0x25, 0x3, 0x25, 0x6, 0x25, 0xd0, 0xa, 0x25, 0xd, 0x25, 0xe, 0x25, 0xd1,
|
||||
0x3, 0x26, 0x3, 0x26, 0x5, 0x26, 0xd6, 0xa, 0x26, 0x3, 0x26, 0x6, 0x26,
|
||||
0xd9, 0xa, 0x26, 0xd, 0x26, 0xe, 0x26, 0xda, 0x3, 0x27, 0x3, 0x27, 0x3,
|
||||
0x27, 0x3, 0x27, 0x5, 0x27, 0xe1, 0xa, 0x27, 0x3, 0x27, 0x6, 0x27, 0xe4,
|
||||
0xa, 0x27, 0xd, 0x27, 0xe, 0x27, 0xe5, 0x3, 0x27, 0x3, 0x27, 0x7, 0x27,
|
||||
0xea, 0xa, 0x27, 0xc, 0x27, 0xe, 0x27, 0xed, 0xb, 0x27, 0x3, 0x27, 0x3,
|
||||
0x27, 0x6, 0x27, 0xf1, 0xa, 0x27, 0xd, 0x27, 0xe, 0x27, 0xf2, 0x3, 0x27,
|
||||
0x6, 0x27, 0xf6, 0xa, 0x27, 0xd, 0x27, 0xe, 0x27, 0xf7, 0x5, 0x27, 0xfa,
|
||||
0xa, 0x27, 0x3, 0x27, 0x3, 0x27, 0x3, 0x27, 0x3, 0x27, 0x6, 0x27, 0x100,
|
||||
0xa, 0x27, 0xd, 0x27, 0xe, 0x27, 0x101, 0x3, 0x27, 0x5, 0x27, 0x105,
|
||||
0xa, 0x27, 0x3, 0x27, 0x6, 0x27, 0x108, 0xa, 0x27, 0xd, 0x27, 0xe, 0x27,
|
||||
0x109, 0x3, 0x27, 0x3, 0x27, 0x7, 0x27, 0x10e, 0xa, 0x27, 0xc, 0x27,
|
||||
0xe, 0x27, 0x111, 0xb, 0x27, 0x3, 0x27, 0x5, 0x27, 0x114, 0xa, 0x27,
|
||||
0x3, 0x27, 0x6, 0x27, 0x117, 0xa, 0x27, 0xd, 0x27, 0xe, 0x27, 0x118,
|
||||
0x3, 0x27, 0x3, 0x27, 0x5, 0x27, 0x11d, 0xa, 0x27, 0x3, 0x28, 0x3, 0x28,
|
||||
0x3, 0x28, 0x7, 0x28, 0x122, 0xa, 0x28, 0xc, 0x28, 0xe, 0x28, 0x125,
|
||||
0xb, 0x28, 0x3, 0x28, 0x3, 0x28, 0x6, 0x28, 0x129, 0xa, 0x28, 0xd, 0x28,
|
||||
0xe, 0x28, 0x12a, 0x3, 0x28, 0x3, 0x28, 0x3, 0x28, 0x3, 0x28, 0x5, 0x28,
|
||||
0x131, 0xa, 0x28, 0x3, 0x28, 0x6, 0x28, 0x134, 0xa, 0x28, 0xd, 0x28,
|
||||
0xe, 0x28, 0x135, 0x5, 0x28, 0x138, 0xa, 0x28, 0x3, 0x29, 0x3, 0x29,
|
||||
0x7, 0x29, 0x13c, 0xa, 0x29, 0xc, 0x29, 0xe, 0x29, 0x13f, 0xb, 0x29,
|
||||
0x3, 0x2a, 0x6, 0x2a, 0x142, 0xa, 0x2a, 0xd, 0x2a, 0xe, 0x2a, 0x143,
|
||||
0x3, 0x2a, 0x3, 0x2a, 0x3, 0x2b, 0x3, 0x2b, 0x3, 0x2b, 0x3, 0x2b, 0x7,
|
||||
0x2b, 0x14c, 0xa, 0x2b, 0xc, 0x2b, 0xe, 0x2b, 0x14f, 0xb, 0x2b, 0x3,
|
||||
0x2b, 0x3, 0x2b, 0x3, 0x2c, 0x3, 0x2c, 0x3, 0x2c, 0x3, 0x2c, 0x7, 0x2c,
|
||||
0x157, 0xa, 0x2c, 0xc, 0x2c, 0xe, 0x2c, 0x15a, 0xb, 0x2c, 0x3, 0x2c,
|
||||
0x3, 0x2c, 0x3, 0x2c, 0x3, 0x2c, 0x3, 0x2c, 0x3, 0x158, 0x2, 0x2d, 0x3,
|
||||
0x3, 0x5, 0x4, 0x7, 0x5, 0x9, 0x6, 0xb, 0x7, 0xd, 0x8, 0xf, 0x9, 0x11,
|
||||
0xa, 0x13, 0xb, 0x15, 0xc, 0x17, 0xd, 0x19, 0xe, 0x1b, 0xf, 0x1d, 0x10,
|
||||
0x1f, 0x11, 0x21, 0x12, 0x23, 0x13, 0x25, 0x14, 0x27, 0x15, 0x29, 0x16,
|
||||
0x2b, 0x17, 0x2d, 0x18, 0x2f, 0x19, 0x31, 0x1a, 0x33, 0x1b, 0x35, 0x1c,
|
||||
0x37, 0x1d, 0x39, 0x1e, 0x3b, 0x1f, 0x3d, 0x20, 0x3f, 0x21, 0x41, 0x22,
|
||||
0x43, 0x23, 0x45, 0x2, 0x47, 0x2, 0x49, 0x2, 0x4b, 0x2, 0x4d, 0x24,
|
||||
0x4f, 0x25, 0x51, 0x26, 0x53, 0x27, 0x55, 0x28, 0x57, 0x29, 0x3, 0x2,
|
||||
0xd, 0x3, 0x2, 0x32, 0x3b, 0x5, 0x2, 0x32, 0x3b, 0x43, 0x48, 0x63, 0x68,
|
||||
0x4, 0x2, 0x47, 0x47, 0x67, 0x67, 0x4, 0x2, 0x2d, 0x2d, 0x2f, 0x2f,
|
||||
0x4, 0x2, 0x52, 0x52, 0x72, 0x72, 0x3, 0x2, 0x33, 0x3b, 0x3, 0x2, 0x32,
|
||||
0x39, 0x5, 0x2, 0x43, 0x5c, 0x61, 0x61, 0x63, 0x7c, 0x6, 0x2, 0x32,
|
||||
0x3b, 0x43, 0x5c, 0x61, 0x61, 0x63, 0x7c, 0x5, 0x2, 0xb, 0xc, 0xf, 0xf,
|
||||
0x22, 0x22, 0x4, 0x2, 0xc, 0xc, 0xf, 0xf, 0x2, 0x17a, 0x2, 0x3, 0x3,
|
||||
0x2, 0x2, 0x2, 0x2, 0x5, 0x3, 0x2, 0x2, 0x2, 0x2, 0x7, 0x3, 0x2, 0x2,
|
||||
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2, 0x2, 0xf7, 0xf5,
|
||||
0x3, 0x2, 0x2, 0x2, 0xf7, 0xf8, 0x3, 0x2, 0x2, 0x2, 0xf8, 0xfa, 0x3,
|
||||
0x2, 0x2, 0x2, 0xf9, 0xe3, 0x3, 0x2, 0x2, 0x2, 0xf9, 0xee, 0x3, 0x2,
|
||||
0x2, 0x2, 0xf9, 0xf5, 0x3, 0x2, 0x2, 0x2, 0xfa, 0xfb, 0x3, 0x2, 0x2,
|
||||
0x2, 0xfb, 0xfc, 0x5, 0x4b, 0x26, 0x2, 0xfc, 0x11d, 0x3, 0x2, 0x2, 0x2,
|
||||
0xfd, 0xff, 0x7, 0x30, 0x2, 0x2, 0xfe, 0x100, 0x5, 0x45, 0x23, 0x2,
|
||||
0xff, 0xfe, 0x3, 0x2, 0x2, 0x2, 0x100, 0x101, 0x3, 0x2, 0x2, 0x2, 0x101,
|
||||
0xff, 0x3, 0x2, 0x2, 0x2, 0x101, 0x102, 0x3, 0x2, 0x2, 0x2, 0x102, 0x104,
|
||||
0x3, 0x2, 0x2, 0x2, 0x103, 0x105, 0x5, 0x49, 0x25, 0x2, 0x104, 0x103,
|
||||
0x3, 0x2, 0x2, 0x2, 0x104, 0x105, 0x3, 0x2, 0x2, 0x2, 0x105, 0x11d,
|
||||
0x3, 0x2, 0x2, 0x2, 0x106, 0x108, 0x5, 0x45, 0x23, 0x2, 0x107, 0x106,
|
||||
0x3, 0x2, 0x2, 0x2, 0x108, 0x109, 0x3, 0x2, 0x2, 0x2, 0x109, 0x107,
|
||||
0x3, 0x2, 0x2, 0x2, 0x109, 0x10a, 0x3, 0x2, 0x2, 0x2, 0x10a, 0x10b,
|
||||
0x3, 0x2, 0x2, 0x2, 0x10b, 0x10f, 0x7, 0x30, 0x2, 0x2, 0x10c, 0x10e,
|
||||
0x5, 0x45, 0x23, 0x2, 0x10d, 0x10c, 0x3, 0x2, 0x2, 0x2, 0x10e, 0x111,
|
||||
0x3, 0x2, 0x2, 0x2, 0x10f, 0x10d, 0x3, 0x2, 0x2, 0x2, 0x10f, 0x110,
|
||||
0x3, 0x2, 0x2, 0x2, 0x110, 0x113, 0x3, 0x2, 0x2, 0x2, 0x111, 0x10f,
|
||||
0x3, 0x2, 0x2, 0x2, 0x112, 0x114, 0x5, 0x49, 0x25, 0x2, 0x113, 0x112,
|
||||
0x3, 0x2, 0x2, 0x2, 0x113, 0x114, 0x3, 0x2, 0x2, 0x2, 0x114, 0x11d,
|
||||
0x3, 0x2, 0x2, 0x2, 0x115, 0x117, 0x5, 0x45, 0x23, 0x2, 0x116, 0x115,
|
||||
0x3, 0x2, 0x2, 0x2, 0x117, 0x118, 0x3, 0x2, 0x2, 0x2, 0x118, 0x116,
|
||||
0x3, 0x2, 0x2, 0x2, 0x118, 0x119, 0x3, 0x2, 0x2, 0x2, 0x119, 0x11a,
|
||||
0x3, 0x2, 0x2, 0x2, 0x11a, 0x11b, 0x5, 0x49, 0x25, 0x2, 0x11b, 0x11d,
|
||||
0x3, 0x2, 0x2, 0x2, 0x11c, 0xe0, 0x3, 0x2, 0x2, 0x2, 0x11c, 0xfd, 0x3,
|
||||
0x2, 0x2, 0x2, 0x11c, 0x107, 0x3, 0x2, 0x2, 0x2, 0x11c, 0x116, 0x3,
|
||||
0x2, 0x2, 0x2, 0x11d, 0x4e, 0x3, 0x2, 0x2, 0x2, 0x11e, 0x138, 0x7, 0x32,
|
||||
0x2, 0x2, 0x11f, 0x123, 0x9, 0x7, 0x2, 0x2, 0x120, 0x122, 0x9, 0x2,
|
||||
0x2, 0x2, 0x121, 0x120, 0x3, 0x2, 0x2, 0x2, 0x122, 0x125, 0x3, 0x2,
|
||||
0x2, 0x2, 0x123, 0x121, 0x3, 0x2, 0x2, 0x2, 0x123, 0x124, 0x3, 0x2,
|
||||
0x2, 0x2, 0x124, 0x138, 0x3, 0x2, 0x2, 0x2, 0x125, 0x123, 0x3, 0x2,
|
||||
0x2, 0x2, 0x126, 0x128, 0x7, 0x32, 0x2, 0x2, 0x127, 0x129, 0x9, 0x8,
|
||||
0x2, 0x2, 0x128, 0x127, 0x3, 0x2, 0x2, 0x2, 0x129, 0x12a, 0x3, 0x2,
|
||||
0x2, 0x2, 0x12a, 0x128, 0x3, 0x2, 0x2, 0x2, 0x12a, 0x12b, 0x3, 0x2,
|
||||
0x2, 0x2, 0x12b, 0x138, 0x3, 0x2, 0x2, 0x2, 0x12c, 0x12d, 0x7, 0x32,
|
||||
0x2, 0x2, 0x12d, 0x131, 0x7, 0x7a, 0x2, 0x2, 0x12e, 0x12f, 0x7, 0x32,
|
||||
0x2, 0x2, 0x12f, 0x131, 0x7, 0x5a, 0x2, 0x2, 0x130, 0x12c, 0x3, 0x2,
|
||||
0x2, 0x2, 0x130, 0x12e, 0x3, 0x2, 0x2, 0x2, 0x131, 0x133, 0x3, 0x2,
|
||||
0x2, 0x2, 0x132, 0x134, 0x9, 0x3, 0x2, 0x2, 0x133, 0x132, 0x3, 0x2,
|
||||
0x2, 0x2, 0x134, 0x135, 0x3, 0x2, 0x2, 0x2, 0x135, 0x133, 0x3, 0x2,
|
||||
0x2, 0x2, 0x135, 0x136, 0x3, 0x2, 0x2, 0x2, 0x136, 0x138, 0x3, 0x2,
|
||||
0x2, 0x2, 0x137, 0x11e, 0x3, 0x2, 0x2, 0x2, 0x137, 0x11f, 0x3, 0x2,
|
||||
0x2, 0x2, 0x137, 0x126, 0x3, 0x2, 0x2, 0x2, 0x137, 0x130, 0x3, 0x2,
|
||||
0x2, 0x2, 0x138, 0x50, 0x3, 0x2, 0x2, 0x2, 0x139, 0x13d, 0x9, 0x9, 0x2,
|
||||
0x2, 0x13a, 0x13c, 0x9, 0xa, 0x2, 0x2, 0x13b, 0x13a, 0x3, 0x2, 0x2,
|
||||
0x2, 0x13c, 0x13f, 0x3, 0x2, 0x2, 0x2, 0x13d, 0x13b, 0x3, 0x2, 0x2,
|
||||
0x2, 0x13d, 0x13e, 0x3, 0x2, 0x2, 0x2, 0x13e, 0x52, 0x3, 0x2, 0x2, 0x2,
|
||||
0x13f, 0x13d, 0x3, 0x2, 0x2, 0x2, 0x140, 0x142, 0x9, 0xb, 0x2, 0x2,
|
||||
0x141, 0x140, 0x3, 0x2, 0x2, 0x2, 0x142, 0x143, 0x3, 0x2, 0x2, 0x2,
|
||||
0x143, 0x141, 0x3, 0x2, 0x2, 0x2, 0x143, 0x144, 0x3, 0x2, 0x2, 0x2,
|
||||
0x144, 0x145, 0x3, 0x2, 0x2, 0x2, 0x145, 0x146, 0x8, 0x2a, 0x2, 0x2,
|
||||
0x146, 0x54, 0x3, 0x2, 0x2, 0x2, 0x147, 0x148, 0x7, 0x31, 0x2, 0x2,
|
||||
0x148, 0x149, 0x7, 0x31, 0x2, 0x2, 0x149, 0x14d, 0x3, 0x2, 0x2, 0x2,
|
||||
0x14a, 0x14c, 0xa, 0xc, 0x2, 0x2, 0x14b, 0x14a, 0x3, 0x2, 0x2, 0x2,
|
||||
0x14c, 0x14f, 0x3, 0x2, 0x2, 0x2, 0x14d, 0x14b, 0x3, 0x2, 0x2, 0x2,
|
||||
0x14d, 0x14e, 0x3, 0x2, 0x2, 0x2, 0x14e, 0x150, 0x3, 0x2, 0x2, 0x2,
|
||||
0x14f, 0x14d, 0x3, 0x2, 0x2, 0x2, 0x150, 0x151, 0x8, 0x2b, 0x2, 0x2,
|
||||
0x151, 0x56, 0x3, 0x2, 0x2, 0x2, 0x152, 0x153, 0x7, 0x31, 0x2, 0x2,
|
||||
0x153, 0x154, 0x7, 0x2c, 0x2, 0x2, 0x154, 0x158, 0x3, 0x2, 0x2, 0x2,
|
||||
0x155, 0x157, 0xb, 0x2, 0x2, 0x2, 0x156, 0x155, 0x3, 0x2, 0x2, 0x2,
|
||||
0x157, 0x15a, 0x3, 0x2, 0x2, 0x2, 0x158, 0x159, 0x3, 0x2, 0x2, 0x2,
|
||||
0x158, 0x156, 0x3, 0x2, 0x2, 0x2, 0x159, 0x15b, 0x3, 0x2, 0x2, 0x2,
|
||||
0x15a, 0x158, 0x3, 0x2, 0x2, 0x2, 0x15b, 0x15c, 0x7, 0x2c, 0x2, 0x2,
|
||||
0x15c, 0x15d, 0x7, 0x31, 0x2, 0x2, 0x15d, 0x15e, 0x3, 0x2, 0x2, 0x2,
|
||||
0x15e, 0x15f, 0x8, 0x2c, 0x2, 0x2, 0x15f, 0x58, 0x3, 0x2, 0x2, 0x2,
|
||||
0x1d, 0x2, 0xcc, 0xd1, 0xd5, 0xda, 0xe0, 0xe5, 0xeb, 0xf2, 0xf7, 0xf9,
|
||||
0x101, 0x104, 0x109, 0x10f, 0x113, 0x118, 0x11c, 0x123, 0x12a, 0x130,
|
||||
0x135, 0x137, 0x13d, 0x143, 0x14d, 0x158, 0x3, 0x8, 0x2, 0x2,
|
||||
};
|
||||
|
||||
atn::ATNDeserializer deserializer;
|
||||
_atn = deserializer.deserialize(_serializedATN);
|
||||
|
||||
size_t count = _atn.getNumberOfDecisions();
|
||||
_decisionToDFA.reserve(count);
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
_decisionToDFA.emplace_back(_atn.getDecisionState(i), i);
|
||||
}
|
||||
}
|
||||
|
||||
SysYLexer::Initializer SysYLexer::_init;
|
||||
@ -0,0 +1,62 @@
|
||||
|
||||
// Generated from SysY.g4 by ANTLR 4.7.2
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "antlr4-runtime.h"
|
||||
|
||||
|
||||
|
||||
|
||||
class SysYLexer : public antlr4::Lexer {
|
||||
public:
|
||||
enum {
|
||||
T__0 = 1, T__1 = 2, T__2 = 3, T__3 = 4, T__4 = 5, T__5 = 6, T__6 = 7,
|
||||
T__7 = 8, T__8 = 9, T__9 = 10, T__10 = 11, T__11 = 12, T__12 = 13, T__13 = 14,
|
||||
T__14 = 15, T__15 = 16, T__16 = 17, T__17 = 18, T__18 = 19, T__19 = 20,
|
||||
T__20 = 21, T__21 = 22, T__22 = 23, T__23 = 24, T__24 = 25, T__25 = 26,
|
||||
T__26 = 27, T__27 = 28, T__28 = 29, T__29 = 30, T__30 = 31, T__31 = 32,
|
||||
T__32 = 33, FloatConst = 34, IntConst = 35, Ident = 36, WS = 37, LINE_COMMENT = 38,
|
||||
BLOCK_COMMENT = 39
|
||||
};
|
||||
|
||||
SysYLexer(antlr4::CharStream *input);
|
||||
~SysYLexer();
|
||||
|
||||
virtual std::string getGrammarFileName() const override;
|
||||
virtual const std::vector<std::string>& getRuleNames() const override;
|
||||
|
||||
virtual const std::vector<std::string>& getChannelNames() const override;
|
||||
virtual const std::vector<std::string>& getModeNames() const override;
|
||||
virtual const std::vector<std::string>& getTokenNames() const override; // deprecated, use vocabulary instead
|
||||
virtual antlr4::dfa::Vocabulary& getVocabulary() const override;
|
||||
|
||||
virtual const std::vector<uint16_t> getSerializedATN() const override;
|
||||
virtual const antlr4::atn::ATN& getATN() const override;
|
||||
|
||||
private:
|
||||
static std::vector<antlr4::dfa::DFA> _decisionToDFA;
|
||||
static antlr4::atn::PredictionContextCache _sharedContextCache;
|
||||
static std::vector<std::string> _ruleNames;
|
||||
static std::vector<std::string> _tokenNames;
|
||||
static std::vector<std::string> _channelNames;
|
||||
static std::vector<std::string> _modeNames;
|
||||
|
||||
static std::vector<std::string> _literalNames;
|
||||
static std::vector<std::string> _symbolicNames;
|
||||
static antlr4::dfa::Vocabulary _vocabulary;
|
||||
static antlr4::atn::ATN _atn;
|
||||
static std::vector<uint16_t> _serializedATN;
|
||||
|
||||
|
||||
// Individual action functions triggered by action() above.
|
||||
|
||||
// Individual semantic predicate functions triggered by sempred() above.
|
||||
|
||||
struct Initializer {
|
||||
Initializer();
|
||||
};
|
||||
static Initializer _init;
|
||||
};
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,513 @@
|
||||
|
||||
// Generated from SysY.g4 by ANTLR 4.7.2
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "antlr4-runtime.h"
|
||||
|
||||
|
||||
|
||||
|
||||
class SysYParser : public antlr4::Parser {
|
||||
public:
|
||||
enum {
|
||||
T__0 = 1, T__1 = 2, T__2 = 3, T__3 = 4, T__4 = 5, T__5 = 6, T__6 = 7,
|
||||
T__7 = 8, T__8 = 9, T__9 = 10, T__10 = 11, T__11 = 12, T__12 = 13, T__13 = 14,
|
||||
T__14 = 15, T__15 = 16, T__16 = 17, T__17 = 18, T__18 = 19, T__19 = 20,
|
||||
T__20 = 21, T__21 = 22, T__22 = 23, T__23 = 24, T__24 = 25, T__25 = 26,
|
||||
T__26 = 27, T__27 = 28, T__28 = 29, T__29 = 30, T__30 = 31, T__31 = 32,
|
||||
T__32 = 33, FloatConst = 34, IntConst = 35, Ident = 36, WS = 37, LINE_COMMENT = 38,
|
||||
BLOCK_COMMENT = 39
|
||||
};
|
||||
|
||||
enum {
|
||||
RuleCompUnit = 0, RuleDecl = 1, RuleConstDecl = 2, RuleBType = 3, RuleConstDef = 4,
|
||||
RuleConstInitVal = 5, RuleVarDecl = 6, RuleVarDef = 7, RuleInitVal = 8,
|
||||
RuleFuncDef = 9, RuleFuncType = 10, RuleFuncFParams = 11, RuleFuncFParam = 12,
|
||||
RuleBlock = 13, RuleBlockItem = 14, RuleStmt = 15, RuleExp = 16, RuleCond = 17,
|
||||
RuleLVal = 18, RulePrimaryExp = 19, RuleNumber = 20, RuleUnaryExp = 21,
|
||||
RuleUnaryOp = 22, RuleFuncRParams = 23, RuleMulExp = 24, RuleAddExp = 25,
|
||||
RuleRelExp = 26, RuleEqExp = 27, RuleLAndExp = 28, RuleLOrExp = 29,
|
||||
RuleConstExp = 30
|
||||
};
|
||||
|
||||
SysYParser(antlr4::TokenStream *input);
|
||||
~SysYParser();
|
||||
|
||||
virtual std::string getGrammarFileName() const override;
|
||||
virtual const antlr4::atn::ATN& getATN() const override { return _atn; };
|
||||
virtual const std::vector<std::string>& getTokenNames() const override { return _tokenNames; }; // deprecated: use vocabulary instead.
|
||||
virtual const std::vector<std::string>& getRuleNames() const override;
|
||||
virtual antlr4::dfa::Vocabulary& getVocabulary() const override;
|
||||
|
||||
|
||||
class CompUnitContext;
|
||||
class DeclContext;
|
||||
class ConstDeclContext;
|
||||
class BTypeContext;
|
||||
class ConstDefContext;
|
||||
class ConstInitValContext;
|
||||
class VarDeclContext;
|
||||
class VarDefContext;
|
||||
class InitValContext;
|
||||
class FuncDefContext;
|
||||
class FuncTypeContext;
|
||||
class FuncFParamsContext;
|
||||
class FuncFParamContext;
|
||||
class BlockContext;
|
||||
class BlockItemContext;
|
||||
class StmtContext;
|
||||
class ExpContext;
|
||||
class CondContext;
|
||||
class LValContext;
|
||||
class PrimaryExpContext;
|
||||
class NumberContext;
|
||||
class UnaryExpContext;
|
||||
class UnaryOpContext;
|
||||
class FuncRParamsContext;
|
||||
class MulExpContext;
|
||||
class AddExpContext;
|
||||
class RelExpContext;
|
||||
class EqExpContext;
|
||||
class LAndExpContext;
|
||||
class LOrExpContext;
|
||||
class ConstExpContext;
|
||||
|
||||
class CompUnitContext : public antlr4::ParserRuleContext {
|
||||
public:
|
||||
CompUnitContext(antlr4::ParserRuleContext *parent, size_t invokingState);
|
||||
virtual size_t getRuleIndex() const override;
|
||||
std::vector<DeclContext *> decl();
|
||||
DeclContext* decl(size_t i);
|
||||
std::vector<FuncDefContext *> funcDef();
|
||||
FuncDefContext* funcDef(size_t i);
|
||||
|
||||
virtual antlrcpp::Any accept(antlr4::tree::ParseTreeVisitor *visitor) override;
|
||||
|
||||
};
|
||||
|
||||
CompUnitContext* compUnit();
|
||||
|
||||
class DeclContext : public antlr4::ParserRuleContext {
|
||||
public:
|
||||
DeclContext(antlr4::ParserRuleContext *parent, size_t invokingState);
|
||||
virtual size_t getRuleIndex() const override;
|
||||
ConstDeclContext *constDecl();
|
||||
VarDeclContext *varDecl();
|
||||
|
||||
virtual antlrcpp::Any accept(antlr4::tree::ParseTreeVisitor *visitor) override;
|
||||
|
||||
};
|
||||
|
||||
DeclContext* decl();
|
||||
|
||||
class ConstDeclContext : public antlr4::ParserRuleContext {
|
||||
public:
|
||||
ConstDeclContext(antlr4::ParserRuleContext *parent, size_t invokingState);
|
||||
virtual size_t getRuleIndex() const override;
|
||||
BTypeContext *bType();
|
||||
std::vector<ConstDefContext *> constDef();
|
||||
ConstDefContext* constDef(size_t i);
|
||||
|
||||
virtual antlrcpp::Any accept(antlr4::tree::ParseTreeVisitor *visitor) override;
|
||||
|
||||
};
|
||||
|
||||
ConstDeclContext* constDecl();
|
||||
|
||||
class BTypeContext : public antlr4::ParserRuleContext {
|
||||
public:
|
||||
BTypeContext(antlr4::ParserRuleContext *parent, size_t invokingState);
|
||||
virtual size_t getRuleIndex() const override;
|
||||
|
||||
virtual antlrcpp::Any accept(antlr4::tree::ParseTreeVisitor *visitor) override;
|
||||
|
||||
};
|
||||
|
||||
BTypeContext* bType();
|
||||
|
||||
class ConstDefContext : public antlr4::ParserRuleContext {
|
||||
public:
|
||||
ConstDefContext(antlr4::ParserRuleContext *parent, size_t invokingState);
|
||||
virtual size_t getRuleIndex() const override;
|
||||
antlr4::tree::TerminalNode *Ident();
|
||||
ConstInitValContext *constInitVal();
|
||||
std::vector<ConstExpContext *> constExp();
|
||||
ConstExpContext* constExp(size_t i);
|
||||
|
||||
virtual antlrcpp::Any accept(antlr4::tree::ParseTreeVisitor *visitor) override;
|
||||
|
||||
};
|
||||
|
||||
ConstDefContext* constDef();
|
||||
|
||||
class ConstInitValContext : public antlr4::ParserRuleContext {
|
||||
public:
|
||||
ConstInitValContext(antlr4::ParserRuleContext *parent, size_t invokingState);
|
||||
virtual size_t getRuleIndex() const override;
|
||||
ConstExpContext *constExp();
|
||||
std::vector<ConstInitValContext *> constInitVal();
|
||||
ConstInitValContext* constInitVal(size_t i);
|
||||
|
||||
virtual antlrcpp::Any accept(antlr4::tree::ParseTreeVisitor *visitor) override;
|
||||
|
||||
};
|
||||
|
||||
ConstInitValContext* constInitVal();
|
||||
|
||||
class VarDeclContext : public antlr4::ParserRuleContext {
|
||||
public:
|
||||
VarDeclContext(antlr4::ParserRuleContext *parent, size_t invokingState);
|
||||
virtual size_t getRuleIndex() const override;
|
||||
BTypeContext *bType();
|
||||
std::vector<VarDefContext *> varDef();
|
||||
VarDefContext* varDef(size_t i);
|
||||
|
||||
virtual antlrcpp::Any accept(antlr4::tree::ParseTreeVisitor *visitor) override;
|
||||
|
||||
};
|
||||
|
||||
VarDeclContext* varDecl();
|
||||
|
||||
class VarDefContext : public antlr4::ParserRuleContext {
|
||||
public:
|
||||
VarDefContext(antlr4::ParserRuleContext *parent, size_t invokingState);
|
||||
virtual size_t getRuleIndex() const override;
|
||||
antlr4::tree::TerminalNode *Ident();
|
||||
std::vector<ConstExpContext *> constExp();
|
||||
ConstExpContext* constExp(size_t i);
|
||||
InitValContext *initVal();
|
||||
|
||||
virtual antlrcpp::Any accept(antlr4::tree::ParseTreeVisitor *visitor) override;
|
||||
|
||||
};
|
||||
|
||||
VarDefContext* varDef();
|
||||
|
||||
class InitValContext : public antlr4::ParserRuleContext {
|
||||
public:
|
||||
InitValContext(antlr4::ParserRuleContext *parent, size_t invokingState);
|
||||
virtual size_t getRuleIndex() const override;
|
||||
ExpContext *exp();
|
||||
std::vector<InitValContext *> initVal();
|
||||
InitValContext* initVal(size_t i);
|
||||
|
||||
virtual antlrcpp::Any accept(antlr4::tree::ParseTreeVisitor *visitor) override;
|
||||
|
||||
};
|
||||
|
||||
InitValContext* initVal();
|
||||
|
||||
class FuncDefContext : public antlr4::ParserRuleContext {
|
||||
public:
|
||||
FuncDefContext(antlr4::ParserRuleContext *parent, size_t invokingState);
|
||||
virtual size_t getRuleIndex() const override;
|
||||
FuncTypeContext *funcType();
|
||||
antlr4::tree::TerminalNode *Ident();
|
||||
BlockContext *block();
|
||||
FuncFParamsContext *funcFParams();
|
||||
|
||||
virtual antlrcpp::Any accept(antlr4::tree::ParseTreeVisitor *visitor) override;
|
||||
|
||||
};
|
||||
|
||||
FuncDefContext* funcDef();
|
||||
|
||||
class FuncTypeContext : public antlr4::ParserRuleContext {
|
||||
public:
|
||||
FuncTypeContext(antlr4::ParserRuleContext *parent, size_t invokingState);
|
||||
virtual size_t getRuleIndex() const override;
|
||||
|
||||
virtual antlrcpp::Any accept(antlr4::tree::ParseTreeVisitor *visitor) override;
|
||||
|
||||
};
|
||||
|
||||
FuncTypeContext* funcType();
|
||||
|
||||
class FuncFParamsContext : public antlr4::ParserRuleContext {
|
||||
public:
|
||||
FuncFParamsContext(antlr4::ParserRuleContext *parent, size_t invokingState);
|
||||
virtual size_t getRuleIndex() const override;
|
||||
std::vector<FuncFParamContext *> funcFParam();
|
||||
FuncFParamContext* funcFParam(size_t i);
|
||||
|
||||
virtual antlrcpp::Any accept(antlr4::tree::ParseTreeVisitor *visitor) override;
|
||||
|
||||
};
|
||||
|
||||
FuncFParamsContext* funcFParams();
|
||||
|
||||
class FuncFParamContext : public antlr4::ParserRuleContext {
|
||||
public:
|
||||
FuncFParamContext(antlr4::ParserRuleContext *parent, size_t invokingState);
|
||||
virtual size_t getRuleIndex() const override;
|
||||
BTypeContext *bType();
|
||||
antlr4::tree::TerminalNode *Ident();
|
||||
std::vector<ExpContext *> exp();
|
||||
ExpContext* exp(size_t i);
|
||||
|
||||
virtual antlrcpp::Any accept(antlr4::tree::ParseTreeVisitor *visitor) override;
|
||||
|
||||
};
|
||||
|
||||
FuncFParamContext* funcFParam();
|
||||
|
||||
class BlockContext : public antlr4::ParserRuleContext {
|
||||
public:
|
||||
BlockContext(antlr4::ParserRuleContext *parent, size_t invokingState);
|
||||
virtual size_t getRuleIndex() const override;
|
||||
std::vector<BlockItemContext *> blockItem();
|
||||
BlockItemContext* blockItem(size_t i);
|
||||
|
||||
virtual antlrcpp::Any accept(antlr4::tree::ParseTreeVisitor *visitor) override;
|
||||
|
||||
};
|
||||
|
||||
BlockContext* block();
|
||||
|
||||
class BlockItemContext : public antlr4::ParserRuleContext {
|
||||
public:
|
||||
BlockItemContext(antlr4::ParserRuleContext *parent, size_t invokingState);
|
||||
virtual size_t getRuleIndex() const override;
|
||||
DeclContext *decl();
|
||||
StmtContext *stmt();
|
||||
|
||||
virtual antlrcpp::Any accept(antlr4::tree::ParseTreeVisitor *visitor) override;
|
||||
|
||||
};
|
||||
|
||||
BlockItemContext* blockItem();
|
||||
|
||||
class StmtContext : public antlr4::ParserRuleContext {
|
||||
public:
|
||||
StmtContext(antlr4::ParserRuleContext *parent, size_t invokingState);
|
||||
virtual size_t getRuleIndex() const override;
|
||||
LValContext *lVal();
|
||||
ExpContext *exp();
|
||||
BlockContext *block();
|
||||
CondContext *cond();
|
||||
std::vector<StmtContext *> stmt();
|
||||
StmtContext* stmt(size_t i);
|
||||
|
||||
virtual antlrcpp::Any accept(antlr4::tree::ParseTreeVisitor *visitor) override;
|
||||
|
||||
};
|
||||
|
||||
StmtContext* stmt();
|
||||
|
||||
class ExpContext : public antlr4::ParserRuleContext {
|
||||
public:
|
||||
ExpContext(antlr4::ParserRuleContext *parent, size_t invokingState);
|
||||
virtual size_t getRuleIndex() const override;
|
||||
AddExpContext *addExp();
|
||||
|
||||
virtual antlrcpp::Any accept(antlr4::tree::ParseTreeVisitor *visitor) override;
|
||||
|
||||
};
|
||||
|
||||
ExpContext* exp();
|
||||
|
||||
class CondContext : public antlr4::ParserRuleContext {
|
||||
public:
|
||||
CondContext(antlr4::ParserRuleContext *parent, size_t invokingState);
|
||||
virtual size_t getRuleIndex() const override;
|
||||
LOrExpContext *lOrExp();
|
||||
|
||||
virtual antlrcpp::Any accept(antlr4::tree::ParseTreeVisitor *visitor) override;
|
||||
|
||||
};
|
||||
|
||||
CondContext* cond();
|
||||
|
||||
class LValContext : public antlr4::ParserRuleContext {
|
||||
public:
|
||||
LValContext(antlr4::ParserRuleContext *parent, size_t invokingState);
|
||||
virtual size_t getRuleIndex() const override;
|
||||
antlr4::tree::TerminalNode *Ident();
|
||||
std::vector<ExpContext *> exp();
|
||||
ExpContext* exp(size_t i);
|
||||
|
||||
virtual antlrcpp::Any accept(antlr4::tree::ParseTreeVisitor *visitor) override;
|
||||
|
||||
};
|
||||
|
||||
LValContext* lVal();
|
||||
|
||||
class PrimaryExpContext : public antlr4::ParserRuleContext {
|
||||
public:
|
||||
PrimaryExpContext(antlr4::ParserRuleContext *parent, size_t invokingState);
|
||||
virtual size_t getRuleIndex() const override;
|
||||
ExpContext *exp();
|
||||
LValContext *lVal();
|
||||
NumberContext *number();
|
||||
|
||||
virtual antlrcpp::Any accept(antlr4::tree::ParseTreeVisitor *visitor) override;
|
||||
|
||||
};
|
||||
|
||||
PrimaryExpContext* primaryExp();
|
||||
|
||||
class NumberContext : public antlr4::ParserRuleContext {
|
||||
public:
|
||||
NumberContext(antlr4::ParserRuleContext *parent, size_t invokingState);
|
||||
virtual size_t getRuleIndex() const override;
|
||||
antlr4::tree::TerminalNode *FloatConst();
|
||||
antlr4::tree::TerminalNode *IntConst();
|
||||
|
||||
virtual antlrcpp::Any accept(antlr4::tree::ParseTreeVisitor *visitor) override;
|
||||
|
||||
};
|
||||
|
||||
NumberContext* number();
|
||||
|
||||
class UnaryExpContext : public antlr4::ParserRuleContext {
|
||||
public:
|
||||
UnaryExpContext(antlr4::ParserRuleContext *parent, size_t invokingState);
|
||||
virtual size_t getRuleIndex() const override;
|
||||
PrimaryExpContext *primaryExp();
|
||||
antlr4::tree::TerminalNode *Ident();
|
||||
FuncRParamsContext *funcRParams();
|
||||
UnaryOpContext *unaryOp();
|
||||
UnaryExpContext *unaryExp();
|
||||
|
||||
virtual antlrcpp::Any accept(antlr4::tree::ParseTreeVisitor *visitor) override;
|
||||
|
||||
};
|
||||
|
||||
UnaryExpContext* unaryExp();
|
||||
|
||||
class UnaryOpContext : public antlr4::ParserRuleContext {
|
||||
public:
|
||||
UnaryOpContext(antlr4::ParserRuleContext *parent, size_t invokingState);
|
||||
virtual size_t getRuleIndex() const override;
|
||||
|
||||
virtual antlrcpp::Any accept(antlr4::tree::ParseTreeVisitor *visitor) override;
|
||||
|
||||
};
|
||||
|
||||
UnaryOpContext* unaryOp();
|
||||
|
||||
class FuncRParamsContext : public antlr4::ParserRuleContext {
|
||||
public:
|
||||
FuncRParamsContext(antlr4::ParserRuleContext *parent, size_t invokingState);
|
||||
virtual size_t getRuleIndex() const override;
|
||||
std::vector<ExpContext *> exp();
|
||||
ExpContext* exp(size_t i);
|
||||
|
||||
virtual antlrcpp::Any accept(antlr4::tree::ParseTreeVisitor *visitor) override;
|
||||
|
||||
};
|
||||
|
||||
FuncRParamsContext* funcRParams();
|
||||
|
||||
class MulExpContext : public antlr4::ParserRuleContext {
|
||||
public:
|
||||
MulExpContext(antlr4::ParserRuleContext *parent, size_t invokingState);
|
||||
virtual size_t getRuleIndex() const override;
|
||||
std::vector<UnaryExpContext *> unaryExp();
|
||||
UnaryExpContext* unaryExp(size_t i);
|
||||
|
||||
virtual antlrcpp::Any accept(antlr4::tree::ParseTreeVisitor *visitor) override;
|
||||
|
||||
};
|
||||
|
||||
MulExpContext* mulExp();
|
||||
|
||||
class AddExpContext : public antlr4::ParserRuleContext {
|
||||
public:
|
||||
AddExpContext(antlr4::ParserRuleContext *parent, size_t invokingState);
|
||||
virtual size_t getRuleIndex() const override;
|
||||
std::vector<MulExpContext *> mulExp();
|
||||
MulExpContext* mulExp(size_t i);
|
||||
|
||||
virtual antlrcpp::Any accept(antlr4::tree::ParseTreeVisitor *visitor) override;
|
||||
|
||||
};
|
||||
|
||||
AddExpContext* addExp();
|
||||
|
||||
class RelExpContext : public antlr4::ParserRuleContext {
|
||||
public:
|
||||
RelExpContext(antlr4::ParserRuleContext *parent, size_t invokingState);
|
||||
virtual size_t getRuleIndex() const override;
|
||||
std::vector<AddExpContext *> addExp();
|
||||
AddExpContext* addExp(size_t i);
|
||||
|
||||
virtual antlrcpp::Any accept(antlr4::tree::ParseTreeVisitor *visitor) override;
|
||||
|
||||
};
|
||||
|
||||
RelExpContext* relExp();
|
||||
|
||||
class EqExpContext : public antlr4::ParserRuleContext {
|
||||
public:
|
||||
EqExpContext(antlr4::ParserRuleContext *parent, size_t invokingState);
|
||||
virtual size_t getRuleIndex() const override;
|
||||
std::vector<RelExpContext *> relExp();
|
||||
RelExpContext* relExp(size_t i);
|
||||
|
||||
virtual antlrcpp::Any accept(antlr4::tree::ParseTreeVisitor *visitor) override;
|
||||
|
||||
};
|
||||
|
||||
EqExpContext* eqExp();
|
||||
|
||||
class LAndExpContext : public antlr4::ParserRuleContext {
|
||||
public:
|
||||
LAndExpContext(antlr4::ParserRuleContext *parent, size_t invokingState);
|
||||
virtual size_t getRuleIndex() const override;
|
||||
std::vector<EqExpContext *> eqExp();
|
||||
EqExpContext* eqExp(size_t i);
|
||||
|
||||
virtual antlrcpp::Any accept(antlr4::tree::ParseTreeVisitor *visitor) override;
|
||||
|
||||
};
|
||||
|
||||
LAndExpContext* lAndExp();
|
||||
|
||||
class LOrExpContext : public antlr4::ParserRuleContext {
|
||||
public:
|
||||
LOrExpContext(antlr4::ParserRuleContext *parent, size_t invokingState);
|
||||
virtual size_t getRuleIndex() const override;
|
||||
std::vector<LAndExpContext *> lAndExp();
|
||||
LAndExpContext* lAndExp(size_t i);
|
||||
|
||||
virtual antlrcpp::Any accept(antlr4::tree::ParseTreeVisitor *visitor) override;
|
||||
|
||||
};
|
||||
|
||||
LOrExpContext* lOrExp();
|
||||
|
||||
class ConstExpContext : public antlr4::ParserRuleContext {
|
||||
public:
|
||||
ConstExpContext(antlr4::ParserRuleContext *parent, size_t invokingState);
|
||||
virtual size_t getRuleIndex() const override;
|
||||
AddExpContext *addExp();
|
||||
|
||||
virtual antlrcpp::Any accept(antlr4::tree::ParseTreeVisitor *visitor) override;
|
||||
|
||||
};
|
||||
|
||||
ConstExpContext* constExp();
|
||||
|
||||
|
||||
private:
|
||||
static std::vector<antlr4::dfa::DFA> _decisionToDFA;
|
||||
static antlr4::atn::PredictionContextCache _sharedContextCache;
|
||||
static std::vector<std::string> _ruleNames;
|
||||
static std::vector<std::string> _tokenNames;
|
||||
|
||||
static std::vector<std::string> _literalNames;
|
||||
static std::vector<std::string> _symbolicNames;
|
||||
static antlr4::dfa::Vocabulary _vocabulary;
|
||||
static antlr4::atn::ATN _atn;
|
||||
static std::vector<uint16_t> _serializedATN;
|
||||
|
||||
|
||||
struct Initializer {
|
||||
Initializer();
|
||||
};
|
||||
static Initializer _init;
|
||||
};
|
||||
|
||||
@ -0,0 +1,7 @@
|
||||
|
||||
// Generated from SysY.g4 by ANTLR 4.7.2
|
||||
|
||||
|
||||
#include "SysYVisitor.h"
|
||||
|
||||
|
||||
@ -0,0 +1,86 @@
|
||||
|
||||
// Generated from SysY.g4 by ANTLR 4.7.2
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "antlr4-runtime.h"
|
||||
#include "SysYParser.h"
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* This class defines an abstract visitor for a parse tree
|
||||
* produced by SysYParser.
|
||||
*/
|
||||
class SysYVisitor : public antlr4::tree::AbstractParseTreeVisitor {
|
||||
public:
|
||||
|
||||
/**
|
||||
* Visit parse trees produced by SysYParser.
|
||||
*/
|
||||
virtual antlrcpp::Any visitCompUnit(SysYParser::CompUnitContext *context) = 0;
|
||||
|
||||
virtual antlrcpp::Any visitDecl(SysYParser::DeclContext *context) = 0;
|
||||
|
||||
virtual antlrcpp::Any visitConstDecl(SysYParser::ConstDeclContext *context) = 0;
|
||||
|
||||
virtual antlrcpp::Any visitBType(SysYParser::BTypeContext *context) = 0;
|
||||
|
||||
virtual antlrcpp::Any visitConstDef(SysYParser::ConstDefContext *context) = 0;
|
||||
|
||||
virtual antlrcpp::Any visitConstInitVal(SysYParser::ConstInitValContext *context) = 0;
|
||||
|
||||
virtual antlrcpp::Any visitVarDecl(SysYParser::VarDeclContext *context) = 0;
|
||||
|
||||
virtual antlrcpp::Any visitVarDef(SysYParser::VarDefContext *context) = 0;
|
||||
|
||||
virtual antlrcpp::Any visitInitVal(SysYParser::InitValContext *context) = 0;
|
||||
|
||||
virtual antlrcpp::Any visitFuncDef(SysYParser::FuncDefContext *context) = 0;
|
||||
|
||||
virtual antlrcpp::Any visitFuncType(SysYParser::FuncTypeContext *context) = 0;
|
||||
|
||||
virtual antlrcpp::Any visitFuncFParams(SysYParser::FuncFParamsContext *context) = 0;
|
||||
|
||||
virtual antlrcpp::Any visitFuncFParam(SysYParser::FuncFParamContext *context) = 0;
|
||||
|
||||
virtual antlrcpp::Any visitBlock(SysYParser::BlockContext *context) = 0;
|
||||
|
||||
virtual antlrcpp::Any visitBlockItem(SysYParser::BlockItemContext *context) = 0;
|
||||
|
||||
virtual antlrcpp::Any visitStmt(SysYParser::StmtContext *context) = 0;
|
||||
|
||||
virtual antlrcpp::Any visitExp(SysYParser::ExpContext *context) = 0;
|
||||
|
||||
virtual antlrcpp::Any visitCond(SysYParser::CondContext *context) = 0;
|
||||
|
||||
virtual antlrcpp::Any visitLVal(SysYParser::LValContext *context) = 0;
|
||||
|
||||
virtual antlrcpp::Any visitPrimaryExp(SysYParser::PrimaryExpContext *context) = 0;
|
||||
|
||||
virtual antlrcpp::Any visitNumber(SysYParser::NumberContext *context) = 0;
|
||||
|
||||
virtual antlrcpp::Any visitUnaryExp(SysYParser::UnaryExpContext *context) = 0;
|
||||
|
||||
virtual antlrcpp::Any visitUnaryOp(SysYParser::UnaryOpContext *context) = 0;
|
||||
|
||||
virtual antlrcpp::Any visitFuncRParams(SysYParser::FuncRParamsContext *context) = 0;
|
||||
|
||||
virtual antlrcpp::Any visitMulExp(SysYParser::MulExpContext *context) = 0;
|
||||
|
||||
virtual antlrcpp::Any visitAddExp(SysYParser::AddExpContext *context) = 0;
|
||||
|
||||
virtual antlrcpp::Any visitRelExp(SysYParser::RelExpContext *context) = 0;
|
||||
|
||||
virtual antlrcpp::Any visitEqExp(SysYParser::EqExpContext *context) = 0;
|
||||
|
||||
virtual antlrcpp::Any visitLAndExp(SysYParser::LAndExpContext *context) = 0;
|
||||
|
||||
virtual antlrcpp::Any visitLOrExp(SysYParser::LOrExpContext *context) = 0;
|
||||
|
||||
virtual antlrcpp::Any visitConstExp(SysYParser::ConstExpContext *context) = 0;
|
||||
|
||||
|
||||
};
|
||||
|
||||
@ -1,17 +1,164 @@
|
||||
// 维护局部变量声明的注册与查找。
|
||||
#include "../../include/sem/SymbolTable.h"
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
#include "sem/SymbolTable.h"
|
||||
// 进入新作用域
|
||||
void SymbolTable::EnterScope() {
|
||||
scopes_.push(ScopeEntry());
|
||||
}
|
||||
|
||||
// 离开当前作用域
|
||||
void SymbolTable::LeaveScope() {
|
||||
if (scopes_.empty()) {
|
||||
throw std::runtime_error("SymbolTable Error: 作用域栈为空,无法退出");
|
||||
}
|
||||
scopes_.pop();
|
||||
}
|
||||
|
||||
// 绑定变量到当前作用域
|
||||
void SymbolTable::BindVar(const std::string& name, const VarInfo& info, void* decl_ctx) {
|
||||
if (CurrentScopeHasVar(name)) {
|
||||
throw std::runtime_error("变量'" + name + "'在当前作用域重复定义");
|
||||
}
|
||||
scopes_.top().var_symbols[name] = {info, decl_ctx};
|
||||
}
|
||||
|
||||
// 绑定函数到当前作用域
|
||||
void SymbolTable::BindFunc(const std::string& name, const FuncInfo& info, void* decl_ctx) {
|
||||
if (CurrentScopeHasFunc(name)) {
|
||||
throw std::runtime_error("函数'" + name + "'在当前作用域重复定义");
|
||||
}
|
||||
scopes_.top().func_symbols[name] = {info, decl_ctx};
|
||||
}
|
||||
|
||||
// 查找变量(从当前作用域向上遍历)
|
||||
bool SymbolTable::LookupVar(const std::string& name, VarInfo& out_info, void*& out_decl_ctx) const {
|
||||
if (scopes_.empty()) {
|
||||
return false;
|
||||
}
|
||||
auto temp_stack = scopes_;
|
||||
while (!temp_stack.empty()) {
|
||||
auto& scope = temp_stack.top();
|
||||
auto it = scope.var_symbols.find(name);
|
||||
if (it != scope.var_symbols.end()) {
|
||||
out_info = it->second.first;
|
||||
out_decl_ctx = it->second.second;
|
||||
return true;
|
||||
}
|
||||
temp_stack.pop();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// 查找函数(从当前作用域向上遍历,通常函数在全局作用域)
|
||||
bool SymbolTable::LookupFunc(const std::string& name, FuncInfo& out_info, void*& out_decl_ctx) const {
|
||||
if (scopes_.empty()) {
|
||||
return false;
|
||||
}
|
||||
auto temp_stack = scopes_;
|
||||
while (!temp_stack.empty()) {
|
||||
auto& scope = temp_stack.top();
|
||||
auto it = scope.func_symbols.find(name);
|
||||
if (it != scope.func_symbols.end()) {
|
||||
out_info = it->second.first;
|
||||
out_decl_ctx = it->second.second;
|
||||
return true;
|
||||
}
|
||||
temp_stack.pop();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void SymbolTable::Add(const std::string& name,
|
||||
SysYParser::VarDefContext* decl) {
|
||||
table_[name] = decl;
|
||||
// 检查当前作用域是否包含指定变量
|
||||
bool SymbolTable::CurrentScopeHasVar(const std::string& name) const {
|
||||
if (scopes_.empty()) {
|
||||
return false;
|
||||
}
|
||||
return scopes_.top().var_symbols.count(name) > 0;
|
||||
}
|
||||
|
||||
bool SymbolTable::Contains(const std::string& name) const {
|
||||
return table_.find(name) != table_.end();
|
||||
// 检查当前作用域是否包含指定函数
|
||||
bool SymbolTable::CurrentScopeHasFunc(const std::string& name) const {
|
||||
if (scopes_.empty()) {
|
||||
return false;
|
||||
}
|
||||
return scopes_.top().func_symbols.count(name) > 0;
|
||||
}
|
||||
|
||||
SysYParser::VarDefContext* SymbolTable::Lookup(const std::string& name) const {
|
||||
auto it = table_.find(name);
|
||||
return it == table_.end() ? nullptr : it->second;
|
||||
// 进入循环
|
||||
void SymbolTable::EnterLoop() {
|
||||
loop_depth_++;
|
||||
}
|
||||
|
||||
// 离开循环
|
||||
void SymbolTable::ExitLoop() {
|
||||
if (loop_depth_ > 0) loop_depth_--;
|
||||
}
|
||||
|
||||
// 检查是否在循环内
|
||||
bool SymbolTable::InLoop() const {
|
||||
return loop_depth_ > 0;
|
||||
}
|
||||
|
||||
// 清空所有作用域和状态
|
||||
void SymbolTable::Clear() {
|
||||
while (!scopes_.empty()) {
|
||||
scopes_.pop();
|
||||
}
|
||||
loop_depth_ = 0;
|
||||
}
|
||||
|
||||
// 获取当前作用域中所有变量名
|
||||
std::vector<std::string> SymbolTable::GetCurrentScopeVarNames() const {
|
||||
std::vector<std::string> names;
|
||||
if (!scopes_.empty()) {
|
||||
for (const auto& pair : scopes_.top().var_symbols) {
|
||||
names.push_back(pair.first);
|
||||
}
|
||||
}
|
||||
return names;
|
||||
}
|
||||
|
||||
// 获取当前作用域中所有函数名
|
||||
std::vector<std::string> SymbolTable::GetCurrentScopeFuncNames() const {
|
||||
std::vector<std::string> names;
|
||||
if (!scopes_.empty()) {
|
||||
for (const auto& pair : scopes_.top().func_symbols) {
|
||||
names.push_back(pair.first);
|
||||
}
|
||||
}
|
||||
return names;
|
||||
}
|
||||
|
||||
// 调试:打印符号表内容
|
||||
void SymbolTable::Dump() const {
|
||||
std::cout << "符号表内容 (作用域深度: " << scopes_.size() << "):\n";
|
||||
int scope_idx = 0;
|
||||
auto temp_stack = scopes_;
|
||||
|
||||
while (!temp_stack.empty()) {
|
||||
std::cout << "\n作用域 " << scope_idx++ << ":\n";
|
||||
auto& scope = temp_stack.top();
|
||||
|
||||
std::cout << " 变量:\n";
|
||||
for (const auto& var_pair : scope.var_symbols) {
|
||||
const VarInfo& info = var_pair.second.first;
|
||||
std::cout << " " << var_pair.first << ": "
|
||||
<< SymbolTypeToString(info.type)
|
||||
<< (info.is_const ? " (const)" : "")
|
||||
<< (info.IsArray() ? " [数组]" : "")
|
||||
<< "\n";
|
||||
}
|
||||
|
||||
std::cout << " 函数:\n";
|
||||
for (const auto& func_pair : scope.func_symbols) {
|
||||
const FuncInfo& info = func_pair.second.first;
|
||||
std::cout << " " << func_pair.first << ": "
|
||||
<< SymbolTypeToString(info.ret_type) << " ("
|
||||
<< info.param_types.size() << " 个参数)\n";
|
||||
}
|
||||
|
||||
temp_stack.pop();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue