로딩중...
검색중...
일치하는것 없음
by::parser 클래스 참조

Parser for byeol language source code 더 자세히 ...

#include <parser.hpp>

by::parser에 대한 상속 다이어그램 :
by::tworker< str, pod > by::tokenScanable

Public 멤버 함수

nodegetSubPod ()
 Retrieves the root node of the parsed sub-pod.
 
const nodegetSubPod () const BY_CONST_FUNC(getSubPod()) srcSupplies &getSrcSupplies()
 
const srcSuppliesgetSrcSupplies () const BY_CONST_FUNC(getSrcSupplies()) me &addSupply(const srcSupply &new 1)
 
me & addSupply (const tucontainable< srcSupply > &new1)
 
me & relSupplies ()
 
tokenDispatchergetDispatcher ()
 
std::vector< ncnt > & getIndents ()
 
nbool isInit () const
 
template<typename T >
void setScan ()
 Sets the scanning mode for the lexer.
 
void rel () override
 
int pushState (int newState)
 Pushes a new Flex scanner state onto the state stack.
 
int popState ()
 Pops a Flex scanner state from the state stack.
 
nint onScan (parser &ps, YYSTYPE *val, YYLTYPE *loc, yyscan_t scanner, nbool &isBypass) override
 Handles scanning for the lexer, overriding the base tokenScanable behavior.
 
nint onTokenEndOfFile ()
 Handles the end-of-file token.
 
nint onTokenColon (nint tok)
 Handles the colon token.
 
nint onTokenNewLine (nint tok)
 Handles the newline token.
 
nint onTokenLParan (nint tok)
 Handles the left parenthesis token.
 
nint onTokenRParan (nint tok)
 Handles the right parenthesis token.
 
nint onTokenComma (nint tok)
 Handles the comma token.
 
nbool onTokenEndOfBraces ()
 Handles the end of a braces block (e.g., }).
 
