41 lines
1.0 KiB
C++
41 lines
1.0 KiB
C++
#pragma once
|
|
|
|
#include "libsyntax.h"
|
|
#include "ast_basic.h"
|
|
|
|
|
|
namespace ast_gen {
|
|
|
|
/**
|
|
* @brief 语法解析器
|
|
*/
|
|
class LIBSYNTAX_EXPORT SyntaxParser {
|
|
private:
|
|
std::shared_ptr<const lib_syntax::IBasicRule> _rule_bind = nullptr;
|
|
|
|
public:
|
|
SyntaxParser(std::shared_ptr<const lib_syntax::IBasicRule> rule);
|
|
|
|
/**
|
|
* @brief 依据源码语法规则,解析源码链表
|
|
* @param wods 源码链表
|
|
* @return 所有解析路径,按照错误数量排序:少->多
|
|
*/
|
|
QList<std::shared_ptr<const lib_syntax::MatchCursor>> parse(std::shared_ptr<const lib_words::IPrimitiveWord> words);
|
|
|
|
/**
|
|
* @brief 依据指定解析路径,提取程序解构
|
|
* @param cursor 解析路径
|
|
* @param root 表达式树预制根节点
|
|
* @return 完善后的根节点
|
|
*/
|
|
std::shared_ptr<ast_basic::IExprInstance> getAst(
|
|
std::shared_ptr<const lib_syntax::MatchCursor> cursor, std::shared_ptr<ast_basic::IExprInstance> root);
|
|
|
|
void astPresent(std::shared_ptr<const ast_basic::IExprInstance> node, int depth = 0);
|
|
|
|
};
|
|
|
|
|
|
|
|
} |