forked from NUDT-compiler/nudt-compiler-cpp
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
667 B
20 lines
667 B
// 符号表:记录变量和常量定义。
|
|
#pragma once
|
|
|
|
#include <string>
|
|
#include <unordered_map>
|
|
|
|
#include "SysYParser.h"
|
|
|
|
class SymbolTable {
|
|
public:
|
|
void AddVar(const std::string& name, SysYParser::VarDefContext* decl);
|
|
void AddConst(const std::string& name, SysYParser::ConstDefContext* decl);
|
|
bool Contains(const std::string& name) const;
|
|
SysYParser::VarDefContext* LookupVar(const std::string& name) const;
|
|
SysYParser::ConstDefContext* LookupConst(const std::string& name) const;
|
|
|
|
private:
|
|
std::unordered_map<std::string, SysYParser::VarDefContext*> var_table_;
|
|
std::unordered_map<std::string, SysYParser::ConstDefContext*> const_table_;
|
|
}; |