로딩중...
검색중...
일치하는것 없음
parser.hpp
이 파일의 문서화 페이지로 가기
1
2#pragma once
3
6#include "core/ast/node.hpp"
7#include "core/ast/origin.hpp"
8#include "core/ast/params.hpp"
9#include "core/ast/pod.hpp"
10#include "core/ast/func.hpp"
18
19namespace by {
20
21 class expr;
22 class ctor;
23 class blockExpr;
24 class evalExpr;
25 class asExpr;
26 class isExpr;
27 class addExpr;
28 class getExpr;
29 class retExpr;
30 class breakExpr;
31 class nextExpr;
32 class ifExpr;
33 class FUOExpr;
34 class defPropExpr;
35 class genericOrigin;
36 class defNestedFuncExpr;
37 class endExpr;
38
127 class _nout parser: public tworker<str, pod>, public tokenScanable {
128 typedef tworker<str, pod> __super5;
129 BY(CLASS(parser, __super5))
130 friend class coreInternal;
131
132 public:
133 parser();
134
135 public:
141 node* getSubPod();
142 const node* getSubPod() const BY_CONST_FUNC(getSubPod())
143
144 srcSupplies& getSrcSupplies();
145 const srcSupplies& getSrcSupplies() const BY_CONST_FUNC(getSrcSupplies())
146 me& addSupply(const srcSupply& new1);
147 me& addSupply(const tucontainable<srcSupply>& new1);
148 me& relSupplies();
149
150 tokenDispatcher& getDispatcher();
151 std::vector<ncnt>& getIndents();
152
153 nbool isInit() const;
154
160 template <typename T> void setScan() {
161 BY_DI("change scanmode(%s -> %s)", _mode ? _mode->getType().getName() : "null", T::instance);
162 _mode = &T::instance;
163 }
164
165 void rel() override;
166
172 int pushState(int newState);
177 int popState();
178
179 // events:
180 // scan:
181 using tokenScanable::onScan;
191 nint onScan(parser& ps, YYSTYPE* val, YYLTYPE* loc, yyscan_t scanner, nbool& isBypass) override;
196 nint onTokenEndOfFile();
202 nint onTokenColon(nint tok);
208 nint onTokenNewLine(nint tok);
214 nint onTokenLParan(nint tok);
220 nint onTokenRParan(nint tok);
226 nint onTokenComma(nint tok);
231 nbool onTokenEndOfBraces();
236 void onTokenStartOfStrTemplateBrace();
244 void onTokenBeginStr(nchar token);
249 nchar getOpenStrToken();
256 nint onIndent(ncnt col, nint tok);
263 nint onDedent(ncnt col, nint tok);
269 nint onIgnoreIndent(nint tok);
275 nchar onScanUnexpected(const nchar* token);
280 void onSrcArea(const area& area);
281
282 // err:
283 // operator:
284 // dot:
285 node* onGet(const std::string& name);
286 node* onGet(const std::string& name, const narr& args);
287 node* onGet(node& from, const std::string& name);
288 node* onGet(node& from, node& it);
289 node* onGet(const std::string& name, const std::string& name2);
290 node* onCallAccess(node& it, const narr& args);
291
292 // unary operation:
293 FBOExpr* onUnaryMinus(const node& it);
294 FBOExpr* onUnaryNot(const node& it);
295 FUOExpr* onUnaryBitwiseNot(const node& it);
296 node* onUnaryDoublePlus(node& it);
297 node* onUnaryDoubleMinus(node& it);
298 FUOExpr* onUnaryPostfixDoublePlus(const node& it);
299 FUOExpr* onUnaryPostfixDoubleMinus(const node& it);
300 // binary operation:
301 // arithmetic:
302 FBOExpr* onAdd(const node& lhs, const node& rhs);
303 FBOExpr* onSub(const node& lhs, const node& rhs);
304 FBOExpr* onMul(const node& lhs, const node& rhs);
305 FBOExpr* onDiv(const node& lhs, const node& rhs);
306 FBOExpr* onMod(const node& lhs, const node& rhs);
307 // bitwise:
308 FBOExpr* onBitwiseAnd(const node& lhs, const node& rhs);
309 FBOExpr* onBitwiseXor(const node& lhs, const node& rhs);
310 FBOExpr* onBitwiseOr(const node& lhs, const node& rhs);
311 FBOExpr* onLShift(const node& lhs, const node& rhs);
312 FBOExpr* onRShift(const node& lhs, const node& rhs);
313 // assign:
314 node* onAssign(node& lhs, node& rhs);
315 node* onAddAssign(node& lhs, node& rhs);
316 node* onSubAssign(node& lhs, node& rhs);
317 node* onMulAssign(node& lhs, node& rhs);
318 node* onDivAssign(node& lhs, node& rhs);
319 node* onModAssign(node& lhs, node& rhs);
320 // logical:
321 FBOExpr* onGt(const node& lhs, const node& rhs);
322 FBOExpr* onGe(const node& lhs, const node& rhs);
323 FBOExpr* onLt(const node& lhs, const node& rhs);
324 FBOExpr* onLe(const node& lhs, const node& rhs);
325 FBOExpr* onEq(const node& lhs, const node& rhs);
326 FBOExpr* onNe(const node& lhs, const node& rhs);
327 FBOExpr* onAnd(const node& lhs, const node& rhs);
328 FBOExpr* onOr(const node& lhs, const node& rhs);
329
330 // generic:
331 node* onGetGeneric(const std::string& orgName, const args& typeParams);
332 node* onGetElem(const node& arr, const node& idx);
333 // container:
334 node* onGetArray(node& elemType);
335
336 // keyword:
337 obj* onPod(const node& path);
338 obj* onPod(const std::string& path);
339 obj* onPod();
340 obj* onSubPod(obj& subpod);
341 endExpr* onEnd(const blockExpr& blk);
342 blockExpr* onBlock(const node* stmt);
343 blockExpr* onBlock(blockExpr* blk, const node* stmt);
344 blockExpr* onBlock();
345 defBlock* onDefBlock(node* stmt);
346 defBlock* onDefBlock(defBlock* blk, node* stmt);
347 defBlock* onDefBlock();
348 node* onFor(const std::string& iterName, const node& expr, const blockExpr& blk);
349 node* onWhile(const node& condition, const blockExpr& blk);
350
351 // expr:
352 // def:
353 // list:
354 node* onParanthesisAsTuple(narr& tuple);
355 args* onTuple();
356 args* onTuple(const node& elem);
357 args* onTuple(args& as, const node& elem);
358 args* onFuncCallTuple();
359 args* onFuncCallTuple(const node& elem);
360 args* onFuncCallTuple(args& as, const node& elem);
361 // typenames:
362 args* onTypeNames(const node& param);
363 args* onTypeNames(args& params, const node& param);
364
365 // var:
366 template <typename T, typename Arg> T* onPrimitive(const Arg& arg) {
367 BY_DI("on%s(...)", ttype<T>::get());
368 return new T(arg);
369 }
370
371 template <typename T> T* onPrimitive() {
372 BY_DI("on%s()", ttype<T>::get());
373 return new T();
374 }
375
376 node* onDefProp(const modifier& mod, const std::string& name, const node& rhs);
377 node* onDefProp(const std::string& name, const node& rhs);
378 node* onDefProp(const node& rhs);
379 node* onDefProp(const modifier& mod, const node& rhs);
380 node* onDefAssign(const modifier& mod, const std::string& name, const node* rhs);
381 node* onDefAssign(const defPropExpr* prop, const node* rhs);
382 node* onDefAssign(const std::string& name, const node* rhs);
383 // obj:
384 obj* onDefOrigin(const std::string& name, defBlock& blk);
385 obj* onDefOrigin(const std::string& name, const narr& args, defBlock& blk);
386 genericOrigin* onDefObjGeneric(const std::string& name, const args& typeParams, defBlock& blk);
387 genericOrigin* onDefObjGeneric(const std::string& name, const args& typeParams, const narr& args,
388 defBlock& blk);
389 // container:
390 node* onDefArray(const narr& items);
391 node* onDefSeq(const node& start, const node& end);
392 // file:
393 void onCompilationUnit(obj* subpod);
394 void onCompilationUnit(obj* subpod, defBlock* blk);
395 // func:
396 func* onFuncSignature(const modifier& mod, const getExpr& access, const node* retType);
397 func* onFuncSignature(const getExpr& access, const node* retType);
398 func* onFuncSignature(const modifier& mod, node& it, const node* retType);
399 func* onFuncSignature(node& it, const node* retType);
400 func* onAbstractFunc(func& f);
401 node* onFunc(func& func, const blockExpr& blk);
402 defNestedFuncExpr* onLambda(const narr& params, const node& retType, const blockExpr& blk);
403 ctor* onCtor(const modifier& mod, const narr& args, const blockExpr& blk);
404 ctor* onCtor(const narr& args, const blockExpr& blk);
405 ctor* onCtor(const modifier& mod, const blockExpr& blk);
406 ctor* onCtor(const blockExpr& blk);
407 // params:
408 narr* onParams();
409 narr* onParams(const defPropExpr* elem);
410 narr* onParams(narr& it, const defPropExpr* elem);
411 // modifier:
412 modifier* onModifier(nbool isPublic, nbool isOverriden);
413
414 // stmt:
415 node* onDeclStmt(const narr& dotnames) {
416 // TODO:
417 return nullptr;
418 }
419
420 // return:
421 retExpr* onRet();
422 retExpr* onRet(node& exp);
423 breakExpr* onBreak();
424 nextExpr* onNext();
425 // eval:
426 evalExpr* onFillFromOfFuncCall(const node& me, evalExpr& to);
427 evalExpr* onEvalExpr(node& type, const narr& a);
428 evalExpr* onEvalExpr(node& type, const args& a);
429 // cast:
430 isExpr* onIs(const node& me, const node& to);
431 asExpr* onAs(const node& me, const node& as);
432 // if:
433 ifExpr* onIf(const node& condition, const blockExpr& then);
434 ifExpr* onIf(const node& condition, const blockExpr& then, const blockExpr& elseBlk);
435 ifExpr* onIf(const node& condition, const blockExpr& then, const ifExpr& elseIf);
436 // in:
437 evalExpr* onIn(const node& it, const node& container);
438
444 void onEndFunc();
450 void onParseErr(const std::string& msg, const nchar* symbolName);
451
452 protected:
453 void* _scanString(const std::string& src, void* scanner);
454 exprMaker& _getMaker();
455 void _prepare() override;
456 void _onEndWork() override;
457
463 str _onWork() override;
464
465 private:
466 node* _onDefAssign(const modifier& mod, const node* type, const std::string& name, const node* rhs);
467 nint _onTokenEndOfInlineBlock(nint tok);
468 node* _onSetElem(evalExpr& lhs, const node& rhs);
469 node* _onAssignElem(FBOExpr::symbol type, node& lhs, node& rhs);
470 node* _onConvertAssignElem(evalExpr& lhs, node& rhs);
471 evalExpr* _onEvalExpr(node* me, node& type, const args& a);
472
473 nint _onScan(YYSTYPE* val, YYLTYPE* loc, yyscan_t scanner);
474 void _report(baseErr* new1);
475 params _asParams(const args& exprs);
476
477 nbool _onInjectObjSubs(obj& it, defBlock& blk);
478 nbool _onInjectCtor(obj& it, defBlock& blk);
479 std::vector<std::string> _extractParamTypeNames(const args& types);
480 std::string _joinVectorString(const std::vector<std::string>& container) const;
481 const node& _onDefArrayType(const narr& items);
482 std::vector<std::string> _toDotnames(const node& path);
483 void _onCompilationUnit(obj* subpod, defBlock* blk);
484 tstr<modifier> _makeDefaultModifier();
485
486 private:
487 tokenScan* _mode;
488 nbool _isIgnoreWhitespace;
489 tokenDispatcher _dispatcher;
490 std::vector<ncnt> _indents;
491 str _subpod;
492 tstr<scope> _filescope;
493 std::vector<nint> _states;
494 exprMaker _maker;
495 smartDedent _dedent;
496 srcSupplies _supplies;
497 std::vector<func*> _funcs;
498 ncnt _strTemplateCnt;
499 nchar _strOpenToken;
500 };
501} // namespace by
Function or object evaluation arguments
Definition args.hpp:22
Base class for error hierarchy
Definition baseErr.hpp:48
Definition block for organizing object definitions
Definition defBlock.hpp:16
Function/method call expression
Definition evalExpr.hpp:15
Factory for creating expressions with source location information
Definition exprMaker.hpp:18
Access modifier for type members
Definition modifier.hpp:13
Base class for all AST nodes in the byeol language
Definition node.hpp:195
Byeol runtime environment object
Definition obj.hpp:62
Function parameter list container
Definition params.hpp:16
Smart indentation management for code parsing
Definition smartDedent.hpp:23
Definition tnarr.hpp:9
Token queue management for parser
Definition tokenDispatcher.hpp:49
Base class for token scanning strategies
Definition tokenScan.hpp:29
to Top