📄 cs-parser.jay
字号:
{ if ($1 != null) { Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants", ((MemberCore)$1).GetSignatureForError ()); } } | class_declaration { if ($1 != null) { Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants", ((MemberCore)$1).GetSignatureForError ()); } } | struct_declaration { if ($1 != null) { Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants", ((MemberCore)$1).GetSignatureForError ()); } } | enum_declaration { if ($1 != null) { Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants", ((MemberCore)$1).GetSignatureForError ()); } } | interface_declaration { if ($1 != null) { Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants", ((MemberCore)$1).GetSignatureForError ()); } } | constant_declaration { Report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants"); } ;opt_new : opt_modifiers { int val = (int) $1; val = Modifiers.Check (Modifiers.NEW | Modifiers.UNSAFE, val, 0, GetLocation ($1)); $$ = val; } ;interface_method_declaration : opt_attributes opt_new type namespace_or_type_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS SEMICOLON { $$ = new Method (current_class, (Expression) $3, (int) $2, true, (MemberName) $4, (Parameters) $6, (Attributes) $1); if (RootContext.Documentation != null) ((Method) $$).DocComment = Lexer.consume_doc_comment (); } | opt_attributes opt_new type namespace_or_type_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS OPEN_BRACE opt_statement_list CLOSE_BRACE { $$ = new Method (current_class, (Expression) $3, (int) $2, true, (MemberName) $4, (Parameters) $6, (Attributes) $1); Report.Error (531, lexer.Location, "`{0}': interface members cannot have a definition", ((Method)$$).GetSignatureForError ()); } ;interface_property_declaration : opt_attributes opt_new type IDENTIFIER OPEN_BRACE { lexer.PropertyParsing = true; } accessor_declarations { has_get = has_set = false; lexer.PropertyParsing = false; } CLOSE_BRACE { LocatedToken lt = (LocatedToken) $4; MemberName name = new MemberName (lt.Value, lt.Location); if ($3 == TypeManager.system_void_expr) { Report.Error (547, lt.Location, "`{0}': property or indexer cannot have void type", lt.Value); break; } Property p = null; if ($7 == null) { p = new Property (current_class, (Expression) $3, (int) $2, true, name, (Attributes) $1, null, null); Report.Error (548, p.Location, "`{0}': property or indexer must have at least one accessor", p.GetSignatureForError ()); break; } Pair pair = (Pair) $7; p = new Property (current_class, (Expression) $3, (int) $2, true, name, (Attributes) $1, (Accessor)pair.First, (Accessor)pair.Second); if (pair.First != null && ((Accessor)(pair.First)).Block != null) { Report.Error (531, p.Location, "`{0}.get': interface members cannot have a definition", p.GetSignatureForError ()); $$ = null; break; } if (pair.Second != null && ((Accessor)(pair.Second)).Block != null) { Report.Error (531, p.Location, "`{0}.set': interface members cannot have a definition", p.GetSignatureForError ()); $$ = null; break; } if (RootContext.Documentation != null) p.DocComment = Lexer.consume_doc_comment (); $$ = p; } | opt_attributes opt_new type error { CheckIdentifierToken (yyToken, GetLocation ($4)); $$ = null; } ;interface_event_declaration : opt_attributes opt_new EVENT type IDENTIFIER SEMICOLON { LocatedToken lt = (LocatedToken) $5; $$ = new EventField (current_class, (Expression) $4, (int) $2, true, new MemberName (lt.Value, lt.Location), null, (Attributes) $1); if (RootContext.Documentation != null) ((EventField) $$).DocComment = Lexer.consume_doc_comment (); } | opt_attributes opt_new EVENT type error { CheckIdentifierToken (yyToken, GetLocation ($5)); $$ = null; } | opt_attributes opt_new EVENT type IDENTIFIER ASSIGN { LocatedToken lt = (LocatedToken) $5; Report.Error (68, lt.Location, "`{0}.{1}': event in interface cannot have initializer", current_container.Name, lt.Value); $$ = null; } | opt_attributes opt_new EVENT type IDENTIFIER OPEN_BRACE { lexer.EventParsing = true; } event_accessor_declarations { lexer.EventParsing = false; } CLOSE_BRACE { Report.Error (69, (Location) $3, "Event in interface cannot have add or remove accessors"); $$ = null; } ;interface_indexer_declaration : opt_attributes opt_new type THIS OPEN_BRACKET formal_parameter_list CLOSE_BRACKET OPEN_BRACE { lexer.PropertyParsing = true; } accessor_declarations { has_get = has_set = false; lexer.PropertyParsing = false; } CLOSE_BRACE { Indexer i = null; if ($10 == null) { i = new Indexer (current_class, (Expression) $3, new MemberName (TypeContainer.DefaultIndexerName, (Location) $4), (int) $2, true, (Parameters) $6, (Attributes) $1, null, null); Report.Error (548, i.Location, "`{0}': property or indexer must have at least one accessor", i.GetSignatureForError ()); break; } Pair pair = (Pair) $10; i = new Indexer (current_class, (Expression) $3, new MemberName (TypeContainer.DefaultIndexerName, (Location) $4), (int) $2, true, (Parameters) $6, (Attributes) $1, (Accessor)pair.First, (Accessor)pair.Second); if (pair.First != null && ((Accessor)(pair.First)).Block != null) { Report.Error (531, i.Location, "`{0}.get': interface members cannot have a definition", i.GetSignatureForError ()); $$ = null; break; } if (pair.Second != null && ((Accessor)(pair.Second)).Block != null) { Report.Error (531, i.Location, "`{0}.set': interface members cannot have a definition", i.GetSignatureForError ()); $$ = null; break; } if (RootContext.Documentation != null) i.DocComment = ConsumeStoredComment (); $$ = i; } ;operator_declaration : opt_attributes opt_modifiers operator_declarator { iterator_container = SimpleIteratorContainer.GetSimple (); } operator_body { if ($3 == null) break; OperatorDeclaration decl = (OperatorDeclaration) $3; Parameter [] param_list = new Parameter [decl.arg2type != null ? 2 : 1]; param_list[0] = new Parameter (decl.arg1type, decl.arg1name, Parameter.Modifier.NONE, null, decl.location); if (decl.arg2type != null) param_list[1] = new Parameter (decl.arg2type, decl.arg2name, Parameter.Modifier.NONE, null, decl.location); Operator op = new Operator ( current_class, decl.optype, decl.ret_type, (int) $2, new Parameters (param_list, null), (ToplevelBlock) $5, (Attributes) $1, decl.location); if (RootContext.Documentation != null) { op.DocComment = tmpComment; Lexer.doc_state = XmlCommentState.Allowed; } if (SimpleIteratorContainer.Simple.Yields) op.SetYields (); // Note again, checking is done in semantic analysis current_container.AddOperator (op); current_local_parameters = null; iterator_container = null; } ;operator_body : block | SEMICOLON { $$ = null; } ; operator_declarator : type OPERATOR overloadable_operator OPEN_PARENS type IDENTIFIER CLOSE_PARENS { LocatedToken lt = (LocatedToken) $6; Operator.OpType op = (Operator.OpType) $3; CheckUnaryOperator (op, lt.Location); if (op == Operator.OpType.Addition) op = Operator.OpType.UnaryPlus; if (op == Operator.OpType.Subtraction) op = Operator.OpType.UnaryNegation; Parameter [] pars = new Parameter [1]; Expression type = (Expression) $5; pars [0] = new Parameter (type, lt.Value, Parameter.Modifier.NONE, null, lt.Location); current_local_parameters = new Parameters (pars, null); if (RootContext.Documentation != null) { tmpComment = Lexer.consume_doc_comment (); Lexer.doc_state = XmlCommentState.NotAllowed; } $$ = new OperatorDeclaration (op, (Expression) $1, type, lt.Value, null, null, (Location) $2); } | type OPERATOR overloadable_operator OPEN_PARENS type IDENTIFIER COMMA type IDENTIFIER CLOSE_PARENS { LocatedToken ltParam1 = (LocatedToken) $6; LocatedToken ltParam2 = (LocatedToken) $9; CheckBinaryOperator ((Operator.OpType) $3, (Location) $2); Parameter [] pars = new Parameter [2]; Expression typeL = (Expression) $5; Expression typeR = (Expression) $8; pars [0] = new Parameter (typeL, ltParam1.Value, Parameter.Modifier.NONE, null, ltParam1.Location); pars [1] = new Parameter (typeR, ltParam2.Value, Parameter.Modifier.NONE, null, ltParam2.Location); current_local_parameters = new Parameters (pars, null); if (RootContext.Documentation != null) { tmpComment = Lexer.consume_doc_comment (); Lexer.doc_state = XmlCommentState.NotAllowed; } $$ = new OperatorDeclaration ((Operator.OpType) $3, (Expression) $1, typeL, ltParam1.Value, typeR, ltParam2.Value, (Location) $2); } | conversion_operator_declarator | type OPERATOR overloadable_operator OPEN_PARENS type IDENTIFIER COMMA type IDENTIFIER COMMA type IDENTIFIER CLOSE_PARENS { Report.Error (1534, (Location) $2, "Overloaded binary operator `{0}' takes two parameters", Operator.GetName ((Operator.OpType) $3)); $$ = null; } | type OPERATOR overloadable_operator OPEN_PARENS CLOSE_PARENS { Report.Error (1535, (Location) $2, "Overloaded unary operator `{0}' takes one parameter", Operator.GetName ((Operator.OpType) $3)); $$ = null; } ;overloadable_operator// Unary operators: : BANG { $$ = Operator.OpType.LogicalNot; } | TILDE { $$ = Operator.OpType.OnesComplement; } | OP_INC { $$ = Operator.OpType.Increment; } | OP_DEC { $$ = Operator.OpType.Decrement; } | TRUE { $$ = Operator.OpType.True; } | FALSE { $$ = Operator.OpType.False; }// Unary and binary: | PLUS { $$ = Operator.OpType.Addition; } | MINUS { $$ = Operator.OpType.Subtraction; }// Binary: | STAR { $$ = Operator.OpType.Multiply; } | DIV { $$ = Operator.OpType.Division; } | PERCENT { $$ = Operator.OpType.Modulus; } | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; } | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; } | CARRET { $$ = Operator.OpType.ExclusiveOr; } | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; } | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; } | OP_EQ { $$ = Operator.OpType.Equality; } | OP_NE { $$ = Operator.OpType.Inequality; } | OP_GT { $$ = Operator.OpType.GreaterThan; } | OP_LT { $$ = Operator.OpType.LessThan; } | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; } | OP_LE { $$ = Operator.OpType.LessThanOrEqual; } ;conversion_operator_declarator : IMPLICIT OPERATOR type OPEN_PARENS type IDENTIFIER CLOSE_PARENS { LocatedToken lt = (LocatedToken) $6; Parameter [] pars = new Parameter [1]; pars [0] = new Parameter ((Expression) $5, lt.Value, Parameter.Modifier.NONE, null, lt.Location); current_local_parameters = new Parameters (pars, null); if (RootContext.Documentation != null) { tmpComment = Lexer.consume_doc_comment (); Lexer.doc_state = XmlCommentState.NotAllowed; } $$ = new OperatorDeclaration (Operator.OpType.Implicit, (Expression) $3, (Expression) $5, lt.Value, null, null, (Location) $2); } | EXPLICIT OPERATOR type OPEN_PARENS type IDENTIFIER CLOSE_PARENS { LocatedToken lt = (LocatedToken) $6; Parameter [] pars = new Parameter [1]; pars [0] = new Parameter ((Expression) $5, lt.Value, Parameter.Modifier.NONE, null, lt.Location); current_local_parameters = new Parameters (pars, null); if (RootContext.Documentation != null) { tmpComment = Lexer.consume_doc_comment (); Lexer.doc_state = XmlCommentState.NotAllowed; } $$ = new OperatorDeclaration (Operator.OpType.Explicit, (Expression) $3, (Expression) $5, lt.Value, null, null, (Location) $2); } | IMPLICIT error { syntax_error ((Location) $1, "'operator' expected"); } | EXPLICIT error { syntax_error ((Location) $1, "'operator' expected"); } ;constructor_declaration : opt_attributes opt_modifiers constructor_declarator constructor_body { Constructor c = (Constructor) $3; c.Block = (ToplevelBlock) $4; c.OptAttributes = (Attributes) $1; c.ModFlags = (int) $2; if (RootContext.Documentation != null) c.DocComment = ConsumeStoredComment (); if (c.Name == current_container.Basename){ if ((c.ModFlags & Modifiers.STATIC) != 0){ if ((c.ModFlags & Modifiers.Accessibility) != 0){ Report.Error (515, c.Location, "`{0}': access modifiers are not allowed on static constructors", c.GetSignatureForError ()); } c.ModFlags = Modifiers.Check (Constructor.AllowedModifiers, (int) $2, Modifiers.PRIVATE, c.Location); if (c.Initializer != null){ Report.Error (514, c.Location, "`{0}': static constructor cannot have an explicit `this' or `base' constructor call", c.GetSignatureForError ()); } if (!c.Parameters.Empty){ Report.Error (132, c.Location, "`{0}': The static constructor must be parameterless", c.GetSignatureForError ()); } } else { c.ModFlags = Modifiers.Check (Constructor.AllowedModifiers, (int) $2, Modifiers.PRIVATE, c.Location); } } else { // We let another layer check the validity of the constructor. //Console.WriteLine ("{0} and {1}", c.Name, current_container.Basename); } current_container.AddConstructor (c); current_local_parameters = null; if (RootContext.Documentation != null) Lexer.doc_state = XmlCommentState.Allowed; } ;constructor_declarator : IDENTIFIER { if (RootContext.Documentation != null) { tmpComment = Lexer.consume_doc_comment (); Lexer.doc_state = XmlCommentState.Allowed; } } OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS { current_local_parameters = (Parameters) $4; } opt_constructor_initializer { LocatedToken lt = (LocatedToken) $1; $$ = new Constructor (current_class, lt.Value, 0, (Parameters) $4, (ConstructorInitializer) $7, lt.Location); } ;constructor_body : block | SEMICOLON { $$ = null; } ;opt_constructor_initializer : /* empty */ { $$ = null; } | constructor_initializer ;constructor_initializer : COLON BASE OPEN_PARENS opt_argument_list CLOSE_PARENS { $$ = new ConstructorBaseInitializer ((ArrayList) $4, (Location) $2); } | COLON THIS OPEN_PARENS opt_argument_list CLOSE_PARENS { $$ = new ConstructorThisInitializer ((ArrayList) $4, (Location) $2); } | COLON error { Report.Error (1018, (Location) $1, "Keyword this or base expected"); $$ = null; } ;opt_finalizer : /* EMPTY */ { $$ = 0; } | UNSAFE { $$ = Modifiers.UNSAFE; } | EXTERN { $$ = Modifiers.EXTERN; } ; destructor_declaration : opt_attributes opt_finalizer TILDE { if (RootContext.Documentation != null) { tmpComment = Lexer.consume_doc_comment (); Lexer.doc_state = XmlCommentState.NotAllowed; } } IDENTIFIER OPEN_PARENS CLOSE_PARENS block { LocatedToken lt = (LocatedToken) $5; if (lt.Value != current_container.Basename){ Report.Error (574, lt.Location, "Name of destructor must match name of class"); } else if (current_container.Kind != Kind.Class){ Report.Error (575, lt.Location, "Only class types can contain destructor"); } else { Location l = lt.Location;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -