#include "ParsingAutomaton.h"
namespace
{
namespace
{
using
namespace
collections
;
using
namespace
definitions
;
namespace
{
class
:
public
,
public
::
{
public
:
<
>
;
ParsingDefinitionRuleDefinition
*
;
*
;
*
;
*
;
*
;
(
<
>
,
ParsingDefinitionRuleDefinition
*
,
*
,
*
,
*
)
:automaton(
)
,rule(
)
,ruleGrammar(
)
,startState(
)
,endState(
)
,result(
0
)
{
}
static
*
(
*
,
<
>
,
ParsingDefinitionRuleDefinition
*
,
*
,
*
,
*
)
{
(
,
,
,
,
);
->
(&
visitor
);
return
visitor
.
;
}
*
(
*
,
*
,
*
)
{
return
(
,
,
,
,
,
);
}
void
(
ParsingDefinitionPrimitiveGrammar
*
)
override
{
=
(
,
,
->
(
));
}
void
(
ParsingDefinitionTextGrammar
*
)
override
{
=
(
,
,
->
(
));
}
void
(
ParsingDefinitionSequenceGrammar
*
)
override
{
*
=
(
->
,
,
->
.
());
(
->
.
(),
,
middleState
);
(
->
.
(),
middleState
,
);
}
void
(
ParsingDefinitionAlternativeGrammar
*
)
override
{
(
->
.
(),
,
);
(
->
.
(),
,
);
}
void
(
ParsingDefinitionLoopGrammar
*
)
override
{
*
=
(
->
,
,
->
.
());
(
,
loopStart
);
(
loopStart
,
);
(
->
.
(),
loopStart
,
loopStart
);
}
void
(
ParsingDefinitionOptionalGrammar
*
)
override
{
(
->
.
(),
,
);
(
,
);
}
void
(
ParsingDefinitionCreateGrammar
*
)
override
{
*
=
(
->
,
,
->
.
());
(
->
.
(),
,
middleState
);
*
=
(
middleState
,
);
<
>
=
new
;
action
=
::
;
action
=
->
(
->
.
(),
0
);
action
=
;
transition
->
.
(
action
);
}
void
(
ParsingDefinitionAssignGrammar
*
)
override
{
*
=
(
->
.
(),
,
);
<
>
=
new
;
action
=
::
;
action
=
->
(
);
action
=
;
transition
->
.
(
action
);
}
void
(
ParsingDefinitionUseGrammar
*
)
override
{
*
=
(
->
.
(),
,
);
<
>
=
new
;
action
=
::
;
action
=
;
transition
->
.
(
action
);
}
void
(
ParsingDefinitionSetterGrammar
*
)
override
{
*
=
(
->
,
,
->
.
());
(
->
.
(),
,
middleState
);
*
=
(
middleState
,
);
<
>
=
new
;
action
=
::
;
action
=
->
(
);
action
=
action
->
()->
(
->
);
action
=
;
transition
->
.
(
action
);
}
};
void
(
<
>
,
<
definitions
::
ParsingDefinitionRuleDefinition
>
,
*
)
{
<
>
=
new
;
(
.
(),
ruleInfo
);
ruleInfo
=
(
.
());
ruleInfo
=
(
.
());
ruleInfo
=
(
.
());
(
ruleInfo
,
ruleInfo
);
FOREACH(Ptr<ParsingDefinitionGrammar>, grammar, rule->grammars)
if
(
bool
=
true
)
for
(
const
::
vl
::
collections
::
<
<
>>&
= ::
vl
::
collections
::
(
);
__scope_variable_flag__
;
__scope_variable_flag__
=
false
)
for
(
<
>
;
__foreach_iterator__
.
(
grammar
);)
{
*
=
(
.
(),
grammar
.
(),
grammar
.
());
*
=
(
.
(),
grammar
.
(),
grammar
.
());
grammarEndState
->
+=
L".End"
;
grammarEndState
->
=
true
;
(
ruleInfo
,
grammarStartState
);
(
grammarEndState
,
ruleInfo
);
ruleInfo
.
(
grammarEndState
);
::
(
grammar
.
(),
,
.
(),
grammar
.
(),
grammarStartState
,
grammarEndState
);
}
}
<
>
(
<
definitions
::
>
,
*
)
{
<
>
=
new
(
);
FOREACH(Ptr<ParsingDefinitionRuleDefinition>, rule, definition->rules)
if
(
bool
=
true
)
for
(
const
::
vl
::
collections
::
<
<
ParsingDefinitionRuleDefinition
>>&
= ::
vl
::
collections
::
(
);
__scope_variable_flag__
;
__scope_variable_flag__
=
false
)
for
(
<
ParsingDefinitionRuleDefinition
>
;
__foreach_iterator__
.
(
rule
);)
{
(
automaton
,
rule
,
);
}
return
automaton
;
}
}
}
}