void onTokenStartOfStrTemplateBrace ()
 Handles the start of a string template brace (e.g., ${).
 
void onTokenBeginStr (nchar token)
 Handles the start of a string literal.
 
nchar getOpenStrToken ()
 returns quote character which used to start current string sequence.
 
nint onIndent (ncnt col, nint tok)
 Handles an increase in indentation.
 
nint onDedent (ncnt col, nint tok)
 Handles a decrease in indentation.
 
nint onIgnoreIndent (nint tok)
 Handles ignoring indentation (e.g., for inline blocks).
 
nchar onScanUnexpected (const nchar *token)
 Handles an unexpected token encountered during scanning.
 
void onSrcArea (const area &area)
 Callback for processing source area information from the lexer.
 
nodeonGet (const std::string &name)
 
nodeonGet (const std::string &name, const narr &args)
 
nodeonGet (node &from, const std::string &name)
 
nodeonGet (node &from, node &it)
 
nodeonGet (const std::string &name, const std::string &name2)
 
nodeonCallAccess (node &it, const narr &args)
 
FBOExpronUnaryMinus (const node &it)
 
FBOExpronUnaryNot (const node &it)
 
FUOExpronUnaryBitwiseNot (const node &it)
 
nodeonUnaryDoublePlus (node &it)
 
nodeonUnaryDoubleMinus (node &it)
 
FUOExpronUnaryPostfixDoublePlus (const node &it)
 
FUOExpronUnaryPostfixDoubleMinus (const node &it)
 
FBOExpronAdd (const node &lhs, const node &rhs)
 
FBOExpronSub (const node &lhs, const node &rhs)
 
FBOExpronMul (const node &lhs, const node &rhs)
 
FBOExpronDiv (const node &lhs, const node &rhs)
 
FBOExpronMod (const node &lhs, const node &rhs)
 
FBOExpronBitwiseAnd (const node &lhs, const node &rhs)
 
FBOExpronBitwiseXor (const node &lhs, const node &rhs)
 
FBOExpronBitwiseOr (const node &lhs, const node &rhs)
 
FBOExpronLShift (const node &lhs, const node &rhs)
 
FBOExpronRShift (const node &lhs, const node &rhs)
 
nodeonAssign (node &lhs, node &rhs)
 
nodeonAddAssign (node &lhs, node &rhs)
 
nodeonSubAssign (node &lhs, node &rhs)
 
nodeonMulAssign (node &lhs, node &rhs)
 
nodeonDivAssign (node &lhs, node &rhs)
 
nodeonModAssign (node &lhs, node &rhs)
 
FBOExpronGt (const node &lhs, const node &rhs)
 
FBOExpronGe (const node &lhs, const node &rhs)
 
FBOExpronLt (const node &lhs, const node &rhs)
 
FBOExpronLe (const node &lhs, const node &rhs)
 
FBOExpronEq (const node &lhs, const node &rhs)
 
FBOExpronNe (const node &lhs, const node &rhs)
 
FBOExpronAnd (const node &lhs, const node &rhs)
 
FBOExpronOr (const node &lhs, const node &rhs)
 
nodeonGetGeneric (const std::string &orgName, const args &typeParams)
 
nodeonGetElem (const node &arr, const node &idx)
 
nodeonGetArray (node &elemType)
 
objonPod (const node &path)
 
objonPod (const std::string &path)
 
objonPod ()
 
objonSubPod (obj &subpod)
 
endExpronEnd (const blockExpr &blk)
 
blockExpronBlock (const node *stmt)
 
blockExpronBlock (blockExpr *blk, const node *stmt)
 
blockExpronBlock ()
 
defBlockonDefBlock (node *stmt)
 
defBlockonDefBlock (defBlock *blk, node *stmt)
 
defBlockonDefBlock ()
 
nodeonFor (const std::string &iterName, const node &expr, const blockExpr &blk)
 
nodeonWhile (const node &condition, const blockExpr &blk)
 
nodeonParanthesisAsTuple (narr &tuple)
 
argsonTuple ()
 
argsonTuple (const node &elem)
 
argsonTuple (args &as, const node &elem)
 
argsonFuncCallTuple ()
 
argsonFuncCallTuple (const node &elem)
 
argsonFuncCallTuple (args &as, const node &elem)
 
argsonTypeNames (const node &param)
 
argsonTypeNames (args &params, const node &param)
 
template<typename T , typename Arg >
T * onPrimitive (const Arg &arg)
 
template<typename T >
T * onPrimitive ()
 
nodeonDefProp (const modifier &mod, const std::string &name, const node &rhs)
 
nodeonDefProp (const std::string &name, const node &rhs)
 
nodeonDefProp (const node &rhs)
 
nodeonDefProp (const modifier &mod, const node &rhs)
 
nodeonDefAssign (const modifier &mod, const std::string &name, const node *rhs)
 
nodeonDefAssign (const defPropExpr *prop, const node *rhs)
 
nodeonDefAssign (const std::string &name, const node *rhs)
 
objonDefOrigin (const std::string &name, defBlock &blk)
 
objonDefOrigin (const std::string &name, const narr &args, defBlock &blk)
 
genericOriginonDefObjGeneric (const std::string &name, const args &typeParams, defBlock &blk)
 
genericOriginonDefObjGeneric (const std::string &name, const args &typeParams, const narr &args, defBlock &blk)
 
nodeonDefArray (const narr &items)
 
nodeonDefSeq (const node &start, const node &end)
 
void onCompilationUnit (obj *subpod)
 
void onCompilationUnit (obj *subpod, defBlock *blk)
 
funconFuncSignature (const modifier &mod, const getExpr &access, const node *retType)
 
funconFuncSignature (const getExpr &access, const node *retType)
 
funconFuncSignature (const modifier &mod, node &it, const node *retType)
 
funconFuncSignature (node &it, const node *retType)
 
funconAbstractFunc (func &f)
 
nodeonFunc (func &func, const blockExpr &blk)
 
defNestedFuncExpronLambda (const narr &params, const node &retType, const blockExpr &blk)
 
ctoronCtor (const modifier &mod, const narr &args, const blockExpr &blk)
 
ctoronCtor (const narr &args, const blockExpr &blk)
 
ctoronCtor (const modifier &mod, const blockExpr &blk)
 
ctoronCtor (const blockExpr &blk)
 
narronParams ()
 
narronParams (const defPropExpr *elem)
 
narronParams (narr &it, const defPropExpr *elem)
 
modifieronModifier (nbool isPublic, nbool isOverriden)
 
nodeonDeclStmt (const narr &dotnames)
 
retExpronRet ()
 
retExpronRet (node &exp)
 
breakExpronBreak ()
 
nextExpronNext ()
 
evalExpronFillFromOfFuncCall (const node &me, evalExpr &to)
 
evalExpronEvalExpr (node &type, const narr &a)
 
evalExpronEvalExpr (node &type, const args &a)
 
isExpronIs (const node &me, const node &to)
 
asExpronAs (const node &me, const node &as)
 
ifExpronIf (const node &condition, const blockExpr &then)
 
ifExpronIf (const node &condition, const blockExpr &then, const blockExpr &elseBlk)
 
ifExpronIf (const node &condition, const blockExpr &then, const ifExpr &elseIf)
 
evalExpronIn (const node &it, const node &container)
 
void onEndFunc ()
 Callback invoked at the end of parsing a function definition.
 
void onParseErr (const std::string &msg, const nchar *symbolName)
 Reports a parsing error.
 
nint onScan (parser &ps, YYSTYPE *val, YYLTYPE *loc, yyscan_t scanner)
 Default entry point for token scanning.
 
virtual nint onScan (parser &ps, YYSTYPE *yylval, YYLTYPE *loc, yyscan_t yyscanner, nbool &isBypass)=0
 Pure virtual method for concrete token scanning implementations.
 
- by::tworker< str, pod >(으)로부터 상속된 Public 멤버 함수
 tworker (const errReport &rpt)
 
errReportgetReport ()
 
const errReportgetReport () const BY_CONST_FUNC(getReport()) me &setReport(errReport &rpt)
 
me & setFlag (nint newFlag)
 
me & addFlag (nint flag)
 
me & delFlag (nint clear)
 
nbool isFlag (nint flag) const
 
nint getFlag () const
 
me & setTask (const pod &root)
 
me & setTask (const pod *it) BY_SIDE_FUNC(it
 
podgetTask ()
 
const podgetTask () const BY_CONST_FUNC(getTask()) virtual void rel()
 
str work ()
 
const areagetArea () const BY_CONST_FUNC(_getArea()) nbool isOk() const
 
- by::tokenScanable(으)로부터 상속된 Public 멤버 함수
nint onScan (parser &ps, YYSTYPE *val, YYLTYPE *loc, yyscan_t scanner)
 Default entry point for token scanning.
 

Protected 멤버 함수

void * _scanString (const std::string &src, void *scanner)
 
exprMaker_getMaker ()
 
void _prepare () override
 Protected virtual method for preparation before starting the work.
 
void _onEndWork () override
 Protected virtual method called after the work is completed.
 
str _onWork () override
 
- by::tworker< str, pod >(으)로부터 상속된 Protected 멤버 함수
void _report (baseErr *e)
 
area_getArea ()
 
void _onEndErrReport (const errReport &rpt) const
 

Friends

class coreInternal
 

추가로 상속된 멤버들

- by::tworker< str, pod >(으)로부터 상속된 Public 타입
enum  logFlag
 
- by::tworker< str, pod >(으)로부터 상속된 Public 속성
me setTask it
 
me setTask * this
 

상세한 설명

Parser for byeol language source code

Entry point for the byeol parsing component, inheriting from worker. work() returns the parsed result as pod.

Similar Structure to Stela Parser

Since the stela language itself is part of the byeol language, its parser is also based on the byeol language parser. The stela parser is less complex compared to the byeol parser, so it's recommended to examine the stela parser code first before looking at the core module.

Scanner - Bison - Parser Structure

Uses flex and bison, naming flex as lowscanner and bison as lowparser. These low-level scanner and parser only exist inside the parser component and are not exposed externally. When parser::work() executes, it runs lowscanner, which tokenizes and passes tokens to lowparser. Lowparser matches rules and passes those events back to parser. Therefore, parser's functions starting with on are event handling functions that define how to create nodes and construct the AST.

lowparser.y Lifecycle Management

In each rule, calling parser::onXXXX() functions often creates new objects on the heap using the new keyword (not all functions do this). If these arguments are placed directly into tbicontainer, that's fine, but otherwise they must be bound with tstr beforehand to avoid memory leaks.

// - lowparser.y
$$ = PS.onPod(*$2); // onpod() returns new pod()
}
tstr<obj> pak($1); // Without binding with tstr like this,
PS.onCompilationUnit(pak.get()); // if the pak value has issues inside onCompilationUnit()
// and the operation is cancelled, the pod object
// created on the heap becomes a memory leak.
}
Pod
Definition pod.hpp:21
Definition tnarr.hpp:9

