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

📄 cs-parser.jay

📁 C#编译器源代码。Micorsoft开放源代码
💻 JAY
📖 第 1 页 / 共 5 页
字号:
				if (RootContext.Documentation != null) {					Lexer.check_incorrect_doc_comment ();					Lexer.doc_state =						XmlCommentState.Allowed;				}			}		} else {			$$ = new Attributes (sect);		}				current_attr_target = null;	  }	| attribute_sections attribute_section	  {		Attributes attrs = $1 as Attributes;		ArrayList sect = (ArrayList) $2;		if (global_attrs_enabled) {			if (current_attr_target == "module") {				CodeGen.Module.AddAttributes (sect);				$$ = null;			} else if (current_attr_target == "assembly") {				CodeGen.Assembly.AddAttributes (sect);				$$ = null;			} else {				if (attrs == null)					attrs = new Attributes (sect);				else					attrs.AddAttributes (sect);						}		} else {			if (attrs == null)				attrs = new Attributes (sect);			else				attrs.AddAttributes (sect);		}				$$ = attrs;		current_attr_target = null;	  }	;attribute_section	: OPEN_BRACKET attribute_target_specifier attribute_list opt_comma CLOSE_BRACKET	  {		$$ = $3; 	  }        | OPEN_BRACKET attribute_list opt_comma CLOSE_BRACKET	  {		$$ = $2;	  }	; attribute_target_specifier	: attribute_target COLON	  {		current_attr_target = (string)$1;		$$ = $1;	  }	;attribute_target	: IDENTIFIER	  {		LocatedToken lt = (LocatedToken) $1;		CheckAttributeTarget (lt.Value, lt.Location);		$$ = lt.Value; // Location won't be required anymore.	  }        | EVENT  { $$ = "event"; }	          | RETURN { $$ = "return"; }	;attribute_list	: attribute	  {		ArrayList attrs = new ArrayList (4);		attrs.Add ($1);		$$ = attrs;	       	  }	| attribute_list COMMA attribute	  {		ArrayList attrs = (ArrayList) $1;		attrs.Add ($3);		$$ = attrs;	  }	;attribute	: attribute_name opt_attribute_arguments	  {		MemberName mname = (MemberName) $1;		ArrayList arguments = (ArrayList) $2;		MemberName left = mname.Left;		string identifier = mname.Name;		Expression left_expr = left == null ? null : left.GetTypeExpression ();		if (current_attr_target == "assembly" || current_attr_target == "module")			// FIXME: supply "nameEscaped" parameter here.			$$ = new GlobalAttribute (current_class, current_attr_target,						  left_expr, identifier, arguments, mname.Location, lexer.IsEscapedIdentifier (mname.Location));		else			$$ = new Attribute (current_attr_target, left_expr, identifier, arguments, mname.Location, lexer.IsEscapedIdentifier (mname.Location));	  }	;attribute_name	: namespace_or_type_name  { /* reserved attribute name or identifier: 17.4 */ }	;opt_attribute_arguments	: /* empty */   { $$ = null; }	| OPEN_PARENS attribute_arguments CLOSE_PARENS	  {		$$ = $2;	  }	;attribute_arguments	: opt_positional_argument_list	  {		if ($1 == null)			$$ = null;		else {			ArrayList args = new ArrayList (4);			args.Add ($1);					$$ = args;		}	  }        | positional_argument_list COMMA named_argument_list	  {		ArrayList args = new ArrayList (4);		args.Add ($1);		args.Add ($3);		$$ = args;	  }        | named_argument_list	  {		ArrayList args = new ArrayList (4);		args.Add (null);		args.Add ($1);				$$ = args;	  }        ;opt_positional_argument_list	: /* empty */ 		{ $$ = null; } 	| positional_argument_list	;positional_argument_list	: expression	  {		ArrayList args = new ArrayList (4);		args.Add (new Argument ((Expression) $1, Argument.AType.Expression));		$$ = args;	  }        | positional_argument_list COMMA expression	 {		ArrayList args = (ArrayList) $1;		args.Add (new Argument ((Expression) $3, Argument.AType.Expression));		$$ = args;	 }        ;named_argument_list	: named_argument	  {		ArrayList args = new ArrayList (4);		args.Add ($1);		$$ = args;	  }        | named_argument_list COMMA named_argument	  {	  		ArrayList args = (ArrayList) $1;		args.Add ($3);		$$ = args;	  }	  | named_argument_list COMMA expression	    {		  Report.Error (1016, ((Expression) $3).Location, "Named attribute argument expected");		  $$ = null;		}        ;named_argument	: IDENTIFIER ASSIGN expression	  {		// FIXME: keep location		$$ = new DictionaryEntry (			((LocatedToken) $1).Value, 			new Argument ((Expression) $3, Argument.AType.Expression));	  }	;		  class_body	:  OPEN_BRACE opt_class_member_declarations CLOSE_BRACE	;opt_class_member_declarations	: /* empty */	| class_member_declarations	;class_member_declarations	: class_member_declaration	| class_member_declarations 	  class_member_declaration	;class_member_declaration	: constant_declaration			// done	| field_declaration			// done	| method_declaration			// done	| property_declaration			// done	| event_declaration			// done	| indexer_declaration			// done	| operator_declaration			// done	| constructor_declaration		// done	| destructor_declaration		// done	| type_declaration	;struct_declaration	: opt_attributes	  opt_modifiers	  opt_partial	  STRUCT member_name	  { 		MemberName name = MakeName ((MemberName) $5);		if ($3 != null) {			ClassPart part = PartialContainer.CreatePart (				current_namespace, current_class, name, (int) $2,				(Attributes) $1, Kind.Struct, (Location) $3);			current_container = part.PartialContainer;			current_class = part;		} else {			current_class = new Struct (				current_namespace, current_class, name, (int) $2,				(Attributes) $1);			current_container.AddClassOrStruct (current_class);			current_container = current_class;			RootContext.Tree.RecordDecl (current_namespace.NS, name, current_class);		}	  }	  opt_class_base	  {		if ($7 != null)			current_class.Bases = (ArrayList) $7;		if (RootContext.Documentation != null)			current_class.DocComment = Lexer.consume_doc_comment ();	  }	  struct_body	  {		if (RootContext.Documentation != null)			Lexer.doc_state = XmlCommentState.Allowed;	  }	  opt_semicolon	  {		$$ = pop_current_class ();	  }	| opt_attributes opt_modifiers opt_partial STRUCT error {		CheckIdentifierToken (yyToken, GetLocation ($5));	  }	;struct_body	: OPEN_BRACE	  {		if (RootContext.Documentation != null)			Lexer.doc_state = XmlCommentState.Allowed;	  }	  opt_struct_member_declarations CLOSE_BRACE	;opt_struct_member_declarations	: /* empty */	| struct_member_declarations	;struct_member_declarations	: struct_member_declaration	| struct_member_declarations struct_member_declaration	;struct_member_declaration	: constant_declaration	| field_declaration	| method_declaration	| property_declaration	| event_declaration	| indexer_declaration	| operator_declaration	| constructor_declaration	| type_declaration	/*	 * This is only included so we can flag error 575: 	 * destructors only allowed on class types	 */	| destructor_declaration 	;constant_declaration	: opt_attributes 	  opt_modifiers	  CONST	  type	  constant_declarators	  SEMICOLON	  {		int modflags = (int) $2;		foreach (VariableDeclaration constant in (ArrayList) $5){			Location l = constant.Location;			if ((modflags & Modifiers.STATIC) != 0) {				Report.Error (504, l, "The constant `{0}' cannot be marked static", current_container.GetSignatureForError () + '.' + (string) constant.identifier);				continue;			}			Const c = new Const (				current_class, (Expression) $4, (string) constant.identifier, 				(Expression) constant.expression_or_array_initializer, modflags, 				(Attributes) $1, l);			if (RootContext.Documentation != null) {				c.DocComment = Lexer.consume_doc_comment ();				Lexer.doc_state = XmlCommentState.Allowed;			}			current_container.AddConstant (c);		}	  }	;constant_declarators	: constant_declarator 	  {		ArrayList constants = new ArrayList (4);		if ($1 != null)			constants.Add ($1);		$$ = constants;	  }	| constant_declarators COMMA constant_declarator	  {		if ($3 != null) {			ArrayList constants = (ArrayList) $1;			constants.Add ($3);		}	  }	;constant_declarator	: IDENTIFIER ASSIGN constant_expression	  {		$$ = new VariableDeclaration ((LocatedToken) $1, $3);	  }	| IDENTIFIER	  {		// A const field requires a value to be provided		Report.Error (145, ((LocatedToken) $1).Location, "A const field requires a value to be provided");		$$ = null;	  }	;field_declaration	: opt_attributes	  opt_modifiers	  type 	  variable_declarators	  SEMICOLON	  { 		Expression type = (Expression) $3;		int mod = (int) $2;		foreach (VariableDeclaration var in (ArrayList) $4){			Field field = new Field (current_class, type, mod, var.identifier, 						 var.expression_or_array_initializer, 						 (Attributes) $1, var.Location);			if (RootContext.Documentation != null) {				field.DocComment = Lexer.consume_doc_comment ();				Lexer.doc_state = XmlCommentState.Allowed;			}			current_container.AddField (field);			$$ = field; // FIXME: might be better if it points to the top item		}	  }	| opt_attributes	  opt_modifiers	  FIXED	  type 	  fixed_variable_declarators	  SEMICOLON	  { 			Expression type = (Expression) $4;			int mod = (int) $2;			foreach (VariableDeclaration var in (ArrayList) $5) {				FixedField field = new FixedField (current_class, type, mod, var.identifier,					(Expression)var.expression_or_array_initializer, (Attributes) $1, var.Location);				if (RootContext.Documentation != null) {					field.DocComment = Lexer.consume_doc_comment ();					Lexer.doc_state = XmlCommentState.Allowed;				}				current_container.AddField (field);				$$ = field; // FIXME: might be better if it points to the top item			}	  }	| opt_attributes	  opt_modifiers	  VOID  	  variable_declarators	  SEMICOLON {		Report.Error (670, (Location) $3, "Fields cannot have void type");	  }	;fixed_variable_declarators	: fixed_variable_declarator	  {		ArrayList decl = new ArrayList (2);		decl.Add ($1);		$$ = decl;  	  }	| fixed_variable_declarators COMMA fixed_variable_declarator	  {		ArrayList decls = (ArrayList) $1;		decls.Add ($3);		$$ = $1;	  }	;fixed_variable_declarator	: IDENTIFIER OPEN_BRACKET expression CLOSE_BRACKET	  {		$$ = new VariableDeclaration ((LocatedToken) $1, $3);	  }	| IDENTIFIER OPEN_BRACKET CLOSE_BRACKET	  {		Report.Error (443, lexer.Location, "Value or constant expected");		$$ = new VariableDeclaration ((LocatedToken) $1, null);	  }	;variable_declarators	: variable_declarator 	  {		ArrayList decl = new ArrayList (4);		if ($1 != null)			decl.Add ($1);		$$ = decl;	  }	| variable_declarators COMMA variable_declarator	  {		ArrayList decls = (ArrayList) $1;		decls.Add ($3);		$$ = $1;	  }	;variable_declarator	: IDENTIFIER ASSIGN variable_initializer	  {		$$ = new VariableDeclaration ((LocatedToken) $1, $3);	  }	| IDENTIFIER	  {		$$ = new VariableDeclaration ((LocatedToken) $1, null);	  }	| IDENTIFIER OPEN_BRACKET opt_expression CLOSE_BRACKET	  {		Report.Error (650, ((LocatedToken) $1).Location, "Syntax error, bad array declarator. To declare a managed array the rank specifier precedes the variable's identifier. " +			"To declare a fixed size buffer field, use the fixed keyword before the field type");		$$ = null;	  }	;variable_initializer	: expression	  {		$$ = $1;	  }	| array_initializer	  {		$$ = $1;	  }	| STACKALLOC type OPEN_BRACKET expression CLOSE_BRACKET	  {		$$ = new StackAlloc ((Expression) $2, (Expression) $4, (Location) $1);	  }	| STACKALLOC type	  {		Report.Error (1575, (Location) $1, "A stackalloc expression requires [] after type");                $$ = null;	  }	;method_declaration	: method_header {		iterator_container = (IIteratorContainer) $1;		if (RootContext.Documentation != null)			Lexer.doc_state = XmlCommentState.NotAllowed;	  }	  method_body	  {		Method method = (Method) $1;		method.Block = (ToplevelBlock) $3;		current_container.AddMethod (method);		current_local_parameters = null;		iterator_container = null;		if (RootContext.Documentation != null)

⌨️ 快捷键说明

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