Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
macaon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Franck Dary
macaon
Commits
5cc6a43b
Commit
5cc6a43b
authored
5 years ago
by
Franck Dary
Browse files
Options
Downloads
Patches
Plain Diff
Introduced optional state in transitions
parent
eac4e36f
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
reading_machine/include/Transition.hpp
+1
-0
1 addition, 0 deletions
reading_machine/include/Transition.hpp
reading_machine/src/Transition.cpp
+18
-10
18 additions, 10 deletions
reading_machine/src/Transition.cpp
with
19 additions
and
10 deletions
reading_machine/include/Transition.hpp
+
1
−
0
View file @
5cc6a43b
...
...
@@ -10,6 +10,7 @@ class Transition
private
:
std
::
string
name
;
std
::
string
state
;
std
::
vector
<
Action
>
sequence
;
std
::
function
<
int
(
const
Config
&
config
)
>
cost
;
...
...
This diff is collapsed.
Click to expand it.
reading_machine/src/Transition.cpp
+
18
−
10
View file @
5cc6a43b
...
...
@@ -3,8 +3,7 @@
Transition
::
Transition
(
const
std
::
string
&
name
)
{
this
->
name
=
name
;
std
::
regex
nameRegex
(
"(<(.+)> )?(.+)"
);
std
::
regex
writeRegex
(
"WRITE ([bs])
\\
.(.+) (.+) (.+)"
);
std
::
regex
shiftRegex
(
"SHIFT"
);
std
::
regex
reduceRegex
(
"REDUCE"
);
...
...
@@ -14,23 +13,29 @@ Transition::Transition(const std::string & name)
try
{
if
(
util
::
doIfNameMatch
(
writeRegex
,
name
,
[
this
](
auto
sm
){
initWrite
(
sm
[
3
],
sm
[
1
],
sm
[
2
],
sm
[
4
]);}))
if
(
!
util
::
doIfNameMatch
(
nameRegex
,
name
,
[
this
,
name
](
auto
sm
)
{
this
->
state
=
sm
[
2
];
this
->
name
=
sm
[
3
];
}))
util
::
myThrow
(
"doesn't match nameRegex"
);
if
(
util
::
doIfNameMatch
(
writeRegex
,
this
->
name
,
[
this
](
auto
sm
){
initWrite
(
sm
[
3
],
sm
[
1
],
sm
[
2
],
sm
[
4
]);}))
return
;
if
(
util
::
doIfNameMatch
(
shiftRegex
,
name
,
[
this
](
auto
){
initShift
();}))
if
(
util
::
doIfNameMatch
(
shiftRegex
,
this
->
name
,
[
this
](
auto
){
initShift
();}))
return
;
if
(
util
::
doIfNameMatch
(
reduceRegex
,
name
,
[
this
](
auto
){
initReduce
();}))
if
(
util
::
doIfNameMatch
(
reduceRegex
,
this
->
name
,
[
this
](
auto
){
initReduce
();}))
return
;
if
(
util
::
doIfNameMatch
(
leftRegex
,
name
,
[
this
](
auto
sm
){
initLeft
(
sm
[
1
]);}))
if
(
util
::
doIfNameMatch
(
leftRegex
,
this
->
name
,
[
this
](
auto
sm
){
initLeft
(
sm
[
1
]);}))
return
;
if
(
util
::
doIfNameMatch
(
rightRegex
,
name
,
[
this
](
auto
sm
){
initRight
(
sm
[
1
]);}))
if
(
util
::
doIfNameMatch
(
rightRegex
,
this
->
name
,
[
this
](
auto
sm
){
initRight
(
sm
[
1
]);}))
return
;
if
(
util
::
doIfNameMatch
(
eosRegex
,
name
,
[
this
](
auto
){
initEOS
();}))
if
(
util
::
doIfNameMatch
(
eosRegex
,
this
->
name
,
[
this
](
auto
){
initEOS
();}))
return
;
throw
std
::
invalid_argument
(
"no match"
);
}
catch
(
std
::
exception
&
e
)
{
util
::
myThrow
(
fmt
::
format
(
"Invalid name '{}' ({})"
,
name
,
e
.
what
()));}
}
catch
(
std
::
exception
&
e
)
{
util
::
myThrow
(
fmt
::
format
(
"Invalid name '{}' ({})"
,
this
->
name
,
e
.
what
()));}
}
...
...
@@ -42,6 +47,9 @@ void Transition::apply(Config & config)
bool
Transition
::
appliable
(
const
Config
&
config
)
const
{
if
(
!
state
.
empty
()
&&
state
!=
config
.
getState
())
return
false
;
for
(
const
Action
&
action
:
sequence
)
if
(
!
action
.
appliable
(
config
,
action
))
return
false
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment