rockit 0.7.1 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. data/README +24 -160
  2. data/TODO +17 -17
  3. data/VERSION +1 -1
  4. data/doc/rockit_paper.pdf +0 -0
  5. data/lib/packrat/grammar.rb +139 -84
  6. data/rakefile +27 -9
  7. data/tests/acceptance/packrat/java/atest_java.rb +37 -0
  8. data/tests/acceptance/packrat/java/java.rb +136 -0
  9. data/tests/acceptance/packrat/java/t.rb +10 -0
  10. data/tests/acceptance/packrat/java/todo +10 -0
  11. data/tests/acceptance/packrat/java/xtc.lang.java/Java.rats +446 -0
  12. data/tests/acceptance/packrat/java/xtc.lang.java/JavaConstant.rats +111 -0
  13. data/tests/acceptance/packrat/java/xtc.lang.java/JavaCore.rats +508 -0
  14. data/tests/acceptance/packrat/java/xtc.lang.java/JavaIdentifier.rats +62 -0
  15. data/tests/acceptance/packrat/java/xtc.lang.java/JavaSymbol.rats +38 -0
  16. data/tests/acceptance/packrat/java/xtc.lang.java/JavaTree.rats +40 -0
  17. data/tests/acceptance/packrat/java/xtc.lang.java/JavaType.rats +61 -0
  18. data/tests/acceptance/packrat/java/xtc.lang.java/Spacing.rats +36 -0
  19. data/tests/acceptance/packrat/java/xtc.lang.java/Symbol.rats +77 -0
  20. data/tests/acceptance/packrat/minibasic/README +13 -0
  21. data/tests/acceptance/packrat/minibasic/atest_minibasic.rb +151 -13
  22. data/tests/acceptance/packrat/minibasic/minibasic.rb +94 -76
  23. data/tests/acceptance/packrat/minibasic/mult3.basic +6 -0
  24. data/tests/acceptance/packrat/minibasic/sumeven.basic +19 -0
  25. data/tests/unit/packrat/test_ast.rb +116 -0
  26. data/tests/unit/packrat/test_interpreting_parser.rb +15 -55
  27. metadata +22 -59
  28. data/lib/rockit/prettyprint/box.rb +0 -60
  29. data/lib/rockit/prettyprint/renderer.rb +0 -41
  30. data/lib/rockit/prettyprint/text_renderer.rb +0 -47
  31. data/lib/rockit/tree/base.rb +0 -223
  32. data/lib/rockit/tree/enter_leave_visitor.rb +0 -12
  33. data/lib/rockit/tree/graphviz.rb +0 -69
  34. data/lib/rockit/tree/visitor.rb +0 -12
  35. data/lib/util/array_alternatives.rb +0 -20
  36. data/lib/util/enter_leave_visitor.rb +0 -69
  37. data/lib/util/graphviz_dot.rb +0 -182
  38. data/lib/util/string_location.rb +0 -42
  39. data/lib/util/visitor.rb +0 -49
  40. data/lib/util/visitor_combinators.rb +0 -14
  41. data/tests/acceptance/rockit/dparser/atest_any_operator.rb +0 -33
  42. data/tests/acceptance/rockit/dparser/atest_arithmetic_grammar.rb +0 -30
  43. data/tests/acceptance/rockit/dparser/atest_list_operator.rb +0 -57
  44. data/tests/acceptance/rockit/dparser/atest_mult_operator.rb +0 -60
  45. data/tests/acceptance/rockit/dparser/atest_operator_grammar.rb +0 -61
  46. data/tests/acceptance/rockit/dparser/atest_plus_operator.rb +0 -55
  47. data/tests/acceptance/rockit/dparser/atest_samples_calculator.rb +0 -14
  48. data/tests/acceptance/rockit/dparser/atest_samples_minibasic.rb +0 -20
  49. data/tests/acceptance/rockit/dparser/atest_samples_multifunccalculator.rb +0 -36
  50. data/tests/acceptance/rockit/dparser/atest_simple_grammar.rb +0 -34
  51. data/tests/acceptance/rockit/dparser/atest_speculative_code_action.rb +0 -128
  52. data/tests/acceptance/rockit/dparser/calc_tests_common.rb +0 -103
  53. data/tests/unit/parse/utest_ebnf_grammar.rb +0 -50
  54. data/tests/unit/parse/utest_expand_grammar.rb +0 -23
  55. data/tests/unit/parse/utest_grammar.rb +0 -160
  56. data/tests/unit/rockit/assembler/llvm/utest_instructions.rb +0 -41
  57. data/tests/unit/rockit/assembler/llvm/utest_module.rb +0 -19
  58. data/tests/unit/rockit/prettyprint/utest_box.rb +0 -44
  59. data/tests/unit/rockit/tree/utest_tree_base.rb +0 -301
  60. data/tests/unit/rockit/tree/utest_tree_enter_leave_visitor.rb +0 -69
  61. data/tests/unit/rockit/tree/utest_tree_visitor.rb +0 -63
  62. data/tests/unit/rockit/utest_grammar.rb +0 -145
  63. data/tests/unit/rockit/utest_grammar_symbol.rb +0 -11
  64. data/tests/unit/rockit/utest_maybe_operator.rb +0 -12
  65. data/tests/unit/rockit/utest_regexp_terminal.rb +0 -45
  66. data/tests/unit/rockit/utest_repetition_operators.rb +0 -35
  67. data/tests/unit/rockit/utest_rule.rb +0 -23
  68. data/tests/unit/rockit/utest_string_terminal.rb +0 -40
  69. data/tests/unit/util/utest_array_alternatives.rb +0 -23
  70. data/tests/unit/util/utest_enter_leave_visitor.rb +0 -89
  71. data/tests/unit/util/utest_string_location.rb +0 -42
  72. data/tests/unit/util/utest_visitor.rb +0 -92
  73. data/tests/unit/util/utest_visitor_combinators.rb +0 -64
