#include "ParsingState.h"
#if defined(VCZH_GCC) && defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wnull-dereference"
#endif
namespace
{
namespace
{
namespace
{
using
namespace
collections
;
using
namespace
regex
;
::
::
(
const
*
,
)
:walker(
)
,firstToken(
)
,currentToken(
)
,currentValue(-
1
)
,index(-
1
)
{
}
::
::
(
const
&
)
:walker(
.
)
,firstToken(
.
)
,currentToken(
.
)
,currentValue(
.
)
,index(
.
)
{
}
<
>*
::
::
()
const
{
return
new
(*
this
);
}
const
&
::
::
()
const
{
return
;
}
::
::
()
const
{
return
;
}
bool
::
::
()
{
=
->
(
);
if
(
newToken
==-
3
)
return
false
;
=
newToken
;
++;
=
->
(
);
return
true
;
}
void
::
::
()
{
=
;
=-
1
;
=-
1
;
}
::
::
(
const
*
)
:walker(
)
{
}
collections
::
<
>*
::
::
()
const
{
return
new
(
,
->
);
}
::
::
(
const
*
)
:walker(
)
{
}
collections
::
<
>*
::
::
()
const
{
return
new
(
,
->
-
1
);
}
::
(
)
const
{
if
(
==-
2
)
{
return
-
1
;
}
else
if
(-
1
<=
&&
<
.
())
{
++;
while
(
0
<=
&&
<
.
())
{
if
(
(
].
))
{
break
;
}
else
{
++;
}
}
return
;
}
else
{
return
-
3
;
}
}
::
(
)
const
{
if
(
==-
1
)
{
return
::
;
}
else
if
(
==
.
())
{
return
::
;
}
else
if
(
0
<=
&&
<
.
())
{
return
(
].
);
}
else
{
return
-
1
;
}
}
::
(
collections
::
<
regex
::
>&
,
<
>
)
:tokens(
)
,table(
)
,currentToken(-
2
)
, tokenLookAhead(
this
)
, reduceLookAhead(
this
)
{
}
::
()
{
}
const
collections
::
<
>&
::
()
const
{
return
;
}
const
collections
::
<
>&
::
()
const
{
return
;
}
void
::
()
{
=-
2
;
}
bool
::
()
{
=
(
);
return
!=-
3
;
}
::
()
const
{
return
(
);
}
regex
::
*
::
()
const
{
=
();
return
index
==-
1
?
0
:&
index
];
}
::
()
const
{
if
(
0
<=
&&
<
.
())
{
return
;
}
else
{
return
-
1
;
}
}
::
::
()
:currentState(-
1
)
,tokenSequenceIndex(
0
)
,shiftToken(
0
)
,reduceToken(
0
)
{
}
::
::
(
const
::
&
)
:currentState(
.
)
,tokenSequenceIndex(
0
)
,shiftToken(
0
)
,reduceToken(
0
)
{
}
::
::
(
const
&
)
:currentState(
.
)
,tokenSequenceIndex(
.
)
,shiftToken(
.
)
,reduceToken(
.
)
{
(
,
.
);
(
,
.
);
}
::
(
const
&
,
<
>
,
)
:input(
.
())
,table(
)
,parsingRuleStartState(-
1
)
{
(
,
().
(
,
));
new
(
,
);
}
::
()
{
}
const
&
::
()
{
return
;
}
<
>
::
()
{
return
;
}
const
collections
::
<
regex
::
>&
::
()
{
return
;
}
regex
::
*
::
(
)
{
if
(
<=
0
)
{
=
0
;
}
else
if
(
>
.
())
{
=
.
();
}
return
==
.
()?
0
:&
];
}
::
(
const
&
)
{
const
::
&
=
(
);
auto
= &
info
;
if
(
infoExists
)
{
();
();
new
(
info
);
;
=
info
.
;
return
;
}
return
-
1
;
}
::
()
{
return
;
}
::
()
{
return
;
}
::
()
{
return
()==
::
?
.
()
:
();
}
::
GetCurrentTableTokenIndex
()
{
return
();
}
const
collections
::
<
>&
::
()
{
return
;
}
::
()
{
return
;
}
void
::
()
{
();
}
bool
::
TestTransitionItemInFuture
(
,
*
,
::
*
,
const
collections
::
<
>*
)
{
bool
=
true
;
if
(
->
.
()>
0
&&
)
{
passLookAheadTest
=
false
;
FOREACH(Ptr<ParsingTable::LookAheadInfo>, info, item->lookAheads)
if
(
bool
=
true
)
for
(
const
::
vl
::
collections
::
<
<
::
>>&
= ::
vl
::
collections
::
(
->
);
__scope_variable_flag__
;
__scope_variable_flag__
=
false
)
for
(
<
::
>
;
__foreach_iterator__
.
(
info
);)
{
=
0
;
FOREACH(vint, token, *lookAheadTokens)
if
(
bool
=
true
)
for
(
const
::
vl
::
collections
::
<
>&
= ::
vl
::
collections
::
(*
);
__scope_variable_flag__
;
__scope_variable_flag__
=
false
)
for
(
;
__foreach_iterator__
.
(
token
);)
{
if
(
info
index
]!=
token
)
{
break
;
}
index
++;
if
(
index
>=
info
.
())
{
break
;
}
}
if
(
index
==
info
.
())
{
passLookAheadTest
=
true
;
break
;
}
}
}
if
(!
passLookAheadTest
)
{
return
false
;
}
=
.
()-
->
;
=
.
()-
->
+
->
.
();
if
(
->
.
()<=
totalStackDepth
)
{
if
(
!=
::
||
->
.
()==
totalStackDepth
)
{
bool
=
true
;
for
(
=
0
;
j
<
->
.
();
j
++)
{
=
j
<
->
.
()
?
->
->
.
()-
1
-
j
]
:
availableStackDepth
-
1
-(
j
-
->
.
())]
;
if
(
->
j
]!=
state
)
{
match
=
false
;
}
}
if
(
match
)
{
return
true
;
}
}
}
return
false
;
}
::
*
::
(
,
*
,
const
collections
::
<
>*
)
{
::
*
=
(
->
,
).
();
if
(
bag
)
{
for
(
=
0
;
i
<
bag
->
.
();
i
++)
{
::
*
=
bag
->
i
].
();
if
(
TestTransitionItemInFuture
(
,
,
item
,
))
{
return
item
;
}
}
}
return
0
;
}
::
*
::
(
,
const
collections
::
<
>*
)
{
;
future
.
=
;
return
(
, &
future
,
);
}
void
::
(
::
*
,
*
,
*
)
{
if
(
)
{
->
=
->
;
(
->
,
->
);
}
else
{
->
=
0
;
->
.
();
}
->
=
->
;
->
=
->
;
->
=
;
->
=
;
->
=
0
;
for
(
=
0
;
j
<
->
.
();
j
++)
{
::
&
=
->
j
];
switch
(
ins
.
)
{
case
::
::
:
{
->
.
(
ins
.
);
}
break
;
case
::
::
:
{
if
(
->
.
()==
0
)
{
->
++;
}
else
{
->
.
(
->
.
()-
1
);
}
}
break
;
default
:;
}
}
}
::
::
(
::
*
,
regex
::
*
,
,
,
bool
)
{
if
(
)
{
if
(!
)
{
=
;
=
;
}
}
if
(
->
>=
::
)
{
if
(
==
0
)
{
.
(
);
}
++;
}
;
result
.
=
->
;
result
.
=
;
result
.
=
?
():-
1
;
result
.
=
;
result
.
=
->
;
result
.
=
;
result
.
=
;
result
.
=
;
for
(
=
;
j
<
+
;
j
++)
{
::
&
=
->
j
];
switch
(
ins
.
)
{
case
::
::
:
{
.
(
ins
.
);
.
(
);
=
;
=
;
}
break
;
case
::
::
:
{
.
(
.
()-
1
);
result
.
(
,
);
=
.
()-
1
];
.
(
.
()-
1
);
}
break
;
case
::
::
:
{
result
.
(
,
);
if
(
)
{
=
;
}
}
break
;
default
:;
}
}
if
(
)
{
=
;
}
if
(
->
==
::
&&
)
{
=
.
()-
1
];
.
(
.
()-
1
);
result
.
(
,
);
}
=
->
;
return
result
;
}
::
::
(
::
*
,
regex
::
*
)
{
return
(
,
,
0
,
->
.
(),
true
);
}
bool
::
(
,
*
,
*
,
const
collections
::
<
>*
)
{
::
*
=
0
;
if
(
)
{
selectedItem
=
(
,
,
);
}
else
{
selectedItem
=
(
,
);
}
if
(!
selectedItem
)
{
return
false
;
}
(
selectedItem
,
,
);
return
true
;
}
::
::
(
,
regex
::
*
,
const
collections
::
<
>*
)
{
::
*
=
(
,
);
if
(
item
)
{
return
(
item
,
);
}
return
();
}
::
::
()
{
if
(
()==-
1
)
{
return
();
}
=
();
*
=
();
bool
=
false
;
=
(
token
,
regexToken
, &
());
if
(!
result
)
{
result
(
::
,
0
, &
());
tryReduce
=
true
;
}
if
(!
result
)
{
result
(
::
,
0
, &
());
tryReduce
=
true
;
}
if
(
result
&& !
tryReduce
)
{
();
}
return
result
;
}
bool
::
(
,
*
)
{
;
fakePrevious
.
=
;
*
=
?
:&
fakePrevious
;
::
*
=
(
realPrevious
->
,
).
();
if
(
bag
)
{
for
(
=
0
;
i
<
bag
->
.
();
i
++)
{
::
*
=
bag
->
i
].
();
if
(
TestTransitionItemInFuture
(
,
realPrevious
,
item
,
0
))
{
return
true
;
}
}
}
return
false
;
}
bool
::
(
,
*
,
collections
::
<
*>&
)
{
;
fakePrevious
.
=
;
*
=
?
:&
fakePrevious
;
::
*
=
(
realPrevious
->
,
).
();
bool
=
false
;
if
(
bag
)
{
for
(
=
0
;
i
<
bag
->
.
();
i
++)
{
::
*
=
bag
->
i
].
();
if
(
TestTransitionItemInFuture
(
,
realPrevious
,
item
,
0
))
{
*
=
new
;
(
item
,
,
now
);
.
(
now
);
successful
=
true
;
}
}
}
return
successful
;
}
bool
::
(
collections
::
<
*>&
,
,
,
collections
::
<
*>&
)
{
if
(
()==-
1
)
{
return
false
;
}
=
();
*
=
();
=
.
();
for
(
=
0
;
i
<
;
i
++)
{
*
=
+
i
];
(
token
,
previous
,
);
}
if
(
.
() ==
oldPossibilitiesCount
)
{
return
false
;
}
for
(
=
oldPossibilitiesCount
;
i
<
.
();
i
++)
{
i
]->
=
regexToken
;
}
return
true
;
}
bool
::
(
collections
::
<
*>&
,
,
,
collections
::
<
*>&
)
{
if
(
()==-
1
)
{
return
false
;
}
=
.
();
for
(
=
0
;
i
<
;
i
++)
{
*
=
+
i
];
(
::
,
previous
,
);
}
return
.
() >
oldPossibilitiesCount
;
}
bool
::
ExploreLeftRecursiveReduce
(
collections
::
<
*>&
,
,
,
collections
::
<
*>&
)
{
if
(
()==-
1
)
{
return
false
;
}
=
.
();
for
(
=
0
;
i
<
;
i
++)
{
*
=
+
i
];
(
::
,
previous
,
);
}
return
.
() >
oldPossibilitiesCount
;
}
::
*
::
()
{
*
=
new
;
future
->
=
;
return
future
;
}
<
::
>
::
()
{
return
new
(*
.
());
}
void
::
(
<
>
)
{
new
(*
.
());
}
::
()
:processingAmbiguityBranch(
false
)
,ambiguityBranchSharedNodeCount(
0
)
{
}
::
()
{
}
void
::
()
{
0
;
new
();
.
();
processingAmbiguityBranch
=
false
;
ambiguityBranchCreatedObject
0
;
ambiguityBranchOperationTarget
0
;
ambiguityBranchSharedNodeCount
=
0
;
.
();
.
();
}
bool
::
(
const
::
&
)
{
if
(!
)
{
return
false
;
}
switch
(
.
)
{
case
::
::
:
{
if
(
processingAmbiguityBranch
)
return
false
;
processingAmbiguityBranch
=
true
;
if
(
)
{
ambiguityBranchCreatedObject
();
}
else
{
ambiguityBranchCreatedObject
0
;
}
ambiguityBranchOperationTarget
().
<
>();
.
();
ambiguityBranchSharedNodeCount
=
.
()-
.
ambiguityAffectedStackNodeCount
+
1
;
for
(
=
ambiguityBranchSharedNodeCount
;
i
<
.
();
i
++)
{
.
(
i
]
().
<
>());
}
.
();
}
break
;
case
::
::
:
{
if
(!
processingAmbiguityBranch
)
return
false
;
if
(
.
()!=
ambiguityBranchSharedNodeCount
)
return
false
;
.
(
);
if
(
ambiguityBranchCreatedObject
)
{
ambiguityBranchCreatedObject
();
}
else
{
0
;
}
ambiguityBranchOperationTarget
().
<
>();
for
(
=
0
;
i
<
.
();
i
++)
{
.
(
i
]
().
<
>());
}
}
break
;
case
::
::
:
{
if
(!
processingAmbiguityBranch
)
return
false
;
if
(
.
()!=
ambiguityBranchSharedNodeCount
)
return
false
;
.
(
);
processingAmbiguityBranch
=
false
;
0
;
ambiguityBranchCreatedObject
0
;
ambiguityBranchOperationTarget
0
;
ambiguityBranchSharedNodeCount
=
0
;
.
();
{
<
>
=
new
(
.
,
());
<
>
=
new
(
L""
,
());
FOREACH(Ptr<ParsingTreeObject>, node, ambiguityNodes)
if
(
bool
=
true
)
for
(
const
::
vl
::
collections
::
<
<
>>&
= ::
vl
::
collections
::
(
);
__scope_variable_flag__
;
__scope_variable_flag__
=
false
)
for
(
<
>
;
__foreach_iterator__
.
(
node
);)
{
items
(
node
);
}
ambiguousNode
(
L"items"
,
items
);
ambiguousNode
;
}
.
();
}
break
;
case
::
::
:
{
=
0
;
for
(
=
.
;
j
<
.
+
.
;
j
++)
{
::
&
=
.
->
j
];
switch
(
ins
.
)
{
case
::
::
:
{
if
(
()
L""
)
{
return
false
;
}
(
ins
.
);
().
(
ins
.
);
}
break
;
case
::
::
:
{
if
(
()
L""
|| !
)
{
return
false
;
}
<
>
=
.
<
>();
if
(!
obj
)
{
return
false
;
}
for
(
=
0
;
i
<
().
();
i
++)
{
=
().
().
(
i
);
<
>
=
().
().
(
i
);
obj
(
name
,
value
);
}
obj
;
().
(
ins
.
);
0
;
}
break
;
case
::
::
:
{
if
(!
)
{
<
>
;
if
(
.
==
0
)
{
value
new
(
L""
,
.
);
}
else
{
value
new
(
(
.
->
,
.
->
),
.
);
value
(
(
.
,
.
));
}
(
ins
.
,
value
);
}
else
{
(
ins
.
,
);
0
;
}
}
break
;
case
::
::
:
{
<
>
=
(
ins
.
).
<
>();;
if
(!
arr
)
{
arr
new
();
(
ins
.
,
arr
);
}
=
arr
();
;
if
(!
)
{
<
>
;
if
(
.
==
0
)
{
value
new
(
L""
,
.
);
}
else
{
value
new
(
(
.
->
,
.
->
),
.
);
value
(
(
.
,
.
));
itemRange
value
();
}
arr
(
value
);
}
else
{
arr
(
);
itemRange
();
0
;
}
if
(
arrRange
.
.
==
::
||
itemRange
.
<
arrRange
.
)
{
arrRange
.
itemRange
.
;
}
if
(
arrRange
.
.
==
::
||
itemRange
.
>
arrRange
.
)
{
arrRange
.
itemRange
.
;
}
arr
(
arrRange
);
}
break
;
case
::
::
:
{
<
>
=
new
(
ins
.
, -
1
);
(
ins
.
,
value
);
}
break
;
case
::
::
:
{
.
(
);
new
();
0
;
}
break
;
case
::
::
:
{
if
(
.
()==
0
)
{
return
false
;
}
;
.
()-
1
];
.
(
.
()-
1
);
if
(
.
)
{
::
=
.
(
shiftReduceRangeIndex
++);
if
(
tokenRange
.
&&
tokenRange
.
)
{
(
tokenRange
.
,
tokenRange
.
);
(
codeRange
);
}
}
}
break
;
case
::
::
:
{
;
new
();
if
(
.
)
{
::
=
.
(
shiftReduceRangeIndex
++);
if
(
tokenRange
.
&&
tokenRange
.
)
{
(
tokenRange
.
,
tokenRange
.
);
(
codeRange
);
}
}
}
break
;
default
:
return
false
;
}
}
if
(
.
==
::
&& !
processingAmbiguityBranch
)
{
if
(
.
)
{
::
=
.
(
shiftReduceRangeIndex
++);
if
(
tokenRange
.
&&
tokenRange
.
)
{
(
tokenRange
.
,
tokenRange
.
);
(
codeRange
);
}
}
}
}
break
;
default
:
return
false
;
}
return
true
;
}
bool
::
GetProcessingAmbiguityBranch
()
{
return
processingAmbiguityBranch
;
}
<
>
::
()
const
{
if
(
.
()==
0
)
{
return
;
}
else
{
return
0
;
}
}
ParsingTransitionCollector
::
ParsingTransitionCollector
()
:ambiguityBegin(-
1
)
{
}
ParsingTransitionCollector
::
~
ParsingTransitionCollector
()
{
}
void
ParsingTransitionCollector
::
()
{
=-
1
;
.
();
.
();
.
();
.
();
}
bool
ParsingTransitionCollector
::
(
const
::
&
)
{
=
.
();
switch
(
.
)
{
case
::
::
:
if
(
!=-
1
)
return
false
;
=
index
;
break
;
case
::
::
:
{
if
(
==-
1
)
return
false
;
.
(
,
index
);
.
(
index
,
);
}
break
;
case
::
::
:
{
if
(
==-
1
)
return
false
;
.
(
,
index
);
=-
1
;
}
break
;
case
::
::
:
break
;
default
:
return
false
;
}
.
(
);
return
true
;
}
bool
ParsingTransitionCollector
::
GetProcessingAmbiguityBranch
()
{
return
!=-
1
;
}
const
ParsingTransitionCollector
::
&
ParsingTransitionCollector
::
()
const
{
return
;
}
ParsingTransitionCollector
::
(
)
const
{
=
.
().
(
);
return
index
==-
1
?-
1
:
.
()
index
];
}
const
collections
::
<
>&
ParsingTransitionCollector
::
GetAmbiguityBranchesFromBegin
(
)
const
{
=
.
().
(
);
return
index
==-
1
?*(
collections
::
<
>*)
0
:
.
(
index
);
}
ParsingTransitionCollector
::
GetAmbiguityBeginFromBranch
(
)
const
{
=
.
().
(
);
return
index
==-
1
?-
1
:
.
()
index
];
}
}
}
}
#if defined(VCZH_GCC) && defined(__clang__)
#pragma clang diagnostic pop
#endif