3 # Copyright (C) 2000, 2001 Paul F. Kinnucan, Jr.
5 # Author: Paul F. Kinnucan, Jr. <paulk@mathworks.com>
6 # Augmented by David Ponce <david@dponce.com>
7 # $Id: java.bnf,v 1.17 2001/01/17 18:22:15 paulk Exp $
9 # java.bnf is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2, or (at your option)
14 # This software is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with GNU Emacs; see the file COPYING. If not, write to the
21 # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 # Boston, MA 02111-1307, USA.
24 # TABLE: jde-java-grammar.el:jde-parse-bovine-java-grammar
30 %outputfile jde-java-grammar.el
31 %parsetable jde-parse-bovine-java-grammar
32 %keywordtable jde-parse-bovine-java-keywords
33 %languagemode jde-mode
34 %setupfunction jde-parse-semantic-default-setup
37 ;; Java is case sensitive
38 (setq semantic-case-fold nil)
39 ;; imenu & speedbar setup
41 ;; initial parsing of the current buffer
42 (semantic-bovinate-toplevel)
43 (jde-parse-update-after-parse)
46 %token ABSTRACT "abstract"
47 %token BOOLEAN "boolean"
55 %token CONTINUE "continue"
56 %token DEFAULT "default"
58 %token DOUBLE "double"
60 %token EXTENDS "extends"
62 %token FINALLY "finally"
67 %token IMPLEMENTS "implements"
68 %token IMPORT "import"
69 %token INSTANCEOF "instanceof"
71 %token INTERFACE "interface"
73 %token NATIVE "native"
75 %token PACKAGE "package"
76 %token PRIVATE "private"
77 %token PROTECTED "protected"
78 %token PUBLIC "public"
79 %token RETURN "return"
81 %token STATIC "static"
82 %token STRICTFP "strictfp"
84 %token SWITCH "switch"
85 %token SYNCHRONIZED "synchronized"
88 %token THROWS "throws"
89 %token TRANSIENT "transient"
92 %token VOLATILE "volatile"
98 bovine-toplevel : package_declaration
103 number : symbol "[0-9]" punctuation "\\." symbol "[0-9Ee]" punctuation "[-+]" symbol "[0-9fFdD]"
104 | symbol "[0-9]" punctuation "\\." symbol "[0-9EefFdD]"
113 type : reference_type
119 primitive_type : BOOLEAN | BYTE | SHORT | INT | LONG | CHAR | FLOAT | DOUBLE
123 reference_type : array_type
129 array_type : primitive_type dims
130 ((concat (car $1) (car $2)))
131 | qualified_name dims
132 ((concat (car $1) (car $2)))
135 qualified_name : symbol punctuation "\\." qualified_name
136 ((concat $1 $2 (car $3)))
141 package_declaration : PACKAGE qualified_name punctuation ";"
145 import_declaration : IMPORT qualified_name punctuation ";"
147 | IMPORT qualified_name punctuation "\\." punctuation "*" punctuation ";"
148 ((concat (car $2) $3 $4) include nil)
151 type_declaration : punctuation ";"
153 | interface_declaration
156 modifiers_opt : modifiers
162 modifiers : modifier modifiers
163 (,(cons (car $1) ,$2))
168 modifier : PUBLIC | PROTECTED | PRIVATE | STATIC | ABSTRACT
169 | FINAL | NATIVE | SYNCHRONIZED | TRANSIENT | VOLATILE | STRICTFP
172 class_declaration : modifiers_opt CLASS qualified_name class_parents class_body
173 (,$3 type "class" $5 $4 $1 nil) # semantic 1.2
174 # ^^^ empty comment spot
178 # `semantic-token-type-parent' returns
180 # nil | ( ["extends_this" | nil] ["implements_this1" ... "implements_thisN"] )
182 class_parents: super interfaces
193 super : EXTENDS qualified_name
197 interfaces : IMPLEMENTS qualified_name_list
201 qualified_name_list : qualified_name punctuation "," qualified_name_list
202 (,(cons (car $1) ,$3))
207 class_body : semantic-list # ::= {class_body_declarations}
208 (EXPANDFULL $1 class_body_declarations)
211 # class_body_declarations : open-paren "{"
215 # | class_declaration
216 class_body_declarations : class_declaration
218 | interface_declaration
224 #| static_initializer
225 | constructor_declaration
230 field_declaration : modifiers_opt type variable_declarators punctuation ";"
231 (,$3 variable ,$2 nil nil $1 nil) # semantic 1.2
232 # ^^^ empty comment spot
235 variable_declarators : variable_declarator variable_declarators_opt
239 variable_declarators_opt: punctuation "," variable_declarators
243 variable_declarator : variable_declarator_id variable_assign_opt
247 variable_assign_opt: punctuation "=" variable_initializer
251 variable_declarator_id : symbol dims
252 ((concat $1 (car $2)))
257 variable_initializer : array_initializer
261 method_declaration : method_header method_body
265 method_header : modifiers_opt method_type symbol formal_parameter_list_opt throws_opt
266 ($3 function ,$2 $4 $1 $5 nil) # semantic 1.2
267 # ^^^ empty comment spot
276 formal_parameter_list_opt : semantic-list # ::= (formal_parameter_list)
277 (EXPAND $1 formal_parameter_list)
280 formal_parameter_list : open-paren "(" close-paren ")"
282 | open-paren "(" formal_parameter formal_parameter_list_next
286 formal_parameter_list_next: close-paren ")"
288 | punctuation "," formal_parameter formal_parameter_list_next
292 formal_parameter-modifier : FINAL
296 formal_parameter : formal_parameter-modifier type variable_declarator_id
297 ((car $3) variable (car $2) nil nil $1 nil) # semantic 1.2
298 # ^^^ empty comment spot
306 throws : THROWS qualified_name_list
310 method_body : punctuation ";"
316 #static_initializer : STATIC block
319 constructor_declaration : modifiers_opt symbol formal_parameter_list_opt throws_opt constructor_body
320 ($2 function nil $3 $1 $4 nil) # semantic 1.2
321 # ^^^ empty comment spot
324 constructor_body : block
328 interface_declaration : modifiers_opt INTERFACE symbol interface_parents interface_body
329 ($3 type "interface" $5 $4 $1 nil) # semantic 1.2
330 # ^^^ empty comment spot
334 # `semantic-token-type-parent' returns:
336 # nil | ( "extends_this1" ... "extends_thisN" )
338 interface_parents : EXTENDS qualified_name_list
343 interface_body : semantic-list # ::= { interface_body_declarations }
344 (EXPANDFULL $1 interface_body_declarations)
347 # interface_body_declarations : open-paren "{"
351 # | class_declaration
352 interface_body_declarations : class_declaration
354 | interface_declaration
356 | method_header punctuation ";"
362 array_initializer : semantic-list "\\`{" # ::= {expression, expression, ...}
365 block : semantic-list "\\`{" # ::= {statements}
368 primary : array_creation_expression
369 | primary_no_new_array primary_dim_opt
372 primary_dim_opt : semantic-list "\\`\\["
376 primary_no_new_array : qualified_name semantic-list "\\`(" # method_invocation
377 | class_instance_creation_expression
378 | semantic-list "\\`(" # (expression)
379 | array_type punctuation "\\." CLASS
383 class_instance_creation_expression : NEW qualified_name semantic-list "\\`(" semantic-list "\\`{" # ::= { class_body_declarations }
384 | NEW qualified_name semantic-list "\\`("
387 array_creation_expression : NEW qualified_name dims array_initializer
388 | NEW qualified_name dims #dim_exprs dims_opt
397 dims: semantic-list "\\`\\[" dims_opt
398 ((concat "[]" (car ,$2)))
401 field_access : primary punctuation "\\." symbol
405 postfix_expression : primary postfix_operator_opt
408 postfix_operator_opt: punctuation "[-+]" punctuation "[-+]"
412 unary_expression : punctuation "[-+^!]" unary_expression
413 | punctuation "[-+]" punctuation "[-+]" unary_expression
414 | semantic-list "\\`(" unary_expression # cast
418 operator: punctuation "[-+*/%=<>^~&|!?:.]" # added DOT as field/method access operator
422 operators: operator operators
426 operators_expression_opt: operators expression
430 expression: unary_expression operators_expression_opt
434 # Revision 1.17 2001/01/17 18:22:15 paulk
435 # Changed the definition of formal_parameter_list to improve performance (less
436 # backtracking) when parsing parameters in method and constructor
437 # declarations. Thanks to David Ponce.
439 # Revision 1.16 2000/10/25 04:31:37 paulk
440 # Modified to reflect new location of generated files.
442 # Revision 1.15 2000/10/25 03:29:05 paulk
443 # David Ponce's fixes for various semantic-list matching
444 # problems. For example, this caused the parser to find a variable
445 # declaration for a method declaration like the following:
447 # [modifiers] type name(..., any_occurence_of[], ...);
449 # Revision 1.14 2000/10/20 04:00:38 paulk
450 # *** empty log message ***
452 # Revision 1.13 2000/08/19 06:37:58 paulk
453 # Changed regular expressions for modifiers to match whole words.
455 # Revision 1.12 2000/08/16 05:03:55 paulk
456 # Changed regular expression for modifier to match only words.
458 # Revision 1.11 2000/07/08 07:09:31 paulk
459 # Latest updates from David Ponce.
461 # Revision 1.8 2000/06/21 06:57:23 paulk
462 # Added rules for arithmetic and string expressions.
464 # Revision 1.7 2000/06/16 06:48:40 paulk
465 # Now handles arrays in field declarations.
467 # Revision 1.6 2000/06/09 04:08:43 paulk
468 # Added volatile to list of variable modifiers. Thanks to David Ponce and Mike Bowler.
470 # Revision 1.5 2000/05/26 09:14:10 paulk
471 # Updated grammar to handle argument variables with modifiers and array arguments.
473 # Revision 1.4 2000/05/16 04:41:28 paulk
474 # *** empty log message ***
476 # Revision 1.3 2000/05/11 04:41:05 paulk
477 # Now handles native method declarations.
479 # Revision 1.2 2000/05/11 02:49:41 paulk
480 # Now parses constructors.
482 # Revision 1.1 2000/05/02 04:10:23 paulk