// cs-parser.jay: The Parser for the C# compiler
//
// Author: Miguel de Icaza (miguel@gnu.org)
+// Ravi Pratap (ravi@ximian.com)
//
// Licensed under the terms of the GNU GPL
//
%nonassoc HIGHPREC
%start compilation_unit
-/*%start namespace_declaration */
%%
compilation_unit
- : opt_using_directives opt_namespace_member_declarations opt_attributes opt_EOF
- {
- // Check that using comes only before namespace elements
- }
- ;
-
+ : outer_declarations opt_EOF
+ | outer_declarations attribute_sections opt_EOF
+ | attribute_sections opt_EOF
+ ;
+
opt_EOF
: /* empty */
| EOF
;
+outer_declarations
+ : outer_declaration
+ | outer_declarations outer_declaration
+ ;
+
+outer_declaration
+ : using_directive
+ | namespace_member_declaration
+ ;
+
using_directives
: using_directive
| using_directives using_directive
}
;
-// namespace_declarations
-// : namespace_declaration
-// | namespace_declarations namespace_declaration
-
+//
+// Strictly speaking, namespaces don't have attributes but
+// we parse global attributes along with namespace declarations and then
+// detach them
+//
namespace_declaration
- : NAMESPACE qualified_identifier
- {
- current_namespace = RootContext.Tree.RecordNamespace (current_namespace, name, (string) $2);
- }
+ : opt_attributes NAMESPACE qualified_identifier
+ {
+ Attributes attrs = (Attributes) $1;
+
+ if (attrs != null) {
+ foreach (AttributeSection asec in attrs.AttributeSections)
+ if (asec.Target == "assembly")
+ RootContext.AddGlobalAttribute (asec, lexer.Location);
+ }
+
+ current_namespace = RootContext.Tree.RecordNamespace (current_namespace, name, (string) $3);
+ }
namespace_body opt_semicolon
{
current_namespace = current_namespace.Parent;
//
// Attributes 17.2
//
+
opt_attributes
- : /* empty */ { $$ = null; }
- | attribute_section opt_attributes
+ : /* empty */
+ | attribute_sections { $$ = $1; }
+ ;
+
+attribute_sections
+ : attribute_section
+ {
+ AttributeSection sect = (AttributeSection) $1;
+
+ if (sect.Target == "assembly")
+ RootContext.AddGlobalAttribute (sect, lexer.Location);
+
+ $$ = new Attributes ((AttributeSection) $1, lexer.Location);
+ }
+ | attribute_sections attribute_section
{
Attributes attrs = null;
- AttributeSection sect = (AttributeSection) $1;
+ AttributeSection sect = (AttributeSection) $2;
- if (sect.Target == "assembly"){
- RootContext.AddGlobalAttributes (sect, lexer.Location);
- sect = null;
- }
+ if (sect.Target == "assembly")
+ RootContext.AddGlobalAttribute (sect, lexer.Location);
- if ($2 != null) {
- if (sect != null){
- attrs = (Attributes) $2;
- attrs.AddAttribute (sect);
- }
- } else {
- if (sect != null)
- attrs = new Attributes (sect, lexer.Location);
+ if ($1 != null) {
+ attrs = (Attributes) $1;
+ attrs.AddAttribute (sect);
}
$$ = attrs;
(Attributes) $1, lexer.Location);
current_container = new_struct;
current_container.Namespace = current_namespace;
- RootContext.Tree.RecordStruct (full_struct_name, new_struct);
+ RootContext.Tree.RecordDecl (full_struct_name, new_struct);
}
opt_struct_interfaces
struct_body
accessor_body
: block
- | SEMICOLON { $$ = new Block (null); }
+ | SEMICOLON { $$ = null; }
;
interface_declaration
}
current_interface = new_interface;
new_interface.Namespace = current_namespace;
- RootContext.Tree.RecordInterface (full_interface_name, new_interface);
+ RootContext.Tree.RecordDecl (full_interface_name, new_interface);
}
opt_interface_base
interface_body opt_semicolon
Location l = lexer.Location;
Method d = new Method (
- "System.Void", 0, "Finalize",
+ "System.Void",
+ Modifiers.PROTECTED | Modifiers.OVERRIDE,
+ "Finalize",
new Parameters (null, null, l), (Attributes) $1, l);
d.Block = (Block) $6;
e.Namespace = current_namespace;
CheckDef (current_container.AddEnum (e), full_name, enum_location);
- RootContext.Tree.RecordEnum (full_name, e);
+ RootContext.Tree.RecordDecl (full_name, e);
}
;
MakeName ((string) $5), (Parameters) $7,
(Attributes) $1, l);
-
+ del.Namespace = current_namespace;
CheckDef (current_container.AddDelegate (del), del.Name, l);
}
| opt_attributes
"System.Void", (int) $2, MakeName ((string) $5), (Parameters) $7,
(Attributes) $1, l);
+ del.Namespace = current_namespace;
CheckDef (current_container.AddDelegate (del), del.Name, l);
}
;
{
Location l = lexer.Location;
- $$ = new Assign ((Expression) $1,
- new Binary (Binary.Operator.Multiply,
- (Expression) $1,
- (Expression) $3, l), l);
+ $$ = new CompoundAssign (
+ (Expression) $1,
+ new Binary (Binary.Operator.Multiply,
+ (Expression) $1,
+ (Expression) $3, l),
+ (Expression) $3, l);
}
| prefixed_unary_expression OP_DIV_ASSIGN expression
{
Location l = lexer.Location;
- $$ = new Assign ((Expression) $1,
- new Binary (Binary.Operator.Division,
- (Expression) $1,
- (Expression) $3, l), l);
+ $$ = new CompoundAssign (
+ (Expression) $1,
+ new Binary (Binary.Operator.Division,
+ (Expression) $1,
+ (Expression) $3, l),
+ (Expression) $3, l);
}
| prefixed_unary_expression OP_MOD_ASSIGN expression
{
Location l = lexer.Location;
- $$ = new Assign ((Expression) $1,
- new Binary (Binary.Operator.Modulus,
- (Expression) $1,
- (Expression) $3, l), l);
+ $$ = new CompoundAssign (
+ (Expression) $1,
+ new Binary (Binary.Operator.Modulus,
+ (Expression) $1,
+ (Expression) $3, l),
+ (Expression) $3, l);
}
| prefixed_unary_expression OP_ADD_ASSIGN expression
{
Location l = lexer.Location;
- $$ = new Assign ((Expression) $1,
- new Binary (Binary.Operator.Addition,
- (Expression) $1,
- (Expression) $3, l), l);
+ $$ = new CompoundAssign (
+ (Expression) $1,
+ new Binary (Binary.Operator.Addition,
+ (Expression) $1,
+ (Expression) $3, l),
+ (Expression) $3, l);
}
| prefixed_unary_expression OP_SUB_ASSIGN expression
{
Location l = lexer.Location;
- $$ = new Assign ((Expression) $1,
- new Binary (Binary.Operator.Subtraction,
- (Expression) $1,
- (Expression) $3, l), l);
+ $$ = new CompoundAssign (
+ (Expression) $1,
+ new Binary (Binary.Operator.Subtraction,
+ (Expression) $1,
+ (Expression) $3, l),
+ (Expression) $3, l);
}
| prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
{
Location l = lexer.Location;
- $$ = new Assign ((Expression) $1,
- new Binary (Binary.Operator.LeftShift,
- (Expression) $1,
- (Expression) $3, l), l);
+ $$ = new CompoundAssign (
+ (Expression) $1,
+ new Binary (Binary.Operator.LeftShift,
+ (Expression) $1,
+ (Expression) $3, l),
+ (Expression) $3, l);
}
| prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
{
Location l = lexer.Location;
- $$ = new Assign ((Expression) $1,
- new Binary (Binary.Operator.RightShift,
- (Expression) $1,
- (Expression) $3, l), l);
+ $$ = new CompoundAssign (
+ (Expression) $1,
+ new Binary (Binary.Operator.RightShift,
+ (Expression) $1,
+ (Expression) $3, l),
+ (Expression) $3, l);
}
| prefixed_unary_expression OP_AND_ASSIGN expression
{
Location l = lexer.Location;
- $$ = new Assign ((Expression) $1,
- new Binary (Binary.Operator.BitwiseAnd,
- (Expression) $1,
- (Expression) $3, l), l);
+ $$ = new CompoundAssign (
+ (Expression) $1,
+ new Binary (Binary.Operator.BitwiseAnd,
+ (Expression) $1,
+ (Expression) $3, l),
+ (Expression) $3, l);
}
| prefixed_unary_expression OP_OR_ASSIGN expression
{
Location l = lexer.Location;
- $$ = new Assign ((Expression) $1,
- new Binary (Binary.Operator.BitwiseOr,
- (Expression) $1,
- (Expression) $3, l), l);
+ $$ = new CompoundAssign (
+ (Expression) $1,
+ new Binary (Binary.Operator.BitwiseOr,
+ (Expression) $1,
+ (Expression) $3, l),
+ (Expression) $3, l);
}
| prefixed_unary_expression OP_XOR_ASSIGN expression
{
Location l = lexer.Location;
- $$ = new Assign ((Expression) $1,
- new Binary (Binary.Operator.ExclusiveOr,
- (Expression) $1,
- (Expression) $3, l), l);
+ $$ = new CompoundAssign (
+ (Expression) $1,
+ new Binary (Binary.Operator.ExclusiveOr,
+ (Expression) $1,
+ (Expression) $3, l),
+ (Expression) $3, l);
}
;
(Attributes) $1, lexer.Location);
current_container = new_class;
current_container.Namespace = current_namespace;
- RootContext.Tree.RecordClass (name, new_class);
+ RootContext.Tree.RecordDecl (name, new_class);
}
opt_class_base
class_body
// as `expression' is allowed in argument_lists, which
// do not exist inside a block.
//
-#if BLAH
- if (current_block != null){
- if (current_block.IsVariableDefined (name)){
- return new LocalVariableReference (current_block, name, loc);
- }
- }
-#endif
if (current_local_parameters != null){
int idx;
public override int parse ()
{
- StringBuilder value = new StringBuilder ();
-
global_errors = 0;
try {
if (yacc_verbose_flag)