data/rakefile CHANGED
@@ -20,8 +20,9 @@ TODO_FILE = "TODO"
20
20
  RAKE_FILE = "rakefile"
21
21
  CHANGELOG = "Changelog"
22
22
 
23
+ CLEAN.include("rockit_paper.pdf")
23
24
 
24
- task :default => :ptest
25
+ task :default => [:ptest, :patest]
25
26
 
26
27
 
27
28
  #############################################################################
@@ -102,14 +103,15 @@ BaseFileToIncludeGlobs = [
102
103
  "README", "TODO", "BUGS", "LICENSE", "VERSION",
103
104
  "rakefile", "Manifest",
104
105
  "lib/packrat/**/*",
105
- "lib/rockit/prettyprint/**/*",
106
- "lib/rockit/tree/**/*",
107
- "lib/util/**/*",
106
+ "doc/rockit_paper.pdf",
107
+ #"lib/rockit/prettyprint/**/*",
108
+ #"lib/rockit/tree/**/*",
109
+ #"lib/util/**/*",
108
110
  ]
109
111
 
110
112
  TestFilesToIncludeGlobs = [
111
- "tests/acceptance/**/*",
112
- "tests/unit/**/*",
113
+ "tests/acceptance/packrat/**/*",
114
+ "tests/unit/packrat/**/*",
113
115
  ]
114
116
 
115
117
  PkgFileGlobs = BaseFileToIncludeGlobs + TestFilesToIncludeGlobs
@@ -164,6 +166,17 @@ task :changelog do
164
166
  end
165
167
  end
166
168
 
169
+ #############################################################################
170
+ # Doc related
171
+ #############################################################################
172
+ task :gen_paper do
173
+ Dir.chdir("doc/rockit_paper") do
174
+ system "rake"
175
+ File.cp "rockit_paper.pdf", ".."
176
+ system "rake clobber"
177
+ end
178
+ end
179
+
167
180
  #############################################################################
168
181
  # Rubyforge related
169
182
  #############################################################################
@@ -186,13 +199,18 @@ def delete_package(packageName)
186
199
  end
187
200
 
188
201
  # We use a temporary package name for now, should be PROJECT later...
189
- PACKAGE_NAME = "1799" # if of the test package in rockit group
202
+ #PACKAGE_NAME = "1801" # if of the test package in rockit group
203
+ PACKAGE_NAME = "368" # Name of rockit package
204
+
205
+ task :pack => [:gen_paper, :package]
190
206
 
