YSTest: SContext.cpp 源文件

YSTest PreAlpha_b800_20170810 The YSLib Test Project

- 首页
- 相关页面
- 模块
- 命名空间
- 类
- 文件

- 文件列表
- 文件成员

SContext.cpp
浏览该文件的文档.
1 /*
2 © 2012-2017 FrankHB.
3
4 This file is part of the YSLib project, and may only be used,
5 modified, and distributed under the terms of the YSLib project
6 license, LICENSE.TXT. By continuing to use, modify, or distribute
7 this file you indicate that you have read the license and
8 understand and accept it fully.
9 */
10
28 #include "NPL/YModules.h"
29 #include YFM_NPL_SContext
30
31 using namespace YSLib;
32
33 namespace NPL
34 {
35
36 void
37 Session::DefaultParseByte(LexicalAnalyzer& lexer, char c)
38 {
39 lexer.ParseByte(c);
40 }
41
42 void
43 Session::DefaultParseQuoted(LexicalAnalyzer& lexer, char c)
44 {
45 lexer.ParseQuoted(c);
46 }
47
48
49 namespace SContext
50 {
51
52 TLCIter
53 Validate(TLCIter b, TLCIter e)
54 {
55 while(b != e && *b != ")")
56 if(*b == "(")
57 {
58 // FIXME: Potential overflow.
59 auto res(Validate(++b, e));
60
61 if(res == e || *res != ")")
62 throw LoggedEvent("Redundant '(' found.", Alert);
63 b = ++res;
64 }
65 else
66 ++b;
67 return b;
68 }
69
70 TLCIter
71 Reduce(TermNode& term, TLCIter b, TLCIter e)
72 {
73 while(b != e && *b != ")")
74 if(*b == "(")
75 {
76 // FIXME: Potential overflow.
77 // NOTE: Explicit type 'TermNode' is intended.
78 TermNode tm(AsIndexNode(term));
79 auto res(Reduce(tm, ++b, e));
80
81 if(res == e || *res != ")")
82 throw LoggedEvent("Redundant '(' found.", Alert);
83 term += std::move(tm);
84 b = ++res;
85 }
86 else
87 term += AsIndexNode(term, *b++);
88 return b;
89 }
90
91 void
92 Analyze(TermNode& root, const TokenList& token_list)
93 {
94 if(Reduce(root, token_list.cbegin(), token_list.cend())
95 != token_list.cend())
96 throw LoggedEvent("Redundant ')' found.", Alert);
97 }
98 void
99 Analyze(TermNode& root, const Session& session)
100 {
101 Analyze(root, session.GetTokenList());
102 }
103
104 } // namespace SContext;
105
106 } // namespace NPL;
107
platform::Descriptions::Alert
Definition: YCommon.h:164
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:45
YModules.h
NPL::Session
会话：分析指定 NPL 代码。
Definition: SContext.h:103
YSLib::LoggedEvent
记录日志的异常事件类。
Definition: YException.h:50
NPL::LexicalAnalyzer
词法分析器。
Definition: Lexical.h:156
NPL::LexicalAnalyzer::ParseQuoted
void ParseQuoted(char, Unescaper=NPLUnescape, PrefixHandler=HandleBackslashPrefix)
解析单个字面量字符并添加至字符解析结果：反转义以外无视边界字符。
Definition: Lexical.cpp:210
NPL::TLCIter
TokenList::const_iterator TLCIter
Definition: SContext.h:44
YSLib::AsIndexNode
const ValueNode &node ImplRet(MakeIndex(node.GetContainer())) YF_API size_t GetLastIndexOf(const ValueNode typename _tParams ValueNode AsIndexNode(_tParam &&arg, _tParams &&...args)
Definition: ValueNode.h:1227
NPL::TermNode
yimpl(ValueNode) TermNode
项节点：存储语法分析结果的值类型节点。
Definition: SContext.h:51
CHRLib::e
const char const char * e
Definition: CharacterProcessing.h:109
NPL::A1::Reduce
YF_API ReductionStatus Reduce(TermNode &, ContextNode &)
NPLA1 表达式节点规约：调用至少一次求值例程规约子表达式。
Definition: NPLA1.cpp:552
NPL::TokenList
list< string > TokenList
Definition: SContext.h:42
NPL
Definition: NPL/Configuration.h:34
CHRLib::c
c
Definition: CharacterProcessing.h:81
NPL::SContext::Analyze
YF_API void Analyze(TermNode &, const TokenList &)
分析指定源，取抽象语法树储存至指定值类型节点。
Definition: SContext.cpp:92
NPL::SContext::Validate
YF_API TLCIter Validate(TLCIter b, TLCIter e)
遍历记号列表，验证基本合法性：圆括号是否对应。
Definition: SContext.cpp:53