Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
sarah.grebing
ProofScriptParser
Commits
c6f8d090
Commit
c6f8d090
authored
May 19, 2017
by
Sarah Grebing
Browse files
Cases Statement (partially)
parent
0521f0df
Pipeline
#10607
failed with stage
in 3 minutes and 29 seconds
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
src/main/java/edu/kit/formal/interpreter/Interpreter.java
View file @
c6f8d090
...
...
@@ -135,30 +135,67 @@ public class Interpreter<T> extends DefaultASTVisitor<T> {
for
(
GoalNode
node
:
allGoalsBeforeCases
)
{
node
.
enterNewVarScope
();
}
List
<
GoalNode
>
goalsAfterCases
=
new
ArrayList
<>();
//copy the list of goal nodes for keeping track of goals
Lis
t
<
GoalNode
>
copiedList
=
new
ArrayLis
t
<>();
Se
t
<
GoalNode
>
copiedList
=
new
HashSe
t
<>();
for
(
GoalNode
goalNode
:
allGoalsBeforeCases
)
{
copiedList
.
add
(
goalNode
);
}
//handle cases
TODO
//handle cases
List
<
CaseStatement
>
cases
=
casesStatement
.
getCases
();
Iterator
<
CaseStatement
>
casesIter
=
cases
.
iterator
();
while
(
casesIter
.
hasNext
())
{
CaseStatement
currentCase
=
casesIter
.
next
();
currentCase
.
getGuard
();
Expression
guard
=
currentCase
.
getGuard
();
Statements
body
=
currentCase
.
getBody
();
Iterator
<
GoalNode
>
goalIter
=
copiedList
.
iterator
();
Set
<
GoalNode
>
forCase
=
new
HashSet
<>();
while
(
goalIter
.
hasNext
())
{
GoalNode
g
=
goalIter
.
next
();
Evaluator
goalEval
=
new
Evaluator
(
g
);
Value
eval
=
goalEval
.
eval
(
guard
);
if
(
eval
.
getData
().
equals
(
Value
.
TRUE
))
{
forCase
.
add
(
g
);
//copiedList.remove(g);
}
}
copiedList
.
removeAll
(
forCase
);
Iterator
<
GoalNode
>
caseGoals
=
forCase
.
iterator
();
while
(
caseGoals
.
hasNext
())
{
GoalNode
current
=
caseGoals
.
next
();
List
<
GoalNode
>
goalList
=
new
ArrayList
<>();
goalList
.
add
(
current
);
State
s
=
new
State
(
goalList
,
current
);
stateStack
.
push
(
s
);
visit
(
body
);
State
aftercase
=
(
State
)
stateStack
.
pop
();
goalsAfterCases
.
addAll
(
aftercase
.
getGoals
());
}
//jetzt body auswerten mit der Liste der Ziele
}
casesStatement
.
getDefaultCase
();
//exit scope
State
aftercases
=
(
State
)
stateStack
.
pop
();
List
<
GoalNode
>
goalsAfterCases
=
a
fter
c
ases
.
getGoals
()
;
State
newStateA
fter
C
ases
;
if
(!
goalsAfterCases
.
isEmpty
())
{
for
(
GoalNode
goalAfterCases
:
goalsAfterCases
)
{
goalAfterCases
.
exitNewVarScope
();
}
if
(
goalsAfterCases
.
size
()
==
1
)
{
newStateAfterCases
=
new
State
(
goalsAfterCases
,
goalsAfterCases
.
get
(
0
));
}
else
{
newStateAfterCases
=
new
State
(
goalsAfterCases
,
null
);
}
stateStack
.
push
(
newStateAfterCases
);
}
return
null
;
}
...
...
src/main/java/edu/kit/formal/interpreter/Value.java
View file @
c6f8d090
...
...
@@ -40,11 +40,11 @@ public class Value<T> {
}
public
static
Value
<
Boolean
>
from
(
BooleanLiteral
b
)
{
return
new
Value
<>
(
Type
.
BOOL
,
b
.
isValue
());
return
new
Value
(
Type
.
BOOL
,
(
b
.
isValue
()
?
Value
.
TRUE
:
Value
.
FALSE
)
);
}
public
static
Value
<
Boolean
>
from
(
boolean
equals
)
{
return
new
Value
<>
(
Type
.
BOOL
,
equals
);
return
new
Value
(
Type
.
BOOL
,
(
equals
?
Value
.
TRUE
:
Value
.
FALSE
)
);
}
public
static
Value
<
BigInteger
>
from
(
BigInteger
apply
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment