Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
sarah.grebing
ProofScriptParser
Commits
c6f8d090
Commit
c6f8d090
authored
May 19, 2017
by
Sarah Grebing
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cases Statement (partially)
parent
0521f0df
Pipeline
#10607
failed with stage
in 3 minutes and 29 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
7 deletions
+44
-7
src/main/java/edu/kit/formal/interpreter/Interpreter.java
src/main/java/edu/kit/formal/interpreter/Interpreter.java
+42
-5
src/main/java/edu/kit/formal/interpreter/Value.java
src/main/java/edu/kit/formal/interpreter/Value.java
+2
-2
No files found.
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