Skip to content

Commit 7c4b045

Browse files
committed
all statements updated, will polish later
1 parent 7194db3 commit 7c4b045

File tree

3 files changed

+41
-34
lines changed

3 files changed

+41
-34
lines changed

src/common/core-functions.k

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,10 @@ rule true::bool ~> true? => . [structural]
191191
/*@ Represent a parser form for a sequence of terms. Is desugared into the pretty form [...]*/
192192
syntax KLabel ::= "'ListWrap"
193193
rule 'ListWrap(Ks:KList) => [Ks] [structural, anywhere]
194-
195-
//@ Sequence of terms and of any other statements. The first term is moved to the top of computation.
194+
//todo: both 'KListWrap and 'ListWrap are associted with the same production, so how to get rid of it
196195
syntax KListWrap ::= "[" KList "]" [klabel('KListWrap)]
197196

197+
//@ Sequence of terms and of any other statements. The first term is moved to the top of computation.
198198
rule [S1:K,, Stmts:KList] => S1 ~> [Stmts] [structural]
199199
rule [.KList] => .K [structural]
200200

src/common/stmt-syntax.k

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,39 @@ require "core-classes.k"
44
module STMT-SYNTAX
55
imports CORE-SORTS
66
imports CORE-CLASSES
7-
7+
//todo:be specific
88
syntax Stmt ::= "if" "(" K ")" "{" K "}" "else" "{" K "}" [strict(1),klabel('If)]
99
|"if" "(" K ")" "{" K "}" [strict(1),klabel('If)]
1010
|"while" "(" K ")" "{" K "}" [strict(1),klabel('While)]
1111
|"do" "{" K "}" "while" "(" K ")"[strict(2),klabel('DoWhile)]
1212
|"for" "(" K ";" K ";" K ")" "{" K "}" [klabel('For)]
13-
//todo:
14-
// |"{" K "}" [klabel('Block)]
13+
14+
1515
|Exp ";" [strict, klabel('ExprStm)]
1616
|"assert" Exp ";" [strict, klabel('AssertStm)]
1717
|"assert" Exp ":" Exp ";" [strict(1), klabel('AssertStm)]
18-
|"switch" "(" K ")" SwitchBlock [strict(1),klabel('Switch)]
19-
|KListWrap ":" KListWrap [klabel('SwitchGroup)]
20-
|"case" Exp [strict, klabel('Case)]
21-
|"default" [klabel('Default)]
18+
|Id ":" K [klabel('Labeled)]
19+
|"switch" "(" Exp ")" SwitchBlock [strict(1),klabel('Switch)]
20+
|"try" K KListWrap "finally" Block [klabel('Try)]
21+
|"try" K KListWrap [klabel('Try)]
22+
|"catch" "(" K ")" Block [klabel('Catch)]
23+
//todo:change K above and below
24+
syntax Block ::= "{" K "}" [klabel('Block)]
2225

23-
syntax SwitchBlock::= "{" KListWrap K "}" [klabel('SwitchBlock)]
26+
syntax SwitchGroup ::= KListWrap KListWrap [klabel('SwitchGroup)]
27+
syntax SwitchLabel ::= "case" Exp ":" [strict, klabel('Case)]
28+
|"default:" [klabel('Default)]
29+
syntax SwitchBlock::= "{" KListWrap KListWrap "}" [klabel('SwitchBlock)]
2430

25-
syntax Stmt ::= StackConsumerStmt
31+
syntax Stmt ::= StackConsumerStmt | EmptyStmt
32+
syntax EmptyStmt ::= ";" [klabel('Empty)]
2633
syntax StackConsumerStmt ::= "dummyStackConsumerStmt"
2734
|"throw" K ";" [strict, klabel('Throw)]
2835
|"continue" K ";" [klabel('Continue)]
2936
|"break" K ";" [klabel('Break)]
3037
|"return" K ";" [klabel('Return)]
3138

39+
40+
3241
endmodule
42+

src/exec/statements.k

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ rule [ExecutionPhase-Start]:
2626
<mainClass> ListItem(MainClassS:String) </mainClass>
2727
<globalPhase> UnfoldingPhase => ExecutionPhase </globalPhase>
2828

29-
syntax KLabel ::= "'Empty"
30-
| "'Labeled"
29+
syntax KLabel ::= "'Block"
30+
// | "'Labeled"
3131
// | "'ExprStm"
3232
// | "'AssertStm"
3333
// | "'Switch"
@@ -44,7 +44,6 @@ syntax KLabel ::= "'Empty"
4444
// | "'Throw"
4545
| "'Try"
4646
| "'Catch"
47-
| "'Block"
4847

4948

5049
//@ \subsection{Blocks} JLS \$14.2
@@ -80,12 +79,12 @@ rule [LocalVarDec]:
8079
//@ \subsection{Empty statement} JLS \$14.6
8180

8281
rule [Empty]:
83-
'Empty(_) => .
82+
; => .
8483

8584
//@ \subsection{Labeled statements} JLS \$14.7
8685

8786
rule [Labeled]:
88-
'Labeled(X:Id,, S:K) => S ~> labeledImpl(X)
87+
X:Id : S:K => S ~> labeledImpl(X)
8988

9089
//@ Processed version of the labeled statement
9190
syntax KItem ::= labeledImpl ( Id )
@@ -128,19 +127,17 @@ rule [AssertStm-FirstFalse]:
128127

129128
syntax KItem ::= switchImpl (
130129
TypedVal, // TV - switch argument
131-
KListWrap, // switch body - list of 'SwitchGroup labels "case Exp : body"
130+
KListWrap, // switch body - list of 'SwitchGroup labels
132131
K // DefaultStm - default block, if any
133132
)
134133

135-
//context 'Switch(HOLE,,_)
136-
137134
//@ The switchEnd in the right-hand side of => is required to properly interact with break.
138135
rule [Switch]:
139-
switch(TV:TypedVal){[Ks:KList] TrailingLabels:K}
140-
=> switchImpl(TV, [Ks,, TrailingLabels : .K], .K)
136+
switch(TV:TypedVal){[Ks:KList] [TrailingLabels:KList]}
137+
=> switchImpl(TV, [Ks,, [TrailingLabels] .K], .K)
141138
~> switchEnd
142139

143-
context switchImpl( _, [ [case HOLE ,, _:KList] : _ ,, _:KList ], _)
140+
context switchImpl( _, [ [case HOLE : ,, _:KList] _ ,, _:KList], _)
144141

145142
/*@ The type associated to V and V2 is not important for match, only the value.
146143
JLS3 \$14.11, page 377: Every case constant expression associated with
@@ -149,7 +146,7 @@ a switch statement must be assignable (�5.2) to the type of the switch Express
149146
rule [switchImpl-CaseNotMatch]:
150147
switchImpl(
151148
V:RawVal :: _,
152-
[ [ ( case V2:RawVal :: _ => .KList ),, _:KList ] : _ ,, _],
149+
[ [ ( case V2:RawVal :: _ :=> .KList ),, _:KList ] _ ,, _],
153150
_
154151
)
155152
when
@@ -161,30 +158,30 @@ constructs and will execute the statements. */
161158
rule [switchImpl-CaseMatch]:
162159
switchImpl(
163160
V:RawVal :: _,
164-
[[case V :: _ ,, _:KList] : S:K,, Ks:KList],
161+
[[case V :: _ : ,, _:KList] S:K,, Ks:KList],
165162
_
166163
)
167164
=> [S,,Ks]
168165

169166
rule [switchImpl-DefaultSave]:
170167
switchImpl(
171168
TV:TypedVal,
172-
[[ ( default => .KList ),, _:KList] : S:K,, Ks:KList],
169+
[[ ( default: => .KList ),, _:KList] S:K,, Ks:KList],
173170
( _:K => [S,, Ks] )
174171
)
175172

176173
rule [switchImpl-SwitchGroup-Discard]:
177174
switchImpl(
178175
TV:TypedVal,
179-
[( [ .KList ]: _ => .KList ),, _],
176+
[( [ .KList ] _ => .KList ),, _],
180177
_
181178
)
182179

183180
rule [switchImpl-Default-Exec]:
184181
switchImpl( _, [.KList], DefaultStm:K) => DefaultStm
185182

186183
rule [SwitchGroup-Exec]:
187-
_:KListWrap : S => S
184+
_:KListWrap S:K => S
188185

189186
syntax KItem ::= "switchEnd"
190187

@@ -439,20 +436,20 @@ rule [Throw-CausesThreadTermination]:
439436
//@ \subsection{Try statement}
440437

441438
rule [Try-Catch-Finally-Desugar]:
442-
'Try(TryS:K,, [K:K,, Ks:KList],,FinallyS:K)
443-
=> 'Try('Try(TryS,,[K,,Ks]),,[.KList],,FinallyS)
439+
try TryS:K [K:K,, Ks:KList] finally FinallyS:K
440+
=> try {try TryS [K,,Ks]} [.KList] finally FinallyS
444441
[structural]
445442

446443
/*@ \subsubsection{Execution of try-catch} JLS \$14.20.1
447444
*/
448445

449446
//resolve the catch clauses of try statement
450-
context 'Try(_:K,,[_,, HOLE,, _])
447+
context try _:K [_,, HOLE,, _]
451448

452449
//resolve 'Param term of the catch clause
453-
context 'Catch(HOLE,, _) [result(ExtKResult)]
450+
context catch(HOLE)_ [result(ExtKResult)]
454451

455-
rule 'Catch(KR:ExtKResult,, S:K) => catchImpl(KR,S)
452+
rule catch(KR:ExtKResult)S:K => catchImpl(KR,S)
456453

457454
/*@ Extended K Result.
458455
Represents KLabels that should be treated as KResult during execution phase, but not during elaboration phase.
@@ -470,7 +467,7 @@ syntax KResult ::= catchImpl (
470467
)
471468

472469
rule [Try-Catch]:
473-
'Try(TryS:K,, [KRs:KList]) => TryS ~> catchBlocks([KRs])
470+
try TryS:K [KRs:KList] => TryS ~> catchBlocks([KRs])
474471
when isKResult(KRs)
475472

476473
/*@ The auxiliary construct that holds catch clauses
@@ -487,7 +484,7 @@ rule [catchBlocks-Discard]:
487484
*/
488485

489486
rule [Try-Finally]:
490-
'Try(TryS:K,,[.KList],,FinallyS:K) => TryS ~> finallyBlock(FinallyS)
487+
try TryS:K [.KList] finally FinallyS:K => TryS ~> finallyBlock(FinallyS)
491488

492489
/*@ The auxiliary construct that holds finally clause
493490
after try clause has been moved to the top of computation*/

0 commit comments

Comments
 (0)