Files
nudt-compiler-cpp/include/frontend/AntlrDriver.h
2026-03-12 10:34:02 +08:00

21 lines
568 B
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 包装 ANTLR4提供简易的解析入口。
#pragma once
#include <memory>
#include <string>
#include "SysYLexer.h"
#include "SysYParser.h"
#include "antlr4-runtime.h"
struct AntlrResult {
std::unique_ptr<antlr4::ANTLRInputStream> input;
std::unique_ptr<SysYLexer> lexer;
std::unique_ptr<antlr4::CommonTokenStream> tokens;
std::unique_ptr<SysYParser> parser;
antlr4::tree::ParseTree* tree = nullptr; // owned by parser
};
// 解析指定文件,发生错误时抛出 std::runtime_error。
AntlrResult ParseFileWithAntlr(const std::string& path);