bux API Reference
1.12.6
Static library of whatever are seen required in general purpose but not directly supported from Modern C++. Or whatever reusable originated from my side projects.
Toggle main menu visibility
Loading...
Searching...
No Matches
include
bux
GLR.h
Go to the documentation of this file.
1
#pragma once
2
3
#include "
ParserBase.h
"
// bux::T_StateID, bux::F_GetProducedT<>, LexBase.h
4
#include <memory>
// std::shared_ptr<>
5
#include <optional>
// std::optional<>
6
#include <vector>
// std::vector<>
7
8
namespace
bux
{
9
namespace
GLR
{
10
11
//
12
// Constants
13
//
14
enum
15
{
16
ACTION_SHIFT
,
17
ACTION_ACCEPT
,
18
ACTION_REDUCE_MIN
// Ensure it's the last ACTION_-constant
19
};
20
21
//
22
// Types
23
//
24
typedef
unsigned
T_ActionId
;
25
typedef
std::shared_ptr<const I_LexAttr>
C_LexPtr
;
26
typedef
C_LexInfoT<const I_LexAttr,std::shared_ptr>
C_LexInfo
;
27
typedef
F_GetProducedT<const I_LexAttr,std::shared_ptr>
F_GetProduced
;
28
29
class
C_Parser
;
30
typedef
std::function<void(
C_Parser
&parser)>
F_OncePostShift
;
31
typedef
std::function<void(
C_Parser
&,
const
F_GetProduced
&,
C_LexPtr
&,
F_OncePostShift
&)>
FH_Reduce
;
32
33
class
C_Parser
;
34
35
struct
I_ParserPolicy
36
{
37
// Types
38
struct
C_ReduceInfo
39
{
40
size_t
m_PopLength
;
41
T_LexID
m_ResultID
;
42
FH_Reduce
m_Reduce
;
43
};
44
45
// Virtuals
46
virtual
std::vector<T_ActionId>
action
(
T_StateID
state,
T_LexID
token)
const
= 0;
47
virtual
bool
changeToken
(
T_LexID
&token,
C_LexPtr
&attr)
const
;
48
virtual
size_t
getAcceptId
()
const
= 0;
49
virtual
bool
getTokenName
(
T_LexID
token, std::string &name)
const
;
50
virtual
T_StateID
nextState
(
T_StateID
state,
T_LexID
lex)
const
= 0;
51
virtual
void
getReduceInfo
(
size_t
prodId,
C_ReduceInfo
&info)
const
= 0;
52
virtual
void
onError
(
C_Parser
&parser,
const
C_SourcePos
&pos, std::string_view message)
const
= 0;
53
54
// Nonvirtuals
55
std::string
printToken
(
T_LexID
token)
const
;
56
};
57
58
class
C_Parser
:
public
I_Parser
59
{
60
public
:
61
62
// Data
63
const
I_ParserPolicy
&
m_policy
;
64
65
// Nonvirtuals
66
C_Parser
(
const
I_ParserPolicy
&policy);
67
void
eachAccepted
(std::function<
void
(
C_LexPtr
&)> apply);
68
void
onError
(
const
C_SourcePos
&pos, std::string_view message);
69
void
userData
(
void
*p) { m_userData = p; }
70
void
*
userData
()
const
{
return
m_userData; }
71
72
// Implement I_Parser
73
void
add
(
T_LexID
token,
unsigned
line,
unsigned
col,
I_LexAttr
*unownedAttr)
override
;
74
std::string_view
setSource
(std::string_view src)
override
;
75
76
private
:
77
78
// Types
79
struct
C_StateLR1;
80
typedef
std::shared_ptr<C_StateLR1> C_StateLR1Ptr;
81
82
struct
C_StateLR1:
C_LexInfo
83
{
84
// Data
85
C_StateLR1Ptr m_prev;
86
T_StateID
m_StateID;
87
T_LexID
m_TokenID;
88
89
// Nonvirtuals
90
C_StateLR1() =
default
;
91
C_StateLR1(C_StateLR1 &another);
92
void
operator=(C_StateLR1 &another);
93
};
94
typedef
std::vector<C_StateLR1Ptr> C_StateLR1Ptrs;
95
typedef
std::pair<C_StateLR1Ptr,F_OncePostShift> T_Reduced;
96
97
// Data
98
void
*m_userData{};
99
C_StateLR1Ptrs m_curTops, m_accepted;
100
std::string_view m_srcPath;
101
bool
m_added{};
102
103
// Nonvirtuals
104
C_Parser
(
C_Parser
&root,
const
C_StateLR1Ptr &nestedTop);
105
std::optional<T_Reduced> reduceOn(
size_t
id
, C_StateLR1Ptr iTop,
const
C_SourcePos &pos);
106
static
T_StateID
state(C_StateLR1Ptr &p);
107
};
108
109
}
// namespace GLR
110
}
// namespace bux
ParserBase.h
bux::GLR::C_Parser
Definition
GLR.h:59
bux::GLR::C_Parser::setSource
std::string_view setSource(std::string_view src) override
Definition
GLR.cpp:229
bux::GLR::C_Parser::C_Parser
C_Parser(const I_ParserPolicy &policy)
Definition
GLR.cpp:45
bux::GLR::C_Parser::m_policy
const I_ParserPolicy & m_policy
Definition
GLR.h:63
bux::GLR::C_Parser::userData
void userData(void *p)
Definition
GLR.h:69
bux::GLR::C_Parser::userData
void * userData() const
Definition
GLR.h:70
bux::GLR::C_Parser::onError
void onError(const C_SourcePos &pos, std::string_view message)
Definition
GLR.cpp:191
bux::GLR::C_Parser::eachAccepted
void eachAccepted(std::function< void(C_LexPtr &)> apply)
Definition
GLR.cpp:185
bux::GLR::C_Parser::add
void add(T_LexID token, unsigned line, unsigned col, I_LexAttr *unownedAttr) override
Definition
GLR.cpp:56
bux::GLR
Definition
GLR.cpp:6
bux::GLR::FH_Reduce
std::function< void(C_Parser &, const F_GetProduced &, C_LexPtr &, F_OncePostShift &)> FH_Reduce
Definition
GLR.h:31
bux::GLR::C_LexInfo
C_LexInfoT< const I_LexAttr, std::shared_ptr > C_LexInfo
Definition
GLR.h:26
bux::GLR::F_OncePostShift
std::function< void(C_Parser &parser)> F_OncePostShift
Definition
GLR.h:30
bux::GLR::ACTION_SHIFT
@ ACTION_SHIFT
Definition
GLR.h:16
bux::GLR::ACTION_ACCEPT
@ ACTION_ACCEPT
Definition
GLR.h:17
bux::GLR::ACTION_REDUCE_MIN
@ ACTION_REDUCE_MIN
Definition
GLR.h:18
bux::GLR::T_ActionId
unsigned T_ActionId
Definition
GLR.h:24
bux::GLR::C_LexPtr
std::shared_ptr< const I_LexAttr > C_LexPtr
Definition
GLR.h:25
bux::GLR::F_GetProduced
F_GetProducedT< const I_LexAttr, std::shared_ptr > F_GetProduced
Definition
GLR.h:27
bux
THE common namespace of bux library.
Definition
AtomiX.cpp:3
bux::F_GetProducedT
std::function< C_LexInfoT< T, C_Ptr > &(size_t)> F_GetProducedT
Definition
ParserBase.h:20
bux::T_LexID
uint32_t T_LexID
Definition
LexBase.h:36
bux::T_StateID
unsigned T_StateID
Definition
ParserBase.h:17
bux::C_LexInfoT
Definition
LexBase.h:54
bux::C_SourcePos
Definition
LexBase.h:39
bux::GLR::I_ParserPolicy::C_ReduceInfo
Definition
GLR.h:39
bux::GLR::I_ParserPolicy::C_ReduceInfo::m_PopLength
size_t m_PopLength
Definition
GLR.h:40
bux::GLR::I_ParserPolicy::C_ReduceInfo::m_Reduce
FH_Reduce m_Reduce
Definition
GLR.h:42
bux::GLR::I_ParserPolicy::C_ReduceInfo::m_ResultID
T_LexID m_ResultID
Definition
GLR.h:41
bux::GLR::I_ParserPolicy
Definition
GLR.h:36
bux::GLR::I_ParserPolicy::printToken
std::string printToken(T_LexID token) const
Definition
GLR.cpp:21
bux::GLR::I_ParserPolicy::getTokenName
virtual bool getTokenName(T_LexID token, std::string &name) const
Definition
GLR.cpp:16
bux::GLR::I_ParserPolicy::action
virtual std::vector< T_ActionId > action(T_StateID state, T_LexID token) const =0
bux::GLR::I_ParserPolicy::getAcceptId
virtual size_t getAcceptId() const =0
bux::GLR::I_ParserPolicy::onError
virtual void onError(C_Parser &parser, const C_SourcePos &pos, std::string_view message) const =0
bux::GLR::I_ParserPolicy::nextState
virtual T_StateID nextState(T_StateID state, T_LexID lex) const =0
bux::GLR::I_ParserPolicy::getReduceInfo
virtual void getReduceInfo(size_t prodId, C_ReduceInfo &info) const =0
bux::GLR::I_ParserPolicy::changeToken
virtual bool changeToken(T_LexID &token, C_LexPtr &attr) const
Definition
GLR.cpp:11
bux::I_LexAttr
Definition
LexBase.h:93
bux::I_Parser
Definition
LexBase.h:98
Generated by
1.18.0