#include "ParsingTable.h"
namespace
{
namespace
{
namespace
{
using
namespace
vl
::
parsing
::
tabling
;
BEGIN_SERIALIZATION(ParsingTable::AttributeInfo)
template
<>
struct
<
::
> {
template
<
typename
>
static
void
(
&
,
::
&
) {
BEGIN_SERIALIZATION(ParsingTable::AttributeInfoList)
template
<>
struct
<
::
> {
template
<
typename
>
static
void
(
&
,
::
&
) {
BEGIN_SERIALIZATION(ParsingTable::TreeTypeInfo)
template
<>
struct
<
::
> {
template
<
typename
>
static
void
(
&
,
::
&
) {
SERIALIZE(attributeIndex)
BEGIN_SERIALIZATION(ParsingTable::TreeFieldInfo)
template
<>
struct
<
::
> {
template
<
typename
>
static
void
(
&
,
::
&
) {
SERIALIZE(attributeIndex)
BEGIN_SERIALIZATION(ParsingTable::TokenInfo)
template
<>
struct
<
::
> {
template
<
typename
>
static
void
(
&
,
::
&
) {
SERIALIZE(regexTokenIndex)
SERIALIZE(attributeIndex)
BEGIN_SERIALIZATION(ParsingTable::StateInfo)
template
<>
struct
<
::
> {
template
<
typename
>
static
void
(
&
,
::
&
) {
SERIALIZE(stateExpression)
BEGIN_SERIALIZATION(ParsingTable::RuleInfo)
template
<>
struct
<
::
> {
template
<
typename
>
static
void
(
&
,
::
&
) {
SERIALIZE(rootStartState)
SERIALIZE(attributeIndex)
BEGIN_SERIALIZATION(ParsingTable::Instruction)
template
<>
struct
<
::
> {
template
<
typename
>
static
void
(
&
,
::
&
) {
SERIALIZE(instructionType)
SERIALIZE(stateParameter)
SERIALIZE_ENUM(ParsingTable::Instruction::InstructionType)
template
<>
struct
<
::
::
> {
template
<
typename
>
static
void
(
<
>&
,
::
::
&
) {
=
0
;
<
>::
(
,
v
);
= (
::
::
)
v
; }
template
<
typename
>
static
void
(
<
>&
,
::
::
&
) {
= (
)
;
<
>::
(
,
v
); } };
BEGIN_SERIALIZATION(ParsingTable::LookAheadInfo)
template
<>
struct
<
::
> {
template
<
typename
>
static
void
(
&
,
::
&
) {
BEGIN_SERIALIZATION(ParsingTable::TransitionItem)
template
<>
struct
<
::
> {
template
<
typename
>
static
void
(
&
,
::
&
) {
BEGIN_SERIALIZATION(ParsingTable::TransitionBag)
template
<>
struct
<
::
> {
template
<
typename
>
static
void
(
&
,
::
&
) {
SERIALIZE(transitionItems)
}
}
namespace
{
namespace
{
using
namespace
collections
;
using
namespace
regex
;
#ifdef VCZH_GCC
const vint ParsingTable::TokenBegin;
const vint ParsingTable::TokenFinish;
const vint ParsingTable::NormalReduce;
const vint ParsingTable::LeftRecursiveReduce;
const vint ParsingTable::UserTokenStart;
#endif
<
::
>
::
::
(
const
&
)
{
for
(
=
0
;
i
<
.
();
i
++)
{
if
(
i
]
==
)
{
return
i
];
}
}
return
0
;
}
::
::
::
::
(
<
>
,
<
>
)
{
if
(
.
()>
.
())
{
return
::
::
;
}
for
(
=
0
;
i
<
.
();
i
++)
{
if
(
i
]!=
i
])
{
return
::
::
;
}
}
return
.
()<
.
()?
::
::
:
::
::
;
}
void
::
::
(
<
>
,
<
>
,
,
collections
::
<
>&
,
collections
::
<
<
>>&
)
{
if
(
.
(
))
return
;
.
(
);
for
(
=
0
;
i
<
();
i
++)
{
if
(
<
>
=
(
,
i
))
{
FOREACH(Ptr<TransitionItem>, item, bag->transitionItems)
if
(
bool
=
true
)
for
(
const
::
vl
::
collections
::
<
<
>>&
= ::
vl
::
collections
::
(
bag
);
__scope_variable_flag__
;
__scope_variable_flag__
=
false
)
for
(
<
>
;
__foreach_iterator__
.
(
item
);)
{
if
(
i
==
::
||
i
==
::
)
{
(
,
,
item
,
,
);
}
else
{
<
>
=
new
;
info
=
item
;
if
(
)
{
(
info
,
);
}
info
.
(
i
);
.
(
info
);
}
}
}
}
.
(
);
}
void
::
::
(
<
>
,
<
>
,
,
collections
::
<
<
>>&
)
{
<
>
;
(
,
,
,
walkedStates
,
);
}
enum
{
,
LeftRecursiveReduceTransition
,
,
};
(
<
::
>
)
{
bool
=
false
;
bool
=
false
;
FOREACH(ParsingTable::Instruction, ins, t->instructions)
if
(
bool
=
true
)
for
(
const
::
vl
::
collections
::
<
::
>&
= ::
vl
::
collections
::
(
);
__scope_variable_flag__
;
__scope_variable_flag__
=
false
)
for
(
::
;
__foreach_iterator__
.
(
ins
);)
{
switch
(
ins
.
)
{
case
::
::
:
hasReduce
=
true
;
break
;
case
::
::
:
hasLrReduce
=
true
;
break
;
default
:;
}
}
return
hasLrReduce
?
LeftRecursiveReduceTransition
:
hasReduce
?
:
;
}
::
::
::
::
(
<
>
,
<
>
,
)
{
if
(
!=
)
return
;
if
(
!=
)
{
=
(
);
=
(
);
if
(
level1
>
level2
)
return
;
if
(
level1
<
level2
)
return
;
}
=
.
();
=
.
();
=
ic1
<
ic2
?
ic1
:
ic2
;
for
(
=
0
;
i
<
ic
;
i
++)
{
=
i
];
=
i
];
if
(
s1
>
s2
)
{
return
;
}
else
if
(
s1
<
s2
)
{
return
;
}
}
if
(
==
)
{
if
(
ic1
>
ic2
)
{
return
;
}
else
if
(
ic1
<
ic2
)
{
return
;
}
}
return
;
}
::
::
(
<
>
,
<
>
,
)
{
=
(
,
,
);
switch
(
order
)
{
case
:
return
-
1
;
case
:
return
1
;
default
:
return
0
;
}
}
template
<
typename
>
void
::
(
&
)
{
<<
<<
<<
<<
<<
<<
<<
<<
<<
<<
<<
;
}
::
(
stream
::
&
)
{
stream
::
internal
::
(
);
(
reader
);
}
void
::
(
stream
::
&
)
{
stream
::
internal
::
(
);
(
writer
);
}
#if defined(VCZH_GCC) && defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wnull-dereference"
#endif
::
(
,
,
,
,
,
,
)
:ambiguity(
false
)
,tokenCount(
+
)
,stateCount(
)
,attributeInfos(
)
,treeTypeInfos(
)
,treeFieldInfos(
)
,tokenInfos(
+
)
,discardTokenInfos(
)
,stateInfos(
)
,ruleInfos(
)
,transitionBags((
+
)*
)
{
}
::
()
{
}
bool
::
()
{
return
;
}
void
::
(
bool
)
{
=
;
}
::
()
{
return
.
();
}
<
::
>
::
(
)
{
return
];
}
void
::
(
,
<
>
)
{
]
;
}
::
()
{
return
.
();
}
const
::
&
::
(
)
{
return
];
}
const
::
&
::
(
const
&
)
{
=
.
().
(
);
if
(
index
==-
1
)
return
*(
const
*)
0
;
return
.
().
(
index
)];
}
void
::
(
,
const
&
)
{
]
;
}
::
()
{
return
.
();
}
const
::
&
::
(
)
{
return
];
}
const
::
&
::
(
const
&
,
const
&
)
{
<
,
>
(
,
);
=
.
().
(
key
);
if
(
index
==-
1
)
return
*(
const
*)
0
;
return
.
().
(
index
)];
}
void
::
(
,
const
&
)
{
]
;
}
::
()
{
return
;
}
const
::
&
::
(
)
{
return
];
}
void
::
(
,
const
&
)
{
]
;
}
::
()
{
return
.
();
}
const
::
&
::
(
)
{
return
];
}
void
::
(
,
const
&
)
{
]
;
}
::
()
{
return
;
}
const
::
&
::
(
)
{
return
];
}
void
::
(
,
const
&
)
{
]
;
}
::
()
{
return
.
();
}
const
::
&
::
(
const
&
)
{
=
.
().
(
);
if
(
index
==-
1
)
return
*(
const
*)
0
;
return
.
().
(
index
)];
}
const
::
&
::
(
)
{
return
];
}
void
::
(
,
const
&
)
{
]
;
}
const
regex
::
&
::
()
{
return
*
.
();
}
<
::
>
::
(
,
)
{
return
*
+
];
}
void
::
(
,
,
<
>
)
{
*
+
]
;
}
void
::
()
{
<
>
;
FOREACH(TokenInfo, info, From(tokenInfos).Skip(UserTokenStart))
if
(
bool
=
true
)
for
(
const
::
vl
::
collections
::
<
>&
= ::
vl
::
collections
::
(
(
).Skip(
));
__scope_variable_flag__
;
__scope_variable_flag__
=
false
)
for
(
;
__foreach_iterator__
.
(
info
);)
{
tokens
.
(
info
.
regex
);
}
FOREACH(TokenInfo, info, discardTokenInfos)
if
(
bool
=
true
)
for
(
const
::
vl
::
collections
::
<
>&
= ::
vl
::
collections
::
(
);
__scope_variable_flag__
;
__scope_variable_flag__
=
false
)
for
(
;
__foreach_iterator__
.
(
info
);)
{
tokens
.
(
info
.
regex
);
}
=
0
;
for
(
=
;
i
<
.
();
i
++)
{
i
].
=
regexTokenIndex
++;
}
for
(
=
0
;
i
<
.
();
i
++)
{
i
].
=
regexTokenIndex
++;
}
new
(
tokens
, {});
.
();
FOREACH_INDEXER(RuleInfo, rule, index, ruleInfos)
if
(
bool
=
true
)
for
(
const
::
vl
::
collections
::
<
>&
= ::
vl
::
collections
::
(
);
__scope_variable_flag__
;
__scope_variable_flag__
=
false
)
if
(
bool
=
true
)
for
(
=
0
;
__scope_variable_flag__
;
__scope_variable_flag__
=
false
)
for
(
;
__foreach_iterator__
.
(
rule
);
index
++)
{
.
(
rule
.
,
index
);
}
for
(
=
0
;
i
<
.
();
i
++)
{
&
=
i
];
info
.
info
.
]].
;
}
.
();
FOREACH_INDEXER(TreeTypeInfo, info, index, treeTypeInfos)
if
(
bool
=
true
)
for
(
const
::
vl
::
collections
::
<
>&
= ::
vl
::
collections
::
(
);
__scope_variable_flag__
;
__scope_variable_flag__
=
false
)
if
(
bool
=
true
)
for
(
=
0
;
__scope_variable_flag__
;
__scope_variable_flag__
=
false
)
for
(
;
__foreach_iterator__
.
(
info
);
index
++)
{
.
(
info
.
,
index
);
}
.
();
FOREACH_INDEXER(TreeFieldInfo, info, index, treeFieldInfos)
if
(
bool
=
true
)
for
(
const
::
vl
::
collections
::
<
>&
= ::
vl
::
collections
::
(
);
__scope_variable_flag__
;
__scope_variable_flag__
=
false
)
if
(
bool
=
true
)
for
(
=
0
;
__scope_variable_flag__
;
__scope_variable_flag__
=
false
)
for
(
;
__foreach_iterator__
.
(
info
);
index
++)
{
<
,
>
(
info
.
,
info
.
);
.
(
key
,
index
);
}
}
bool
::
(
)
{
return
>=
0
&&
<
-
;
}
::
(
)
{
return
(
)?
+
:-
1
;
}
::
GetTableDiscardTokenIndex
(
)
{
return
>=
-
?
-(
-
):-
1
;
}
#if defined(VCZH_GCC) && defined(__clang__)
#pragma clang diagnostic pop
#endif
}
}
}