This applies not only to onXXXX() functions but also to string tokens. See the following code:

// -- lowscanner.l
<stateString>\" { // When string scan ends
if(!yylval->asStr) yylval->asStr = new std::string(); // Creates string object with new
....
return STRVAL;
}
// -- lowparser.y
...
| STRVAL { // When STRVAL comes from scanner
$$ = PS.onPrimitive<nStr>(*$1); // Pass it first. String is always immutable in this project
// so the object is always copied.
delete $1; // Since the object is copied, delete the original object.

Indentation Rule

The byeol language applies the offside rule, making it very sensitive to indentation. Unlike typical languages, it must be able to count how many spaces exist immediately after a newline. Once indentation is determined and the code line's scope is confirmed, subsequent spaces should be ignored. Consider the following byeol language example:

foo(val int) void
if val > 0
if val < 5
print("0 < val < 5")
print("end of func") # 1)
Function definition in byeol language
Definition func.hpp:38

After parsing print("0 < val < 5"), when parsing the next line print("end of func"), the parser must count the leading spaces and compare with the space counts for each scope to determine which scope this code line belongs to. Looking at the example, we can intuitively see that print("end of func") has the same spacing as if val > 0, meaning it belongs directly inside the foo() body. This means at this point, both the scope inside if val > 0 and the scope inside if val < 5 are closed. So lowscanner must add 2 DEDENT tokens (signifying scope termination) before lowparser recognizes print("end of func").

tokenDispatcher

Flex uses a separately designated stream called yyin to get characters and define them as tokens. As shown in the example above, adding tokens during parsing means adding specific characters to this stream. Typically unput is used for this, but to flexibly handle multiple unputs or pushing to the front, lowscanner internally uses tokenDispatcher.

tokenScan

As explained earlier, detecting indentation is crucial. Accurate space counting is required, so a strategy pattern is applied, switching between normalScan and indentScan. When a newline is detected, it switches to indentScan to count spaces accurately and determine scope.

멤버 함수 문서화

◆ _onEndWork()

void by::parser::_onEndWork ( )
overrideprotectedvirtual

Protected virtual method called after the work is completed.

This hook allows derived classes to perform any necessary cleanup or finalization after _onWork() has finished.

by::tworker< str, pod >(으)로부터 재구현되었습니다.

◆ _onWork()

str by::parser::_onWork ( )
overrideprotectedvirtual

parse with given srcSupply instances.

매개변수
scriptis null terminated cstring.
반환값
last parsed sub pod.

by::tworker< str, pod >를 구현.

◆ _prepare()

void by::parser::_prepare ( )
overrideprotectedvirtual

Protected virtual method for preparation before starting the work.

This hook allows derived classes to perform any necessary setup or initialization before _onWork() is invoked.

by::tworker< str, pod >(으)로부터 재구현되었습니다.

◆ getOpenStrToken()

nchar by::parser::getOpenStrToken ( )

returns quote character which used to start current string sequence.

반환값
quote or double quote to be used to open string literal.

◆ getSubPod()

node * by::parser::getSubPod ( )

Retrieves the root node of the parsed sub-pod.

This method provides access to the top-level AST node representing the entire parsed sub-pod.

반환값
A pointer to the root node of the sub-pod.

◆ onDedent()

nint by::parser::onDedent ( ncnt col,
nint tok )

Handles a decrease in indentation.

매개변수
colThe column count of the new indentation level.
tokThe token ID that triggered the dedentation.
반환값
The token ID for DEDENT.

◆ onEndFunc()

void by::parser::onEndFunc ( )

Callback invoked at the end of parsing a function definition.

This method handles any cleanup or finalization required after a function's body has been parsed.

◆ onIgnoreIndent()

nint by::parser::onIgnoreIndent ( nint tok)

Handles ignoring indentation (e.g., for inline blocks).

매개변수
tokThe token ID.
반환값
The token ID.

◆ onIndent()

nint by::parser::onIndent ( ncnt col,
nint tok )

Handles an increase in indentation.

매개변수
colThe column count of the new indentation level.
tokThe token ID that triggered the indentation.
반환값
The token ID for INDENT.

◆ onParseErr()

void by::parser::onParseErr ( const std::string & msg,
const nchar * symbolName )

Reports a parsing error.

매개변수
msgThe error message.
symbolNameThe name of the symbol related to the error.

◆ onScan() [1/3]

nint by::tokenScanable::onScan ( parser & ps,
YYSTYPE * val,
YYLTYPE * loc,
yyscan_t scanner )

Default entry point for token scanning.

This non-virtual method acts as a wrapper that internally dispatches to the pure virtual onScan method, which must be implemented by concrete scanner strategies.

매개변수
psThe parser instance.
valThe YYSTYPE value pointer for the token.
locThe YYLTYPE location pointer for the token.
scannerThe Flex scanner instance.
반환값
The token ID.

◆ onScan() [2/3]

nint by::parser::onScan ( parser & ps,
YYSTYPE * val,
YYLTYPE * loc,
yyscan_t scanner,
nbool & isBypass )
overridevirtual

Handles scanning for the lexer, overriding the base tokenScanable behavior.

매개변수
psThe parser instance.
valThe YYSTYPE value pointer for the token.
locThe YYLTYPE location pointer for the token.
scannerThe Flex scanner instance.
isBypassFlag indicating if indentation bypass is active.
반환값
The token ID.

by::tokenScanable를 구현.

◆ onScan() [3/3]

virtual nint by::tokenScanable::onScan ( parser & ps,
YYSTYPE * yylval,
YYLTYPE * loc,
yyscan_t yyscanner,
nbool & isBypass )
virtual

Pure virtual method for concrete token scanning implementations.

매개변수
psThe parser instance.
yylvalThe YYSTYPE value pointer for the token.
locThe YYLTYPE location pointer for the token.
yyscannerThe Flex scanner instance.
isBypassFlag indicating if indentation bypass is active.
반환값
The token ID.

by::tokenScanable를 구현.

◆ onScanUnexpected()

nchar by::parser::onScanUnexpected ( const nchar * token)

Handles an unexpected token encountered during scanning.

매개변수
tokenThe unexpected token string.
반환값
The token ID for an error.

◆ onSrcArea()

void by::parser::onSrcArea ( const area & area)

Callback for processing source area information from the lexer.

매개변수
areaThe source area (e.g., line, column) information.

◆ onTokenBeginStr()

void by::parser::onTokenBeginStr ( nchar token)

Handles the start of a string literal.

Stores the opening quote character ('"' or '\'') to distinguish between double-quoted and single-quoted strings during parsing. This enables support for both quote types using the same scanner state.

매개변수
tokenThe opening quote character ('"' or '\'')

◆ onTokenColon()

nint by::parser::onTokenColon ( nint tok)

Handles the colon token.

매개변수
tokThe token ID of the colon.
반환값
The token ID.

◆ onTokenComma()

nint by::parser::onTokenComma ( nint tok)

Handles the comma token.

매개변수
tokThe token ID of the comma.
반환값
The token ID.

◆ onTokenEndOfBraces()

nbool by::parser::onTokenEndOfBraces ( )

Handles the end of a braces block (e.g., }).

