3 // cs-parser.jay: The Parser for the C# compiler
5 // Author: Miguel de Icaza (miguel@gnu.org)
7 // Licensed under the terms of the GNU GPL
9 // (C) 2001 Ximian, Inc (http://www.ximian.com)
12 // (1) Get rid of the *Collections.cs, that is an idea I took from System.CodeDOM
13 // And come to think of it, it is not that great, it duplicates a lot of code
14 // for something which is not really needed. We still have piles of typecasts
15 // anwyays (due to the nature of the stack being a collection of Objects).
17 // (2) Figure out why error productions dont work. `type-declaration' is a
18 // great spot to put an `error' because you can reproduce it with this input:
21 // (3) Move Modifier checking from each object into the parser itself, that will
22 // get rid of the global "error" symbol that we use now to report errors.
23 // We still need to pass a pointer to the tree.ErrorHandler, but that is a
31 using System.Collections;
37 public class CSharpParser : GenericParser {
38 Namespace current_namespace;
39 TypeContainer current_container;
42 // Current block is used to add statements as we find
49 // Current interface is used by the various declaration
50 // productions in the interface declaration to "add"
51 // the interfaces as we find them.
53 Interface current_interface;
56 // This is used by the unary_expression code to resolve
57 // a name against a parameter.
59 Parameters current_local_parameters;
62 // Using during property parsing to describe the implicit
63 // value parameter that is passed to the "set" and "get"accesor
64 // methods (properties and indexers).
66 string implicit_value_parameter_type;
67 Parameters indexer_parameters;
70 // Used to determine if we are parsing the get/set pair
71 // of an indexer or a property
76 // An out-of-band stack.
82 %token NONE /* This token is never returned by our lexer */
83 %token ERROR // This is used not by the parser, but by the tokenizer.
87 *These are the C# keywords
167 /* C# keywords which are not really keywords */
171 /* C# single character operators/punctuation. */
172 %token OPEN_BRACE "{"
173 %token CLOSE_BRACE "}"
174 %token OPEN_BRACKET "["
175 %token CLOSE_BRACKET "]"
176 %token OPEN_PARENS "("
177 %token CLOSE_PARENS ")"
190 %token BITWISE_AND "&"
191 %token BITWISE_OR "|"
198 /* C# multi-character operators. */
201 %token OP_SHIFT_LEFT "<<"
202 %token OP_SHIFT_RIGHT ">>"
209 %token OP_MULT_ASSIGN "*="
210 %token OP_DIV_ASSIGN "/="
211 %token OP_MOD_ASSIGN "%="
212 %token OP_ADD_ASSIGN "+="
213 %token OP_SUB_ASSIGN "-="
214 %token OP_SHIFT_LEFT_ASSIGN "<<="
215 %token OP_SHIFT_RIGHT_ASSIGN ">>="
216 %token OP_AND_ASSIGN "&="
217 %token OP_XOR_ASSIGN "^="
218 %token OP_OR_ASSIGN "|="
222 %token LITERAL_INTEGER "int literal"
223 %token LITERAL_FLOAT "float literal"
224 %token LITERAL_DOUBLE "double literal"
225 %token LITERAL_DECIMAL "decimal literal"
226 %token LITERAL_CHARACTER "character literal"
227 %token LITERAL_STRING "string literal"
231 /* Add precedence rules to solve dangling else s/r conflict */
240 %left OP_SHIFT_LEFT OP_SHIFT_RIGHT
242 %left STAR DIV PERCENT
243 %right BANG CARRET UMINUS
244 %nonassoc OP_INC OP_DEC
246 %left OPEN_BRACKET OPEN_BRACE
250 %start compilation_unit
251 /*%start namespace_declaration */
255 : opt_using_directives opt_namespace_member_declarations opt_EOF
257 // Check that using comes only before namespace elements
268 | using_directives using_directive
272 : using_alias_directive
273 | using_namespace_directive
276 using_alias_directive
277 : USING IDENTIFIER ASSIGN
278 namespace_or_type_name SEMICOLON
280 current_namespace.UsingAlias ((string) $2, (string) $4);
284 using_namespace_directive
285 : USING namespace_name SEMICOLON
287 current_namespace.Using ((string) $2);
291 // namespace_declarations
292 // : namespace_declaration
293 // | namespace_declarations namespace_declaration
295 namespace_declaration
296 : NAMESPACE qualified_identifier
298 current_namespace = RootContext.Tree.RecordNamespace (current_namespace, name, (string) $2);
300 namespace_body opt_semicolon
302 current_namespace = current_namespace.Parent;
318 | qualified_identifier DOT IDENTIFIER {
319 $$ = (($1).ToString ()) + "." + ($3.ToString ()); }
324 : namespace_or_type_name
330 opt_namespace_member_declarations
341 opt_namespace_member_declarations
343 | namespace_member_declarations
346 namespace_member_declarations
347 : namespace_member_declaration
348 | namespace_member_declarations namespace_member_declaration
351 namespace_member_declaration
358 Class c = (Class) $1;
359 mod_flags = c.ModFlags;
361 } else if ($1 is Struct){
362 Struct s = (Struct) $1;
363 mod_flags = s.ModFlags;
368 if ((mod_flags & (Modifiers.PRIVATE|Modifiers.PROTECTED)) != 0){
369 error (1527, "Namespace elements cant be explicitly " +
370 "declared private or protected in `" + name + "'");
373 | namespace_declaration
379 | interface_declaration
381 | delegate_declaration
388 : /* empty */ { $$ = null; }
389 | attribute_section opt_attributes
394 attrs = (Attributes) $2;
395 attrs.AddAttribute ((AttributeSection) $1);
397 attrs = new Attributes ((AttributeSection) $1);
404 : OPEN_BRACKET attribute_target_specifier attribute_list CLOSE_BRACKET
406 string target = null;
409 target = (string) $2;
411 $$ = new AttributeSection (target, (ArrayList) $3);
413 | OPEN_BRACKET attribute_list CLOSE_BRACKET
415 $$ = new AttributeSection (null, (ArrayList) $2);
419 attribute_target_specifier
420 : attribute_target COLON
429 CheckAttributeTarget ((string) $1);
432 | EVENT { $$ = "event"; }
433 | RETURN { $$ = "return"; }
439 ArrayList attrs = new ArrayList ();
445 | attribute_list COMMA attribute
447 ArrayList attrs = (ArrayList) $1;
459 opt_attribute_arguments
461 $$ = new Attribute ((string) $1, (ArrayList) $3, (Location) $2);
466 : type_name { /* reserved attribute name or identifier: 17.4 */ }
469 opt_attribute_arguments
470 : /* empty */ { $$ = null; }
471 | OPEN_PARENS attribute_arguments CLOSE_PARENS
479 : positional_argument_list
481 ArrayList args = new ArrayList ();
486 | positional_argument_list COMMA named_argument_list
488 ArrayList args = new ArrayList ();
494 | named_argument_list
496 ArrayList args = new ArrayList ();
505 positional_argument_list
508 ArrayList args = new ArrayList ();
509 args.Add (new Argument ((Expression) $1, Argument.AType.Expression));
513 | positional_argument_list COMMA expression
515 ArrayList args = (ArrayList) $1;
516 args.Add (new Argument ((Expression) $3, Argument.AType.Expression));
525 ArrayList args = new ArrayList ();
530 | named_argument_list COMMA named_argument
532 ArrayList args = (ArrayList) $1;
540 : IDENTIFIER ASSIGN expression
542 $$ = new DictionaryEntry (
544 new Argument ((Expression) $3, Argument.AType.Expression));
550 : OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
553 opt_class_member_declarations
555 | class_member_declarations
558 class_member_declarations
559 : class_member_declaration
560 | class_member_declarations
561 class_member_declaration
564 class_member_declaration
565 : constant_declaration // done
566 | field_declaration // done
567 | method_declaration // done
568 | property_declaration // done
569 | event_declaration // done
570 | indexer_declaration // done
571 | operator_declaration // done
572 | constructor_declaration // done
573 | destructor_declaration // done
583 string full_struct_name = MakeName ((string) $4);
585 new_struct = new Struct (current_container, full_struct_name, (int) $2,
586 (Attributes) $1, lexer.Location);
587 current_container = new_struct;
588 current_container.Namespace = current_namespace;
589 RootContext.Tree.RecordStruct (full_struct_name, new_struct);
591 opt_struct_interfaces
595 Struct new_struct = (Struct) current_container;
597 current_container = current_container.Parent;
598 CheckDef (current_container.AddStruct (new_struct), new_struct.Name);
603 opt_struct_interfaces
610 | struct_interfaces struct_interface
618 : OPEN_BRACE opt_struct_member_declarations CLOSE_BRACE
621 opt_struct_member_declarations
623 | struct_member_declarations
626 struct_member_declarations
627 : struct_member_declaration
628 | struct_member_declarations struct_member_declaration
631 struct_member_declaration
632 : constant_declaration
635 | property_declaration
637 | indexer_declaration
638 | operator_declaration
639 | constructor_declaration
643 * This is only included so we can flag error 575:
644 * destructors only allowed on class types
646 | destructor_declaration
657 foreach (VariableDeclaration constant in (ArrayList) $5){
658 Const c = new Const (
659 (string) $4, (string) constant.identifier,
660 (Expression) constant.expression_or_array_initializer, (int) $2, (Attributes) $1,
663 CheckDef (current_container.AddConstant (c), c.Name);
669 : constant_declarator
671 ArrayList constants = new ArrayList ();
675 | constant_declarators COMMA constant_declarator
677 ArrayList constants = (ArrayList) $1;
684 : IDENTIFIER ASSIGN constant_expression
686 $$ = new VariableDeclaration ((string) $1, $3, lexer.Location);
697 string type = (string) $3;
700 foreach (VariableDeclaration var in (ArrayList) $4){
701 Field field = new Field (type, mod, var.identifier,
702 var.expression_or_array_initializer, (Attributes) $1, var.Location);
704 CheckDef (current_container.AddField (field), field.Name);
710 : variable_declarator
712 ArrayList decl = new ArrayList ();
716 | variable_declarators COMMA variable_declarator
718 ArrayList decls = (ArrayList) $1;
725 : IDENTIFIER ASSIGN variable_initializer
727 $$ = new VariableDeclaration ((string) $1, $3, lexer.Location);
731 $$ = new VariableDeclaration ((string) $1, null, lexer.Location);
750 Method method = (Method) $1;
751 Block b = (Block) $2;
754 if ((method.ModFlags & (Modifiers.EXTERN | Modifiers.ABSTRACT)) == 0){
756 501, lexer.Location, "`" +
757 current_container.Name + "." + method.Name + "'" +
758 "must declare a body because it is not marked abstract or extern");
762 method.Block = (Block) $2;
763 CheckDef (current_container.AddMethod (method), method.Name);
765 current_local_parameters = null;
779 1585, lexer.Location, "Member modifier `" +
780 Modifiers.Name (i) + "' must precede member type and name");
793 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
795 Method method = new Method ((string) $3, (int) $2, (string) $4,
796 (Parameters) $6, (Attributes) $1, lexer.Location);
798 current_local_parameters = (Parameters) $6;
806 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
808 Method method = new Method ("System.Void", (int) $2, (string) $4,
809 (Parameters) $6, (Attributes) $1, lexer.Location);
811 current_local_parameters = (Parameters) $6;
818 | SEMICOLON { $$ = null; }
821 opt_formal_parameter_list
822 : /* empty */ { $$ = Parameters.GetEmptyReadOnlyParameters (); }
823 | formal_parameter_list
826 formal_parameter_list
829 ArrayList pars_list = (ArrayList) $1;
831 Parameter [] pars = new Parameter [pars_list.Count];
832 pars_list.CopyTo (pars);
834 $$ = new Parameters (pars, null, lexer.Location);
836 | fixed_parameters COMMA parameter_array
838 ArrayList pars_list = (ArrayList) $1;
840 Parameter [] pars = new Parameter [pars_list.Count];
841 pars_list.CopyTo (pars);
843 $$ = new Parameters (pars, (Parameter) $3, lexer.Location);
847 $$ = new Parameters (null, (Parameter) $1, lexer.Location);
854 ArrayList pars = new ArrayList ();
859 | fixed_parameters COMMA fixed_parameter
861 ArrayList pars = (ArrayList) $1;
870 opt_parameter_modifier
874 $$ = new Parameter ((string) $3, (string) $4, (Parameter.Modifier) $2, (Attributes) $1);
878 opt_parameter_modifier
879 : /* empty */ { $$ = Parameter.Modifier.NONE; }
884 : REF { $$ = Parameter.Modifier.REF; }
885 | OUT { $$ = Parameter.Modifier.OUT; }
889 : opt_attributes PARAMS type IDENTIFIER
891 $$ = new Parameter ((string) $3, (string) $4, Parameter.Modifier.PARAMS, (Attributes) $1);
892 note ("type must be a single-dimension array type");
897 : qualified_identifier
906 implicit_value_parameter_type = (string) $3;
908 lexer.PropertyParsing = true;
912 accessor_declarations
914 lexer.PropertyParsing = false;
919 Pair pair = (Pair) $7;
920 Block get_block = null;
921 Block set_block = null;
923 if (pair.First != null)
924 get_block = (Block) pair.First;
925 if (pair.Second != null)
926 set_block = (Block) pair.Second;
928 prop = new Property ((string) $3, (string) $4, (int) $2, get_block, set_block,
929 (Attributes) $1, (Location) $6);
931 CheckDef (current_container.AddProperty (prop), prop.Name);
932 implicit_value_parameter_type = null;
936 accessor_declarations
937 : get_accessor_declaration opt_set_accessor_declaration
939 $$ = new Pair ($1, $2);
941 | set_accessor_declaration opt_get_accessor_declaration
943 $$ = new Pair ($2, $1);
947 opt_get_accessor_declaration
948 : /* empty */ { $$ = null; }
949 | get_accessor_declaration
952 opt_set_accessor_declaration
953 : /* empty */ { $$ = null; }
954 | set_accessor_declaration
957 get_accessor_declaration
960 // If this is not the case, then current_local_parameters has already
961 // been set in indexer_declaration
962 if (parsing_indexer == false)
963 current_local_parameters = null;
965 current_local_parameters = indexer_parameters;
966 lexer.PropertyParsing = false;
971 current_local_parameters = null;
972 lexer.PropertyParsing = true;
976 set_accessor_declaration
980 Parameter implicit_value_parameter = new Parameter (
981 implicit_value_parameter_type, "value",
982 Parameter.Modifier.NONE, null);
984 if (parsing_indexer == false) {
985 args = new Parameter [1];
986 args [0] = implicit_value_parameter;
988 Parameter [] fp = indexer_parameters.FixedParameters;
989 int count = fp.Length;
991 args = new Parameter [count + 1];
994 args [count] = implicit_value_parameter;
997 current_local_parameters = new Parameters (args, null, lexer.Location);
998 lexer.PropertyParsing = false;
1003 current_local_parameters = null;
1004 lexer.PropertyParsing = true;
1010 | SEMICOLON { $$ = new Block (null); }
1013 interface_declaration
1016 INTERFACE IDENTIFIER
1018 Interface new_interface;
1019 string full_interface_name = MakeName ((string) $4);
1021 new_interface = new Interface (current_container, full_interface_name, (int) $2,
1022 (Attributes) $1, lexer.Location);
1023 if (current_interface != null) {
1024 Location l = lexer.Location;
1025 Report.Error (-2, l, "Internal compiler error: interface inside interface");
1027 current_interface = new_interface;
1028 new_interface.Namespace = current_namespace;
1029 RootContext.Tree.RecordInterface (full_interface_name, new_interface);
1034 Interface new_interface = (Interface) current_interface;
1037 new_interface.Bases = (ArrayList) $6;
1039 current_interface = null;
1040 CheckDef (current_container.AddInterface (new_interface), new_interface.Name);
1045 : /* empty */ { $$ = null; }
1050 : COLON interface_type_list { $$ = $2; }
1056 ArrayList interfaces = new ArrayList ();
1058 interfaces.Add ($1);
1061 | interface_type_list COMMA interface_type
1063 ArrayList interfaces = (ArrayList) $1;
1064 interfaces.Add ($3);
1071 opt_interface_member_declarations
1075 opt_interface_member_declarations
1077 | interface_member_declarations
1080 interface_member_declarations
1081 : interface_member_declaration
1082 | interface_member_declarations interface_member_declaration
1085 interface_member_declaration
1086 : interface_method_declaration
1088 InterfaceMethod m = (InterfaceMethod) $1;
1090 CheckDef (current_interface.AddMethod (m), m.Name);
1092 | interface_property_declaration
1094 InterfaceProperty p = (InterfaceProperty) $1;
1096 CheckDef (current_interface.AddProperty (p), p.Name);
1098 | interface_event_declaration
1100 InterfaceEvent e = (InterfaceEvent) $1;
1102 CheckDef (current_interface.AddEvent (e), e.Name);
1104 | interface_indexer_declaration
1106 InterfaceIndexer i = (InterfaceIndexer) $1;
1108 CheckDef (current_interface.AddIndexer (i), "indexer");
1113 : /* empty */ { $$ = false; }
1114 | NEW { $$ = true; }
1117 interface_method_declaration
1118 : opt_attributes opt_new type IDENTIFIER
1119 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1122 $$ = new InterfaceMethod ((string) $3, (string) $4, (bool) $2,
1123 (Parameters) $6, (Attributes) $1, lexer.Location);
1125 | opt_attributes opt_new VOID IDENTIFIER
1126 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1129 $$ = new InterfaceMethod ("System.Void", (string) $4, (bool) $2, (Parameters) $6,
1130 (Attributes) $1, lexer.Location);
1134 interface_property_declaration
1139 { lexer.PropertyParsing = true; }
1141 { lexer.PropertyParsing = false; }
1146 $$ = new InterfaceProperty ((string) $3, (string) $4, (bool) $2,
1147 (gs & 1) == 1, (gs & 2) == 2, (Attributes) $1,
1153 : opt_attributes GET SEMICOLON { $$ = 1; }
1154 | opt_attributes SET SEMICOLON { $$ = 2; }
1155 | opt_attributes GET SEMICOLON opt_attributes SET SEMICOLON
1157 | opt_attributes SET SEMICOLON opt_attributes GET SEMICOLON
1161 interface_event_declaration
1162 : opt_attributes opt_new EVENT type IDENTIFIER SEMICOLON
1164 $$ = new InterfaceEvent ((string) $4, (string) $5, (bool) $2, (Attributes) $1);
1168 interface_indexer_declaration
1169 : opt_attributes opt_new type THIS
1170 OPEN_BRACKET formal_parameter_list CLOSE_BRACKET
1172 { lexer.PropertyParsing = true; }
1174 { lexer.PropertyParsing = false; }
1177 int a_flags = (int) $10;
1179 bool do_get = (a_flags & 1) == 1;
1180 bool do_set = (a_flags & 2) == 2;
1182 $$ = new InterfaceIndexer ((string) $3, (Parameters) $6, do_get, do_set,
1183 (bool) $2, (Attributes) $1, lexer.Location);
1187 operator_declaration
1188 : opt_attributes opt_modifiers operator_declarator block
1190 OperatorDeclaration decl = (OperatorDeclaration) $3;
1192 Operator op = new Operator (decl.optype, decl.ret_type, (int) $2, decl.arg1type, decl.arg1name,
1193 decl.arg2type, decl.arg2name, (Block) $4, (Attributes) $1, decl.location);
1195 // Note again, checking is done in semantic analysis
1196 current_container.AddOperator (op);
1198 current_local_parameters = null;
1203 : type OPERATOR overloadable_operator
1204 OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1206 Operator.OpType op = (Operator.OpType) $3;
1207 CheckUnaryOperator (op);
1209 if (op == Operator.OpType.Addition)
1210 op = Operator.OpType.UnaryPlus;
1212 if (op == Operator.OpType.Subtraction)
1213 op = Operator.OpType.UnaryNegation;
1215 Parameter [] pars = new Parameter [1];
1217 pars [0] = new Parameter ((string) $5, (string) $6, Parameter.Modifier.NONE, null);
1219 current_local_parameters = new Parameters (pars, null, lexer.Location);
1221 $$ = new OperatorDeclaration (op, (string) $1, (string) $5, (string) $6,
1222 null, null, lexer.Location);
1224 | type OPERATOR overloadable_operator
1226 type IDENTIFIER COMMA
1230 CheckBinaryOperator ((Operator.OpType) $3);
1232 Parameter [] pars = new Parameter [2];
1234 pars [0] = new Parameter ((string) $5, (string) $6, Parameter.Modifier.NONE, null);
1235 pars [1] = new Parameter ((string) $8, (string) $9, Parameter.Modifier.NONE, null);
1237 current_local_parameters = new Parameters (pars, null, lexer.Location);
1239 $$ = new OperatorDeclaration ((Operator.OpType) $3, (string) $1, (string) $5, (string) $6,
1240 (string) $8, (string) $9, lexer.Location);
1242 | conversion_operator_declarator
1245 overloadable_operator
1247 : BANG { $$ = Operator.OpType.LogicalNot; }
1248 | TILDE { $$ = Operator.OpType.OnesComplement; }
1249 | OP_INC { $$ = Operator.OpType.Increment; }
1250 | OP_DEC { $$ = Operator.OpType.Decrement; }
1251 | TRUE { $$ = Operator.OpType.True; }
1252 | FALSE { $$ = Operator.OpType.False; }
1253 // Unary and binary:
1254 | PLUS { $$ = Operator.OpType.Addition; }
1255 | MINUS { $$ = Operator.OpType.Subtraction; }
1257 | STAR { $$ = Operator.OpType.Multiply; }
1258 | DIV { $$ = Operator.OpType.Division; }
1259 | PERCENT { $$ = Operator.OpType.Modulus; }
1260 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
1261 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
1262 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
1263 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
1264 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
1265 | OP_EQ { $$ = Operator.OpType.Equality; }
1266 | OP_NE { $$ = Operator.OpType.Inequality; }
1267 | OP_GT { $$ = Operator.OpType.GreaterThan; }
1268 | OP_LT { $$ = Operator.OpType.LessThan; }
1269 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
1270 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
1273 conversion_operator_declarator
1274 : IMPLICIT OPERATOR type OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1276 Parameter [] pars = new Parameter [1];
1278 pars [0] = new Parameter ((string) $5, (string) $6, Parameter.Modifier.NONE, null);
1280 current_local_parameters = new Parameters (pars, null, lexer.Location);
1282 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (string) $3, (string) $5, (string) $6,
1283 null, null, lexer.Location);
1285 | EXPLICIT OPERATOR type OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1287 Parameter [] pars = new Parameter [1];
1289 pars [0] = new Parameter ((string) $5, (string) $6, Parameter.Modifier.NONE, null);
1291 current_local_parameters = new Parameters (pars, null, lexer.Location);
1293 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (string) $3, (string) $5, (string) $6,
1294 null, null, lexer.Location);
1298 syntax_error (lexer.Location, "'operator' expected");
1302 syntax_error (lexer.Location, "'operator' expected");
1306 constructor_declaration
1309 constructor_declarator
1312 Constructor c = (Constructor) $3;
1313 c.Block = (Block) $4;
1314 c.ModFlags = (int) $2;
1315 c.OptAttributes = (Attributes) $1;
1317 if ((c.ModFlags & Modifiers.STATIC) != 0){
1318 if ((c.ModFlags & Modifiers.Accessibility) != 0) {
1319 Location l = lexer.Location;
1320 Report.Error (515, l, "Access modifiers are not allowed on static constructors");
1323 if (c.Initializer != null){
1324 Location l = lexer.Location;
1325 Report.Error (514, l, "Static constructors can not have an explicit this or base constructor invocations");
1328 if (!c.Parameters.Empty){
1329 Location l = lexer.Location;
1330 Report.Error (132, l, "Static constructors should not have parameters");
1334 CheckDef (current_container.AddConstructor (c), c.Name);
1336 current_local_parameters = null;
1340 constructor_declarator
1342 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1344 oob_stack.Push (lexer.Location);
1346 current_local_parameters = (Parameters) $3;
1348 opt_constructor_initializer
1350 Location l = (Location) oob_stack.Pop ();
1351 $$ = new Constructor ((string) $1, (Parameters) $3, (ConstructorInitializer) $6, l);
1355 opt_constructor_initializer
1356 : /* empty */ { $$ = null; }
1357 | constructor_initializer
1360 constructor_initializer
1361 : COLON BASE OPEN_PARENS opt_argument_list CLOSE_PARENS
1363 $$ = new ConstructorBaseInitializer ((ArrayList) $4, lexer.Location);
1365 | COLON THIS OPEN_PARENS opt_argument_list CLOSE_PARENS
1367 $$ = new ConstructorThisInitializer ((ArrayList) $4, lexer.Location);
1371 destructor_declaration
1372 : opt_attributes TILDE IDENTIFIER OPEN_PARENS CLOSE_PARENS block
1374 if ((string) $3 != current_container.Basename){
1375 Report.Error (574, lexer.Location, "Name of destructor must match name of class");
1376 } else if (!(current_container is Class)){
1377 Report.Error (575, lexer.Location, "Destructors are only allowed in class types");
1379 Location l = lexer.Location;
1381 Method d = new Method (
1382 "System.Void", 0, "Finalize",
1383 new Parameters (null, null, l), (Attributes) $1, l);
1385 d.Block = (Block) $6;
1386 CheckDef (current_container.AddMethod (d), d.Name);
1394 EVENT type variable_declarators SEMICOLON
1396 foreach (VariableDeclaration var in (ArrayList) $5) {
1398 Event e = new Event ((string) $4, var.identifier, var.expression_or_array_initializer,
1399 (int) $2, null, null, (Attributes) $1, lexer.Location);
1401 CheckDef (current_container.AddEvent (e), e.Name);
1407 EVENT type member_name
1410 implicit_value_parameter_type = (string) $4;
1411 lexer.EventParsing = true;
1413 event_accessor_declarations
1415 lexer.EventParsing = false;
1419 Pair pair = (Pair) $8;
1420 Block add_block = null;
1421 Block rem_block = null;
1423 if (pair.First != null)
1424 add_block = (Block) pair.First;
1425 if (pair.Second != null)
1426 rem_block = (Block) pair.Second;
1428 Event e = new Event ((string) $4, (string) $5, null, (int) $2, add_block, rem_block,
1429 (Attributes) $1, lexer.Location);
1431 CheckDef (current_container.AddEvent (e), e.Name);
1432 implicit_value_parameter_type = null;
1436 event_accessor_declarations
1437 : add_accessor_declaration remove_accessor_declaration
1439 $$ = new Pair ($1, $2);
1441 | remove_accessor_declaration add_accessor_declaration
1443 $$ = new Pair ($2, $1);
1447 add_accessor_declaration
1448 : opt_attributes ADD
1450 Parameter [] args = new Parameter [1];
1451 Parameter implicit_value_parameter = new Parameter (
1452 implicit_value_parameter_type, "value",
1453 Parameter.Modifier.NONE, null);
1455 args [0] = implicit_value_parameter;
1457 current_local_parameters = new Parameters (args, null, lexer.Location);
1458 lexer.EventParsing = false;
1463 lexer.EventParsing = true;
1467 remove_accessor_declaration
1468 : opt_attributes REMOVE
1470 Parameter [] args = new Parameter [1];
1471 Parameter implicit_value_parameter = new Parameter (
1472 implicit_value_parameter_type, "value",
1473 Parameter.Modifier.NONE, null);
1475 args [0] = implicit_value_parameter;
1477 current_local_parameters = new Parameters (args, null, lexer.Location);
1478 lexer.EventParsing = false;
1483 lexer.EventParsing = true;
1488 : opt_attributes opt_modifiers indexer_declarator
1491 IndexerDeclaration decl = (IndexerDeclaration) $3;
1493 implicit_value_parameter_type = decl.type;
1495 lexer.PropertyParsing = true;
1496 parsing_indexer = true;
1498 indexer_parameters = decl.param_list;
1499 $$ = lexer.Location;
1501 accessor_declarations
1503 lexer.PropertyParsing = false;
1504 parsing_indexer = false;
1508 // The signature is computed from the signature of the indexer. Look
1509 // at section 3.6 on the spec
1512 IndexerDeclaration decl = (IndexerDeclaration) $3;
1513 Pair pair = (Pair) $6;
1514 Block get_block = null;
1515 Block set_block = null;
1517 if (pair.First != null)
1518 get_block = (Block) pair.First;
1519 if (pair.Second != null)
1520 set_block = (Block) pair.Second;
1522 indexer = new Indexer (decl.type, decl.interface_type, (int) $2, decl.param_list,
1523 get_block, set_block, (Attributes) $1, (Location) $5);
1525 // Note that there is no equivalent of CheckDef for this case
1526 // We shall handle this in semantic analysis
1528 current_container.AddIndexer (indexer);
1530 current_local_parameters = null;
1531 implicit_value_parameter_type = null;
1532 indexer_parameters = null;
1537 : type THIS OPEN_BRACKET formal_parameter_list CLOSE_BRACKET
1539 $$ = new IndexerDeclaration ((string) $1, null, (Parameters) $4);
1541 | type qualified_identifier DOT THIS OPEN_BRACKET formal_parameter_list CLOSE_BRACKET
1543 $$ = new IndexerDeclaration ((string) $1, (string) $2, (Parameters) $6);
1555 string full_name = MakeName ((string) $4);
1556 Enum e = new Enum ((string) $5, (int) $2, full_name, (Attributes) $1, lexer.Location);
1558 foreach (VariableDeclaration ev in (ArrayList) $6){
1559 CheckDef (e.AddEnumMember (ev.identifier,
1560 (Expression) ev.expression_or_array_initializer,
1561 (Location) ev.Location),
1565 CheckDef (current_container.AddEnum (e), name);
1570 : /* empty */ { $$ = "System.Int32"; }
1571 | COLON type { $$ = $2; }
1575 : OPEN_BRACE opt_enum_member_declarations CLOSE_BRACE
1581 opt_enum_member_declarations
1582 : /* empty */ { $$ = new ArrayList (); }
1583 | enum_member_declarations opt_comma { $$ = $1; }
1586 enum_member_declarations
1587 : enum_member_declaration
1589 ArrayList l = new ArrayList ();
1594 | enum_member_declarations COMMA enum_member_declaration
1596 ArrayList l = (ArrayList) $1;
1604 enum_member_declaration
1605 : opt_attributes IDENTIFIER
1607 $$ = new VariableDeclaration ((string) $2, null, lexer.Location);
1609 | opt_attributes IDENTIFIER
1611 $$ = lexer.Location;
1615 $$ = new VariableDeclaration ((string) $2, $5, lexer.Location);
1619 delegate_declaration
1623 IDENTIFIER OPEN_PARENS
1624 opt_formal_parameter_list
1628 Delegate del = new Delegate ((string) $4, (int) $2,
1629 MakeName ((string) $5), (Parameters) $7,
1630 (Attributes) $1, lexer.Location);
1632 CheckDef (current_container.AddDelegate (del), del.Name);
1637 IDENTIFIER OPEN_PARENS
1638 opt_formal_parameter_list
1642 Delegate del = new Delegate ("System.Void", (int) $2, (string) $5, (Parameters) $7,
1643 (Attributes) $1, lexer.Location);
1645 CheckDef (current_container.AddDelegate (del), del.Name);
1650 : namespace_or_type_name
1653 namespace_or_type_name
1654 : qualified_identifier
1658 * Before you think of adding a return_type, notice that we have been
1659 * using two rules in the places where it matters (one rule using type
1660 * and another identical one that uses VOID as the return type). This
1661 * gets rid of a shift/reduce couple
1664 : type_name { /* class_type */
1666 This does interfaces, delegates, struct_types, class_types,
1667 parent classes, and more! 4.2
1678 $$ = new SimpleName ((string) $1, lexer.Location);
1680 | non_expression_type rank_specifier
1682 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
1684 | expression rank_specifiers
1686 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
1693 ArrayList types = new ArrayList ();
1698 | type_list COMMA type
1700 ArrayList types = (ArrayList) $1;
1708 * replaces all the productions for isolating the various
1709 * simple types, but we need this to reuse it easily in local_variable_type
1712 : OBJECT { $$ = "System.Object"; }
1713 | STRING { $$ = "System.String"; }
1714 | BOOL { $$ = "System.Boolean"; }
1715 | DECIMAL { $$ = "System.Decimal"; }
1716 | FLOAT { $$ = "System.Single"; }
1717 | DOUBLE { $$ = "System.Double"; }
1722 : SBYTE { $$ = "System.SByte"; }
1723 | BYTE { $$ = "System.Byte"; }
1724 | SHORT { $$ = "System.Int16"; }
1725 | USHORT { $$ = "System.UInt16"; }
1726 | INT { $$ = "System.Int32"; }
1727 | UINT { $$ = "System.UInt32"; }
1728 | LONG { $$ = "System.Int64"; }
1729 | ULONG { $$ = "System.UInt64"; }
1730 | CHAR { $$ = "System.Char"; }
1738 : type rank_specifiers
1740 $$ = (string) $1 + (string) $2;
1745 // Expressions, section 7.5
1753 | qualified_identifier
1755 string name = (string) $1;
1758 $$ = DecomposeQI (name, lexer.Location);
1760 | parenthesized_expression
1762 | invocation_expression
1766 | post_increment_expression
1767 | post_decrement_expression
1771 | checked_expression
1772 | unchecked_expression
1779 | LITERAL_CHARACTER { $$ = new CharLiteral ((char) lexer.Value); }
1780 | LITERAL_STRING { $$ = new StringLiteral ((string) lexer.Value); }
1781 | NULL { $$ = NullLiteral.Null; }
1785 : LITERAL_FLOAT { $$ = new FloatLiteral ((float) lexer.Value); }
1786 | LITERAL_DOUBLE { $$ = new DoubleLiteral ((double) lexer.Value); }
1787 | LITERAL_DECIMAL { $$ = new DecimalLiteral ((decimal) lexer.Value); }
1792 object v = lexer.Value;
1795 // FIXME: Possible optimization would be to
1796 // compute the *Literal objects directly in the scanner
1799 $$ = new IntLiteral ((Int32) v);
1801 $$ = new UIntLiteral ((UInt32) v);
1803 $$ = new LongLiteral ((Int64) v);
1804 else if (v is ulong)
1805 $$ = new ULongLiteral ((UInt64) v);
1807 Console.WriteLine ("OOPS. Unexpected result from scanner");
1812 : TRUE { $$ = new BoolLiteral (true); }
1813 | FALSE { $$ = new BoolLiteral (false); }
1816 parenthesized_expression
1817 : OPEN_PARENS expression CLOSE_PARENS
1822 : primary_expression DOT IDENTIFIER
1824 $$ = new MemberAccess ((Expression) $1, (string) $3, lexer.Location);
1826 | predefined_type DOT IDENTIFIER
1828 $$ = new SimpleName ((string) $1 + "." + (string) $3, lexer.Location);
1836 invocation_expression
1837 : primary_expression OPEN_PARENS opt_argument_list CLOSE_PARENS
1840 Location l = lexer.Location;
1841 Report.Error (1, l, "THIS IS CRAZY");
1843 $$ = new Invocation ((Expression) $1, (ArrayList) $3, lexer.Location);
1848 : /* empty */ { $$ = null; }
1855 ArrayList list = new ArrayList ();
1859 | argument_list COMMA argument
1861 ArrayList list = (ArrayList) $1;
1870 $$ = new Argument ((Expression) $1, Argument.AType.Expression);
1872 | REF variable_reference
1874 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
1876 | OUT variable_reference
1878 $$ = new Argument ((Expression) $2, Argument.AType.Out);
1883 : expression { note ("section 5.4"); $$ = $1; }
1887 : primary_expression OPEN_BRACKET expression_list CLOSE_BRACKET
1889 $$ = new ElementAccess ((Expression) $1, (ArrayList) $3, lexer.Location);
1891 | primary_expression rank_specifiers
1893 // So the super-trick is that primary_expression
1894 // can only be either a SimpleName or a MemberAccess.
1895 // The MemberAccess case arises when you have a fully qualified type-name like :
1897 // SimpleName is when you have
1900 Expression expr = (Expression) $1;
1901 if (!(expr is SimpleName || expr is MemberAccess)) {
1902 Location l = lexer.Location;
1903 Report.Error (-1, l, "Invalid Type definition");
1904 $$ = "System.Object";
1908 // So we extract the string corresponding to the SimpleName
1911 $$ = new SimpleName (GetQualifiedIdentifier (expr) + (string) $2, lexer.Location);
1918 ArrayList list = new ArrayList ();
1922 | expression_list COMMA expression
1924 ArrayList list = (ArrayList) $1;
1933 $$ = new This (lexer.Location);
1938 : BASE DOT IDENTIFIER
1940 $$ = new BaseAccess ((string) $3, lexer.Location);
1942 | BASE OPEN_BRACKET expression_list CLOSE_BRACKET
1944 $$ = new BaseIndexerAccess ((ArrayList) $3, lexer.Location);
1948 post_increment_expression
1949 : primary_expression OP_INC
1951 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement,
1952 (Expression) $1, lexer.Location);
1956 post_decrement_expression
1957 : primary_expression OP_DEC
1959 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement,
1960 (Expression) $1, lexer.Location);
1965 : object_or_delegate_creation_expression
1966 | array_creation_expression
1969 object_or_delegate_creation_expression
1970 : NEW type OPEN_PARENS opt_argument_list CLOSE_PARENS
1972 $$ = new New ((string) $2, (ArrayList) $4, lexer.Location);
1976 array_creation_expression
1977 : NEW type OPEN_BRACKET expression_list CLOSE_BRACKET
1979 opt_array_initializer
1981 $$ = new ArrayCreation ((string) $2, (ArrayList) $4, (string) $6, (ArrayList) $7,
1984 | NEW type rank_specifiers array_initializer
1986 $$ = new ArrayCreation ((string) $2, (string) $3, (ArrayList) $4, lexer.Location);
2006 | rank_specifiers rank_specifier
2008 $$ = (string) $2 + (string) $1;
2013 : OPEN_BRACKET opt_dim_separators CLOSE_BRACKET
2015 $$ = "[" + (string) $2 + "]";
2035 | dim_separators COMMA
2037 $$ = (string) $1 + ",";
2041 opt_array_initializer
2053 : OPEN_BRACE CLOSE_BRACE
2055 ArrayList list = new ArrayList ();
2058 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
2060 $$ = (ArrayList) $2;
2064 variable_initializer_list
2065 : variable_initializer
2067 ArrayList list = new ArrayList ();
2071 | variable_initializer_list COMMA variable_initializer
2073 ArrayList list = (ArrayList) $1;
2080 : TYPEOF OPEN_PARENS type CLOSE_PARENS
2082 $$ = new TypeOf ((string) $3, lexer.Location);
2087 : SIZEOF OPEN_PARENS type CLOSE_PARENS {
2088 $$ = new SizeOf ((string) $3);
2090 note ("Verify type is unmanaged");
2091 note ("if (5.8) builtin, yield constant expression");
2096 : CHECKED OPEN_PARENS expression CLOSE_PARENS
2098 $$ = new CheckedExpr ((Expression) $3);
2102 unchecked_expression
2103 : UNCHECKED OPEN_PARENS expression CLOSE_PARENS
2105 $$ = new UnCheckedExpr ((Expression) $3);
2110 : primary_expression
2111 | BANG prefixed_unary_expression
2113 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, lexer.Location);
2115 | TILDE prefixed_unary_expression
2117 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, lexer.Location);
2119 | OPEN_PARENS expression CLOSE_PARENS unary_expression
2121 $$ = new Cast ((Expression) $2, (Expression) $4, lexer.Location);
2123 | OPEN_PARENS non_expression_type CLOSE_PARENS prefixed_unary_expression
2125 $$ = new Cast ((Expression) $2, (Expression) $4, lexer.Location);
2130 // The idea to split this out is from Rhys' grammar
2131 // to solve the problem with casts.
2133 prefixed_unary_expression
2135 | PLUS prefixed_unary_expression
2137 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, lexer.Location);
2139 | MINUS prefixed_unary_expression
2141 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, lexer.Location);
2143 | OP_INC prefixed_unary_expression
2145 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
2146 (Expression) $2, lexer.Location);
2148 | OP_DEC prefixed_unary_expression
2150 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
2151 (Expression) $2, lexer.Location);
2153 | STAR prefixed_unary_expression
2155 $$ = new Unary (Unary.Operator.Indirection, (Expression) $2, lexer.Location);
2157 | BITWISE_AND prefixed_unary_expression
2159 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, lexer.Location);
2163 pre_increment_expression
2164 : OP_INC prefixed_unary_expression
2166 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
2167 (Expression) $2, lexer.Location);
2171 pre_decrement_expression
2172 : OP_DEC prefixed_unary_expression
2174 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
2175 (Expression) $2, lexer.Location);
2179 multiplicative_expression
2180 : prefixed_unary_expression
2181 | multiplicative_expression STAR prefixed_unary_expression
2183 $$ = new Binary (Binary.Operator.Multiply,
2184 (Expression) $1, (Expression) $3, lexer.Location);
2186 | multiplicative_expression DIV prefixed_unary_expression
2188 $$ = new Binary (Binary.Operator.Division,
2189 (Expression) $1, (Expression) $3, lexer.Location);
2191 | multiplicative_expression PERCENT prefixed_unary_expression
2193 $$ = new Binary (Binary.Operator.Modulus,
2194 (Expression) $1, (Expression) $3, lexer.Location);
2199 : multiplicative_expression
2200 | additive_expression PLUS multiplicative_expression
2202 $$ = new Binary (Binary.Operator.Addition,
2203 (Expression) $1, (Expression) $3, lexer.Location);
2205 | additive_expression MINUS multiplicative_expression
2207 $$ = new Binary (Binary.Operator.Subtraction,
2208 (Expression) $1, (Expression) $3, lexer.Location);
2213 : additive_expression
2214 | shift_expression OP_SHIFT_LEFT additive_expression
2216 $$ = new Binary (Binary.Operator.LeftShift,
2217 (Expression) $1, (Expression) $3, lexer.Location);
2219 | shift_expression OP_SHIFT_RIGHT additive_expression
2221 $$ = new Binary (Binary.Operator.RightShift,
2222 (Expression) $1, (Expression) $3, lexer.Location);
2226 relational_expression
2228 | relational_expression OP_LT shift_expression
2230 $$ = new Binary (Binary.Operator.LessThan,
2231 (Expression) $1, (Expression) $3, lexer.Location);
2233 | relational_expression OP_GT shift_expression
2235 $$ = new Binary (Binary.Operator.GreaterThan,
2236 (Expression) $1, (Expression) $3, lexer.Location);
2238 | relational_expression OP_LE shift_expression
2240 $$ = new Binary (Binary.Operator.LessThanOrEqual,
2241 (Expression) $1, (Expression) $3, lexer.Location);
2243 | relational_expression OP_GE shift_expression
2245 $$ = new Binary (Binary.Operator.GreaterThanOrEqual,
2246 (Expression) $1, (Expression) $3, lexer.Location);
2248 | relational_expression IS type
2250 $$ = new Is ((Expression) $1, (string) $3, lexer.Location);
2252 | relational_expression AS type
2254 $$ = new As ((Expression) $1, (string) $3, lexer.Location);
2259 : relational_expression
2260 | equality_expression OP_EQ relational_expression
2262 $$ = new Binary (Binary.Operator.Equality,
2263 (Expression) $1, (Expression) $3, lexer.Location);
2265 | equality_expression OP_NE relational_expression
2267 $$ = new Binary (Binary.Operator.Inequality,
2268 (Expression) $1, (Expression) $3, lexer.Location);
2273 : equality_expression
2274 | and_expression BITWISE_AND equality_expression
2276 $$ = new Binary (Binary.Operator.BitwiseAnd,
2277 (Expression) $1, (Expression) $3, lexer.Location);
2281 exclusive_or_expression
2283 | exclusive_or_expression CARRET and_expression
2285 $$ = new Binary (Binary.Operator.ExclusiveOr,
2286 (Expression) $1, (Expression) $3, lexer.Location);
2290 inclusive_or_expression
2291 : exclusive_or_expression
2292 | inclusive_or_expression BITWISE_OR exclusive_or_expression
2294 $$ = new Binary (Binary.Operator.BitwiseOr,
2295 (Expression) $1, (Expression) $3, lexer.Location);
2299 conditional_and_expression
2300 : inclusive_or_expression
2301 | conditional_and_expression OP_AND inclusive_or_expression
2303 $$ = new Binary (Binary.Operator.LogicalAnd,
2304 (Expression) $1, (Expression) $3, lexer.Location);
2308 conditional_or_expression
2309 : conditional_and_expression
2310 | conditional_or_expression OP_OR conditional_and_expression
2312 $$ = new Binary (Binary.Operator.LogicalOr,
2313 (Expression) $1, (Expression) $3, lexer.Location);
2317 conditional_expression
2318 : conditional_or_expression
2319 | conditional_or_expression INTERR expression COLON expression
2321 $$ = new Conditional ((Expression) $1, (Expression) $3, (Expression) $5, lexer.Location);
2325 assignment_expression
2326 : prefixed_unary_expression ASSIGN expression
2328 $$ = new Assign ((Expression) $1, (Expression) $3, lexer.Location);
2330 | prefixed_unary_expression OP_MULT_ASSIGN expression
2332 Location l = lexer.Location;
2334 $$ = new Assign ((Expression) $1,
2335 new Binary (Binary.Operator.Multiply,
2337 (Expression) $3, l), l);
2339 | prefixed_unary_expression OP_DIV_ASSIGN expression
2341 Location l = lexer.Location;
2343 $$ = new Assign ((Expression) $1,
2344 new Binary (Binary.Operator.Division,
2346 (Expression) $3, l), l);
2348 | prefixed_unary_expression OP_MOD_ASSIGN expression
2350 Location l = lexer.Location;
2352 $$ = new Assign ((Expression) $1,
2353 new Binary (Binary.Operator.Modulus,
2355 (Expression) $3, l), l);
2357 | prefixed_unary_expression OP_ADD_ASSIGN expression
2359 Location l = lexer.Location;
2361 $$ = new Assign ((Expression) $1,
2362 new Binary (Binary.Operator.Addition,
2364 (Expression) $3, l), l);
2366 | prefixed_unary_expression OP_SUB_ASSIGN expression
2368 Location l = lexer.Location;
2370 $$ = new Assign ((Expression) $1,
2371 new Binary (Binary.Operator.Subtraction,
2373 (Expression) $3, l), l);
2375 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
2377 Location l = lexer.Location;
2379 $$ = new Assign ((Expression) $1,
2380 new Binary (Binary.Operator.LeftShift,
2382 (Expression) $3, l), l);
2384 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
2386 Location l = lexer.Location;
2388 $$ = new Assign ((Expression) $1,
2389 new Binary (Binary.Operator.RightShift,
2391 (Expression) $3, l), l);
2393 | prefixed_unary_expression OP_AND_ASSIGN expression
2395 Location l = lexer.Location;
2397 $$ = new Assign ((Expression) $1,
2398 new Binary (Binary.Operator.BitwiseAnd,
2400 (Expression) $3, l), l);
2402 | prefixed_unary_expression OP_OR_ASSIGN expression
2404 Location l = lexer.Location;
2406 $$ = new Assign ((Expression) $1,
2407 new Binary (Binary.Operator.BitwiseOr,
2409 (Expression) $3, l), l);
2411 | prefixed_unary_expression OP_XOR_ASSIGN expression
2413 Location l = lexer.Location;
2415 $$ = new Assign ((Expression) $1,
2416 new Binary (Binary.Operator.ExclusiveOr,
2418 (Expression) $3, l), l);
2423 : conditional_expression
2424 | assignment_expression
2446 name = MakeName ((string) $4);
2448 new_class = new Class (current_container, name, (int) $2,
2449 (Attributes) $1, lexer.Location);
2450 current_container = new_class;
2451 current_container.Namespace = current_namespace;
2452 RootContext.Tree.RecordClass (name, new_class);
2458 Class new_class = (Class) current_container;
2461 new_class.Bases = (ArrayList) $6;
2463 current_container = current_container.Parent;
2464 CheckDef (current_container.AddClass (new_class), new_class.Name);
2471 : /* empty */ { $$ = (int) 0; }
2477 | modifiers modifier
2482 if ((m1 & m2) != 0) {
2483 Location l = lexer.Location;
2484 Report.Error (1004, l, "Duplicate modifier: `" + Modifiers.Name (m2) + "'");
2486 $$ = (int) (m1 | m2);
2491 : NEW { $$ = Modifiers.NEW; }
2492 | PUBLIC { $$ = Modifiers.PUBLIC; }
2493 | PROTECTED { $$ = Modifiers.PROTECTED; }
2494 | INTERNAL { $$ = Modifiers.INTERNAL; }
2495 | PRIVATE { $$ = Modifiers.PRIVATE; }
2496 | ABSTRACT { $$ = Modifiers.ABSTRACT; }
2497 | SEALED { $$ = Modifiers.SEALED; }
2498 | STATIC { $$ = Modifiers.STATIC; }
2499 | READONLY { $$ = Modifiers.READONLY; }
2500 | VIRTUAL { $$ = Modifiers.VIRTUAL; }
2501 | OVERRIDE { $$ = Modifiers.OVERRIDE; }
2502 | EXTERN { $$ = Modifiers.EXTERN; }
2506 : /* empty */ { $$ = null; }
2507 | class_base { $$ = $1; }
2511 : COLON type_list { $$ = $2; }
2519 // A block is "contained" on the following places:
2521 // property_declaration as part of the accessor body (get/set)
2522 // operator_declaration
2523 // constructor_declaration
2524 // destructor_declaration
2525 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
2530 current_block = new Block (current_block);
2532 opt_statement_list CLOSE_BRACE
2534 while (current_block.Implicit)
2535 current_block = current_block.Parent;
2537 current_block = current_block.Parent;
2548 | statement_list statement
2552 : declaration_statement
2554 if ((Block) $1 != current_block){
2555 current_block.AddStatement ((Statement) $1);
2556 current_block = (Block) $1;
2559 | embedded_statement
2561 Statement s = (Statement) $1;
2564 current_block.AddStatement ((Statement) $1);
2572 | expression_statement
2573 | selection_statement
2574 | iteration_statement
2578 | unchecked_statement
2586 $$ = new EmptyStatement ();
2593 LabeledStatement labeled = new LabeledStatement ((string) $1);
2595 if (!current_block.AddLabel ((string) $1, labeled)){
2596 Location l = lexer.Location;
2597 Report.Error (140, l, "The label '" + ((string) $1) + "' is a duplicate");
2599 current_block.AddStatement (labeled);
2604 declaration_statement
2605 : local_variable_declaration SEMICOLON
2607 DictionaryEntry de = (DictionaryEntry) $1;
2609 $$ = declare_local_variables ((string) de.Key, (ArrayList) de.Value, lexer.Location);
2612 | local_constant_declaration SEMICOLON
2614 DictionaryEntry de = (DictionaryEntry) $1;
2616 $$ = declare_local_constant ((string) de.Key, (VariableDeclaration) de.Value);
2621 * The following is from Rhys' grammar:
2622 * > Types in local variable declarations must be recognized as
2623 * > expressions to prevent reduce/reduce errors in the grammar.
2624 * > The expressions are converted into types during semantic analysis.
2627 : primary_expression opt_rank_specifier
2629 // FIXME: Do something smart here regarding the composition of the type.
2631 // Ok, the above "primary_expression" is there to get rid of
2632 // both reduce/reduce and shift/reduces in the grammar, it should
2633 // really just be "type_name". If you use type_name, a reduce/reduce
2634 // creeps up. If you use qualified_identifier (which is all we need
2635 // really) two shift/reduces appear.
2638 // So the super-trick is that primary_expression
2639 // can only be either a SimpleName or a MemberAccess.
2640 // The MemberAccess case arises when you have a fully qualified type-name like :
2642 // SimpleName is when you have
2645 Expression expr = (Expression) $1;
2646 if (!(expr is SimpleName || expr is MemberAccess)) {
2647 Location l = lexer.Location;
2648 Report.Error (-1, l, "Invalid Type definition");
2649 $$ = "System.Object";
2653 // So we extract the string corresponding to the SimpleName
2656 $$ = GetQualifiedIdentifier (expr) + (string) $2;
2658 | builtin_types opt_rank_specifier
2660 $$ = (string) $1 + (string) $2;
2664 // FIXME : How can the type of a local variable be void ? I don't quite see ;-)
2667 // // FIXME: this is a string that represents the type
2668 // // Figure out something to make this work.
2673 local_variable_declaration
2674 : local_variable_type variable_declarators
2676 $$ = new DictionaryEntry ($1, $2);
2680 local_constant_declaration
2681 : CONST local_variable_type constant_declarator
2683 $$ = new DictionaryEntry ($2, $3);
2687 expression_statement
2688 : statement_expression SEMICOLON
2695 // We have to do the wrapping here and not in the case above,
2696 // because statement_expression is used for example in for_statement
2698 statement_expression
2699 : invocation_expression { $$ = new StatementExpression ((ExpressionStatement) $1); }
2700 | object_creation_expression { $$ = new StatementExpression ((ExpressionStatement) $1); }
2701 | assignment_expression { $$ = new StatementExpression ((ExpressionStatement) $1); }
2702 | post_increment_expression { $$ = new StatementExpression ((ExpressionStatement) $1); }
2703 | post_decrement_expression { $$ = new StatementExpression ((ExpressionStatement) $1); }
2704 | pre_increment_expression { $$ = new StatementExpression ((ExpressionStatement) $1); }
2705 | pre_decrement_expression { $$ = new StatementExpression ((ExpressionStatement) $1); }
2707 Report.Error (1002, lexer.Location, "Expecting `;'");
2711 object_creation_expression
2712 : object_or_delegate_creation_expression
2713 { note ("complain if this is a delegate maybe?"); }
2722 : IF OPEN_PARENS boolean_expression CLOSE_PARENS
2725 $$ = new If ((Expression) $3, (Statement) $5);
2727 | IF OPEN_PARENS boolean_expression CLOSE_PARENS
2728 embedded_statement ELSE embedded_statement
2730 $$ = new If ((Expression) $3, (Statement) $5, (Statement) $7);
2735 : SWITCH OPEN_PARENS
2737 oob_stack.Push (lexer.Location);
2739 expression CLOSE_PARENS
2742 $$ = new Switch ((Expression) $4, (ArrayList) $6, (Location) oob_stack.Pop ());
2756 : /* empty */ { $$ = new ArrayList (); }
2763 ArrayList sections = new ArrayList ();
2768 | switch_sections switch_section
2770 ArrayList sections = (ArrayList) $1;
2780 current_block = new Block (current_block);
2784 while (current_block.Implicit)
2785 current_block = current_block.Parent;
2786 $$ = new SwitchSection ((ArrayList) $1, current_block);
2787 current_block = current_block.Parent;
2794 ArrayList labels = new ArrayList ();
2799 | switch_labels switch_label
2801 ArrayList labels = (ArrayList) ($1);
2809 : CASE constant_expression COLON { $$ = new SwitchLabel ((Expression) $2, lexer.Location); }
2810 | DEFAULT COLON { $$ = new SwitchLabel (null, lexer.Location); }
2821 : WHILE OPEN_PARENS boolean_expression CLOSE_PARENS embedded_statement
2823 $$ = new While ((Expression) $3, (Statement) $5);
2828 : DO embedded_statement
2829 WHILE OPEN_PARENS boolean_expression CLOSE_PARENS SEMICOLON
2831 $$ = new Do ((Statement) $2, (Expression) $5);
2837 opt_for_initializer SEMICOLON
2839 Block assign_block = new Block (current_block);
2840 current_block = assign_block;
2842 if ($3 is DictionaryEntry){
2843 DictionaryEntry de = (DictionaryEntry) $3;
2845 string type = (string) de.Key;
2846 ArrayList var_declarators = (ArrayList) de.Value;
2848 foreach (VariableDeclaration decl in var_declarators){
2850 if (!current_block.AddVariable (type, decl.identifier, current_local_parameters,
2852 Report.Error (128, decl.Location,
2853 "A local variable `" + decl.identifier + "' is already" +
2854 "defined in this scope");
2857 Location l = lexer.Location;
2859 if (decl.expression_or_array_initializer is Expression){
2860 expr = (Expression) decl.expression_or_array_initializer;
2864 ArrayList init = (ArrayList) decl.expression_or_array_initializer;
2866 string base_type = type.Substring (0, type.IndexOf ("["));
2867 string rank = type.Substring (type.IndexOf ("["));
2869 expr = new ArrayCreation (base_type, rank, init, decl.Location);
2872 LocalVariableReference var;
2873 var = new LocalVariableReference (
2874 assign_block, decl.identifier, l);
2876 Assign a = new Assign (var, expr, decl.Location);
2878 assign_block.AddStatement (new StatementExpression (a));
2885 opt_for_condition SEMICOLON
2886 opt_for_iterator CLOSE_PARENS
2889 For f = new For ((Statement) $3, (Expression) $6, (Statement) $8, (Statement) $10);
2891 current_block.AddStatement (f);
2892 while (current_block.Implicit)
2893 current_block = current_block.Parent;
2895 current_block = current_block.Parent;
2900 : /* empty */ { $$ = new EmptyStatement (); }
2905 : local_variable_declaration
2906 | statement_expression_list
2910 : /* empty */ { $$ = null; }
2911 | boolean_expression
2915 : /* empty */ { $$ = new EmptyStatement (); }
2920 : statement_expression_list
2923 statement_expression_list
2924 : statement_expression
2926 Block b = new Block (null, true);
2928 b.AddStatement ((Statement) $1);
2931 | statement_expression_list COMMA statement_expression
2933 Block b = (Block) $1;
2935 b.AddStatement ((Statement) $3);
2941 : FOREACH OPEN_PARENS type IDENTIFIER IN
2943 oob_stack.Push (lexer.Location);
2945 expression CLOSE_PARENS
2947 Block foreach_block = new Block (current_block, true);
2948 LocalVariableReference v;
2949 Location l = lexer.Location;
2951 foreach_block.AddVariable ((string) $3, (string) $4, current_local_parameters, l);
2952 v = new LocalVariableReference (foreach_block, (string) $4, l);
2954 current_block.AddStatement (foreach_block);
2955 current_block = foreach_block;
2957 oob_stack.Push (foreach_block);
2962 LocalVariableReference v = (LocalVariableReference) oob_stack.Pop ();
2963 Block foreach_block = (Block) oob_stack.Pop ();
2964 Location l = (Location) oob_stack.Pop ();
2966 $$ = new Foreach ((string) $3, v, (Expression) $7, (Statement) $10, l);
2972 | continue_statement
2981 $$ = new Break (lexer.Location);
2986 : CONTINUE SEMICOLON
2988 $$ = new Continue (lexer.Location);
2993 : GOTO IDENTIFIER SEMICOLON
2995 $$ = new Goto (current_block, (string) $2, lexer.Location);
2997 | GOTO CASE constant_expression SEMICOLON
2999 $$ = new GotoCase ((Expression) $3, lexer.Location);
3001 | GOTO DEFAULT SEMICOLON
3003 $$ = new GotoDefault (lexer.Location);
3008 : RETURN opt_expression SEMICOLON
3010 $$ = new Return ((Expression) $2, lexer.Location);
3015 : THROW opt_expression SEMICOLON
3017 $$ = new Throw ((Expression) $2, lexer.Location);
3027 : TRY block catch_clauses
3030 ArrayList s = new ArrayList ();
3032 foreach (Catch cc in (ArrayList) $3) {
3033 if (cc.Type == null)
3039 // Now s contains the list of specific catch clauses
3040 // and g contains the general one.
3042 $$ = new Try ((Block) $2, s, g, null);
3044 | TRY block opt_catch_clauses FINALLY block
3047 ArrayList s = new ArrayList ();
3049 foreach (Catch cc in (ArrayList) $3) {
3050 if (cc.Type == null)
3056 $$ = new Try ((Block) $2, s, g, (Block) $5);
3061 : /* empty */ { $$ = null; }
3068 ArrayList l = new ArrayList ();
3073 | catch_clauses catch_clause
3075 ArrayList l = (ArrayList) $1;
3083 : /* empty */ { $$ = null; }
3088 : CATCH opt_catch_args
3090 string type = null, id = null;
3093 DictionaryEntry cc = (DictionaryEntry) $2;
3094 type = (string) cc.Key;
3095 id = (string) cc.Value;
3098 ArrayList one = new ArrayList ();
3099 Location loc = lexer.Location;
3101 one.Add (new VariableDeclaration (id, null, loc));
3104 current_block = new Block (current_block);
3105 Block b = declare_local_variables (type, one, loc);
3112 string type = null, id = null;
3115 DictionaryEntry cc = (DictionaryEntry) $2;
3116 type = (string) cc.Key;
3117 id = (string) cc.Value;
3120 while (current_block != (Block) $1)
3121 current_block = current_block.Parent;
3126 $$ = new Catch (type, id , (Block) $4, lexer.Location);
3131 : /* empty */ { $$ = null; }
3136 : OPEN_PARENS type opt_identifier CLOSE_PARENS
3138 $$ = new DictionaryEntry ($2, $3);
3145 $$ = new Checked ((Block) $2);
3152 $$ = new Unchecked ((Block) $2);
3157 : LOCK OPEN_PARENS expression CLOSE_PARENS
3163 $$ = new Lock ((Expression) $3, (Statement) $6, lexer.Location);
3168 : USING OPEN_PARENS resource_acquisition CLOSE_PARENS
3170 Block assign_block = new Block (current_block);
3171 current_block = assign_block;
3173 oob_stack.Push (lexer.Location);
3175 if ($3 is DictionaryEntry){
3176 DictionaryEntry de = (DictionaryEntry) $3;
3177 Location l = lexer.Location;
3179 string type = (string) de.Key;
3180 ArrayList var_declarators = (ArrayList) de.Value;
3182 foreach (VariableDeclaration decl in var_declarators){
3183 if (!current_block.AddVariable (type, decl.identifier, current_local_parameters,
3185 Report.Error (128, decl.Location,
3186 "A local variable `" + decl.identifier + "' is already" +
3187 "defined in this scope");
3191 ArrayList vars = new ArrayList ();
3193 foreach (VariableDeclaration decl in var_declarators){
3196 if (decl.expression_or_array_initializer is Expression){
3197 expr = (Expression) decl.expression_or_array_initializer;
3201 ArrayList init = (ArrayList) decl.expression_or_array_initializer;
3203 string base_type = type.Substring (0, type.IndexOf ("["));
3204 string rank = type.Substring (type.IndexOf ("["));
3206 expr = new ArrayCreation (base_type, rank, init, decl.Location);
3209 LocalVariableReference var;
3212 var = new LocalVariableReference (assign_block, decl.identifier, l);
3213 vi = var.VariableInfo;
3216 // This is so that it is not a warning on using variables
3219 vars.Add (new DictionaryEntry (var, expr));
3221 // Assign a = new Assign (var, expr, decl.Location);
3222 // assign_block.AddStatement (new StatementExpression (a));
3224 $3 = new DictionaryEntry (type, vars);
3229 Using u = new Using ($3, (Statement) $6, (Location) oob_stack.Pop ());
3230 current_block.AddStatement (u);
3231 while (current_block.Implicit)
3232 current_block = current_block.Parent;
3234 current_block = current_block.Parent;
3238 resource_acquisition
3239 : local_variable_declaration
3246 // A class used to pass around variable declarations and constants
3248 public class VariableDeclaration {
3249 public string identifier;
3250 public object expression_or_array_initializer;
3251 public Location Location;
3253 public VariableDeclaration (string id, object eoai, Location l){
3254 this.identifier = id;
3255 this.expression_or_array_initializer = eoai;
3261 // A class used to hold info about an indexer declarator
3264 public class IndexerDeclaration {
3266 public string interface_type;
3267 public Parameters param_list;
3269 public IndexerDeclaration (string type, string interface_type, Parameters param_list)
3272 this.interface_type = interface_type;
3273 this.param_list = param_list;
3278 // A class used to hold info about an operator declarator
3281 public class OperatorDeclaration {
3282 public Operator.OpType optype;
3283 public string ret_type;
3284 public string arg1type;
3285 public string arg1name;
3286 public string arg2type;
3287 public string arg2name;
3288 public Location location;
3290 public OperatorDeclaration (Operator.OpType op, string ret_type, string arg1type, string arg1name,
3291 string arg2type, string arg2name, Location location)
3294 this.ret_type = ret_type;
3295 this.arg1type = arg1type;
3296 this.arg1name = arg1name;
3297 this.arg2type = arg2type;
3298 this.arg2name = arg2name;
3299 this.location = location;
3305 // Given the @class_name name, it creates a fully qualified name
3306 // based on the containing declaration space
3309 MakeName (string class_name)
3311 string ns = current_namespace.Name;
3312 string container_name = current_container.Name;
3314 if (container_name == ""){
3316 return ns + "." + class_name;
3320 return container_name + "." + class_name;
3324 // Used to report back to the user the result of a declaration
3325 // in the current declaration space
3328 CheckDef (AdditionResult result, string name)
3330 if (result == AdditionResult.Success)
3333 Location l = lexer.Location;
3336 case AdditionResult.NameExists:
3337 Report.Error (102, l, "The namespace `" + current_container.Name +
3338 "' already contains a definition for `"+
3344 // This is handled only for static Constructors, because
3345 // in reality we handle these by the semantic analysis later
3347 case AdditionResult.MethodExists:
3349 111, l, "Class `"+current_container.Name+
3350 "' already defines a member called '" +
3351 name + "' with the same parameter types (more than one default constructor)");
3354 case AdditionResult.EnclosingClash:
3355 Report.Error (542, l, "Member names cannot be the same as their enclosing type");
3358 case AdditionResult.NotAConstructor:
3359 Report.Error (1520, l, "Class, struct, or interface method must have a return type");
3365 CheckDef (bool result, string name)
3369 CheckDef (AdditionResult.NameExists, name);
3373 SimpleLookup (string name, Location loc)
3376 // we need to check against current_block not being null
3377 // as `expression' is allowed in argument_lists, which
3378 // do not exist inside a block.
3380 if (current_block != null){
3381 if (current_block.IsVariableDefined (name))
3382 return new LocalVariableReference (current_block, name, loc);
3385 if (current_local_parameters != null){
3387 Parameter par = current_local_parameters.GetParameterByName (name, out idx);
3389 return new ParameterReference (current_local_parameters, idx, name);
3395 Expression DecomposeQI (string name, Location loc)
3399 if (name.IndexOf ('.') == -1){
3400 o = SimpleLookup (name, loc);
3402 return new SimpleName (name, loc);
3405 int pos = name.LastIndexOf (".");
3406 string left = name.Substring (0, pos);
3407 string right = name.Substring (pos + 1);
3409 o = DecomposeQI (left, loc);
3410 return new MemberAccess (o, right, loc);
3415 // This method is used to get at the complete string representation of
3416 // a fully-qualified type name, hiding inside a MemberAccess ;-)
3417 // This is necessary because local_variable_type admits primary_expression
3418 // as the type of the variable. So we do some extra checking
3420 string GetQualifiedIdentifier (Expression expr)
3422 if (expr is SimpleName)
3423 return ((SimpleName)expr).Name;
3424 else if (expr is MemberAccess)
3425 return GetQualifiedIdentifier (((MemberAccess)expr).Expr) + "." + ((MemberAccess) expr).Identifier;
3427 throw new Exception ("Expr has to be either SimpleName or MemberAccess! (" + expr + ")");
3431 Block declare_local_variables (string type, ArrayList variable_declarators, Location loc)
3433 Block implicit_block;
3434 ArrayList inits = null;
3437 // We use the `Used' property to check whether statements
3438 // have been added to the current block. If so, we need
3439 // to create another block to contain the new declaration
3440 // otherwise, as an optimization, we use the same block to
3441 // add the declaration.
3443 // FIXME: A further optimization is to check if the statements
3444 // that were added were added as part of the initialization
3445 // below. In which case, no other statements have been executed
3446 // and we might be able to reduce the number of blocks for
3447 // situations like this:
3449 // int j = 1; int k = j + 1;
3451 if (current_block.Used)
3452 implicit_block = new Block (current_block, true);
3454 implicit_block = current_block;
3456 foreach (VariableDeclaration decl in variable_declarators){
3458 if (implicit_block.AddVariable (type, decl.identifier, current_local_parameters, decl.Location)) {
3459 if (decl.expression_or_array_initializer != null){
3461 inits = new ArrayList ();
3465 Report.Error (128, decl.Location, "A local variable `" + decl.identifier +
3466 "' is already defined in this scope");
3471 return implicit_block;
3473 foreach (VariableDeclaration decl in inits){
3477 if (decl.expression_or_array_initializer is Expression){
3478 expr = (Expression) decl.expression_or_array_initializer;
3481 ArrayList init = (ArrayList) decl.expression_or_array_initializer;
3483 string base_type = type.Substring (0, type.IndexOf ("["));
3484 string rank = type.Substring (type.IndexOf ("["));
3486 expr = new ArrayCreation (base_type, rank, init, decl.Location);
3490 LocalVariableReference var;
3491 var = new LocalVariableReference (implicit_block, decl.identifier, loc);
3493 assign = new Assign (var, expr, decl.Location);
3495 implicit_block.AddStatement (new StatementExpression (assign));
3498 return implicit_block;
3501 Block declare_local_constant (string type, VariableDeclaration decl)
3503 Block implicit_block;
3505 if (current_block.Used)
3506 implicit_block = new Block (current_block, true);
3508 implicit_block = current_block;
3510 if (!(implicit_block.AddConstant (type, decl.identifier, (Expression) decl.expression_or_array_initializer,
3511 current_local_parameters, decl.Location))){
3512 Report.Error (128, decl.Location, "A local variable `" + decl.identifier +
3513 "' is already defined in this scope");
3516 return implicit_block;
3519 void CheckAttributeTarget (string a)
3523 case "assembly" : case "field" : case "method" : case "param" : case "property" : case "type" :
3527 Location l = lexer.Location;
3528 Report.Error (658, l, "Invalid attribute target");
3534 void CheckUnaryOperator (Operator.OpType op)
3538 case Operator.OpType.LogicalNot:
3539 case Operator.OpType.OnesComplement:
3540 case Operator.OpType.Increment:
3541 case Operator.OpType.Decrement:
3542 case Operator.OpType.True:
3543 case Operator.OpType.False:
3544 case Operator.OpType.Addition:
3545 case Operator.OpType.Subtraction:
3550 Location l = lexer.Location;
3551 Report.Error (1019, l, "Overloadable unary operator expected");
3557 void CheckBinaryOperator (Operator.OpType op)
3561 case Operator.OpType.Addition:
3562 case Operator.OpType.Subtraction:
3563 case Operator.OpType.Multiply:
3564 case Operator.OpType.Division:
3565 case Operator.OpType.Modulus:
3566 case Operator.OpType.BitwiseAnd:
3567 case Operator.OpType.BitwiseOr:
3568 case Operator.OpType.ExclusiveOr:
3569 case Operator.OpType.LeftShift:
3570 case Operator.OpType.RightShift:
3571 case Operator.OpType.Equality:
3572 case Operator.OpType.Inequality:
3573 case Operator.OpType.GreaterThan:
3574 case Operator.OpType.LessThan:
3575 case Operator.OpType.GreaterThanOrEqual:
3576 case Operator.OpType.LessThanOrEqual:
3580 Location l = lexer.Location;
3581 Report.Error (1020, l, "Overloadable binary operator expected");
3587 void syntax_error (Location l, string msg)
3589 Report.Error (1003, l, "Syntax error, " + msg);
3592 void output (string s)
3594 Console.WriteLine (s);
3597 void note (string s)
3599 // Used to put annotations
3604 public Tokenizer Lexer {
3610 public CSharpParser (string name, System.IO.Stream input, ArrayList defines)
3612 current_namespace = new Namespace (null, "");
3615 current_container = RootContext.Tree.Types;
3616 current_container.Namespace = current_namespace;
3617 oob_stack = new Stack ();
3619 lexer = new Tokenizer (input, name, defines);
3622 public override int parse ()
3624 StringBuilder value = new StringBuilder ();
3628 if (yacc_verbose_flag)
3629 yyparse (lexer, new yydebug.yyDebugSimple ());
3632 } catch (Exception e){
3633 // Console.WriteLine ("Fatal error: " + name);
3634 // Console.WriteLine (lexer.location);
3637 // Please do not remove this, it is used during debugging
3640 Console.WriteLine (lexer.location + " : Parsing error ");
3641 Console.WriteLine (e);
3645 return global_errors;