⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 java12.cup

📁 java语法解释器生成器
💻 CUP
📖 第 1 页 / 共 2 页
字号:
import java_cup.runtime.*;/* August 1999 - modified by Gerwin Klein <lsf@jflex.de>                 to interface with JFlex scanners,                 allows empty semicolon in class decls.    changed productions:  class_member_declaration ::=	  	field_declaration  	|	method_declaration    [..]  	|	interface_declaration    | SEMICOLON  	;  interface_member_declaration ::=  		constant_declaration	  |	abstract_method_declaration  	|	class_declaration  	|	interface_declaration    | SEMICOLON	  ;*//* Java 1.2 parser for CUP.   * Copyright (C) 1998 C. Scott Ananian <cananian@alumni.princeton.edu> * This program is released under the terms of the GPL; see the file * COPYING for more details.  There is NO WARRANTY on this code. *//*JDK 1.2 Features added:  strictfp modifier.  explicit_constructor_invocation ::= ...        | primary DOT THIS LPAREN argument_list_opt RPAREN SEMICOLON ;  field_access ::= ...        |       name DOT SUPER DOT IDENTIFIER ;  method_invocation ::= ...        |       name DOT SUPER DOT IDENTIFIER LPAREN argument_list_opt RPAREN ;*/parser code  {:   public void report_error(String message, Object info) {    StringBuffer m = new StringBuffer("Error ");    if (info instanceof java_cup.runtime.Symbol)       m.append( "("+info.toString()+")" );         m.append(" : "+message);       System.out.println(m);  }     public void report_fatal_error(String message, Object info) {    report_error(message, info);    throw new RuntimeException("Fatal Syntax Error");  }:};terminal BOOLEAN; // primitive_typeterminal BYTE, SHORT, INT, LONG, CHAR; // integral_typeterminal FLOAT, DOUBLE; // floating_point_typeterminal LBRACK, RBRACK; // array_typeterminal DOT; // qualified_nameterminal SEMICOLON, MULT, COMMA, LBRACE, RBRACE, EQ, LPAREN, RPAREN, COLON;terminal PACKAGE; // package_declarationterminal IMPORT; // import_declarationterminal PUBLIC, PROTECTED, PRIVATE; // modifierterminal STATIC; // modifierterminal ABSTRACT, FINAL, NATIVE, SYNCHRONIZED, TRANSIENT, VOLATILE;terminal CLASS; // class_declarationterminal EXTENDS; // superterminal IMPLEMENTS; // interfacesterminal VOID; // method_headerterminal THROWS; // throwsterminal THIS, SUPER; // explicit_constructor_invocationterminal INTERFACE; // interface_declarationterminal IF, ELSE; // if_then_statement, if_then_else_statementterminal SWITCH; // switch_statementterminal CASE, DEFAULT; // switch_labelterminal DO, WHILE; // while_statement, do_statementterminal FOR; // for_statementterminal BREAK; // break_statementterminal CONTINUE; // continue_statementterminal RETURN; // return_statementterminal THROW; // throw_statementterminal TRY; // try_statementterminal CATCH; // catch_clauseterminal FINALLY; // finallyterminal NEW; // class_instance_creation_expressionterminal PLUSPLUS; // postincrement_expressionterminal MINUSMINUS; // postdecrement_expressionterminal PLUS, MINUS, COMP, NOT, DIV, MOD;terminal LSHIFT, RSHIFT, URSHIFT; // shift_expressionterminal LT, GT, LTEQ, GTEQ, INSTANCEOF; // relational_expressionterminal EQEQ, NOTEQ; // equality_expressionterminal AND; // and_expressionterminal XOR; // exclusive_or_expressionterminal OR;  // inclusive_or_expressionterminal ANDAND; // conditional_and_expressionterminal OROR; // conditional_or_expressionterminal QUESTION; // conditional_expressionterminal MULTEQ, DIVEQ, MODEQ, PLUSEQ, MINUSEQ; // assignment_operatorterminal LSHIFTEQ, RSHIFTEQ, URSHIFTEQ; // assignment_operatorterminal ANDEQ, XOREQ, OREQ; // assignment_operatorterminal java.lang.Number INTEGER_LITERAL;terminal java.lang.Number FLOATING_POINT_LITERAL;terminal java.lang.Boolean BOOLEAN_LITERAL;terminal java.lang.Character CHARACTER_LITERAL;terminal java.lang.String STRING_LITERAL;terminal java.lang.String IDENTIFIER; // nameterminal NULL_LITERAL;// strictfp keyword, new in Java 1.2terminal STRICTFP;// Reserved but unused:terminal CONST, GOTO;// 19.2) The Syntactic Grammarnon terminal goal;// 19.3) Lexical Structurenon terminal literal;// 19.4) Types, Values, and Variablesnon terminal type, primitive_type, numeric_type;non terminal integral_type, floating_point_type;non terminal reference_type;non terminal class_or_interface_type;non terminal class_type, interface_type;non terminal array_type;// 19.5) Namesnon terminal name, simple_name, qualified_name;// 19.6) Packagesnon terminal compilation_unit;non terminal package_declaration_opt, package_declaration;non terminal import_declarations_opt, import_declarations;non terminal type_declarations_opt, type_declarations;non terminal import_declaration;non terminal single_type_import_declaration;non terminal type_import_on_demand_declaration;non terminal type_declaration;// 19.7) Productions used only in the LALR(1) grammarnon terminal modifiers_opt, modifiers, modifier;// 19.8.1) Class Declarationnon terminal class_declaration, super, super_opt;non terminal interfaces, interfaces_opt, interface_type_list;non terminal class_body;non terminal class_body_declarations, class_body_declarations_opt;non terminal class_body_declaration, class_member_declaration;// 19.8.2) Field Declarationsnon terminal field_declaration, variable_declarators, variable_declarator;non terminal variable_declarator_id, variable_initializer;// 19.8.3) Method Declarationsnon terminal method_declaration, method_header, method_declarator;non terminal formal_parameter_list_opt, formal_parameter_list;non terminal formal_parameter;non terminal throws_opt, throws;non terminal class_type_list, method_body;// 19.8.4) Static Initializersnon terminal static_initializer;// 19.8.5) Constructor Declarationsnon terminal constructor_declaration, constructor_declarator;non terminal constructor_body;non terminal explicit_constructor_invocation;// 19.9.1) Interface Declarationsnon terminal interface_declaration;non terminal extends_interfaces_opt, extends_interfaces;non terminal interface_body;non terminal interface_member_declarations_opt, interface_member_declarations;non terminal interface_member_declaration, constant_declaration;non terminal abstract_method_declaration;// 19.10) Arraysnon terminal array_initializer;non terminal variable_initializers;// 19.11) Blocks and Statementsnon terminal block;non terminal block_statements_opt, block_statements, block_statement;non terminal local_variable_declaration_statement, local_variable_declaration;non terminal statement, statement_no_short_if;non terminal statement_without_trailing_substatement;non terminal empty_statement;non terminal labeled_statement, labeled_statement_no_short_if;non terminal expression_statement, statement_expression;non terminal if_then_statement;non terminal if_then_else_statement, if_then_else_statement_no_short_if;non terminal switch_statement, switch_block;non terminal switch_block_statement_groups;non terminal switch_block_statement_group;non terminal switch_labels, switch_label;non terminal while_statement, while_statement_no_short_if;non terminal do_statement;non terminal for_statement, for_statement_no_short_if;non terminal for_init_opt, for_init;non terminal for_update_opt, for_update;non terminal statement_expression_list;non terminal identifier_opt;non terminal break_statement, continue_statement;non terminal return_statement, throw_statement;non terminal synchronized_statement, try_statement;non terminal catches_opt, catches, catch_clause;non terminal finally;// 19.12) Expressionsnon terminal primary, primary_no_new_array;non terminal class_instance_creation_expression;non terminal argument_list_opt, argument_list;non terminal array_creation_expression;non terminal dim_exprs, dim_expr, dims_opt, dims;non terminal field_access, method_invocation, array_access;non terminal postfix_expression;non terminal postincrement_expression, postdecrement_expression;non terminal unary_expression, unary_expression_not_plus_minus;non terminal preincrement_expression, predecrement_expression;non terminal cast_expression;non terminal multiplicative_expression, additive_expression;non terminal shift_expression, relational_expression, equality_expression;non terminal and_expression, exclusive_or_expression, inclusive_or_expression;non terminal conditional_and_expression, conditional_or_expression;non terminal conditional_expression, assignment_expression;non terminal assignment;non terminal left_hand_side;non terminal assignment_operator;non terminal expression_opt, expression;non terminal constant_expression;start with goal;// 19.2) The Syntactic Grammargoal ::=	compilation_unit	;// 19.3) Lexical Structure.literal ::=	INTEGER_LITERAL	|	FLOATING_POINT_LITERAL	|	BOOLEAN_LITERAL	|	CHARACTER_LITERAL	|	STRING_LITERAL	|	NULL_LITERAL	;// 19.4) Types, Values, and Variablestype	::=	primitive_type	|	reference_type	;primitive_type ::=		numeric_type	|	BOOLEAN	;numeric_type::=	integral_type	|	floating_point_type	;integral_type ::= 		BYTE 	|	SHORT 	|	INT 	|	LONG 	|	CHAR 	;floating_point_type ::= 		FLOAT 	|	DOUBLE	;reference_type ::=		class_or_interface_type	|	array_type	;class_or_interface_type ::= name;class_type ::=	class_or_interface_type;interface_type ::= class_or_interface_type;		array_type ::=	primitive_type dims	|	name dims	;// 19.5) Namesname	::=	simple_name	|	qualified_name	;simple_name ::=	IDENTIFIER	;qualified_name ::=		name DOT IDENTIFIER	;// 19.6) Packagescompilation_unit ::=		package_declaration_opt 		import_declarations_opt		type_declarations_opt		;package_declaration_opt ::= package_declaration | ;import_declarations_opt ::= import_declarations | ;type_declarations_opt   ::= type_declarations   | ;import_declarations ::= 		import_declaration	|	import_declarations import_declaration	;type_declarations ::= 		type_declaration	|	type_declarations type_declaration	;package_declaration ::= 		PACKAGE name SEMICOLON	;import_declaration ::= 		single_type_import_declaration	|	type_import_on_demand_declaration	;single_type_import_declaration ::= 		IMPORT name SEMICOLON	;type_import_on_demand_declaration ::=		IMPORT name DOT MULT SEMICOLON	;type_declaration ::=		class_declaration	|	interface_declaration	|	SEMICOLON	;// 19.7) Productions used only in the LALR(1) grammarmodifiers_opt::=	|	modifiers	;modifiers ::= 	modifier	|	modifiers modifier	;modifier ::=	PUBLIC | PROTECTED | PRIVATE	|	STATIC	|	ABSTRACT | FINAL | NATIVE | SYNCHRONIZED | TRANSIENT | VOLATILE	|	STRICTFP // note that semantic analysis must check that the	                 // context of the modifier allows strictfp.	;// 19.8) Classes// 19.8.1) Class Declaration:class_declaration ::= 	modifiers_opt CLASS IDENTIFIER super_opt interfaces_opt class_body	;super ::=	EXTENDS class_type	;super_opt ::=		|	super	;interfaces ::=	IMPLEMENTS interface_type_list	;interfaces_opt::=	|	interfaces 	;interface_type_list ::= 		interface_type	|	interface_type_list COMMA interface_type	;class_body ::=	LBRACE class_body_declarations_opt RBRACE 	;class_body_declarations_opt ::= 	|	class_body_declarations ;class_body_declarations ::= 		class_body_declaration	|	class_body_declarations class_body_declaration	;class_body_declaration ::=		class_member_declaration	|	static_initializer	|	constructor_declaration	|	block	;class_member_declaration ::=		field_declaration	|	method_declaration	/* repeat the prod for 'class_declaration' here: */	|	modifiers_opt CLASS IDENTIFIER super_opt interfaces_opt class_body	|	interface_declaration  | SEMICOLON	;// 19.8.2) Field Declarationsfield_declaration ::= 		modifiers_opt type variable_declarators SEMICOLON	;variable_declarators ::=		variable_declarator	|	variable_declarators COMMA variable_declarator	;variable_declarator ::=		variable_declarator_id	|	variable_declarator_id EQ variable_initializer	;variable_declarator_id ::=		IDENTIFIER	|	variable_declarator_id LBRACK RBRACK	;variable_initializer ::=		expression	|	array_initializer	;// 19.8.3) Method Declarationsmethod_declaration ::=		method_header method_body	;method_header ::=		modifiers_opt type method_declarator throws_opt	|	modifiers_opt VOID method_declarator throws_opt	;method_declarator ::=		IDENTIFIER LPAREN formal_parameter_list_opt RPAREN	|	method_declarator LBRACK RBRACK // deprecated	// be careful; the above production also allows 'void foo() []'	;formal_parameter_list_opt ::=	|	formal_parameter_list	;formal_parameter_list ::=		formal_parameter	|	formal_parameter_list COMMA formal_parameter	;formal_parameter ::=		type variable_declarator_id	|	FINAL type variable_declarator_id	;throws_opt ::=		|	throws	;throws ::=	THROWS class_type_list	;class_type_list ::=		class_type	|	class_type_list COMMA class_type	;method_body ::=	block	|	SEMICOLON	;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -