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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
|
%%%
%% Section 14.5: Statements
%%
%% @author Martin Bravenboer <martin@cs.uu.nl>
%%%
module languages/java-14/statements/Statements
imports
languages/java-14/statements/LocalVariableDeclarations
languages/java-14/statements/Blocks
languages/java-14/expressions/Main
exports
sorts
Stm
context-free syntax
Block -> Stm
%%%
%% Section 14.6: The Empty Statement
%%%
context-free syntax
";" -> Stm {cons("Empty")}
%%%
%% Section 14.7: Labeled Statements
%%%
context-free syntax
Id ":" Stm -> Stm {cons("Labeled")}
%%%
%% Section 14.8: Expressions Statements
%%%
context-free syntax
Expr ";" -> Stm {cons("ExprStm")}
%%%
%% Section 14.9: The If Statement
%%%
context-free syntax
"if" "(" Expr ")" Stm -> Stm {prefer, cons("If")}
"if" "(" Expr ")" Stm "else" Stm -> Stm {cons("If")}
%%%
%% Section 14.10: The Assert Statement
%%%
context-free syntax
"assert" Expr ";" -> Stm {cons("AssertStm")}
"assert" Expr ":" Expr ";" -> Stm {cons("AssertStm")}
%%%
%% Section 14.11: The Switch Statement
%%%
sorts SwitchBlock SwitchGroup SwitchLabel
context-free syntax
"switch" "(" Expr ")" SwitchBlock -> Stm {cons("Switch")}
"{" SwitchGroup* SwitchLabel* "}" -> SwitchBlock {cons("SwitchBlock")}
SwitchLabel+ BlockStm+ -> SwitchGroup {cons("SwitchGroup")}
"case" Expr ":" -> SwitchLabel {cons("Case")}
"default" ":" -> SwitchLabel {cons("Default")}
%%%
%% Section 14.12: The While Statement
%%%
context-free syntax
"while" "(" Expr ")" Stm -> Stm {cons("While")}
%%%
%% Section 14.13: The Do Statement
%%%
context-free syntax
"do" Stm "while" "(" Expr ")" ";" -> Stm {cons("DoWhile")}
%%%
%% Section 14.14: The For Statement
%%%
context-free syntax
"for" "(" LocalVarDec ";" Expr? ";" {Expr ","}* ")" Stm -> Stm {cons("For")}
"for" "(" {Expr ","}* ";" Expr? ";" {Expr ","}* ")" Stm -> Stm {cons("For")}
%%%
%% Section 14.15: The Break Statement
%%%
context-free syntax
"break" Id? ";" -> Stm {cons("Break")}
%%%
%% Section 14.16: The Continue Statement
%%%
context-free syntax
"continue" Id? ";" -> Stm {cons("Continue")}
%%%
%% Section 14.17: The Return Statement
%%%
context-free syntax
"return" Expr? ";" -> Stm {cons("Return")}
%%%
%% Section 14.18: The Throw Statement
%%%
context-free syntax
"throw" Expr ";" -> Stm {cons("Throw")}
%%%
%% Section 14.19: The Synchronized Statement
%%%
context-free syntax
"synchronized" "(" Expr ")" Block -> Stm {cons("Synchronized")}
%%%
%% Section 14.20: The Try Statement
%%%
sorts CatchClause
context-free syntax
"try" Block CatchClause+ -> Stm {cons("Try")}
"try" Block CatchClause* "finally" Block -> Stm {cons("Try")}
"catch" "(" FormalParam ")" Block -> CatchClause {cons("Catch")}
|