반환값
true if the end of braces was handled, false otherwise.

◆ onTokenEndOfFile()

nint by::parser::onTokenEndOfFile ( )

Handles the end-of-file token.

반환값
The token ID for end-of-file.

◆ onTokenLParan()

nint by::parser::onTokenLParan ( nint tok)

Handles the left parenthesis token.

매개변수
tokThe token ID of the left parenthesis.
반환값
The token ID.

◆ onTokenNewLine()

nint by::parser::onTokenNewLine ( nint tok)

Handles the newline token.

매개변수
tokThe token ID of the newline.
반환값
The token ID.

◆ onTokenRParan()

nint by::parser::onTokenRParan ( nint tok)

Handles the right parenthesis token.

매개변수
tokThe token ID of the right parenthesis.
반환값
The token ID.

◆ onTokenStartOfStrTemplateBrace()

void by::parser::onTokenStartOfStrTemplateBrace ( )

Handles the start of a string template brace (e.g., ${).

주의
This method is likely related to parsing interpolated strings.

◆ popState()

int by::parser::popState ( )

Pops a Flex scanner state from the state stack.

반환값
The previous state.

◆ pushState()

int by::parser::pushState ( int newState)

Pushes a new Flex scanner state onto the state stack.

매개변수
newStateThe new state to push.
반환값
The new state.

◆ setScan()

template<typename T >
void by::parser::setScan ( )
inline

Sets the scanning mode for the lexer.

템플릿 파라메터
TThe type of the scanner strategy (e.g., tokenScan, indentScan).
주의
Logs the change in scan mode for debugging purposes.

이 클래스에 대한 문서화 페이지는 다음의 파일로부터 생성되었습니다.:
to Top