;;; wisent-java.wy -- LALR grammar for Java ;; ;; Copyright (C) 2002, 2003, 2004, 2005, 2006 David Ponce ;; ;; Author: David Ponce ;; Maintainer: David Ponce ;; Created: 19 Feb 2002 ;; Keywords: syntax ;; X-RCS: $Id: wisent-java.wy,v 1.29 2006/05/31 12:49:05 ponced Exp $ ;; ;; This file is not part of GNU Emacs. ;; ;; This program is free software; you can redistribute it and/or ;; modify it under the terms of the GNU General Public License as ;; published by the Free Software Foundation; either version 2, or (at ;; your option) any later version. ;; ;; This software is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;; General Public License for more details. ;; ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs; see the file COPYING. If not, write to the ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, ;; Boston, MA 02110-1301, USA. ;; ;;; Commentary: ;; ;; This grammar fully parses correct Java 1.5 syntax. ;; ;; It is based on the GPLed CUP Grammar for Java version 1.5, plus: ;; ;; - JSR-175 "Program Annotation Facility" productions. ;; - Additional rules to extract tags needed by Semantic. ;; - Error recovery rules to work as safely as possible in an ;; interactive environment. ;; ;; The CUP parser home page is at ;; . ;; ;; TODO: ;; - Finalize production of tags from inside `block_statements'. ;; - Finalize production of `:template-specifier' attribute according ;; to what is done in the C grammar. ;; - Finalize production of tags from annotations? ;; - Review error recovery rules. ;; %{ ;; Stack of enum names in scope. (defvar wisent-java-wy--enums nil) ;; Stack of anonymous class declarations found in an expression. (defvar wisent-java-wy--anons nil) } %package wisent-java-wy %languagemode java-mode ;; The default goal. %start goal ;; Alternate goals needed for re-parse. %start package_declaration %start import_declaration %start class_declaration %start enum_declaration %start enum_constant %start field_declaration %start method_declaration %start formal_parameter %start constructor_declaration %start interface_declaration %start abstract_method_declaration ;; Re-parse inside blocks (not yet finished). %start block_statements %start local_variable_declaration ;; Goal used for `semantic-get-local-variables'. %start block_statement ;; ----------------------------- ;; Block & Parenthesis terminals ;; ----------------------------- %type ;;syntax "\\s(\\|\\s)" matchdatatype block %token PAREN_BLOCK "(LPAREN RPAREN)" %token BRACE_BLOCK "(LBRACE RBRACE)" %token BRACK_BLOCK "(LBRACK RBRACK)" %token LPAREN "(" %token RPAREN ")" %token LBRACE "{" %token RBRACE "}" %token LBRACK "[" %token RBRACK "]" ;; ------------------ ;; Operator terminals ;; ------------------ %type ;;syntax "\\(\\s.\\|\\s$\\|\\s'\\)+" matchdatatype string %token NOT "!" %token NOTEQ "!=" %token MOD "%" %token MODEQ "%=" %token AND "&" %token ANDAND "&&" %token ANDEQ "&=" %token MULT "*" %token MULTEQ "*=" %token PLUS "+" %token PLUSPLUS "++" %token PLUSEQ "+=" %token COMMA "," %token MINUS "-" %token MINUSMINUS "--" %token MINUSEQ "-=" %token DOT "." %token DIV "/" %token DIVEQ "/=" %token COLON ":" %token SEMICOLON ";" %token LT "<" %token LSHIFT "<<" %token LSHIFTEQ "<<=" %token LTEQ "<=" %token EQ "=" %token EQEQ "==" %token GT ">" %token GTEQ ">=" %token RSHIFT ">>" %token RSHIFTEQ ">>=" %token URSHIFT ">>>" %token URSHIFTEQ ">>>=" %token QUESTION "?" %token XOR "^" %token XOREQ "^=" %token OR "|" %token OREQ "|=" %token OROR "||" %token COMP "~" %token ELLIPSIS "..." %token AT "@" ;; ----------------- ;; Literal terminals ;; ----------------- %type ;;syntax "\\(\\sw\\|\\s_\\)+" %token NULL_LITERAL "\\`null\\'" %token BOOLEAN_LITERAL "\\`false\\'" %token BOOLEAN_LITERAL "\\`true\\'" %token IDENTIFIER %type ;;syntax "\\s\"" matchdatatype sexp %token STRING_LITERAL %type ;;syntax semantic-lex-number-expression %token NUMBER_LITERAL ;; ----------------- ;; Keyword terminals ;; ----------------- ;; Generate a keyword analyzer %type ;;syntax "\\(\\sw\\|\\s_\\)+" matchdatatype keyword %keyword ABSTRACT "abstract" %put ABSTRACT summary "Class|Method declaration modifier: abstract {class|} ..." %keyword ASSERT "assert" %put ASSERT summary "Assertion statement: assert [, ...];" %keyword BOOLEAN "boolean" %put BOOLEAN summary "Primitive logical quantity type (true or false)" %keyword BREAK "break" %put BREAK summary "break [