191
207
  desc "Create package and release to rubyforge"
192
- task :rubyforge_release => [:package] do
208
+ task :rubyforge_release => [:pack] do
209
+ puts "Logging in to rubyforge"
193
210
  system "rubyforge login"
211
+
194
212
  release_name = "#{PROJECT}-#{Version()}"
195
- files_to_release = FileList["pkg/#{release_name}.*"]
213
+ files_to_release = FileList["pkg/#{release_name}.gem"]
196
214
  files_to_release.each do |file|
197
215
  puts "Releasing #{file} to Rubyforge"
198
216
  release_file(file, release_name, PACKAGE_NAME)
@@ -0,0 +1,37 @@
1
+ require 'test/unit'
2
+
3
+ require File.join(File.dirname(__FILE__), "java")
4
+
5
+ # We test the grammar in several logical "chunks" below with one TestCase
6
+ # for each logical chunk.
7
+
8
+ class ATestJavaType < Test::Unit::TestCase
9
+ def assert_parse(exp, str, startSymbol)
10
+ res = Java::Parser.parse_string(str, startSymbol)
11
+ assert_equal(exp, res)
12
+ end
13
+
14
+ include Java::Grammar::ASTs
15
+
16
+ def test_01_resulttype_void
17
+ assert_parse([:ResultType, "void"], "void", :ResultType)
18
+ assert_parse([:ResultType, Type[[:TypeName, "byte"], nil]],
19
+ "byte", :ResultType)
20
+ assert_parse([:ResultType, Type[[:TypeName, "byte"], ["[]"]]],
21
+ "byte[]", :ResultType)
22
+ assert_parse([:ResultType, Type[[:TypeName, "short"], ["[]", "[]"]]],
23
+ "short[][]", :ResultType)
24
+ end
25
+
26
+ def test_02_symbols
27
+ # Note! We should make each grammar be its own class so that constants
28
+ # are defined within that scope!
29
+ JavaSymbols.each do |name, symbol_str|
30
+ assert_parse(symbol_str, symbol_str, :Symbol)
31
+ end
32
+ end
33
+
34
+ def test_03
35
+ end
36
+ end
37
+
@@ -0,0 +1,136 @@
1
+ #############################################################################
2
+ # Grammar for the programming language Java.
3
+ # Author: Robert Feldt
4
+ #
5
+ # The grammar is based on the Java grammar from xtc which is accompanied by
6
+ # the following license:
7
+ #
8
+ # xtc - The eXTensible Compiler
9
+ # Copyright (C) 2004-2005 Robert Grimm, New York University
10
+ #
11
+ # This program is free software; you can redistribute it and/or
12
+ # modify it under the terms of the GNU General Public License
13
+ # as published by the Free Software Foundation; either version 2
14
+ # of the License, or (at your option) any later version.
15
+ #
16
+ # This program is distributed in the hope that it will be useful,
17
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
18
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
+ # GNU General Public License for more details.
20
+ #
21
+ # You should have received a copy of the GNU General Public License
22
+ # along with this program; if not, write to the Free Software
23
+ # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24
+ #
25
+ #############################################################################
26
+
27
+ require 'packrat/grammar'
28
+
29
+ module Java; end
30
+
31
+ Java::Grammar = Packrat::Grammar.new do
32
+ start_symbol :CompilationUnit
33
+
34
+ ##########################
35
+ # Java type names
36
+ ##########################
37
+
38
+ rule( :ResultType,
39
+ ["void"],
40
+ [:Type]
41
+ )
42
+
43
+ prod :Type, [:TypeName, maybe(plus(:Dimension)),
44
+ ast(:Type, :type_name => :type, 1 => :dimensions)]
45
+
46
+ BasicTypes = ["byte", "short", "char", "int", "long", "float", "double",
47
+ "boolean"]
48
+
49
+ rule( :TypeName,
50
+ [any(*BasicTypes)],
51
+ [:QualifiedIdentifier]
52
+ )
53
+
54
+ prod :Dimension, ["[]", lift(0)]
55
+
56
+ ##########################
57
+ # Java symbols
58
+ ##########################
59
+
60
+ # Note, we do not use a Hash since we cannot guarantee what order the
61
+ # values will then be listed in => the shorter symbol strings might
62
+ # preceded the longer once and lead to too short matches ("!" match before
63
+ # "!=" when input is "!=" for example).
64
+ JavaSymbols = [
65
+ [:TripleGreaterEqual, ">>>="],
66
+ [:GreaterGreaterEqual, ">>="],
67
+ [:LessLessEqual, "<<="],
68
+ [:TripleGreater, ">>>"],
69
+ [:GreaterGreater, ">>"],
70
+ [:LessLess, "<<"],
71
+ [:PlusEqual, "+="],
72
+ [:MinusEqual, "-="],
73
+ [:StarEqual, "*="],
74
+ [:SlashEqual, "/="],
75
+ [:PercentEqual, "%="],
76
+ [:AmpersandEqual, "&="],
77
+ [:CaretEqual, "^="],
78
+ [:BarEqual, "|="],
79
+ [:PlusPlus, "++"],
80
+ [:MinusMinus, "--"],
81
+ [:AmpersandAmpersand, "&&"],
82
+ [:BarBar, "||"],
83
+ [:LessEqual, "<="],
84
+ [:GreaterEqual, ">="],
85
+ [:EqualEqual, "=="],
86
+ [:BangEqual, "!="],
87
+ [:Semicolon, ";"],
88
+ [:Colon, ":"],
89
+ [:Comma, "],"],
90
+ [:Period, "."],
91
+ [:OpenBrace, "{"],
92
+ [:CloseBrace, "}"],
93
+ [:OpenParenthesis, "("],
94
+ [:CloseParenthesis, ")"],
95
+ [:OpenBracket, "["],
96
+ [:CloseBracket, "]"],
97
+ [:Bang, "!"],
98
+ [:Tilde, "~"],
99
+ [:Plus, "+"],
100
+ [:Minus, "-"],
101
+ [:Star, "*"],
102
+ [:Slash, "/"],
103
+ [:Percent, "%"],
104
+ [:Less, "<"],
105
+ [:Greater, ">"],
106
+ [:Equal, "="],
107
+ [:Ampersand, "&"],
108
+ [:Caret, "^"],
109
+ [:Bar, "|"],
110
+ [:Question, "?"],
111
+ ]
112
+
113
+ SymbolCharacters = any(*JavaSymbols.map {|p| p.last})
114
+
115
+ prod :Symbol, [SymbolCharacters, :Spacing, lift(0)]
116
+
117
+ # Transient
118
+ rule( :Spacing,
119
+ [:Space],
120
+ #[:TraditionalComment],
121
+ #[:EndOfLineComment],
122
+ #[:LineTerminator],
123
+ #[:EndOfFile]
124
+ [eos()]
125
+ )
126
+
127
+ prod :Space, [/ |\t|\f/]
128
+ #prod :TraditionalComment, [
129
+ #transient void Space = ' ' / '\t' / '\f' ;
130
+ #transient void TraditionalComment = "/*" ( '*' !'/' / !'*' _ )* "*/" ;
131
+ #transient void EndOfLineComment = "//" ( ![\n\r] _ )* LineTerminator ;
132
+ #transient void LineTerminator = '\r' '\n' / '\r' / '\n' ;
133
+ #transient void EndOfFile = !_ ;
134
+ end
135
+
136
+ Java::Parser = Java::Grammar.interpreting_parser
@@ -0,0 +1,10 @@
1
+ $DEBUG = true
2
+ $: << "../../../../lib"
3
+ require 'java'
4
+
5
+ #str = "FOR A := 1 TO 3 S:= S + A PRINT S NEXT"
6
+ str = "!="
7
+ pa = Java::Grammar.interpreting_parser(Packrat::ErrorLoggingInterpretingParser)
8
+ res = pa.parse_string(str, :Symbol)
9
+ p res
10
+
@@ -0,0 +1,10 @@
1
+ Finished porting
2
+ ----------------
3
+ JavaType
4
+ JavaSymbol
5
+
6
+ Left to do
7
+ ----------
8
+ JavaIdentifier
9
+ JavaConstant
10
+ JavaCore
@@ -0,0 +1,446 @@
1
+ /*
2
+ * xtc - The eXTensible Compiler
3
+ * Copyright (C) 2004-2005 Robert Grimm
4
+ *
5
+ * This program is free software; you can redistribute it and/or
6
+ * modify it under the terms of the GNU General Public License
7
+ * as published by the Free Software Foundation; either version 2
8
+ * of the License, or (at your option) any later version.
9
+ *
10
+ * This program is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ * GNU General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU General Public License
16
+ * along with this program; if not, write to the Free Software
17
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
+ */
19
+
20
+ /**
21
+ * Java grammar.
22
+ *
23
+ * @author Robert Grimm
24
+ * @version $Revision: 1.5 $
25
+ */
26
+ module xtc.lang.Java;
27
+
28
+ import xtc.lang.JavaIdentifier(xtc.lang.JavaSymbol, xtc.util.Spacing);
29
+ instantiate xtc.util.Symbol(xtc.util.Spacing);
30
+ import xtc.lang.JavaSymbol(xtc.util.Symbol);
31
+ import xtc.util.Spacing;
32
+
33
+ option withLocation, constant, parser(xtc.lang.JavaPackratParser);
34
+
35
+ // ---------------------------------------------------------- Compilation Unit
36
+
37
+ public transient void CompilationUnit =
38
+ Spacing
39
+ ( "package":Word QualifiedIdentifier ";":Symbol )?
40
+ ImportDeclaration*
41
+ Declaration*
42
+ '\u001a'?
43
+ EndOfFile
44
+ ;
45
+
46
+ transient void ImportDeclaration =
47
+ "import":Word QualifiedIdentifier
48
+ ( ".":Symbol "*":Symbol )?
49
+ ";":Symbol
50
+ ;
51
+
52
+ // ---------------------------------------------------------- Declarations
53
+
54
+ void Modifier =
55
+ "public":Word
56
+ / "protected":Word
57
+ / "private":Word
58
+ / "static":Word
59
+ / "abstract":Word
60
+ / "final":Word
61
+ / "native":Word
62
+ / "synchronized":Word
63
+ / "transient":Word
64
+ / "volatile":Word
65
+ / "strictfp":Word
66
+ ;
67
+
68
+ transient void FormalParameter =
69
+ ("final":Word)? Type Identifier Dimensions
70
+ ;
71
+
72
+ void FormalParameters =
73
+ "(":Symbol FormalParameter ( ",":Symbol FormalParameter )* ")":Symbol
74
+ / "(":Symbol ")":Symbol
75
+ ;
76
+
77
+ transient void Declarator =
78
+ Identifier Dimensions ( "=":Symbol VariableInitializer )?
79
+ ;
80
+
81
+ void Declarators =
82
+ Declarator ( ",":Symbol Declarator )*
83
+ ;
84
+
85
+ transient void ClassBody =
86
+ "{":Symbol Declaration* "}":Symbol
87
+ ;
88
+
89
+ transient void Declaration =
90
+
91
+ // Field declaration.
92
+
93
+ Modifier* Type Declarators ";":Symbol
94
+
95
+ // Method declaration.
96
+
97
+ / Modifier*
98
+ ResultType Identifier FormalParameters Dimensions OptionalThrowsClause
99
+ ( Block / ";":Symbol )
100
+
101
+ // Constructor declaration.
102
+
103
+ / Modifier* Identifier FormalParameters OptionalThrowsClause Block
104
+
105
+ // Class declaration.
106
+
107
+ / Modifier* "class":Word Identifier
108
+ ( "extends":Word Type )?
109
+ ( "implements":Word Type ( ",":Symbol Type )* )?
110
+ ClassBody
111
+
112
+ // Interface declaration.
113
+
114
+ / Modifier* "interface":Word Identifier
115
+ ( "extends":Word Type ( ",":Symbol Type )* )?
116
+ ClassBody
117
+
118
+ // Initialization block.
119
+
120
+ / ( "static":Word / /* Empty */ )
121
+ Block
122
+ ;
123
+
124
+ void OptionalThrowsClause =
125
+ "throws":Word QualifiedIdentifier ( ",":Symbol QualifiedIdentifier )*
126
+ / /* Empty */
127
+ ;
128
+
129
+ // ---------------------------------------------------------- Statements
130
+
131
+ void Block =
132
+ "{":Symbol BlockStatement* "}":Symbol
133
+ ;
134
+
135
+ transient void BlockStatement =
136
+ Declaration
137
+ / Statement
138
+ ;
139
+
140
+ transient void Statement =
141
+ Block
142
+ / "if":Word ParExpression Statement ( "else":Word Statement )?
143
+ / "for":Word "(":Symbol
144
+ ForInit ";":Symbol
145
+ Expression? ";":Symbol
146
+ ExpressionList? ")":Symbol Statement
147
+ / "while":Word ParExpression Statement
148
+ / "do":Word Statement "while":Word ParExpression ";":Symbol
149
+ / "try":Word Block CatchClause* "finally":Word Block
150
+ / "try":Word Block CatchClause+
151
+ / "switch":Word ParExpression "{":Symbol SwitchGroup* "}":Symbol
152
+ / "synchronized":Word ParExpression Block
153
+ / "return":Word Expression? ";":Symbol
154
+ / "throw":Word Expression ";":Symbol
155
+ / "break":Word Identifier? ";":Symbol
156
+ / "continue":Word Identifier? ";":Symbol
157
+ / Identifier ":":Symbol Statement
158
+ / Expression ";":Symbol
159
+ / ";":Symbol
160
+ ;
161
+
162
+ transient void ParExpression =
163
+ "(":Symbol Expression ")":Symbol
164
+ ;
165
+
166
+ void ForInit =
167
+ ("final":Word)? Type Declarators
168
+ / ExpressionList
169
+ / /* Empty */
170
+ ;
171
+
172
+ void CatchClause =
173
+ "catch":Word "(":Symbol FormalParameter ")":Symbol Block
174
+ ;
175
+
176
+ void SwitchGroup =
177
+ "case":Word Expression ":":Symbol BlockStatement*
178
+ / "default":Word ":":Symbol BlockStatement*
179
+ ;
180
+
181
+ // ---------------------------------------------------------- Expressions
182
+
183
+ transient void ExpressionList =
184
+ Expression ( ",":Symbol Expression )*
185
+ ;
186
+
187
+ void Expression =
188
+ <Assignment> ConditionalExpression AssignmentOperator Expression
189
+ / <Base> ConditionalExpression
190
+ ;
191
+
192
+ void AssignmentOperator =
193
+ "=":Symbol
194
+ / "+=":Symbol
195
+ / "-=":Symbol
196
+ / "*=":Symbol
197
+ / "/=":Symbol
198
+ / "&=":Symbol
199
+ / "|=":Symbol
200
+ / "^=":Symbol
201
+ / "%=":Symbol
202
+ / "<<=":Symbol
203
+ / ">>=":Symbol
204
+ / ">>>=":Symbol
205
+ ;
206
+
207
+ void ConditionalExpression =
208
+ <Conditional> ConditionalOrExpression "?":Symbol Expression
209
+ ":":Symbol ConditionalExpression
210
+ / <Base> ConditionalOrExpression
211
+ ;
212
+
213
+ void ConditionalOrExpression =
214
+ <Or> ConditionalOrExpression "||":Symbol ConditionalAndExpression
215
+ / <Base> ConditionalAndExpression
216
+ ;
217
+
218
+ transient void ConditionalAndExpression =
219
+ <And> ConditionalAndExpression "&&":Symbol InclusiveOrExpression
220
+ / <Base> InclusiveOrExpression
221
+ ;
222
+
223
+ transient void InclusiveOrExpression =
224
+ <Or> InclusiveOrExpression "|":Symbol ExclusiveOrExpression
225
+ / <Base> ExclusiveOrExpression
226
+ ;
227
+
228
+ transient void ExclusiveOrExpression =
229
+ <Xor> ExclusiveOrExpression "^":Symbol AndExpression
230
+ / <Base> AndExpression
231
+ ;
232
+
233
+ transient void AndExpression =
234
+ <And> AndExpression "&":Symbol EqualityExpression
235
+ / <Base> EqualityExpression
236
+ ;
237
+
238
+ transient void EqualityExpression =
239
+ <Equal> EqualityExpression "==":Symbol InstanceOfExpression
240
+ / <NotEqual> EqualityExpression "!=":Symbol InstanceOfExpression
241
+ / <Base> InstanceOfExpression
242
+ ;
243
+
244
+ transient void InstanceOfExpression =
245
+ RelationalExpression "instanceof":Word Type
246
+ / RelationalExpression
247
+ ;
248
+
249
+ void RelationalExpression =
250
+ <Less> RelationalExpression "<":Symbol ShiftExpression
251
+ / <Greater> RelationalExpression ">":Symbol ShiftExpression
252
+ / <LessEqual> RelationalExpression "<=":Symbol ShiftExpression
253
+ / <GreatEqual> RelationalExpression ">=":Symbol ShiftExpression
254
+ / <Base> ShiftExpression
255
+ ;
256
+
257
+ transient void ShiftExpression =
258
+ <SignedLeft> ShiftExpression "<<":Symbol AdditiveExpression
259
+ / <SignedRigth> ShiftExpression ">>":Symbol AdditiveExpression
260
+ / <UnsignedRight> ShiftExpression ">>>":Symbol AdditiveExpression
261
+ / <Base> AdditiveExpression
262
+ ;
263
+
264
+ transient void AdditiveExpression =
265
+ <Plus> AdditiveExpression "+":Symbol MultiplicativeExpression
266
+ / <Minus> AdditiveExpression "-":Symbol MultiplicativeExpression
267
+ / <Base> MultiplicativeExpression
268
+ ;
269
+
270
+ transient void MultiplicativeExpression =
271
+ <Times> MultiplicativeExpression "*":Symbol UnaryExpression
272
+ / <Over> MultiplicativeExpression "/":Symbol UnaryExpression
273
+ / <Modulo> MultiplicativeExpression "%":Symbol UnaryExpression
274
+ / <Base> UnaryExpression
275
+ ;
276
+
277
+ transient void UnaryExpression =
278
+ <Plus> "+":Symbol UnaryExpression
279
+ / <Minus> "-":Symbol UnaryExpression
280
+ / <Increment> "++":Symbol UnaryExpression
281
+ / <Decrement> "--":Symbol UnaryExpression
282
+ / <Base> UnaryExpressionNotPlusMinus
283
+ ;
284
+
285
+ transient void UnaryExpressionNotPlusMinus =
286
+ <BitwiseNot> "~":Symbol UnaryExpression
287
+ / <LogicalNot> "!":Symbol UnaryExpression
288
+ / <BasicCast> "(":Symbol BasicType Dimensions ")":Symbol UnaryExpression
289
+ / <Cast> "(":Symbol Type ")":Symbol UnaryExpressionNotPlusMinus
290
+ / <Base> PostfixExpression
291
+ ;
292
+
293
+ void PostfixExpression =
294
+ PrimaryExpression PostfixExpressionTail*
295
+ ;
296
+
297
+ void PostfixExpressionTail =
298
+ "[":Symbol Expression? "]":Symbol
299
+ / Arguments
300
+ / ".":Symbol PrimaryExpression
301
+ / ".":Symbol "class":Word
302
+ / "++":Symbol
303
+ / "--":Symbol
304
+ ;
305
+
306
+ transient void PrimaryExpression =
307
+ Literal
308
+ / Identifier
309
+ / "(":Symbol Expression ")":Symbol
310
+ / "this":Word
311
+ / "super":Word
312
+ / "new":Word QualifiedIdentifier Arguments ClassBody?
313
+ / "new":Word TypeName DimensionExpression+ Dimensions
314
+ / "new":Word TypeName Dimensions ArrayInitializer
315
+ / "void":Word ".":Symbol "class":Word
316
+ ;
317
+
318
+ transient void DimensionExpression =
319
+ "[":Symbol Expression "]":Symbol
320
+ ;
321
+
322
+ transient void Arguments =
323
+ "(":Symbol ExpressionList ")":Symbol
324
+ / "(":Symbol ")":Symbol
325
+ ;
326
+
327
+ transient void ArrayInitializer =
328
+ "{":Symbol
329
+ ( VariableInitializer ",":Symbol )*
330
+ "}":Symbol
331
+ / "{":Symbol
332
+ VariableInitializer
333
+ ( ",":Symbol VariableInitializer )*
334
+ "}":Symbol
335
+ ;
336
+
337
+ void VariableInitializer =
338
+ ArrayInitializer
339
+ / Expression
340
+ ;
341
+
342
+ // ---------------------------------------------------------- Types
343
+
344
+ void ResultType =
345
+ "void":Word
346
+ / Type
347
+ ;
348
+
349
+ void Type =
350
+ TypeName Dimensions
351
+ ;
352
+
353
+ void TypeName =
354
+ BasicType
355
+ / QualifiedIdentifier
356
+ ;
357
+
358
+ void BasicType =
359
+ "byte":Word
360
+ / "short":Word
361
+ / "char":Word
362
+ / "int":Word
363
+ / "long":Word
364
+ / "float":Word
365
+ / "double":Word
366
+ / "boolean":Word
367
+ ;
368
+
369
+ void Dimensions =
370
+ ( "[":Symbol "]":Symbol )*
371
+ ;
372
+
373
+ // ---------------------------------------------------------- Literals
374
+
375
+ String Literal =
376
+ FloatingPointLiteral Spacing
377
+ / IntegerLiteral Spacing
378
+ / CharacterLiteral Spacing
379
+ / StringLiteral Spacing
380
+ / BooleanLiteral
381
+ / NullLiteral
382
+ ;
383
+
384
+ // ----- Integer literals
385
+
386
+ String IntegerLiteral =
387
+ HexNumeral IntegerTypeSuffix?
388
+ / OctalNumeral IntegerTypeSuffix?
389
+ / DecimalNumeral IntegerTypeSuffix?
390
+ ;
391
+
392
+ transient String DecimalNumeral = '0' / NonZeroDigit Digit* ;
393
+ transient String NonZeroDigit = [1-9] ;
394
+ transient String Digit = [0-9] ;
395
+
396
+ transient String HexNumeral = '0' [xX] HexDigit+ ;
397
+ transient String HexDigit = [0-9a-fA-F] ;
398
+
399
+ transient String OctalNumeral = '0' OctalDigit+ ;
400
+ transient String OctalDigit = [0-7] ;
401
+
402
+ transient String IntegerTypeSuffix = [lL] ;
403
+
404
+ // ----- Floating point literals
405
+
406
+ String FloatingPointLiteral =
407
+ Digit+ '.' Digit* Exponent? FloatTypeSuffix?
408
+ / '.' Digit+ Exponent? FloatTypeSuffix?
409
+ / Digit+ Exponent FloatTypeSuffix?
410
+ / Digit+ Exponent? FloatTypeSuffix
411
+ ;
412
+
413
+ transient String Exponent = [eE] [+\-]? Digit+ ;
414
+ transient String FloatTypeSuffix = [fFdD] ;
415
+
416
+ // ----- Character and string literals
417
+
418
+ String CharacterLiteral = ['] ( EscapeSequence / !['\\] _ ) ['] ;
419
+ String StringLiteral = ["] ( EscapeSequence / !["\\] _ )* ["] ;
420
+
421
+ transient String EscapeSequence =
422
+ '\\' [btnfr"'\\] / UnicodeEscape / OctalEscape ;
423
+
424
+ transient String OctalEscape =
425
+ '\\' [0-3] OctalDigit OctalDigit
426
+ / '\\' OctalDigit OctalDigit
427
+ / '\\' OctalDigit
428
+ ;
429
+
430
+ transient String UnicodeEscape =
431
+ '\\' 'u' HexDigit HexDigit HexDigit HexDigit ;
432
+
433
+ // ----- Boolean literals
434
+
435
+ String BooleanLiteral =
436
+ "true":Word
437
+ / "false":Word
438
+ ;
439
+
440
+ // ----- Null literals
441
+
442
+ String NullLiteral =
443
+ "null":Word
444
+ ;
445
+
446
+ // ============================================================================