forked from kframework/javascript-semantics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
js-pseudo-code.k
36 lines (31 loc) · 1.63 KB
/
js-pseudo-code.k
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//////////////////////////////////////////////////////////////////////////////
// Pseudo-code evaluation
//////////////////////////////////////////////////////////////////////////////
syntax PseudoCodes ::= PseudoCode PseudoCodes
| PseudoCode
syntax PseudoCode ::= "Let" Id "=" K ";" [seqstrict(2)]
| "Do" K ";"
| "DoI" K ";"
| "If" K "=" K "then" "{" PseudoCodes "}" "else" "{" PseudoCodes "}" [seqstrict(1,2)]
| "If" K "=" K "then" "{" PseudoCodes "}" ";" [seqstrict(1,2)]
| "Return" K ";" [seqstrict(1)]
| "Return" ";"
| "Nop" ";"
syntax Exp ::= Id
rule PC:PseudoCode PCs:PseudoCodes => PC ~> PCs
rule Let X:Id = V:KResult; ~> PCs:PseudoCodes => PCs[V / X]
rule Do K; => K
rule DoI K; => K ~> @Ignore
rule If V1:KResult = V2:KResult then { PCs } else { _ } => PCs when V1 ==K V2
rule If V1:KResult = V2:KResult then { _ } else { PCs } => PCs when V1 =/=K V2
rule If V1:KResult = V2:KResult then { PCs } ; => PCs when V1 ==K V2
rule If V1:KResult = V2:KResult then { _ } ; => .K when V1 =/=K V2
rule Return V:KResult; => V
rule Return; => .K
rule Nop; => .K
syntax K ::= "BEGIN" PseudoCodes "END"
syntax PseudoCode ::= "Exit" ";"
rule <k> BEGIN PCs:PseudoCodes END ~> K => PCs ~> Exit; </k>
<pseudoStack> (. => @pseudo(K)) _ </pseudoStack>
rule <k> V:KResult ~> Exit; ~> _ => V ~> K </k> <pseudoStack> (@pseudo(K) => .) _ </pseudoStack>
rule <k> Exit; ~> _ => K </k> <pseudoStack> (@pseudo(K) => .) _ </pseudoStack>