4
Copyright (c) 2021 МГТУ им. Н.Э. Баумана, кафедра ИУ-6, Михаил Фетисов,
6
https://bmstu.codes/lsx/simodo/loom
9
#include "simodo/parser/fuze/FuzeSblRdp.h"
10
#include "simodo/parser/fuze/BaseOperationCode.h"
12
#include "simodo/inout/format/fmt.h"
16
namespace simodo::parser
19
bool FuzeSblRdp::parse(inout::Tokenizer &tzer, inout::Token &t) {
20
// "{" { <вызов> ";" } "}"
22
ast().addNode_StepInto(SCRIPT_HOST_NAME, static_cast<ast::OperationCode>(BaseOperationCode::Block), t, t);
23
ast().addNode(SCRIPT_HOST_NAME, static_cast<ast::OperationCode>(BaseOperationCode::Block), t, t);
27
while(t.type() != inout::LexemeType::Empty) {
28
if (t.type() == inout::LexemeType::Punctuation && t.lexeme() == u"}") {
29
// "{" { <вызов> ";" } "}"
31
ast().addNode(SCRIPT_HOST_NAME, static_cast<ast::OperationCode>(BaseOperationCode::Block), t, t);
32
/// \todo Обрабатывать возврат false!
39
// "{" { <вызов> ";" } "}"
41
if (!parseProcedureCalling(tzer,t))
44
// "{" { <вызов> ";" } "}"
46
if (t.type() != inout::LexemeType::Punctuation || t.lexeme() != u";") {
47
reportUnexpected(t, "';'");
57
bool FuzeSblRdp::parseProcedureCalling(inout::Tokenizer &tzer, inout::Token &t) {
60
if (!parseAddress(tzer,t))
63
ast().addNode(SCRIPT_HOST_NAME, static_cast<ast::OperationCode>(BaseOperationCode::Pop), t, t);
68
bool FuzeSblRdp::parseAddress(inout::Tokenizer &tzer, inout::Token &t) {
69
// <AddressAtom> {["." <AddressAtom>] | "(" [<список параметров>] ")"}
71
if (!parseAddressAtom(tzer,t))
74
while(t.type() != inout::LexemeType::Empty) {
75
// <AddressAtom> {["." <AddressAtom>] | "(" [<список параметров>] ")"}
77
if (t.type() == inout::LexemeType::Punctuation && t.lexeme() == u".") {
78
// <AddressAtom> {["." <AddressAtom>] | "(" [<список параметров>] ")"}
80
ast().addNode_StepInto(SCRIPT_HOST_NAME, static_cast<ast::OperationCode>(BaseOperationCode::ObjectElement), t, t);
84
if (!parseAddressAtom(tzer,t))
87
/// \todo Обрабатывать возврат false!
90
else if (t.type() == inout::LexemeType::Punctuation && t.lexeme() == u"(") {
91
// <AddressAtom> {["." <AddressAtom>] | "(" [<список параметров>] ")"}
93
ast().addNode_StepInto(SCRIPT_HOST_NAME, static_cast<ast::OperationCode>(BaseOperationCode::FunctionCall), t, t);
97
// <AddressAtom> {["." <AddressAtom>] | "(" [<список параметров>] ")"}
99
if (t.type() != inout::LexemeType::Punctuation || t.lexeme() != u")") {
100
// <AddressAtom> {["." <AddressAtom>] | "(" [<список параметров>] ")"}
102
if (!parseArgumentList(tzer,t))
105
// <AddressAtom> {["." <AddressAtom>] | "(" [<список параметров>] ")"}
107
if (t.type() != inout::LexemeType::Punctuation || t.lexeme() != u")")
109
reportUnexpected(t, "')'");
114
/// \todo Обрабатывать возврат false!
126
bool FuzeSblRdp::parseAddressAtom(inout::Tokenizer &tzer, inout::Token &t)
130
if (t.type() != inout::LexemeType::Id) {
131
reportUnexpected(t, inout::fmt("идентификатор"));
135
ast().addNode(SCRIPT_HOST_NAME, static_cast<ast::OperationCode>(BaseOperationCode::PushVariable), t, t);
142
bool FuzeSblRdp::parseArgumentList(inout::Tokenizer &tzer, inout::Token &t)
144
while(t.type() != inout::LexemeType::Empty)
146
// { NUMBER | ANNOTATION | "true" | "false" | "null" | <адрес> [","] }
148
if (t.type() == inout::LexemeType::Number || t.type() == inout::LexemeType::Annotation)
150
ast().addNode(SCRIPT_HOST_NAME, static_cast<ast::OperationCode>(BaseOperationCode::PushConstant), t, t);
154
else if (t.type() == inout::LexemeType::Punctuation
155
&& t.qualification() == inout::TokenQualification::Keyword
156
&& (t.lexeme() == u"true" || t.lexeme() == u"false" || t.lexeme() == u"null"))
158
ast().addNode(SCRIPT_HOST_NAME, static_cast<ast::OperationCode>(BaseOperationCode::PushConstant), t, t);
162
else if (!parseAddress(tzer,t))
165
// { NUMBER | ANNOTATION | <адрес> [","] }
167
if (t.type() != inout::LexemeType::Punctuation || t.lexeme() != u",")
176
inout::Token FuzeSblRdp::getToken(inout::Tokenizer & tzer) const
178
inout::Token token = tzer.getAnyToken();
180
while (token.type() == inout::LexemeType::Comment) {
181
_syntax_data_collector.collectToken(token);
183
token = tzer.getAnyToken();
186
_syntax_data_collector.collectToken(token);