%token ABSTRACT
%token AS
%token ADD
-%token ASSEMBLY
%token BASE
%token BOOL
%token BREAK
%token ARGLIST
%token PARTIAL
%token ARROW
-%token QUERY_FIRST_TOKEN
%token FROM
%token JOIN
%token ON
%token ASCENDING
%token DESCENDING
%token INTO
-%token QUERY_LAST_TOKEN
%token INTERR_NULLABLE
+%token EXTERN_ALIAS
+
+/* Generics <,> tokens */
+%token OP_GENERICS_LT
+%token OP_GENERICS_LT_DECL
+%token OP_GENERICS_GT
/* C# keywords which are not really keywords */
%token GET
%token CLOSE_BRACKET
%token OPEN_PARENS
%token CLOSE_PARENS
+
%token DOT
%token COMMA
%token COLON
%token BANG
%token ASSIGN
%token OP_LT
-%token OP_GENERICS_LT
%token OP_GT
-%token OP_GENERICS_GT
%token BITWISE_AND
%token BITWISE_OR
%token STAR
%token IDENTIFIER
%token OPEN_PARENS_LAMBDA
-%token CLOSE_PARENS_CAST
-%token CLOSE_PARENS_NO_CAST
-%token CLOSE_PARENS_OPEN_PARENS
-%token CLOSE_PARENS_MINUS
-%token DEFAULT_OPEN_PARENS
+%token OPEN_PARENS_CAST
%token GENERIC_DIMENSION
%token DEFAULT_COLON
;
extern_alias_directive
- : EXTERN IDENTIFIER IDENTIFIER SEMICOLON
+ : EXTERN_ALIAS IDENTIFIER IDENTIFIER SEMICOLON
{
LocatedToken lt = (LocatedToken) $2;
string s = lt.Value;
if (s != "alias"){
- Report.Error (1003, lt.Location, "'alias' expected");
+ syntax_error (lt.Location, "`alias' expected");
} else if (RootContext.Version == LanguageVersion.ISO_1) {
Report.FeatureIsNotAvailable (lt.Location, "external alias");
} else {
current_namespace.AddUsingExternalAlias (lt.Value, lt.Location);
}
}
+ | EXTERN_ALIAS error
+ {
+ syntax_error (GetLocation ($1), "`alias' expected"); // TODO: better
+ }
;
using_directives
;
using_alias_directive
- : USING IDENTIFIER ASSIGN
- namespace_or_type_name SEMICOLON
+ : USING IDENTIFIER ASSIGN namespace_or_type_name SEMICOLON
{
LocatedToken lt = (LocatedToken) $2;
current_namespace.AddUsingAlias (lt.Value, (MemberName) $4, (Location) $1);
;
namespace_name
- : namespace_or_type_name {
+ : namespace_or_type_name
+ {
MemberName name = (MemberName) $1;
if (name.TypeArguments != null)
opt_namespace_member_declarations
EOF
{
- Report.Error (1513, lexer.Location, "} expected");
+ Report.Error (1513, lexer.Location, "Expected `}'");
}
;
type_declaration
: class_declaration
- | struct_declaration
- | interface_declaration
+ | struct_declaration
+ | interface_declaration
| enum_declaration
| delegate_declaration
//
{
$$ = $3;
}
- | OPEN_BRACKET attribute_list opt_comma CLOSE_BRACKET
+ | OPEN_BRACKET attribute_list opt_comma CLOSE_BRACKET
{
$$ = $2;
}
$$ = args;
}
- | named_argument_list COMMA expression
- {
- Report.Error (1016, ((Expression) $3).Location, "Named attribute argument expected");
- $$ = null;
- }
- ;
+ | named_argument_list COMMA expression
+ {
+ Report.Error (1016, ((Expression) $3).Location, "Named attribute argument expected");
+ $$ = null;
+ }
+ ;
named_argument
: IDENTIFIER ASSIGN expression
| constructor_declaration // done
| destructor_declaration // done
| type_declaration
+ | error
+ {
+ Report.Error (1519, lexer.Location, "Unexpected symbol `{0}' in class, struct, or interface member declaration",
+ GetSymbolName (yyToken));
+ $$ = null;
+ }
;
struct_declaration
{
lexer.ConstraintsParsing = true;
}
- type_name
+ type_declaration_name
{
MemberName name = MakeName ((MemberName) $6);
push_current_class (new Struct (current_namespace, current_class, name, (int) $2, (Attributes) $1), $3);
}
struct_body
{
+ --lexer.parsing_declaration;
if (RootContext.Documentation != null)
Lexer.doc_state = XmlCommentState.Allowed;
}
field_declaration
: opt_attributes
opt_modifiers
- type_and_void
+ member_type
variable_declarators
SEMICOLON
{
current_array_type = null;
- foreach (VariableDeclaration var in (ArrayList) $4){
- Field field = new Field (current_class, type, mod, var.identifier,
- (Attributes) $1, var.Location);
+ foreach (VariableMemberDeclaration var in (ArrayList) $4){
+ Field field = new Field (current_class, type, mod, var.MemberName, (Attributes) $1);
field.Initializer = var.expression_or_array_initializer;
| opt_attributes
opt_modifiers
FIXED
- type_and_void
+ member_type
fixed_variable_declarators
SEMICOLON
{
| opt_attributes
opt_modifiers
FIXED
- type_and_void
+ member_type
error
{
Report.Error (1641, GetLocation ($4), "A fixed size buffer field must have the array size specifier after the field name");
$$ = new VariableDeclaration ((LocatedToken) $1, null);
}
;
-
-variable_declarators
- : variable_declarator
+
+
+local_variable_declarators
+ : local_variable_declarator
{
ArrayList decl = new ArrayList (4);
if ($1 != null)
decl.Add ($1);
$$ = decl;
}
- | variable_declarators COMMA variable_declarator
+ | local_variable_declarators COMMA local_variable_declarator
{
ArrayList decls = (ArrayList) $1;
decls.Add ($3);
$$ = $1;
}
;
-
-variable_declarator
- : IDENTIFIER ASSIGN
- {
- ++lexer.parsing_block;
- }
- variable_initializer
+
+local_variable_declarator
+ : IDENTIFIER ASSIGN local_variable_initializer
{
- --lexer.parsing_block;
- $$ = new VariableDeclaration ((LocatedToken) $1, $4);
+ $$ = new VariableDeclaration ((LocatedToken) $1, $3);
}
| IDENTIFIER
{
$$ = new VariableDeclaration ((LocatedToken) $1, null);
}
- | IDENTIFIER OPEN_BRACKET opt_expression CLOSE_BRACKET
+ | IDENTIFIER variable_bad_array
{
- 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
+local_variable_initializer
: expression
- {
- $$ = $1;
- }
| array_initializer
- {
- $$ = $1;
- }
- | STACKALLOC type_expression OPEN_BRACKET expression CLOSE_BRACKET
+ | STACKALLOC simple_type OPEN_BRACKET expression CLOSE_BRACKET
{
$$ = new StackAlloc ((Expression) $2, (Expression) $4, (Location) $1);
}
{
$$ = new ArglistAccess ((Location) $1);
}
- | STACKALLOC type
+ | STACKALLOC simple_type
{
Report.Error (1575, (Location) $1, "A stackalloc expression requires [] after type");
- $$ = null;
+ $$ = new StackAlloc ((Expression) $2, null, (Location) $1);
}
;
+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
+ : member_declaration_name ASSIGN
+ {
+ ++lexer.parsing_block;
+ lexer.parsing_generic_declaration = false;
+ }
+ variable_initializer
+ {
+ --lexer.parsing_block;
+ $$ = new VariableMemberDeclaration ((MemberName) $1, $4);
+ }
+ | member_declaration_name
+ {
+ lexer.parsing_generic_declaration = false;
+ $$ = new VariableMemberDeclaration ((MemberName) $1, null);
+ }
+ | member_declaration_name variable_bad_array
+ {
+ lexer.parsing_generic_declaration = false;
+ $$ = null;
+ }
+ ;
+
+variable_bad_array
+ : OPEN_BRACKET opt_expression CLOSE_BRACKET
+ {
+ Report.Error (650, GetLocation ($1), "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");
+ }
+ ;
+
+variable_initializer
+ : expression
+ | array_initializer
+ ;
+
method_declaration
: method_header {
if (RootContext.Documentation != null)
method_header
: opt_attributes
opt_modifiers
- type_and_void member_name
- OPEN_PARENS
+ member_type
+ method_declaration_name OPEN_PARENS
{
arglist_allowed = true;
}
| opt_attributes
opt_modifiers
PARTIAL
- VOID member_name
+ VOID method_declaration_name
OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
{
lexer.ConstraintsParsing = true;
}
| opt_attributes
opt_modifiers
- type_and_void
- modifiers member_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
+ member_type
+ modifiers method_declaration_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
{
MemberName name = (MemberName) $5;
Report.Error (1585, name.Location,
type
{
Report.Error (1001, GetLocation ($3), "Identifier expected");
- $$ = null;
+ $$ = new Parameter ((FullNamedExpression) $3, "NeedSomeGeneratorHere", (Parameter.Modifier) $2, (Attributes) $1, lexer.Location);
}
| opt_attributes
opt_parameter_modifier
property_declaration
: opt_attributes
opt_modifiers
- type_and_void
- namespace_or_type_name
+ member_type
+ member_declaration_name
{
if (RootContext.Documentation != null)
tmpComment = Lexer.consume_doc_comment ();
MemberName name = (MemberName) $4;
FullNamedExpression ptype = (FullNamedExpression) $3;
- if (name.TypeArguments != null)
- syntax_error (lexer.Location, "a property can't have type arguments");
-
prop = new Property (current_class, ptype, (int) $2,
name, (Attributes) $1, get_block, set_block, order, current_block);
}
| error
{
- Report.Error (1014, GetLocation ($1), "A get or set accessor expected");
- $$ = null;
+ if (yyToken == Token.CLOSE_BRACE) {
+ $$ = null;
+ } else {
+ if (yyToken == Token.SEMICOLON)
+ Report.Error (1597, lexer.Location, "Semicolon after method or accessor block is not valid");
+ else
+ Report.Error (1014, GetLocation ($1), "A get or set accessor expected");
+
+ $$ = new Accessors (null, null);
+ }
}
;
accessor_body
{
if (has_get) {
- Report.Error (1007, (Location) $3, "Property accessor already defined");
+ Report.Error (1007, GetLocation ($3), "Property accessor already defined");
break;
}
Accessor accessor = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, current_local_parameters, (Location) $3);
accessor_body
{
if (has_set) {
- Report.Error (1007, ((LocatedToken) $3).Location, "Property accessor already defined");
+ Report.Error (1007, GetLocation ($3), "Property accessor already defined");
break;
}
Accessor accessor = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, current_local_parameters, (Location) $3);
accessor_body
: block
- | SEMICOLON { $$ = null; }
+ | SEMICOLON
+ {
+ $$ = null;
+ }
+ | error
+ {
+ Error_SyntaxError (1043, yyToken);
+ $$ = null;
+ }
;
interface_declaration
{
lexer.ConstraintsParsing = true;
}
- type_name
+ type_declaration_name
{
MemberName name = MakeName ((MemberName) $6);
push_current_class (new Interface (current_namespace, current_class, name, (int) $2, (Attributes) $1), $3);
}
interface_body
{
+ --lexer.parsing_declaration;
if (RootContext.Documentation != null)
Lexer.doc_state = XmlCommentState.Allowed;
}
}
| IMPLICIT error
{
- syntax_error ((Location) $1, "'operator' expected");
+ Error_SyntaxError (yyToken);
+ $$ = new OperatorDeclaration (Operator.OpType.Implicit, null, GetLocation ($1));
}
| EXPLICIT error
{
- syntax_error ((Location) $1, "'operator' expected");
+ Error_SyntaxError (yyToken);
+ $$ = new OperatorDeclaration (Operator.OpType.Explicit, null, GetLocation ($1));
}
;
EVENT type variable_declarators SEMICOLON
{
current_array_type = null;
- foreach (VariableDeclaration var in (ArrayList) $5) {
-
- MemberName name = new MemberName (var.identifier,
- var.Location);
+ foreach (VariableMemberDeclaration var in (ArrayList) $5) {
EventField e = new EventField (
- current_class, (FullNamedExpression) $4, (int) $2, name,
- (Attributes) $1);
+ current_class, (FullNamedExpression) $4, (int) $2, var.MemberName, (Attributes) $1);
if (var.expression_or_array_initializer != null) {
if (current_container.Kind == Kind.Interface) {
e.Initializer = var.expression_or_array_initializer;
}
+
+ if (var.MemberName.Left != null) {
+ Report.Error (71, e.Location,
+ "`{0}': An explicit interface implementation of an event must use property syntax",
+ e.GetSignatureForError ());
+ }
current_container.AddEvent (e);
}
| opt_attributes
opt_modifiers
- EVENT type namespace_or_type_name
+ EVENT type member_declaration_name
OPEN_BRACE
{
implicit_value_parameter_type = (FullNamedExpression) $4;
} else {
Accessors accessors = (Accessors) $8;
- if (name.TypeArguments != null)
- syntax_error (lexer.Location, "an event can't have type arguments");
-
if (accessors.get_or_add == null || accessors.set_or_remove == null)
// CS0073 is already reported, so no CS0065 here.
$$ = null;
}
current_local_parameters = null;
}
- | opt_attributes opt_modifiers EVENT type namespace_or_type_name error {
+ | opt_attributes opt_modifiers EVENT type member_declaration_name error
+ {
MemberName mn = (MemberName) $5;
-
if (mn.Left != null)
Report.Error (71, mn.Location, "An explicit interface implementation of an event must use property syntax");
- else
- Report.Error (71, mn.Location, "Event declaration should use property syntax");
if (RootContext.Documentation != null)
Lexer.doc_state = XmlCommentState.Allowed;
+
+ Error_SyntaxError (yyToken);
+ $$ = null;
}
;
;
indexer_declaration
- : opt_attributes opt_modifiers indexer_declarator
+ : opt_attributes opt_modifiers
+ member_type indexer_declaration_name OPEN_BRACKET opt_parameter_list_no_mod CLOSE_BRACKET
OPEN_BRACE
{
- IndexerDeclaration decl = (IndexerDeclaration) $3;
-
- implicit_value_parameter_type = decl.type;
+ implicit_value_parameter_type = (FullNamedExpression) $3;
+ indexer_parameters = (Parameters) $6;
+ if (indexer_parameters.IsEmpty)
+ Report.Error (1551, GetLocation ($5), "Indexers must have at least one parameter");
+
+ if (RootContext.Documentation != null) {
+ tmpComment = Lexer.consume_doc_comment ();
+ Lexer.doc_state = XmlCommentState.Allowed;
+ }
+
lexer.PropertyParsing = true;
parsing_indexer = true;
- indexer_parameters = decl.param_list;
}
- accessor_declarations
+ accessor_declarations
{
lexer.PropertyParsing = false;
has_get = has_set = false;
}
CLOSE_BRACE
{
- // The signature is computed from the signature of the indexer. Look
- // at section 3.6 on the spec
- Indexer indexer;
- IndexerDeclaration decl = (IndexerDeclaration) $3;
- Location loc = decl.location;
- Accessors accessors = (Accessors) $6;
+ Accessors accessors = (Accessors) $10;
Accessor get_block = accessors != null ? accessors.get_or_add : null;
Accessor set_block = accessors != null ? accessors.set_or_remove : null;
bool order = accessors != null ? accessors.declared_in_reverse : false;
- MemberName name;
- if (decl.interface_type != null)
- name = new MemberName (decl.interface_type, TypeContainer.DefaultIndexerName, loc);
- else
- name = new MemberName (TypeContainer.DefaultIndexerName, loc);
-
- indexer = new Indexer (current_class, decl.type, name,
- (int) $2, decl.param_list, (Attributes) $1,
- get_block, set_block, order);
+ Indexer indexer = new Indexer (current_class, (FullNamedExpression) $3,
+ (MemberName)$4, (int) $2, (Parameters) $6, (Attributes) $1,
+ get_block, set_block, order);
- if (decl.type == TypeManager.system_void_expr)
- Report.Error (620, loc, "`{0}': indexer return type cannot be `void'", indexer.GetSignatureForError ());
+ if ($3 == TypeManager.system_void_expr)
+ Report.Error (620, GetLocation ($3), "`{0}': indexer return type cannot be `void'", indexer.GetSignatureForError ());
if (accessors == null)
Report.Error (548, indexer.Location, "`{0}': property or indexer must have at least one accessor", indexer.GetSignatureForError ());
}
;
-indexer_declarator
- : type_and_void THIS OPEN_BRACKET opt_parameter_list_no_mod CLOSE_BRACKET
- {
- Parameters pars = (Parameters) $4;
- if (pars.IsEmpty){
- Report.Error (1551, (Location) $2, "Indexers must have at least one parameter");
- }
- if (RootContext.Documentation != null) {
- tmpComment = Lexer.consume_doc_comment ();
- Lexer.doc_state = XmlCommentState.Allowed;
- }
-
- $$ = new IndexerDeclaration ((FullNamedExpression) $1, null, pars, (Location) $2);
- }
- | type_and_void namespace_or_type_name DOT THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
- {
- Parameters pars = (Parameters) $6;
- if (pars.IsEmpty){
- Report.Error (1551, (Location) $4, "Indexers must have at least one parameter");
- }
-
- MemberName name = (MemberName) $2;
- $$ = new IndexerDeclaration ((FullNamedExpression) $1, name, pars, (Location) $4);
-
- if (RootContext.Documentation != null) {
- tmpComment = Lexer.consume_doc_comment ();
- Lexer.doc_state = XmlCommentState.Allowed;
- }
- }
- ;
-
enum_declaration
: opt_attributes
opt_modifiers
- ENUM type_name
+ ENUM type_declaration_name
opt_enum_base {
if (RootContext.Documentation != null)
enumTypeComment = Lexer.consume_doc_comment ();
}
| opt_attributes IDENTIFIER
{
+ ++lexer.parsing_block;
if (RootContext.Documentation != null) {
tmpComment = Lexer.consume_doc_comment ();
Lexer.doc_state = XmlCommentState.NotAllowed;
}
ASSIGN constant_expression
{
+ --lexer.parsing_block;
VariableDeclaration vd = new VariableDeclaration (
(LocatedToken) $2, $5, (Attributes) $1);
: opt_attributes
opt_modifiers
DELEGATE
- type_and_void type_name
+ member_type type_declaration_name
OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
{
MemberName name = MakeName ((MemberName) $5);
;
namespace_or_type_name
- : IDENTIFIER opt_type_argument_list
+ : member_name
+ | qualified_alias_member IDENTIFIER opt_type_argument_list
{
- LocatedToken lt = (LocatedToken) $1;
- $$ = new MemberName (lt.Value, (TypeArguments) $2, lt.Location);
- }
- | qualified_alias_member IDENTIFIER opt_type_argument_list {
LocatedToken lt1 = (LocatedToken) $1;
LocatedToken lt2 = (LocatedToken) $2;
$$ = new MemberName (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
}
- | namespace_or_type_name DOT IDENTIFIER opt_type_argument_list {
- LocatedToken lt = (LocatedToken) $3;
- $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $4, lt.Location);
- }
;
member_name
- : IDENTIFIER opt_type_parameter_list
- {
- LocatedToken lt = (LocatedToken) $1;
- $$ = new MemberName (lt.Value, (TypeArguments) $2, lt.Location);
- }
- | namespace_or_type_name DOT IDENTIFIER opt_type_parameter_list
+ : type_name
+ | namespace_or_type_name DOT IDENTIFIER opt_type_argument_list
{
LocatedToken lt = (LocatedToken) $3;
$$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $4, lt.Location);
;
type_name
- : IDENTIFIER opt_type_parameter_list
+ : IDENTIFIER opt_type_argument_list
{
LocatedToken lt = (LocatedToken) $1;
$$ = new MemberName (lt.Value, (TypeArguments)$2, lt.Location);
}
;
-
+
//
// Generics arguments (any type, without attributes)
//
-
opt_type_argument_list
: /* empty */ { $$ = null; }
| OP_GENERICS_LT type_arguments OP_GENERICS_GT
| OP_GENERICS_LT error
{
Error_TypeExpected (lexer.Location);
+ $$ = new TypeArguments (lexer.Location);
}
;
+type_arguments
+ : type
+ {
+ TypeArguments type_args = new TypeArguments (lexer.Location);
+ type_args.Add ((Expression) $1);
+ $$ = type_args;
+ }
+ | type_arguments COMMA type
+ {
+ TypeArguments type_args = (TypeArguments) $1;
+ type_args.Add ((Expression) $3);
+ $$ = type_args;
+ }
+ ;
+
//
-// Generics parameters (identifiers only, with attributes), used in type, method declarations
+// Generics parameters (identifiers only, with attributes), used in type or method declarations
//
+type_declaration_name
+ : IDENTIFIER
+ {
+ lexer.parsing_generic_declaration = true;
+ }
+ opt_type_parameter_list
+ {
+ lexer.parsing_generic_declaration = false;
+ LocatedToken lt = (LocatedToken) $1;
+ $$ = new MemberName (lt.Value, (TypeArguments)$3, lt.Location);
+ }
+ ;
+member_declaration_name
+ : method_declaration_name
+ {
+ MemberName mn = (MemberName)$1;
+ if (mn.TypeArguments != null)
+ syntax_error (mn.Location, string.Format ("Member `{0}' cannot declare type arguments",
+ mn.GetSignatureForError ()));
+ }
+ ;
+
+method_declaration_name
+ : type_declaration_name
+ | explicit_interface IDENTIFIER opt_type_parameter_list
+ {
+ lexer.parsing_generic_declaration = false;
+ LocatedToken lt = (LocatedToken) $2;
+ $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $3, lt.Location);
+ }
+ ;
+
+indexer_declaration_name
+ : THIS
+ {
+ lexer.parsing_generic_declaration = false;
+ $$ = new MemberName (TypeContainer.DefaultIndexerName, GetLocation ($1));
+ }
+ | explicit_interface THIS
+ {
+ lexer.parsing_generic_declaration = false;
+ $$ = new MemberName ((MemberName) $1, TypeContainer.DefaultIndexerName, null, GetLocation ($1));
+ }
+ ;
+
+explicit_interface
+ : IDENTIFIER opt_type_argument_list DOT
+ {
+ LocatedToken lt = (LocatedToken) $1;
+ $$ = new MemberName (lt.Value, (TypeArguments) $2, lt.Location);
+ }
+ | qualified_alias_member IDENTIFIER opt_type_argument_list DOT
+ {
+ LocatedToken lt1 = (LocatedToken) $1;
+ LocatedToken lt2 = (LocatedToken) $2;
+
+ $$ = new MemberName (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
+ }
+ | explicit_interface IDENTIFIER opt_type_argument_list DOT
+ {
+ LocatedToken lt = (LocatedToken) $2;
+ $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $3, lt.Location);
+ }
+ ;
+
opt_type_parameter_list
: /* empty */ { $$ = null; }
- | OP_GENERICS_LT type_arguments OP_GENERICS_GT
+ | OP_GENERICS_LT_DECL type_parameters OP_GENERICS_GT
{
if (RootContext.Version < LanguageVersion.ISO_2)
Report.FeatureIsNotAvailable (GetLocation ($1), "generics");
$$ = $2;
}
- | OP_GENERICS_LT error
- {
- Error_TypeExpected (lexer.Location);
- }
;
-type_arguments
- : type_argument
+type_parameters
+ : type_parameter
{
TypeArguments type_args = new TypeArguments (lexer.Location);
- type_args.Add ((Expression) $1);
+ type_args.Add ((Expression)$1);
$$ = type_args;
}
- | type_arguments COMMA type_argument
+ | type_parameters COMMA type_parameter
{
TypeArguments type_args = (TypeArguments) $1;
- type_args.Add ((Expression) $3);
+ type_args.Add ((Expression)$3);
$$ = type_args;
}
;
-type_argument
- : type
+type_parameter
+ : opt_attributes IDENTIFIER
{
- $$ = $1;
+ LocatedToken lt = (LocatedToken)$2;
+ $$ = new TypeParameterName (lt.Value, (Attributes)$1, lt.Location);
}
- | attribute_sections type
+ | error
{
- SimpleName sn = $2 as SimpleName;
- if (sn == null)
- Error_TypeExpected (GetLocation ($2));
+ if (GetTokenName (yyToken) == "type")
+ Report.Error (81, GetLocation ($1), "Type parameter declaration must be an identifier not a type");
else
- $2 = new TypeParameterName (sn.Name, (Attributes) $1, lexer.Location);
- $$ = $2;
+ Error_SyntaxError (yyToken);
+
+ $$ = new TypeParameterName ("", null, lexer.Location);
}
;
$$ = TypeManager.system_void_expr;
}
;
+
+member_type
+ : type_and_void
+ {
+ lexer.parsing_generic_declaration = true;
+ }
+ ;
//
// A type which does not allow `void' to be used
$$ = TypeManager.system_void_expr;
}
;
+
+simple_type
+ : type_expression
+ | VOID
+ {
+ Expression.Error_VoidInvalidInTheContext (lexer.Location);
+ $$ = TypeManager.system_void_expr;
+ }
+ ;
type_expression_or_array
: type_expression
- | array_type
+ | type_expression rank_specifiers
+ {
+ string rank_specifiers = (string) $2;
+ $$ = current_array_type = new ComposedCast ((FullNamedExpression) $1, rank_specifiers);
+ }
;
type_expression
}
;
-non_expression_type
- : builtin_types opt_nullable
- {
- if ($2 != null)
- $$ = new ComposedCast ((FullNamedExpression) $1, "?", lexer.Location);
- }
- | VOID
- {
- $$ = TypeManager.system_void_expr;
- }
- | non_expression_type rank_specifiers
- {
- Location loc = GetLocation ($1);
- if (loc.IsNull)
- loc = lexer.Location;
- $$ = new ComposedCast ((FullNamedExpression) $1, (string) $2, loc);
- }
- | non_expression_type STAR
- {
- Location loc = GetLocation ($1);
- if (loc.IsNull)
- loc = lexer.Location;
- $$ = new ComposedCast ((FullNamedExpression) $1, "*", loc);
- }
- //
- // We need this because the parser will happily go and reduce IDENTIFIER STAR
- // through this different path
- //
- | multiplicative_expression STAR
- {
- FullNamedExpression e = $1 as FullNamedExpression;
- if (e != null)
- $$ = new ComposedCast (e, "*");
- else
- Error_TypeExpected (GetLocation ($1));
- }
- ;
-
type_list
: base_type_name
{
/*
* replaces all the productions for isolating the various
- * simple types, but we need this to reuse it easily in local_variable_type
+ * simple types, but we need this to reuse it easily in variable_type
*/
builtin_types
: OBJECT { $$ = TypeManager.system_object_expr; }
| CHAR { $$ = TypeManager.system_char_expr; }
;
-array_type
- : type_expression rank_specifiers
- {
- string rank_specifiers = (string) $2;
- $$ = current_array_type = new ComposedCast ((FullNamedExpression) $1, rank_specifiers);
- }
- ;
-
predefined_type
: builtin_types
| VOID
primary_expression_no_array_creation
: literal
- | type_name
+ | IDENTIFIER opt_type_argument_list
{
- MemberName mn = (MemberName) $1;
- $$ = mn.GetTypeExpression ();
+ LocatedToken lt = (LocatedToken) $1;
+ $$ = new SimpleName (MemberName.MakeName (lt.Value, (TypeArguments)$2), (TypeArguments)$2, lt.Location);
}
| parenthesized_expression
| default_value_expression
| FALSE { $$ = new BoolLiteral (false, lexer.Location); }
;
-parenthesized_expression_0
- : OPEN_PARENS expression CLOSE_PARENS
- {
- $$ = $2;
- lexer.Deambiguate_CloseParens ($$);
- // After this, the next token returned is one of
- // CLOSE_PARENS_CAST, CLOSE_PARENS_NO_CAST (CLOSE_PARENS), CLOSE_PARENS_OPEN_PARENS
- // or CLOSE_PARENS_MINUS.
- }
- | OPEN_PARENS expression error { CheckToken (1026, yyToken, "Expecting ')'", lexer.Location); }
+
+//
+// Here is the trick, tokenizer may think that parens is a special but
+// parser is interested in open parens only, so we merge them.
+// Consider: if (a)foo ();
+//
+open_parens_any
+ : OPEN_PARENS
+ | OPEN_PARENS_CAST
+ | OPEN_PARENS_LAMBDA
;
parenthesized_expression
- : parenthesized_expression_0 CLOSE_PARENS_NO_CAST
- {
- $$ = $1;
- }
- | parenthesized_expression_0 CLOSE_PARENS
- {
- $$ = $1;
- }
- | parenthesized_expression_0 CLOSE_PARENS_MINUS
+ : OPEN_PARENS expression CLOSE_PARENS
{
- // If a parenthesized expression is followed by a minus, we need to wrap
- // the expression inside a ParenthesizedExpression for the CS0075 check
- // in Binary.DoResolve().
- $$ = new ParenthesizedExpression ((Expression) $1);
+ $$ = new ParenthesizedExpression ((Expression) $2);
}
;
-
+
member_access
: primary_expression DOT IDENTIFIER opt_type_argument_list
{
;
invocation_expression
- : primary_expression OPEN_PARENS opt_argument_list CLOSE_PARENS
- {
- if ($1 == null)
- Report.Error (1, (Location) $2, "Parse error");
- else
- $$ = new Invocation ((Expression) $1, (ArrayList) $3);
- }
- | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS CLOSE_PARENS
+ : primary_expression open_parens_any opt_argument_list CLOSE_PARENS
{
- $$ = new Invocation ((Expression) $1, new ArrayList ());
- }
- | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS primary_expression
- {
- $$ = new InvocationOrCast ((Expression) $1, (Expression) $3);
- }
- | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS non_simple_argument CLOSE_PARENS
- {
- ArrayList args = new ArrayList (1);
- args.Add ($4);
- $$ = new Invocation ((Expression) $1, args);
- }
- | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS argument_list COMMA argument CLOSE_PARENS
- {
- ArrayList args = ((ArrayList) $4);
- args.Add ($6);
- $$ = new Invocation ((Expression) $1, args);
+ $$ = new Invocation ((Expression) $1, (ArrayList) $3);
}
;
{
$$ = new Argument ((Expression) $2, Argument.AType.Out);
}
- | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
+ | ARGLIST open_parens_any argument_list CLOSE_PARENS
{
ArrayList list = (ArrayList) $3;
Argument[] args = new Argument [list.Count];
Expression expr = new Arglist (args, (Location) $1);
$$ = new Argument (expr, Argument.AType.Expression);
}
- | ARGLIST OPEN_PARENS CLOSE_PARENS
+ | ARGLIST open_parens_any CLOSE_PARENS
{
$$ = new Argument (new Arglist ((Location) $1), Argument.AType.Expression);
}
{
$$ = new ElementAccess ((Expression) $1, (ArrayList) $3);
}
+ | array_creation_expression OPEN_BRACKET expression_list CLOSE_BRACKET
+ {
+ // LAMESPEC: Not allowed according to specification
+ $$ = new ElementAccess ((Expression) $1, (ArrayList) $3);
+ }
| primary_expression_no_array_creation rank_specifiers
{
// So the super-trick is that primary_expression
post_increment_expression
: primary_expression OP_INC
{
- $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement,
- (Expression) $1, (Location) $2);
+ $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement, (Expression) $1);
}
;
post_decrement_expression
: primary_expression OP_DEC
{
- $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement,
- (Expression) $1, (Location) $2);
+ $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement, (Expression) $1);
}
;
object_or_delegate_creation_expression
- : NEW type OPEN_PARENS opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
+ : NEW simple_type open_parens_any opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
{
if ($6 != null) {
if (RootContext.Version <= LanguageVersion.ISO_2)
else
$$ = new New ((Expression) $2, (ArrayList) $4, (Location) $1);
}
- | NEW type object_or_collection_initializer
+ | NEW simple_type object_or_collection_initializer
{
if (RootContext.Version <= LanguageVersion.ISO_2)
Report.FeatureIsNotAvailable (GetLocation ($1), "collection initializers");
}
;
+
array_creation_expression
- : NEW type_expression OPEN_BRACKET expression_list CLOSE_BRACKET
- opt_rank_specifier
+ : NEW simple_type OPEN_BRACKET expression_list CLOSE_BRACKET
+ opt_rank_specifier // shift/reduce on OPEN_BRACE
opt_array_initializer
{
$$ = new ArrayCreation ((FullNamedExpression) $2, (ArrayList) $4, (string) $6, (ArrayList) $7, (Location) $1);
}
- | NEW type_expression rank_specifiers array_initializer
+ | NEW simple_type rank_specifiers opt_array_initializer
{
+ if ($4 == null)
+ Report.Error (1586, GetLocation ($1), "Array creation must have array size or array initializer");
+
$$ = new ArrayCreation ((FullNamedExpression) $2, (string) $3, (ArrayList) $4, (Location) $1);
}
| NEW rank_specifiers array_initializer
{
$$ = new ImplicitlyTypedArrayCreation ((string) $2, (ArrayList) $3, (Location) $1);
}
- | NEW error
- {
- Report.Error (1031, (Location) $1, "Type expected");
- $$ = null;
- }
- | NEW type_expression error
+ | NEW simple_type error
{
Report.Error (1526, (Location) $1, "A new expression requires () or [] after type");
$$ = null;
opt_rank_specifier
: /* empty */
{
- $$ = "";
+ $$ = "";
}
| rank_specifiers
{
- $$ = $1;
+ $$ = $1;
}
;
;
rank_specifiers
- : rank_specifier opt_rank_specifier
+ : rank_specifier
+ | rank_specifier rank_specifiers
{
$$ = (string) $2 + (string) $1;
}
;
rank_specifier
- : OPEN_BRACKET opt_dim_separators CLOSE_BRACKET
+ : OPEN_BRACKET CLOSE_BRACKET
{
- $$ = "[" + (string) $2 + "]";
+ $$ = "[]";
}
- ;
-
-opt_dim_separators
- : /* empty */
+ | OPEN_BRACKET dim_separators CLOSE_BRACKET
{
- $$ = "";
+ $$ = "[" + (string) $2 + "]";
}
- | dim_separators
+ | OPEN_BRACKET error CLOSE_BRACKET
{
- $$ = $1;
- }
+ ArrayCreation.Error_IncorrectArrayInitializer (GetLocation ($1));
+ $$ = "[]";
+ }
;
dim_separators
list.Add ($3);
$$ = list;
}
+ | error
+ {
+ Error_SyntaxError (yyToken);
+ $$ = new ArrayList ();
+ }
;
typeof_expression
pushed_current_array_type = current_array_type;
lexer.TypeOfParsing = true;
}
- OPEN_PARENS typeof_type_expression CLOSE_PARENS
+ open_parens_any typeof_type_expression CLOSE_PARENS
{
lexer.TypeOfParsing = false;
Expression type = (Expression)$4;
;
sizeof_expression
- : SIZEOF OPEN_PARENS type CLOSE_PARENS {
+ : SIZEOF open_parens_any type CLOSE_PARENS {
$$ = new SizeOf ((Expression) $3, (Location) $1);
}
;
checked_expression
- : CHECKED OPEN_PARENS expression CLOSE_PARENS
+ : CHECKED open_parens_any expression CLOSE_PARENS
{
$$ = new CheckedExpr ((Expression) $3, (Location) $1);
}
;
unchecked_expression
- : UNCHECKED OPEN_PARENS expression CLOSE_PARENS
+ : UNCHECKED open_parens_any expression CLOSE_PARENS
{
$$ = new UnCheckedExpr ((Expression) $3, (Location) $1);
}
}
block
{
- $$ = end_anonymous ((ToplevelBlock) $4, (Location) $1);
+ $$ = end_anonymous ((ToplevelBlock) $4);
}
;
;
default_value_expression
- : DEFAULT_OPEN_PARENS type CLOSE_PARENS
+ : DEFAULT open_parens_any type CLOSE_PARENS
{
if (RootContext.Version < LanguageVersion.ISO_2)
Report.FeatureIsNotAvailable (lexer.Location, "default value expression");
- $$ = new DefaultValueExpression ((Expression) $2, lexer.Location);
+ $$ = new DefaultValueExpression ((Expression) $3, GetLocation ($1));
}
;
: primary_expression
| BANG prefixed_unary_expression
{
- $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, (Location) $1);
+ $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2);
}
| TILDE prefixed_unary_expression
{
- $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, (Location) $1);
+ $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2);
}
| cast_expression
;
-cast_list
- : parenthesized_expression_0 CLOSE_PARENS_CAST unary_expression
+cast_expression
+ : OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
{
- $$ = new Cast ((Expression) $1, (Expression) $3);
+ $$ = new Cast ((Expression) $2, (Expression) $4, GetLocation ($1));
}
- | parenthesized_expression_0 CLOSE_PARENS_NO_CAST default_value_expression
+ | OPEN_PARENS predefined_type CLOSE_PARENS prefixed_unary_expression
{
- $$ = new Cast ((Expression) $1, (Expression) $3);
- }
- | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS cast_expression
- {
- $$ = new Cast ((Expression) $1, (Expression) $3);
- }
- ;
-
-cast_expression
- : cast_list
- | OPEN_PARENS non_expression_type CLOSE_PARENS prefixed_unary_expression
- {
- if ($2 == TypeManager.system_void_expr)
- Expression.Error_VoidInvalidInTheContext (GetLocation ($2));
-
- // TODO: wrong location
- $$ = new Cast ((Expression) $2, (Expression) $4, lexer.Location);
+ $$ = new Cast ((Expression) $2, (Expression) $4, GetLocation ($1));
}
;
: unary_expression
| PLUS prefixed_unary_expression
{
- $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, (Location) $1);
+ $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2);
}
| MINUS prefixed_unary_expression
{
- $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, (Location) $1);
+ $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2);
}
| OP_INC prefixed_unary_expression
{
- $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
- (Expression) $2, (Location) $1);
+ $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, (Expression) $2);
}
| OP_DEC prefixed_unary_expression
{
- $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
- (Expression) $2, (Location) $1);
+ $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, (Expression) $2);
}
| STAR prefixed_unary_expression
{
- $$ = new Indirection ((Expression) $2, (Location) $1);
+ $$ = new Indirection ((Expression) $2, GetLocation ($1));
}
| BITWISE_AND prefixed_unary_expression
{
- $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, (Location) $1);
+ $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2);
}
;
}
| additive_expression MINUS multiplicative_expression
{
- $$ = new Binary (Binary.Operator.Subtraction,
- (Expression) $1, (Expression) $3);
+ $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
}
+ | parenthesized_expression MINUS multiplicative_expression
+ {
+ // Shift/Reduce conflict
+ $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
+ }
| additive_expression AS type
{
$$ = new As ((Expression) $1, (Expression) $3, (Location) $2);
{
LocatedToken lt = (LocatedToken) $1;
Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
- start_anonymous (true, new Parameters (p), (Location) $2);
+ start_anonymous (true, new Parameters (p), GetLocation ($1));
}
lambda_expression_body
{
- $$ = end_anonymous ((ToplevelBlock) $4, (Location) $2);
+ $$ = end_anonymous ((ToplevelBlock) $4);
}
| OPEN_PARENS_LAMBDA opt_lambda_parameter_list CLOSE_PARENS ARROW
{
- start_anonymous (true, (Parameters) $2, (Location) $4);
+ start_anonymous (true, (Parameters) $2, GetLocation ($1));
}
lambda_expression_body
{
- $$ = end_anonymous ((ToplevelBlock) $6, (Location) $4);
+ $$ = end_anonymous ((ToplevelBlock) $6);
}
;
{
lexer.ConstraintsParsing = true;
}
- type_name
+ type_declaration_name
{
MemberName name = MakeName ((MemberName) $6);
push_current_class (new Class (current_namespace, current_class, name, (int) $2, (Attributes) $1), $3);
}
class_body
{
+ --lexer.parsing_declaration;
if (RootContext.Documentation != null)
Lexer.doc_state = XmlCommentState.Allowed;
}
* > expressions to prevent reduce/reduce errors in the grammar.
* > The expressions are converted into types during semantic analysis.
*/
-local_variable_type
- : primary_expression opt_rank_specifier_or_nullable
+variable_type
+ : primary_expression_no_array_creation opt_rank_specifier_or_nullable
{
// FIXME: Do something smart here regarding the composition of the type.
;
local_variable_pointer_type
- : primary_expression STAR
+ : primary_expression_no_array_creation STAR
{
ATypeNameExpression expr = $1 as ATypeNameExpression;
}
| builtin_types STAR
{
- $$ = new ComposedCast ((FullNamedExpression) $1, "*", lexer.Location);
+ $$ = new ComposedCast ((FullNamedExpression) $1, "*", GetLocation ($1));
}
| VOID STAR
{
}
;
+local_variable_type
+ : variable_type
+ | local_variable_pointer_type opt_rank_specifier
+ {
+ if ($1 != null){
+ string rank = (string)$2;
+
+ if (rank == "")
+ $$ = $1;
+ else
+ $$ = current_array_type = new ComposedCast ((FullNamedExpression) $1, rank);
+ } else {
+ $$ = null;
+ }
+ }
+ ;
+
local_variable_declaration
- : local_variable_type variable_declarators
+ : local_variable_type local_variable_declarators
{
if ($1 != null) {
VarExpr ve = $1 as VarExpr;
} else
$$ = null;
}
- | local_variable_pointer_type opt_rank_specifier variable_declarators
- {
- if ($1 != null){
- Expression t;
-
- if ((string) $2 == "")
- t = (Expression) $1;
- else
- t = new ComposedCast ((FullNamedExpression) $1, (string) $2);
- $$ = new DictionaryEntry (t, $3);
- } else
- $$ = null;
- }
;
local_constant_declaration
- : CONST local_variable_type constant_declarators
+ : CONST variable_type constant_declarators
{
if ($2 != null)
$$ = new DictionaryEntry ($2, $3);
if (s == null) {
expr.Error_InvalidExpressionStatement ();
- $$ = null;
- } else {
- $$ = new StatementExpression (s);
}
+
+ $$ = new StatementExpression (s);
}
| error
{
- Report.Error (1002, GetLocation ($1), "Expecting {0}, got {1}", GetExpecting (), GetTokenName (yyToken));
+ Error_SyntaxError (yyToken);
$$ = null;
}
;
}
| error
{
- Report.Error (1002, GetLocation ($1), "Expecting {0}, got {1}", GetExpecting (), GetTokenName (yyToken));
+ Error_SyntaxError (yyToken);
$$ = null;
}
;
;
if_statement
- : IF OPEN_PARENS boolean_expression CLOSE_PARENS
+ : IF open_parens_any boolean_expression CLOSE_PARENS
embedded_statement
{
Location l = (Location) $1;
Report.Warning (642, 3, l, "Possible mistaken empty statement");
}
- | IF OPEN_PARENS boolean_expression CLOSE_PARENS
+ | IF open_parens_any boolean_expression CLOSE_PARENS
embedded_statement ELSE embedded_statement
{
Location l = (Location) $1;
;
switch_statement
- : SWITCH OPEN_PARENS
+ : SWITCH open_parens_any
{
if (switch_stack == null)
switch_stack = new Stack (2);
;
while_statement
- : WHILE OPEN_PARENS boolean_expression CLOSE_PARENS embedded_statement
+ : WHILE open_parens_any boolean_expression CLOSE_PARENS embedded_statement
{
Location l = (Location) $1;
$$ = new While ((Expression) $3, (Statement) $5, l);
do_statement
: DO embedded_statement
- WHILE OPEN_PARENS boolean_expression CLOSE_PARENS SEMICOLON
+ WHILE open_parens_any boolean_expression CLOSE_PARENS SEMICOLON
{
Location l = (Location) $1;
;
for_statement
- : FOR OPEN_PARENS
- opt_for_initializer SEMICOLON
+ : FOR open_parens_any opt_for_initializer SEMICOLON
{
Location l = lexer.Location;
start_block (l);
;
foreach_statement
- : FOREACH OPEN_PARENS type IN expression CLOSE_PARENS
+ : FOREACH open_parens_any type IN expression CLOSE_PARENS
{
Report.Error (230, (Location) $1, "Type and identifier are both required in a foreach statement");
$$ = null;
}
- | FOREACH OPEN_PARENS type IDENTIFIER IN
+ | FOREACH open_parens_any type IDENTIFIER IN
expression CLOSE_PARENS
{
start_block (lexer.Location);
;
catch_args
- : OPEN_PARENS type opt_identifier CLOSE_PARENS
+ : open_parens_any type opt_identifier CLOSE_PARENS
{
$$ = new DictionaryEntry ($2, $3);
}
- | OPEN_PARENS CLOSE_PARENS
+ | open_parens_any CLOSE_PARENS
{
Report.Error (1015, GetLocation ($1), "A type that derives from `System.Exception', `object', or `string' expected");
}
;
fixed_statement
- : FIXED OPEN_PARENS
+ : FIXED open_parens_any
type_and_void fixed_pointer_declarators
CLOSE_PARENS
{
;
lock_statement
- : LOCK OPEN_PARENS expression CLOSE_PARENS
+ : LOCK open_parens_any expression CLOSE_PARENS
{
//
}
;
using_statement
- : USING OPEN_PARENS local_variable_declaration CLOSE_PARENS
+ : USING open_parens_any local_variable_declaration CLOSE_PARENS
{
start_block (lexer.Location);
Block assign_block = current_block;
current_block.AddStatement (stmt);
$$ = end_block (lexer.Location);
}
- | USING OPEN_PARENS expression CLOSE_PARENS
+ | USING open_parens_any expression CLOSE_PARENS
{
start_block (lexer.Location);
}
method.Block = (ToplevelBlock) end_block(lexer.Location);
current_container.AddMethod (method);
+ --lexer.parsing_declaration;
InteractiveResult = pop_current_class ();
current_local_parameters = null;
}
}
}
-// <summary>
-// A class used to hold info about an indexer declarator
-// </summary>
-public class IndexerDeclaration {
- public FullNamedExpression type;
- public MemberName interface_type;
- public Parameters param_list;
- public Location location;
-
- public IndexerDeclaration (FullNamedExpression type, MemberName interface_type,
- Parameters param_list, Location loc)
+class VariableMemberDeclaration
+{
+ public readonly MemberName MemberName;
+ public Expression expression_or_array_initializer;
+
+ public VariableMemberDeclaration (MemberName mn, object initializer)
{
- this.type = type;
- this.interface_type = interface_type;
- this.param_list = param_list;
- this.location = loc;
+ MemberName = mn;
+
+ if (initializer is ArrayList) {
+ this.expression_or_array_initializer = new ArrayCreation (CSharpParser.current_array_type, "", (ArrayList)initializer, mn.Location);
+ } else {
+ this.expression_or_array_initializer = (Expression)initializer;
+ }
}
}
+
// <summary>
// A class used to hold info about an operator declarator
// </summary>
else
current_container = current_container.AddTypeContainer (tc);
-
+ ++lexer.parsing_declaration;
current_class = tc;
}
assign = new SimpleAssign (new SimpleName (decl.identifier, decl.Location), var);
current_block.AddStatement (new StatementExpression (assign));
} else {
- Field f = new Field (current_container, (FullNamedExpression) type, Modifiers.PUBLIC | Modifiers.STATIC, decl.identifier, null, loc);
+ Field f = new Field (current_container, (FullNamedExpression) type, Modifiers.PUBLIC | Modifiers.STATIC,
+ new MemberName (decl.identifier, loc), null);
current_container.AddField (f);
// Register the field to be visible later as a global variable
void
start_anonymous (bool lambda, Parameters parameters, Location loc)
{
+ if (RootContext.Version == LanguageVersion.ISO_1){
+ Report.FeatureIsNotAvailable (loc, "anonymous methods");
+ }
+
oob_stack.Push (current_anonymous_method);
oob_stack.Push (current_local_parameters);
* Completes the anonymous method processing, if lambda_expr is null, this
* means that we have a Statement instead of an Expression embedded
*/
-AnonymousMethodExpression end_anonymous (ToplevelBlock anon_block, Location loc)
+AnonymousMethodExpression end_anonymous (ToplevelBlock anon_block)
{
AnonymousMethodExpression retval;
- if (RootContext.Version == LanguageVersion.ISO_1){
- Report.FeatureIsNotAvailable (loc, "anonymous methods");
- retval = null;
- } else {
- current_anonymous_method.Block = anon_block;
- retval = current_anonymous_method;
- }
+ current_anonymous_method.Block = anon_block;
+ retval = current_anonymous_method;
current_local_parameters = (Parameters) oob_stack.Pop ();
current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();
}
}
-public string GetExpecting ()
+
+void Error_SyntaxError (int token)
{
- int [] tokens = yyExpectingTokens (yyExpectingState);
- if (tokens.Length == 1)
- return "`" + GetTokenName (tokens [0]) + "'";
+ Error_SyntaxError (0, token);
+}
+
+void Error_SyntaxError (int error_code, int token)
+{
+ string symbol = GetSymbolName (token);
+ string expecting = GetExpecting ();
- StringBuilder sb = new StringBuilder ();
- ArrayList names = new ArrayList ();
+ if (error_code == 0) {
+ if (expecting == "`)'")
+ error_code = 1026;
+ else
+ error_code = 1525;
+ }
+
+ if (expecting != null)
+ Report.Error (error_code, lexer.Location, "Unexpected symbol `{0}', expecting {1}",
+ symbol, expecting);
+ else
+ Report.Error (error_code, lexer.Location, "Unexpected symbol `{0}'", symbol);
+}
+
+string GetExpecting ()
+{
+ int [] tokens = yyExpectingTokens (yyExpectingState);
+ ArrayList names = new ArrayList (tokens.Length);
+ bool has_type = false;
+ bool has_identifier = false;
for (int i = 0; i < tokens.Length; i++){
- string name = GetTokenName (tokens [i]);
+ int token = tokens [i];
+ has_identifier |= token == Token.IDENTIFIER;
+
+ string name = GetTokenName (token);
if (name == "<internal>")
continue;
+
+ has_type |= name == "type";
if (names.Contains (name))
continue;
names.Add (name);
}
+ //
+ // Too many tokens to enumerate
+ //
+ if (names.Count > 8)
+ return null;
+
+ if (has_type && has_identifier)
+ names.Remove ("identifier");
+
+ if (names.Count == 1)
+ return "`" + GetTokenName (tokens [0]) + "'";
+
+ StringBuilder sb = new StringBuilder ();
names.Sort ();
int count = names.Count;
for (int i = 0; i < count; i++){
return sb.ToString ();
}
-static public string GetTokenName (int token)
+
+string GetSymbolName (int token)
+{
+ switch (token){
+ case Token.LITERAL_FLOAT:
+ case Token.LITERAL_INTEGER:
+ case Token.LITERAL_DOUBLE:
+ case Token.LITERAL_DECIMAL:
+ case Token.LITERAL_CHARACTER:
+ case Token.LITERAL_STRING:
+ return lexer.Value.ToString ();
+ case Token.IDENTIFIER:
+ return ((LocatedToken)lexer.Value).Value;
+
+ case Token.BOOL:
+ return "bool";
+ case Token.BYTE:
+ return "byte";
+ case Token.CHAR:
+ return "char";
+ case Token.VOID:
+ return "void";
+ case Token.DECIMAL:
+ return "decimal";
+ case Token.DOUBLE:
+ return "double";
+ case Token.FLOAT:
+ return "float";
+ case Token.INT:
+ return "int";
+ case Token.LONG:
+ return "long";
+ case Token.SBYTE:
+ return "sbyte";
+ case Token.SHORT:
+ return "short";
+ case Token.STRING:
+ return "string";
+ case Token.UINT:
+ return "uint";
+ case Token.ULONG:
+ return "ulong";
+ case Token.USHORT:
+ return "ushort";
+ case Token.OBJECT:
+ return "object";
+
+ case Token.PLUS:
+ return "+";
+ case Token.UMINUS:
+ case Token.MINUS:
+ return "-";
+ case Token.BANG:
+ return "!";
+ case Token.BITWISE_AND:
+ return "&";
+ case Token.BITWISE_OR:
+ return "|";
+ case Token.STAR:
+ return "*";
+ case Token.PERCENT:
+ return "%";
+ case Token.DIV:
+ return "/";
+ case Token.CARRET:
+ return "^";
+ case Token.OP_INC:
+ return "++";
+ case Token.OP_DEC:
+ return "--";
+ case Token.OP_SHIFT_LEFT:
+ return "<<";
+ case Token.OP_SHIFT_RIGHT:
+ return ">>";
+ case Token.OP_LT:
+ return "<";
+ case Token.OP_GT:
+ return ">";
+ case Token.OP_LE:
+ return "<=";
+ case Token.OP_GE:
+ return ">=";
+ case Token.OP_EQ:
+ return "==";
+ case Token.OP_NE:
+ return "!=";
+ case Token.OP_AND:
+ return "&&";
+ case Token.OP_OR:
+ return "||";
+ case Token.OP_PTR:
+ return "->";
+ case Token.OP_COALESCING:
+ return "??";
+ case Token.OP_MULT_ASSIGN:
+ return "*=";
+ case Token.OP_DIV_ASSIGN:
+ return "/=";
+ case Token.OP_MOD_ASSIGN:
+ return "%=";
+ case Token.OP_ADD_ASSIGN:
+ return "+=";
+ case Token.OP_SUB_ASSIGN:
+ return "-=";
+ case Token.OP_SHIFT_LEFT_ASSIGN:
+ return "<<=";
+ case Token.OP_SHIFT_RIGHT_ASSIGN:
+ return ">>=";
+ case Token.OP_AND_ASSIGN:
+ return "&=";
+ case Token.OP_XOR_ASSIGN:
+ return "^=";
+ case Token.OP_OR_ASSIGN:
+ return "|=";
+ }
+
+ return GetTokenName (token);
+}
+
+static string GetTokenName (int token)
{
switch (token){
case Token.ABSTRACT:
return "as";
case Token.ADD:
return "add";
- case Token.ASSEMBLY:
- return "assembly";
case Token.BASE:
return "base";
case Token.BREAK:
return "new";
case Token.NULL:
return "null";
- case Token.OBJECT:
- return "object";
case Token.OPERATOR:
return "operator";
case Token.OUT:
return "[";
case Token.CLOSE_BRACKET:
return "]";
- case Token.DEFAULT_OPEN_PARENS:
+ case Token.OPEN_PARENS_CAST:
case Token.OPEN_PARENS_LAMBDA:
case Token.OPEN_PARENS:
return "(";
- case Token.CLOSE_PARENS_CAST:
- case Token.CLOSE_PARENS_NO_CAST:
- case Token.CLOSE_PARENS_OPEN_PARENS:
- case Token.CLOSE_PARENS_MINUS:
case Token.CLOSE_PARENS:
return ")";
case Token.DOT:
case Token.OP_OR:
case Token.OP_PTR:
case Token.OP_COALESCING:
- return "<operator>";
-
case Token.OP_MULT_ASSIGN:
case Token.OP_DIV_ASSIGN:
case Token.OP_MOD_ASSIGN:
case Token.UINT:
case Token.ULONG:
case Token.USHORT:
- return "<type>";
+ case Token.OBJECT:
+ return "type";
case Token.ASSIGN:
return "=";
case Token.EVAL_USING_DECLARATIONS_UNIT_PARSER:
case Token.EVAL_STATEMENT_PARSER:
case Token.LOWPREC:
- case Token.QUERY_LAST_TOKEN:
- case Token.QUERY_FIRST_TOKEN:
case Token.LAST_KEYWORD:
return "<internal>";