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

📄 cs-parser.jay

📁 C#编译器源代码。Micorsoft开放源代码
💻 JAY
📖 第 1 页 / 共 5 页
字号:
%{//// cs-parser.jay: The Parser for the C# compiler//// Authors: Miguel de Icaza (miguel@gnu.org)//          Ravi Pratap     (ravi@ximian.com)//// Licensed under the terms of the GNU GPL//// (C) 2001 Ximian, Inc (http://www.ximian.com)// (C) 2004 Novell, Inc//// TODO://   (1) Figure out why error productions dont work.  `type-declaration' is a//       great spot to put an `error' because you can reproduce it with this input://	 "public X { }"//// Possible optimization://   Run memory profiler with parsing only, and consider dropping //   arraylists where not needed.   Some pieces can use linked lists.//using System.Text;using System.IO;using System;namespace Mono.CSharp{	using System.Collections;	/// <summary>	///    The C# Parser	/// </summary>	public class CSharpParser {		NamespaceEntry  current_namespace;		TypeContainer   current_container;		TypeContainer	current_class;			IIteratorContainer iterator_container;		/// <summary>		///   Current block is used to add statements as we find		///   them.  		/// </summary>		Block      current_block, top_current_block;		/// <summary>		///   This is used by the unary_expression code to resolve		///   a name against a parameter.  		/// </summary>		Parameters current_local_parameters;		/// <summary>		///   Using during property parsing to describe the implicit		///   value parameter that is passed to the "set" and "get"accesor		///   methods (properties and indexers).		/// </summary>		Expression implicit_value_parameter_type;		Parameters indexer_parameters;		/// <summary>		///   Used to determine if we are parsing the get/set pair		///   of an indexer or a property		/// </summmary>		bool  parsing_indexer;		///		/// An out-of-band stack.		///		Stack oob_stack;		///		/// Switch stack.		///		Stack switch_stack;		static public int yacc_verbose_flag;		// Name of the file we are parsing		public string name;		///		/// The current file.		///		SourceFile file;		///		/// Temporary Xml documentation cache.		/// For enum types, we need one more temporary store.		///		string tmpComment;		string enumTypeComment;	       				/// Current attribute target		string current_attr_target;				/// assembly and module attribute definitions are enabled		bool global_attrs_enabled = true;		bool has_get, has_set;%}%token EOF%token NONE   /* This token is never returned by our lexer */%token ERROR		// This is used not by the parser, but by the tokenizer.			// do not remove./* *These are the C# keywords */%token FIRST_KEYWORD%token ABSTRACT	%token AS%token ADD%token ASSEMBLY%token BASE	%token BOOL	%token BREAK	%token BYTE	%token CASE	%token CATCH	%token CHAR	%token CHECKED	%token CLASS	%token CONST	%token CONTINUE	%token DECIMAL	%token DEFAULT	%token DELEGATE	%token DO	%token DOUBLE	%token ELSE	%token ENUM	%token EVENT	%token EXPLICIT	%token EXTERN	%token FALSE	%token FINALLY	%token FIXED	%token FLOAT	%token FOR	%token FOREACH	%token GOTO	%token IF	%token IMPLICIT	%token IN	%token INT	%token INTERFACE%token INTERNAL	%token IS	%token LOCK	%token LONG	%token NAMESPACE%token NEW	%token NULL	%token OBJECT	%token OPERATOR	%token OUT	%token OVERRIDE	%token PARAMS	%token PRIVATE	%token PROTECTED%token PUBLIC	%token READONLY	%token REF	%token RETURN	%token REMOVE%token SBYTE	%token SEALED	%token SHORT	%token SIZEOF	%token STACKALLOC%token STATIC	%token STRING	%token STRUCT	%token SWITCH	%token THIS	%token THROW	%token TRUE	%token TRY	%token TYPEOF	%token UINT	%token ULONG	%token UNCHECKED%token UNSAFE	%token USHORT	%token USING	%token VIRTUAL	%token VOID	%token VOLATILE%token WHILE	%token ARGLIST%token PARTIAL/* C# keywords which are not really keywords */%token GET           "get"%token SET           "set"%left LAST_KEYWORD/* C# single character operators/punctuation. */%token OPEN_BRACE    "{"%token CLOSE_BRACE   "}"%token OPEN_BRACKET  "["%token CLOSE_BRACKET "]"%token OPEN_PARENS   "("%token CLOSE_PARENS  ")"%token DOT           "."%token COMMA         ","%token COLON         ":"%token SEMICOLON     ";"%token TILDE         "~"%token PLUS           "+"%token MINUS          "-"%token BANG           "!"%token ASSIGN         "="%token OP_LT          "<"%token OP_GT          ">"%token BITWISE_AND    "&"%token BITWISE_OR     "|"%token STAR           "*"%token PERCENT        "%"%token DIV            "/"%token CARRET         "^"%token INTERR         "?"/* C# multi-character operators. */%token DOUBLE_COLON	      "::"%token OP_INC                 "++"%token OP_DEC                 "--"%token OP_SHIFT_LEFT          "<<"%token OP_SHIFT_RIGHT         ">>"%token OP_LE                  "<="%token OP_GE                  ">="%token OP_EQ                  "=="%token OP_NE                  "!="%token OP_AND                 "&&"%token OP_OR                  "||"%token OP_MULT_ASSIGN         "*="%token OP_DIV_ASSIGN          "/="%token OP_MOD_ASSIGN          "%="%token OP_ADD_ASSIGN          "+="%token OP_SUB_ASSIGN          "-="%token OP_SHIFT_LEFT_ASSIGN   "<<="%token OP_SHIFT_RIGHT_ASSIGN  ">>="%token OP_AND_ASSIGN          "&="%token OP_XOR_ASSIGN          "^="%token OP_OR_ASSIGN           "|="%token OP_PTR                 "->"/* Numbers */%token LITERAL_INTEGER           "int literal"%token LITERAL_FLOAT             "float literal"%token LITERAL_DOUBLE            "double literal"%token LITERAL_DECIMAL           "decimal literal"%token LITERAL_CHARACTER         "character literal"%token LITERAL_STRING            "string literal"%token IDENTIFIER%token CLOSE_PARENS_CAST%token CLOSE_PARENS_NO_CAST%token CLOSE_PARENS_OPEN_PARENS%token CLOSE_PARENS_MINUS/* Add precedence rules to solve dangling else s/r conflict */%nonassoc LOWPREC%nonassoc IF%nonassoc ELSE%right ASSIGN%left OP_OR%left OP_AND%left BITWISE_OR%left BITWISE_AND%left OP_SHIFT_LEFT OP_SHIFT_RIGHT%left PLUS MINUS%left STAR DIV PERCENT%right BANG CARRET UMINUS%nonassoc OP_INC OP_DEC%left OPEN_PARENS%left OPEN_BRACKET OPEN_BRACE%left DOT%nonassoc HIGHPREC%start compilation_unit%%compilation_unit        : outer_declarations opt_EOF        | outer_declarations global_attributes opt_EOF        | global_attributes opt_EOF	| opt_EOF /* allow empty files */        ;	opt_EOF	: /* empty */	  {		Lexer.check_incorrect_doc_comment ();	  }	| EOF	  {		Lexer.check_incorrect_doc_comment ();	  }	;outer_declarations        : outer_declaration        | outer_declarations outer_declaration        ; outer_declaration	: extern_alias_directive        | using_directive         | namespace_member_declaration        ;extern_alias_directives	: extern_alias_directive	| extern_alias_directives extern_alias_directive;extern_alias_directive	: EXTERN IDENTIFIER IDENTIFIER SEMICOLON	  {		LocatedToken lt = (LocatedToken) $2;		string s = lt.Value;		if (s != "alias"){			Report.Error (1003, lt.Location, "'alias' expected");		} else if (RootContext.Version == LanguageVersion.ISO_1) {			Report.FeatureIsNotStandardized (lt.Location, "external alias");		} else {			lt = (LocatedToken) $3; 			current_namespace.UsingExternalAlias (lt.Value, lt.Location);		}	  }	; using_directives	: using_directive 	| using_directives using_directive	;using_directive	: using_alias_directive	  {		if (RootContext.Documentation != null)			Lexer.doc_state = XmlCommentState.Allowed;	  }	| using_namespace_directive	  {		if (RootContext.Documentation != null)			Lexer.doc_state = XmlCommentState.Allowed;	  }	;using_alias_directive	: USING IDENTIFIER ASSIGN 	  namespace_or_type_name SEMICOLON	  {		LocatedToken lt = (LocatedToken) $2;		current_namespace.UsingAlias (lt.Value, (MemberName) $4, (Location) $1);		current_namespace.UsingFound = true;	  }	| USING error {		CheckIdentifierToken (yyToken, GetLocation ($2));	  }	;using_namespace_directive	: USING namespace_name SEMICOLON 	  {		current_namespace.Using ((MemberName) $2, (Location) $1);		current_namespace.UsingFound = true;          }	;//// Strictly speaking, namespaces don't have attributes but// we parse global attributes along with namespace declarations and then// detach them// namespace_declaration	: opt_attributes NAMESPACE namespace_or_type_name	  {		MemberName name = (MemberName) $3;		if ($1 != null) {			Report.Error(1671, name.Location, "A namespace declaration cannot have modifiers or attributes");		}		current_namespace = new NamespaceEntry (			current_namespace, file, name.GetName (), name.Location);	  } 	  namespace_body opt_semicolon	  { 		current_namespace = current_namespace.Parent;	  }	;opt_semicolon	: /* empty */	| SEMICOLON	;opt_comma	: /* empty */	| COMMA	;namespace_name	: namespace_or_type_name	;namespace_body	: OPEN_BRACE	  {		if (RootContext.Documentation != null)			Lexer.doc_state = XmlCommentState.Allowed;	  }	  opt_extern_alias_directives	  opt_using_directives	  opt_namespace_member_declarations	  CLOSE_BRACE	;opt_using_directives	: /* empty */	| using_directives	;opt_extern_alias_directives	: /* empty */	| extern_alias_directives	;opt_namespace_member_declarations	: /* empty */	| namespace_member_declarations	;namespace_member_declarations	: namespace_member_declaration	| namespace_member_declarations namespace_member_declaration	;namespace_member_declaration	: type_declaration	  {		if ($1 != null) {			DeclSpace ds = (DeclSpace)$1;			if ((ds.ModFlags & (Modifiers.PRIVATE|Modifiers.PROTECTED)) != 0){				Report.Error (1527, ds.Location, 				"Namespace elements cannot be explicitly declared as private, protected or protected internal");			}		}		current_namespace.DeclarationFound = true;	  }	| namespace_declaration {		current_namespace.DeclarationFound = true;	  }	| field_declaration {		Report.Error (116, ((MemberCore) $1).Location, "A namespace can only contain types and namespace declarations");	  }	| method_declaration {		Report.Error (116, ((MemberCore) $1).Location, "A namespace can only contain types and namespace declarations");	  }	;type_declaration	: class_declaration			| struct_declaration			| interface_declaration			| enum_declaration			| delegate_declaration//// Enable this when we have handled all errors, because this acts as a generic fallback////	| error {//		Console.WriteLine ("Token=" + yyToken);//		Report.Error (1518, GetLocation ($1), "Expected class, struct, interface, enum or delegate");//	  }	;//// Attributes 17.2//global_attributes	: attribute_sections{	if ($1 != null)		CodeGen.Assembly.AddAttributes (((Attributes)$1).Attrs);	$$ = $1;}opt_attributes	: /* empty */ 	  {		global_attrs_enabled = false;		$$ = null;      }	| attribute_sections	  { 		global_attrs_enabled = false;		$$ = $1;	  }    ; attribute_sections	: attribute_section	  {		ArrayList sect = (ArrayList) $1;		if (global_attrs_enabled) {			if (current_attr_target == "module") {				CodeGen.Module.AddAttributes (sect);				$$ = null;			} else if (current_attr_target != null && current_attr_target.Length > 0) {				CodeGen.Assembly.AddAttributes (sect);				$$ = null;			} else {				$$ = new Attributes (sect);			}			if ($$ == null) {

⌨️ 快捷键说明

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