Remove non-free old and crusty clearcase pkg
[packages] / xemacs-packages / semantic / java.bnf
1 # BNF grammar for Java
2 #
3 # Copyright (C) 2000, 2001 Paul F. Kinnucan, Jr.
4 # Copyright (C) 2001 David Ponce
5 #
6 # Author: Paul F. Kinnucan, Jr. <paulk@mathworks.com>
7 #         David Ponce <david@dponce.com>
8 #
9 # $Id: java.bnf,v 1.15 2002/05/15 19:21:02 ponced Exp $
10 #
11 # java.bnf is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2, or (at your option)
14 # any later version.
15 #
16 # This software 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 GNU Emacs; see the file COPYING.  If not, write to the
23 # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 # Boston, MA 02111-1307, USA.
25
26 # --------
27 # Settings
28 # --------
29 %outputfile    semantic-java.el
30 %parsetable    semantic-toplevel-java-bovine-table
31 %keywordtable  semantic-java-keyword-table
32 %languagemode  java-mode
33 %setupfunction semantic-default-java-setup
34
35 %(progn
36    (setq
37     ;; Java numbers
38     semantic-number-expression semantic-java-number-regexp
39     ;; Java is case sensitive
40     semantic-case-fold nil
41     ;; special handling of multiple variable declarations/statement
42     semantic-expand-nonterminal 'semantic-expand-java-nonterminal
43     ;; function to use when creating items in imenu
44     semantic-imenu-summary-function 'semantic-prototype-nonterminal
45     ;; function to use for creating the imenu
46     imenu-create-index-function 'semantic-create-imenu-index
47     ;; Character used to separation a parent/child relationship
48     semantic-type-relation-separator-character '(".")
49     semantic-command-separation-character ";"
50     document-comment-start "/**"
51     document-comment-line-prefix " *"
52     document-comment-end " */"
53     ;; speedbar and imenu buckets name
54     semantic-symbol->name-assoc-list-for-type-parts
55     ;; In type parts
56     '((type     . "Classes")
57       (variable . "Variables")
58       (function . "Methods"))
59     semantic-symbol->name-assoc-list
60     ;; Everywhere
61     (append semantic-symbol->name-assoc-list-for-type-parts
62             '((include  . "Imports")
63               (package  . "Package")))
64     ;; Semantic navigation inside 'type children
65     senator-step-at-token-ids '(function variable)
66     )
67    )%
68
69 %token ABSTRACT     "abstract"
70 %put ABSTRACT summary
71 "Class|Method declaration modifier: abstract {class|<type>} <name> ..."
72
73 %token BOOLEAN      "boolean"
74 %put BOOLEAN summary
75 "Primitive logical quantity type (true or false)"
76
77 %token BREAK        "break"
78 %put BREAK summary
79 "break [<label>] ;"
80
81 %token BYTE         "byte"
82 %put BYTE summary
83 "Integral primitive type (-128 to 127)"
84
85 %token CASE         "case"
86 %put CASE summary
87 "switch(<expr>) {case <const-expr>: <stmts> ... }"
88
89 %token CATCH        "catch"
90 %put CATCH summary
91 "try {<stmts>} catch(<parm>) {<stmts>} ... "
92
93 %token CHAR         "char"
94 %put CHAR summary
95 "Integral primitive type ('\u0000' to '\uffff') (0 to 65535)"
96
97 %token CLASS        "class"
98 %put CLASS summary
99 "Class declaration: class <name>"
100
101 %token CONST        "const"
102 %put CONST summary
103 "Unused reserved word"
104
105 %token CONTINUE     "continue"
106 %put CONTINUE summary
107 "continue [<label>] ;"
108
109 %token DEFAULT      "default"
110 %put DEFAULT summary
111 "switch(<expr>) { ... default: <stmts>}"
112
113 %token DO           "do"
114 %put DO summary
115 "do <stmt> while (<expr>);"
116
117 %token DOUBLE       "double"
118 %put DOUBLE summary
119 "Primitive floating-point type (double-precision 64-bit IEEE 754)"
120
121 %token ELSE         "else"
122 %put ELSE summary
123 "if (<expr>) <stmt> else <stmt>"
124
125 %token EXTENDS      "extends"
126 %put EXTENDS summary
127 "SuperClass|SuperInterfaces declaration: extends <name> [, ...]"
128
129 %token FINAL        "final"
130 %put FINAL summary
131 "Class|Member declaration modifier: final {class|<type>} <name> ..."
132
133 %token FINALLY      "finally"
134 %put FINALLY summary
135 "try {<stmts>} ... finally {<stmts>}"
136
137 %token FLOAT        "float"
138 %put FLOAT summary
139 "Primitive floating-point type (single-precision 32-bit IEEE 754)"
140
141 %token FOR          "for"
142 %put FOR summary
143 "for ([<init-expr>]; [<expr>]; [<update-expr>]) <stmt>"
144
145 %token GOTO         "goto"
146 %put GOTO summary
147 "Unused reserved word"
148
149 %token IF           "if"
150 %put IF summary
151 "if (<expr>) <stmt> [else <stmt>]"
152
153 %token IMPLEMENTS   "implements"
154 %put IMPLEMENTS summary
155 "Class SuperInterfaces declaration: implements <name> [, ...]"
156
157 %token IMPORT       "import"
158 %put IMPORT summary
159 "Import package declarations: import <package>"
160
161 %token INSTANCEOF   "instanceof"
162
163 %token INT          "int"
164 %put INT summary
165 "Integral primitive type (-2147483648 to 2147483647)"
166
167 %token INTERFACE    "interface"
168 %put INTERFACE summary
169 "Interface declaration: interface <name>"
170
171 %token LONG         "long"
172 %put LONG summary
173 "Integral primitive type (-9223372036854775808 to 9223372036854775807)"
174
175 %token NATIVE       "native"
176 %put NATIVE summary
177 "Method declaration modifier: native <type> <name> ..."
178
179 %token NEW          "new"
180
181 %token PACKAGE      "package"
182 %put PACKAGE summary
183 "Package declaration: package <name>"
184
185 %token PRIVATE      "private"
186 %put PRIVATE summary
187 "Access level modifier: private {class|interface|<type>} <name> ..."
188
189 %token PROTECTED    "protected"
190 %put PROTECTED summary
191 "Access level modifier: protected {class|interface|<type>} <name> ..."
192
193 %token PUBLIC       "public"
194 %put PUBLIC summary
195 "Access level modifier: public {class|interface|<type>} <name> ..."
196
197 %token RETURN       "return"
198 %put RETURN summary
199 "return [<expr>] ;"
200
201 %token SHORT        "short"
202 %put SHORT summary
203 "Integral primitive type (-32768 to 32767)"
204
205 %token STATIC       "static"
206 %put STATIC summary
207 "Declaration modifier: static {class|interface|<type>} <name> ..."
208
209 %token STRICTFP     "strictfp"
210 %put STRICTFP summary
211 "Declaration modifier: strictfp {class|interface|<type>} <name> ..."
212
213 %token SUPER        "super"
214
215 %token SWITCH       "switch"
216 %put SWITCH summary
217 "switch(<expr>) {[case <const-expr>: <stmts> ...] [default: <stmts>]}"
218
219
220 %token SYNCHRONIZED "synchronized"
221 %put SYNCHRONIZED summary
222 "synchronized (<expr>) ... | Method decl. modifier: synchronized <type> <name> ..."
223
224 %token THIS         "this"
225
226 %token THROW        "throw"
227 %put THROW summary
228 "throw <expr> ;"
229
230 %token THROWS       "throws"
231 %put THROWS summary
232 "Method|Constructor declaration: throws <classType>, ..."
233
234 %token TRANSIENT    "transient"
235 %put TRANSIENT summary
236 "Field declaration modifier: transient <type> <name> ..."
237
238 %token TRY          "try"
239 %put TRY summary
240 "try {<stmts>} [catch(<parm>) {<stmts>} ...] [finally {<stmts>}]"
241
242 %token VOID         "void"
243 %put VOID summary
244 "Method return type: void <name> ..."
245
246 %token VOLATILE     "volatile"
247 %put VOLATILE summary
248 "Field declaration modifier: volatile <type> <name> ..."
249
250 %token WHILE        "while"
251 %put WHILE summary
252 "while (<expr>) <stmt> | do <stmt> while (<expr>);"
253   
254 # --------------------------
255 # Official javadoc line tags
256 # --------------------------
257
258 # Javadoc tags are identified by a 'javadoc' keyword property.  The
259 # value of this property must be itself a property list where the
260 # following properties are recognized:
261 #
262 # - `seq' (mandatory) is the tag sequence number used to check if tags
263 #   are correctly ordered in a javadoc comment block.
264 #
265 # - `usage' (mandatory) is the list of token categories for which this
266 #   documentation tag is allowed.
267 #
268 # - `opt' (optional) if non-nil indicates this is an optional tag.
269 #   By default tags are mandatory.
270 #
271 # - `with-name' (optional) if non-nil indicates that this tag is
272 #   followed by an identifier like in "@param <var-name> description"
273 #   or "@exception <class-name> description".
274 #
275 # - `with-ref' (optional) if non-nil indicates that the tag is
276 #   followed by a reference like in "@see <reference>".
277
278 %token _AUTHOR      "@author"
279 %put   _AUTHOR      javadoc (seq 1 usage (type))
280 %token _VERSION     "@version"
281 %put   _VERSION     javadoc (seq 2 usage (type)) 
282 %token _PARAM       "@param"
283 %put   _PARAM       javadoc (seq 3 usage (function) with-name t) 
284 %token _RETURN      "@return"
285 %put   _RETURN      javadoc (seq 4 usage (function)) 
286 %token _EXCEPTION   "@exception"
287 %put   _EXCEPTION   javadoc (seq 5 usage (function) with-name t) 
288 %token _THROWS      "@throws"
289 %put   _THROWS      javadoc (seq 6 usage (function) with-name t) 
290 %token _SEE         "@see"
291 %put   _SEE         javadoc (seq 7 usage (type function variable) opt t with-ref t) 
292 %token _SINCE       "@since"
293 %put   _SINCE       javadoc (seq 8 usage (type function variable) opt t) 
294 %token _SERIAL      "@serial"
295 %put   _SERIAL      javadoc (seq 9 usage (variable) opt t) 
296 %token _SERIALDATA  "@serialData"
297 %put   _SERIALDATA  javadoc (seq 10 usage (function) opt t) 
298 %token _SERIALFIELD "@serialField"
299 %put   _SERIALFIELD javadoc (seq 11 usage (variable) opt t) 
300 %token _DEPRECATED  "@deprecated"
301 %put   _DEPRECATED  javadoc (seq 12 usage (type function variable) opt t) 
302
303 # --------
304 # Grammar
305 # --------
306 bovine-toplevel : package_declaration
307                 | import_declaration
308                 | type_declaration
309                 ;
310   
311 literal : number
312         | qualified_name
313         | string
314         ;
315
316 type : reference_type
317        (,$1)
318      | primitive_type
319        (,$1)
320      ;
321   
322 primitive_type : BOOLEAN | BYTE | SHORT | INT | LONG | CHAR | FLOAT | DOUBLE
323                ;
324
325 reference_type : array_type
326                  (,$1)
327                | qualified_name
328                  (,$1)
329                ;
330   
331 array_type : primitive_type dims
332              ((concat (car $1) (car $2)))
333            | qualified_name dims
334              ((concat (car $1) (car $2)))
335            ;
336
337 qualified_name : symbol punctuation "\\." qualified_name
338                  ((concat $1 $2 (car $3)))
339                | symbol
340                  ($1)
341                ;
342
343 ## TOP-LEVEL ENTRY: package definition.
344 ##  ("NAME" package DETAIL "DOCSTRING")
345 package_declaration : PACKAGE qualified_name punctuation ";"
346                       (,$2 package nil nil)
347                     ;
348   
349
350 ## TOP-LEVEL ENTRY: import definition.
351 ##  ("FILE" include SYSTEM "DOCSTRING")
352 import_declaration : IMPORT qualified_name punctuation ";"
353                      (,$2 include nil nil)
354                    | IMPORT qualified_name punctuation "\\." punctuation "*" punctuation ";"
355                      ((concat (car $2) $3 $4) include nil nil)
356                    ;
357   
358 type_declaration : punctuation ";"
359                  | class_declaration
360                  | interface_declaration
361                  ;
362
363 modifiers_opt : modifiers
364                 (,$1)
365               | EMPTY
366               ;
367   
368 modifiers : modifier modifiers
369             (,(cons (car $1) ,$2))
370           | modifier
371             (,$1)
372           ;
373   
374 modifier : PUBLIC | PROTECTED | PRIVATE | STATIC | ABSTRACT
375          | FINAL | NATIVE | SYNCHRONIZED | TRANSIENT | VOLATILE | STRICTFP
376          ;
377
378 ## TOP-LEVEL ENTRY: class definition.
379 ##  ("NAME" type "TYPE" PART-LIST PARENTS EXTRA-SPECS "DOCSTRING")
380 class_declaration : modifiers_opt CLASS qualified_name class_parents class_body
381                     ( ,$3 type "class" $5 $4
382                          (ASSOC typemodifiers $1)
383                           nil
384                           )
385                   ;
386
387 # class_parents := nil | (["extends_this" | nil] ["implements_this1" ... "implements_thisN"])
388 class_parents: super interfaces
389                (,(append $1 $2))
390              | interfaces super
391                (,(append $2 $1))
392              | super
393                (,$1)
394              | interfaces
395                (,(cons nil $1))
396              | EMPTY
397              ;
398   
399 super : EXTENDS qualified_name
400         (,$2)
401       ;
402   
403 interfaces : IMPLEMENTS qualified_name_list
404              (,$2)
405            ;
406   
407 qualified_name_list : qualified_name punctuation "," qualified_name_list
408                       (,(cons (car $1) ,$3))
409                     | qualified_name
410                       (,$1)
411                     ;
412   
413 class_body : semantic-list # ::= {class_body_declarations}
414              (EXPANDFULL $1 class_body_declarations)
415            ;
416   
417 class_body_declarations : class_declaration
418                           (,$1)
419                         | interface_declaration
420                           (,$1)
421                         | field_declaration
422                           (,$1)
423                         | method_declaration
424                           (,$1)
425                         #| static_initializer
426                         | constructor_declaration
427                           (,$1)
428                         #| block
429                         ;
430   
431 ## TOP-LEVEL ENTRY: variable definition.
432 ##  ("NAME" variable "TYPE" DEFAULT-VALUE EXTRA-SPECS "DOCSTRING")
433 field_declaration : modifiers_opt type variable_declarators punctuation ";"
434                     (,$3 variable ,$2 nil
435                          (ASSOC typemodifiers $1)
436                           nil)
437                   ;
438
439 ## The following rule is used by `semantic-expand-java-nonterminal' to
440 ## reparse declaration of multiple variables in the same statement.
441 ## Reparsing is done with `semantic-bovinate-from-nonterminal-full' to
442 ## get correct START END information for each variable token.
443 field_declaration_multi : modifiers_opt type variable_declarator punctuation ","
444                           (,$3)
445                         | modifiers_opt type variable_declarator punctuation ";"
446                           (,$3)
447                         | variable_declarator punctuation ","
448                           (,$1)
449                         | variable_declarator punctuation ";"
450                           (,$1)
451                         ;
452                          
453 variable_declarators : variable_declarator variable_declarators_opt
454                        ((cons (car $1) (car $2)))
455                      ;
456
457 variable_declarators_opt: punctuation "," variable_declarators
458                           (,$2)
459                         | EMPTY
460                         ;
461
462 variable_declarator : variable_declarator_id variable_assign_opt
463                       (,$1)
464                     ;
465
466 variable_assign_opt: punctuation "=" variable_initializer
467                    | EMPTY
468                    ;
469
470 variable_declarator_id : symbol dims
471                          ((concat $1 (car $2)))
472                        | symbol
473                          ($1)
474                        ;
475
476 variable_initializer : array_initializer
477                      | expression
478                      ;
479
480 method_declaration : method_header method_body
481                      (,$1)
482                    ;
483   
484 ## TOP-LEVEL ENTRY: method definition.
485 ##  ("NAME" function "TYPE" ARG-LIST EXTRA-SPECS "DOCSTRING")
486 method_header : modifiers_opt method_type symbol formal_parameter_list_opt throws_opt
487                 ($3 function ,$2 $4
488                     (ASSOC typemodifiers $1 throws $5)
489                      nil)
490               ;
491
492 method_type: VOID
493              ($1)
494            | type
495              (,$1)
496            ;
497   
498 formal_parameter_list_opt : semantic-list # ::= (formal_parameter_list)
499                             (EXPANDFULL $1 formal_parameter_list)
500                           | EMPTY
501                           ;
502   
503 formal_parameter_list : formal_parameter punctuation ","
504                         (,$1)
505                       | formal_parameter
506                         (,$1)
507                       ;
508
509 formal_parameter-modifier : FINAL
510                           | EMPTY
511                           ;
512
513 ## TOP-LEVEL ENTRY: variable definition.
514 ##  ("NAME" variable "TYPE" DEFAULT-VALUE EXTRA-SPECS "DOCSTRING")
515 formal_parameter : formal_parameter-modifier type variable_declarator_id
516                    (,$3 variable ,$2 nil
517                     (ASSOC typemodifiers $1)
518                      nil)
519                  ;
520   
521 throws_opt : throws
522              (,$1)
523            | EMPTY
524            ;
525   
526 throws : THROWS qualified_name_list
527          (,$2)
528        ;
529   
530 method_body : punctuation ";"
531             | block
532             ;
533
534 #static_initializer : STATIC block
535 #                   ;
536
537 ## TOP-LEVEL ENTRY: constructor definition.
538 ##  ("NAME" function "TYPE" ARG-LIST EXTRA-SPECS "DOCSTRING")
539 constructor_declaration : modifiers_opt symbol formal_parameter_list_opt throws_opt
540                           constructor_body
541                           ($2 function nil $3
542                               (ASSOC typemodifiers $1 throws $4)
543                                nil)
544                         ;
545   
546 constructor_body : block
547                  ;
548
549 ## TOP-LEVEL ENTRY: interface definition.
550 ##  ("NAME" type "TYPE" PART-LIST PARENTS EXTRA-SPECS "DOCSTRING")
551 interface_declaration : modifiers_opt INTERFACE symbol interface_parents interface_body
552                         ($3 type "interface" $5 $4
553                             (ASSOC typemodifiers $1)
554                              nil)
555                       ;
556
557 # interface_parents := nil | ("extends_this1" ... "extends_thisN")
558 interface_parents : EXTENDS qualified_name_list
559                     (,$2)
560                   | EMPTY
561                   ;
562   
563 interface_body : semantic-list # ::= { interface_body_declarations }
564                  (EXPANDFULL $1 interface_body_declarations)
565                ;
566   
567 interface_body_declarations : class_declaration
568                               (,$1)
569                             | interface_declaration
570                               (,$1)
571                             | method_header punctuation ";"
572                               (,$1)
573                             | field_declaration
574                               (,$1)
575                             ;
576   
577 array_initializer : semantic-list "\\`{" # ::= {expression, expression, ...}
578                   ;
579   
580 block : semantic-list "\\`{" # ::= {statements}
581       ;
582   
583 primary : array_creation_expression
584         | primary_no_new_array primary_dim_opt
585         ;
586
587 primary_dim_opt : semantic-list "\\`\\["
588                 | EMPTY
589                 ;
590   
591 primary_no_new_array : qualified_name semantic-list "\\`(" # method_invocation
592                      | class_instance_creation_expression
593                      | semantic-list "\\`(" # (expression)
594                      | array_type punctuation "\\." CLASS
595                      | literal
596                      ;
597
598 class_instance_creation_expression : NEW qualified_name semantic-list "\\`("
599                                      semantic-list "\\`{" # ::= { class_body_declarations }
600                                    | NEW qualified_name semantic-list "\\`("
601                                    ;
602   
603 ## array_creation_expression : NEW qualified_name dims array_initializer
604 ##                           | NEW qualified_name dims #dim_exprs dims_opt
605 ##                           ;
606 array_creation_expression : NEW array_type array_initializer
607                           | NEW array_type #dim_exprs dims_opt
608                           ;
609   
610 dims_opt : dims
611            (,$1)
612          | EMPTY
613            (nil)
614          ;
615
616 dims: semantic-list "\\`\\[" dims_opt
617       ((concat "[]" (car ,$2)))
618     ;
619   
620 field_access : primary punctuation "\\." symbol
621              | qualified_name
622              ;
623   
624 postfix_expression : primary postfix_operator_opt
625                    ;
626
627 postfix_operator_opt: punctuation "[-+]" punctuation "[-+]"
628                     | EMPTY
629                     ;
630
631 unary_expression : punctuation "[-+^!]" unary_expression
632                  | punctuation "[-+]" punctuation "[-+]" unary_expression
633                  | semantic-list "\\`(" unary_expression # cast
634                  | postfix_expression
635                  ;
636
637 operator: punctuation "[-+*/%=<>^~&|!?:.]" # added DOT as field/method access operator
638         | INSTANCEOF 
639         ;
640
641 operators: operator operators
642          | operator
643          ;
644
645 operators_expression_opt: operators expression
646                         | EMPTY
647                         ;
648
649 expression: unary_expression operators_expression_opt
650           ;
651
652 # End of java.bnf