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
168 /* C# keywords which are not really keywords */
172 /* C# single character operators/punctuation. */
173 %token OPEN_BRACE "{"
174 %token CLOSE_BRACE "}"
175 %token OPEN_BRACKET "["
176 %token CLOSE_BRACKET "]"
177 %token OPEN_PARENS "("
178 %token CLOSE_PARENS ")"
191 %token BITWISE_AND "&"
192 %token BITWISE_OR "|"
199 /* C# multi-character operators. */
202 %token OP_SHIFT_LEFT "<<"
203 %token OP_SHIFT_RIGHT ">>"
210 %token OP_MULT_ASSIGN "*="
211 %token OP_DIV_ASSIGN "/="
212 %token OP_MOD_ASSIGN "%="
213 %token OP_ADD_ASSIGN "+="
214 %token OP_SUB_ASSIGN "-="
215 %token OP_SHIFT_LEFT_ASSIGN "<<="
216 %token OP_SHIFT_RIGHT_ASSIGN ">>="
217 %token OP_AND_ASSIGN "&="
218 %token OP_XOR_ASSIGN "^="
219 %token OP_OR_ASSIGN "|="
223 %token LITERAL_INTEGER "int literal"
224 %token LITERAL_FLOAT "float literal"
225 %token LITERAL_DOUBLE "double literal"
226 %token LITERAL_DECIMAL "decimal literal"
227 %token LITERAL_CHARACTER "character literal"
228 %token LITERAL_STRING "string literal"
232 /* Add precedence rules to solve dangling else s/r conflict */
241 %left OP_SHIFT_LEFT OP_SHIFT_RIGHT
243 %left STAR DIV PERCENT
244 %right BANG CARRET UMINUS
245 %nonassoc OP_INC OP_DEC
247 %left OPEN_BRACKET OPEN_BRACE
251 %start compilation_unit
252 /*%start namespace_declaration */
256 : opt_using_directives opt_namespace_member_declarations opt_EOF
258 // Check that using comes only before namespace elements
269 | using_directives using_directive
273 : using_alias_directive
274 | using_namespace_directive
277 using_alias_directive
278 : USING IDENTIFIER ASSIGN
279 namespace_or_type_name SEMICOLON
281 current_namespace.UsingAlias ((string) $2, (string) $4);
285 using_namespace_directive
286 : USING namespace_name SEMICOLON
288 current_namespace.Using ((string) $2);
292 // namespace_declarations
293 // : namespace_declaration
294 // | namespace_declarations namespace_declaration
296 namespace_declaration
297 : NAMESPACE qualified_identifier
299 current_namespace = RootContext.Tree.RecordNamespace (current_namespace, name, (string) $2);
301 namespace_body opt_semicolon
303 current_namespace = current_namespace.Parent;
319 | qualified_identifier DOT IDENTIFIER {
320 $$ = (($1).ToString ()) + "." + ($3.ToString ()); }
325 : namespace_or_type_name
331 opt_namespace_member_declarations
342 opt_namespace_member_declarations
344 | namespace_member_declarations
347 namespace_member_declarations
348 : namespace_member_declaration
349 | namespace_member_declarations namespace_member_declaration
352 namespace_member_declaration
359 Class c = (Class) $1;
360 mod_flags = c.ModFlags;
362 } else if ($1 is Struct){
363 Struct s = (Struct) $1;
364 mod_flags = s.ModFlags;
369 if ((mod_flags & (Modifiers.PRIVATE|Modifiers.PROTECTED)) != 0){
370 error (1527, "Namespace elements cant be explicitly " +
371 "declared private or protected in `" + name + "'");
374 | namespace_declaration
380 | interface_declaration
382 | delegate_declaration
389 : /* empty */ { $$ = null; }
390 | attribute_section opt_attributes
395 attrs = (Attributes) $2;
396 attrs.AddAttribute ((AttributeSection) $1);
398 attrs = new Attributes ((AttributeSection) $1);
405 : OPEN_BRACKET attribute_target_specifier attribute_list CLOSE_BRACKET
407 string target = null;
410 target = (string) $2;
412 $$ = new AttributeSection (target, (ArrayList) $3);
414 | OPEN_BRACKET attribute_list CLOSE_BRACKET
416 $$ = new AttributeSection (null, (ArrayList) $2);
420 attribute_target_specifier
421 : attribute_target COLON
430 CheckAttributeTarget ((string) $1);
433 | EVENT { $$ = "event"; }
434 | RETURN { $$ = "return"; }
440 ArrayList attrs = new ArrayList ();
446 | attribute_list COMMA attribute
448 ArrayList attrs = (ArrayList) $1;
460 opt_attribute_arguments
462 $$ = new Attribute ((string) $1, (ArrayList) $3, (Location) $2);
467 : type_name { /* reserved attribute name or identifier: 17.4 */ }
470 opt_attribute_arguments
471 : /* empty */ { $$ = null; }
472 | OPEN_PARENS attribute_arguments CLOSE_PARENS
480 : positional_argument_list
482 ArrayList args = new ArrayList ();
487 | positional_argument_list COMMA named_argument_list
489 ArrayList args = new ArrayList ();
495 | named_argument_list
497 ArrayList args = new ArrayList ();
506 positional_argument_list
509 ArrayList args = new ArrayList ();
510 args.Add (new Argument ((Expression) $1, Argument.AType.Expression));
514 | positional_argument_list COMMA expression
516 ArrayList args = (ArrayList) $1;
517 args.Add (new Argument ((Expression) $3, Argument.AType.Expression));
526 ArrayList args = new ArrayList ();
531 | named_argument_list COMMA named_argument
533 ArrayList args = (ArrayList) $1;
541 : IDENTIFIER ASSIGN expression
543 $$ = new DictionaryEntry (
545 new Argument ((Expression) $3, Argument.AType.Expression));
551 : OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
554 opt_class_member_declarations
556 | class_member_declarations
559 class_member_declarations
560 : class_member_declaration
561 | class_member_declarations
562 class_member_declaration
565 class_member_declaration
566 : constant_declaration // done
567 | field_declaration // done
568 | method_declaration // done
569 | property_declaration // done
570 | event_declaration // done
571 | indexer_declaration // done
572 | operator_declaration // done
573 | constructor_declaration // done
574 | destructor_declaration // done
584 string full_struct_name = MakeName ((string) $4);
586 new_struct = new Struct (current_container, full_struct_name, (int) $2,
587 (Attributes) $1, lexer.Location);
588 current_container = new_struct;
589 current_container.Namespace = current_namespace;
590 RootContext.Tree.RecordStruct (full_struct_name, new_struct);
592 opt_struct_interfaces
596 Struct new_struct = (Struct) current_container;
598 current_container = current_container.Parent;
599 CheckDef (current_container.AddStruct (new_struct), new_struct.Name);
604 opt_struct_interfaces
611 | struct_interfaces struct_interface
619 : OPEN_BRACE opt_struct_member_declarations CLOSE_BRACE
622 opt_struct_member_declarations
624 | struct_member_declarations
627 struct_member_declarations
628 : struct_member_declaration
629 | struct_member_declarations struct_member_declaration
632 struct_member_declaration
633 : constant_declaration
636 | property_declaration
638 | indexer_declaration
639 | operator_declaration
640 | constructor_declaration
644 * This is only included so we can flag error 575:
645 * destructors only allowed on class types
647 | destructor_declaration
658 foreach (VariableDeclaration constant in (ArrayList) $5){
659 Const c = new Const (
660 (string) $4, (string) constant.identifier,
661 (Expression) constant.expression_or_array_initializer, (int) $2, (Attributes) $1,
664 CheckDef (current_container.AddConstant (c), c.Name);
670 : constant_declarator
672 ArrayList constants = new ArrayList ();
676 | constant_declarators COMMA constant_declarator
678 ArrayList constants = (ArrayList) $1;
685 : IDENTIFIER ASSIGN constant_expression
687 $$ = new VariableDeclaration ((string) $1, $3, lexer.Location);
698 string type = (string) $3;
701 foreach (VariableDeclaration var in (ArrayList) $4){
702 Field field = new Field (type, mod, var.identifier,
703 var.expression_or_array_initializer, (Attributes) $1, var.Location);
705 CheckDef (current_container.AddField (field), field.Name);
711 : variable_declarator
713 ArrayList decl = new ArrayList ();
717 | variable_declarators COMMA variable_declarator
719 ArrayList decls = (ArrayList) $1;
726 : IDENTIFIER ASSIGN variable_initializer
728 $$ = new VariableDeclaration ((string) $1, $3, lexer.Location);
732 $$ = new VariableDeclaration ((string) $1, null, lexer.Location);
751 Method method = (Method) $1;
752 Block b = (Block) $2;
755 if ((method.ModFlags & (Modifiers.EXTERN | Modifiers.ABSTRACT)) == 0){
757 501, lexer.Location, "`" +
758 current_container.Name + "." + method.Name + "'" +
759 "must declare a body because it is not marked abstract or extern");
763 method.Block = (Block) $2;
764 CheckDef (current_container.AddMethod (method), method.Name);
766 current_local_parameters = null;
780 1585, lexer.Location, "Member modifier `" +
781 Modifiers.Name (i) + "' must precede member type and name");
794 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
796 Method method = new Method ((string) $3, (int) $2, (string) $4,
797 (Parameters) $6, (Attributes) $1, lexer.Location);
799 current_local_parameters = (Parameters) $6;
807 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
809 Method method = new Method ("System.Void", (int) $2, (string) $4,
810 (Parameters) $6, (Attributes) $1, lexer.Location);
812 current_local_parameters = (Parameters) $6;
819 | SEMICOLON { $$ = null; }
822 opt_formal_parameter_list
823 : /* empty */ { $$ = Parameters.GetEmptyReadOnlyParameters (); }
824 | formal_parameter_list
827 formal_parameter_list
830 ArrayList pars_list = (ArrayList) $1;
832 Parameter [] pars = new Parameter [pars_list.Count];
833 pars_list.CopyTo (pars);
835 $$ = new Parameters (pars, null, lexer.Location);
837 | fixed_parameters COMMA parameter_array
839 ArrayList pars_list = (ArrayList) $1;
841 Parameter [] pars = new Parameter [pars_list.Count];
842 pars_list.CopyTo (pars);
844 $$ = new Parameters (pars, (Parameter) $3, lexer.Location);
848 $$ = new Parameters (null, (Parameter) $1, lexer.Location);
855 ArrayList pars = new ArrayList ();
860 | fixed_parameters COMMA fixed_parameter
862 ArrayList pars = (ArrayList) $1;
871 opt_parameter_modifier
875 $$ = new Parameter ((string) $3, (string) $4, (Parameter.Modifier) $2, (Attributes) $1);
879 opt_parameter_modifier
880 : /* empty */ { $$ = Parameter.Modifier.NONE; }
885 : REF { $$ = Parameter.Modifier.REF; }
886 | OUT { $$ = Parameter.Modifier.OUT; }
890 : opt_attributes PARAMS type IDENTIFIER
892 $$ = new Parameter ((string) $3, (string) $4, Parameter.Modifier.PARAMS, (Attributes) $1);
893 note ("type must be a single-dimension array type");
898 : qualified_identifier
907 implicit_value_parameter_type = (string) $3;
909 lexer.PropertyParsing = true;
913 accessor_declarations
915 lexer.PropertyParsing = false;
920 Pair pair = (Pair) $7;
921 Block get_block = null;
922 Block set_block = null;
924 if (pair.First != null)
925 get_block = (Block) pair.First;
926 if (pair.Second != null)
927 set_block = (Block) pair.Second;
929 prop = new Property ((string) $3, (string) $4, (int) $2, get_block, set_block,
930 (Attributes) $1, (Location) $6);
932 CheckDef (current_container.AddProperty (prop), prop.Name);
933 implicit_value_parameter_type = null;
937 accessor_declarations
938 : get_accessor_declaration opt_set_accessor_declaration
940 $$ = new Pair ($1, $2);
942 | set_accessor_declaration opt_get_accessor_declaration
944 $$ = new Pair ($2, $1);
948 opt_get_accessor_declaration
949 : /* empty */ { $$ = null; }
950 | get_accessor_declaration
953 opt_set_accessor_declaration
954 : /* empty */ { $$ = null; }
955 | set_accessor_declaration
958 get_accessor_declaration
961 // If this is not the case, then current_local_parameters has already
962 // been set in indexer_declaration
963 if (parsing_indexer == false)
964 current_local_parameters = null;
966 current_local_parameters = indexer_parameters;
967 lexer.PropertyParsing = false;
972 current_local_parameters = null;
973 lexer.PropertyParsing = true;
977 set_accessor_declaration
981 Parameter implicit_value_parameter = new Parameter (
982 implicit_value_parameter_type, "value",
983 Parameter.Modifier.NONE, null);
985 if (parsing_indexer == false) {
986 args = new Parameter [1];
987 args [0] = implicit_value_parameter;
989 Parameter [] fp = indexer_parameters.FixedParameters;
990 int count = fp.Length;
992 args = new Parameter [count + 1];
995 args [count] = implicit_value_parameter;
998 current_local_parameters = new Parameters (args, null, lexer.Location);
999 lexer.PropertyParsing = false;
1004 current_local_parameters = null;
1005 lexer.PropertyParsing = true;
1011 | SEMICOLON { $$ = new Block (null); }
1014 interface_declaration
1017 INTERFACE IDENTIFIER
1019 Interface new_interface;
1020 string full_interface_name = MakeName ((string) $4);
1022 new_interface = new Interface (current_container, full_interface_name, (int) $2,
1023 (Attributes) $1, lexer.Location);
1024 if (current_interface != null) {
1025 Location l = lexer.Location;
1026 Report.Error (-2, l, "Internal compiler error: interface inside interface");
1028 current_interface = new_interface;
1029 new_interface.Namespace = current_namespace;
1030 RootContext.Tree.RecordInterface (full_interface_name, new_interface);
1035 Interface new_interface = (Interface) current_interface;
1038 new_interface.Bases = (ArrayList) $6;
1040 current_interface = null;
1041 CheckDef (current_container.AddInterface (new_interface), new_interface.Name);
1046 : /* empty */ { $$ = null; }
1051 : COLON interface_type_list { $$ = $2; }
1057 ArrayList interfaces = new ArrayList ();
1059 interfaces.Add ($1);
1062 | interface_type_list COMMA interface_type
1064 ArrayList interfaces = (ArrayList) $1;
1065 interfaces.Add ($3);
1072 opt_interface_member_declarations
1076 opt_interface_member_declarations
1078 | interface_member_declarations
1081 interface_member_declarations
1082 : interface_member_declaration
1083 | interface_member_declarations interface_member_declaration
1086 interface_member_declaration
1087 : interface_method_declaration
1089 InterfaceMethod m = (InterfaceMethod) $1;
1091 CheckDef (current_interface.AddMethod (m), m.Name);
1093 | interface_property_declaration
1095 InterfaceProperty p = (InterfaceProperty) $1;
1097 CheckDef (current_interface.AddProperty (p), p.Name);
1099 | interface_event_declaration
1101 InterfaceEvent e = (InterfaceEvent) $1;
1103 CheckDef (current_interface.AddEvent (e), e.Name);
1105 | interface_indexer_declaration
1107 InterfaceIndexer i = (InterfaceIndexer) $1;
1109 CheckDef (current_interface.AddIndexer (i), "indexer");
1114 : /* empty */ { $$ = false; }
1115 | NEW { $$ = true; }
1118 interface_method_declaration
1119 : opt_attributes opt_new type IDENTIFIER
1120 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1123 $$ = new InterfaceMethod ((string) $3, (string) $4, (bool) $2,
1124 (Parameters) $6, (Attributes) $1, lexer.Location);
1126 | opt_attributes opt_new VOID IDENTIFIER
1127 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1130 $$ = new InterfaceMethod ("System.Void", (string) $4, (bool) $2, (Parameters) $6,
1131 (Attributes) $1, lexer.Location);
1135 interface_property_declaration
1140 { lexer.PropertyParsing = true; }
1142 { lexer.PropertyParsing = false; }
1147 $$ = new InterfaceProperty ((string) $3, (string) $4, (bool) $2,
1148 (gs & 1) == 1, (gs & 2) == 2, (Attributes) $1,
1154 : opt_attributes GET SEMICOLON { $$ = 1; }
1155 | opt_attributes SET SEMICOLON { $$ = 2; }
1156 | opt_attributes GET SEMICOLON opt_attributes SET SEMICOLON
1158 | opt_attributes SET SEMICOLON opt_attributes GET SEMICOLON
1162 interface_event_declaration
1163 : opt_attributes opt_new EVENT type IDENTIFIER SEMICOLON
1165 $$ = new InterfaceEvent ((string) $4, (string) $5, (bool) $2, (Attributes) $1);
1169 interface_indexer_declaration
1170 : opt_attributes opt_new type THIS
1171 OPEN_BRACKET formal_parameter_list CLOSE_BRACKET
1173 { lexer.PropertyParsing = true; }
1175 { lexer.PropertyParsing = false; }
1178 int a_flags = (int) $10;
1180 bool do_get = (a_flags & 1) == 1;
1181 bool do_set = (a_flags & 2) == 2;
1183 $$ = new InterfaceIndexer ((string) $3, (Parameters) $6, do_get, do_set,
1184 (bool) $2, (Attributes) $1, lexer.Location);
1188 operator_declaration
1189 : opt_attributes opt_modifiers operator_declarator block
1191 OperatorDeclaration decl = (OperatorDeclaration) $3;
1193 Operator op = new Operator (decl.optype, decl.ret_type, (int) $2, decl.arg1type, decl.arg1name,
1194 decl.arg2type, decl.arg2name, (Block) $4, (Attributes) $1, decl.location);
1196 // Note again, checking is done in semantic analysis
1197 current_container.AddOperator (op);
1199 current_local_parameters = null;
1204 : type OPERATOR overloadable_operator
1205 OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1207 Operator.OpType op = (Operator.OpType) $3;
1208 CheckUnaryOperator (op);
1210 if (op == Operator.OpType.Addition)
1211 op = Operator.OpType.UnaryPlus;
1213 if (op == Operator.OpType.Subtraction)
1214 op = Operator.OpType.UnaryNegation;
1216 Parameter [] pars = new Parameter [1];
1218 pars [0] = new Parameter ((string) $5, (string) $6, Parameter.Modifier.NONE, null);
1220 current_local_parameters = new Parameters (pars, null, lexer.Location);
1222 $$ = new OperatorDeclaration (op, (string) $1, (string) $5, (string) $6,
1223 null, null, lexer.Location);
1225 | type OPERATOR overloadable_operator
1227 type IDENTIFIER COMMA
1231 CheckBinaryOperator ((Operator.OpType) $3);
1233 Parameter [] pars = new Parameter [2];
1235 pars [0] = new Parameter ((string) $5, (string) $6, Parameter.Modifier.NONE, null);
1236 pars [1] = new Parameter ((string) $8, (string) $9, Parameter.Modifier.NONE, null);
1238 current_local_parameters = new Parameters (pars, null, lexer.Location);
1240 $$ = new OperatorDeclaration ((Operator.OpType) $3, (string) $1, (string) $5, (string) $6,
1241 (string) $8, (string) $9, lexer.Location);
1243 | conversion_operator_declarator
1246 overloadable_operator
1248 : BANG { $$ = Operator.OpType.LogicalNot; }
1249 | TILDE { $$ = Operator.OpType.OnesComplement; }
1250 | OP_INC { $$ = Operator.OpType.Increment; }
1251 | OP_DEC { $$ = Operator.OpType.Decrement; }
1252 | TRUE { $$ = Operator.OpType.True; }
1253 | FALSE { $$ = Operator.OpType.False; }
1254 // Unary and binary:
1255 | PLUS { $$ = Operator.OpType.Addition; }
1256 | MINUS { $$ = Operator.OpType.Subtraction; }
1258 | STAR { $$ = Operator.OpType.Multiply; }
1259 | DIV { $$ = Operator.OpType.Division; }
1260 | PERCENT { $$ = Operator.OpType.Modulus; }
1261 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
1262 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
1263 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
1264 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
1265 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
1266 | OP_EQ { $$ = Operator.OpType.Equality; }
1267 | OP_NE { $$ = Operator.OpType.Inequality; }
1268 | OP_GT { $$ = Operator.OpType.GreaterThan; }
1269 | OP_LT { $$ = Operator.OpType.LessThan; }
1270 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
1271 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
1274 conversion_operator_declarator
1275 : IMPLICIT OPERATOR type OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1277 Parameter [] pars = new Parameter [1];
1279 pars [0] = new Parameter ((string) $5, (string) $6, Parameter.Modifier.NONE, null);
1281 current_local_parameters = new Parameters (pars, null, lexer.Location);
1283 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (string) $3, (string) $5, (string) $6,
1284 null, null, lexer.Location);
1286 | EXPLICIT OPERATOR type OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1288 Parameter [] pars = new Parameter [1];
1290 pars [0] = new Parameter ((string) $5, (string) $6, Parameter.Modifier.NONE, null);
1292 current_local_parameters = new Parameters (pars, null, lexer.Location);
1294 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (string) $3, (string) $5, (string) $6,
1295 null, null, lexer.Location);
1299 syntax_error (lexer.Location, "'operator' expected");
1303 syntax_error (lexer.Location, "'operator' expected");
1307 constructor_declaration
1310 constructor_declarator
1313 Constructor c = (Constructor) $3;
1314 c.Block = (Block) $4;
1315 c.ModFlags = (int) $2;
1316 c.OptAttributes = (Attributes) $1;
1318 if ((c.ModFlags & Modifiers.STATIC) != 0){
1319 if ((c.ModFlags & Modifiers.Accessibility) != 0) {
1320 Location l = lexer.Location;
1321 Report.Error (515, l, "Access modifiers are not allowed on static constructors");
1324 if (c.Initializer != null){
1325 Location l = lexer.Location;
1326 Report.Error (514, l, "Static constructors can not have an explicit this or base constructor invocations");
1329 if (!c.Parameters.Empty){
1330 Location l = lexer.Location;
1331 Report.Error (132, l, "Static constructors should not have parameters");
1335 CheckDef (current_container.AddConstructor (c), c.Name);
1337 current_local_parameters = null;
1341 constructor_declarator
1343 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1345 oob_stack.Push (lexer.Location);
1347 current_local_parameters = (Parameters) $3;
1349 opt_constructor_initializer
1351 Location l = (Location) oob_stack.Pop ();
1352 $$ = new Constructor ((string) $1, (Parameters) $3, (ConstructorInitializer) $6, l);
1356 opt_constructor_initializer
1357 : /* empty */ { $$ = null; }
1358 | constructor_initializer
1361 constructor_initializer
1362 : COLON BASE OPEN_PARENS opt_argument_list CLOSE_PARENS
1364 $$ = new ConstructorBaseInitializer ((ArrayList) $4, lexer.Location);
1366 | COLON THIS OPEN_PARENS opt_argument_list CLOSE_PARENS
1368 $$ = new ConstructorThisInitializer ((ArrayList) $4, lexer.Location);
1372 destructor_declaration
1373 : opt_attributes TILDE IDENTIFIER OPEN_PARENS CLOSE_PARENS block
1375 if ((string) $3 != current_container.Basename){
1376 Report.Error (574, lexer.Location, "Name of destructor must match name of class");
1377 } else if (!(current_container is Class)){
1378 Report.Error (575, lexer.Location, "Destructors are only allowed in class types");
1380 Location l = lexer.Location;
1382 Method d = new Method (
1383 "System.Void", 0, "Finalize",
1384 new Parameters (null, null, l), (Attributes) $1, l);
1386 d.Block = (Block) $6;
1387 CheckDef (current_container.AddMethod (d), d.Name);
1395 EVENT type variable_declarators SEMICOLON
1397 foreach (VariableDeclaration var in (ArrayList) $5) {
1399 Event e = new Event ((string) $4, var.identifier, var.expression_or_array_initializer,
1400 (int) $2, null, null, (Attributes) $1, lexer.Location);
1402 CheckDef (current_container.AddEvent (e), e.Name);
1408 EVENT type member_name
1411 implicit_value_parameter_type = (string) $4;
1412 lexer.EventParsing = true;
1414 event_accessor_declarations
1416 lexer.EventParsing = false;
1420 Pair pair = (Pair) $8;
1421 Block add_block = null;
1422 Block rem_block = null;
1424 if (pair.First != null)
1425 add_block = (Block) pair.First;
1426 if (pair.Second != null)
1427 rem_block = (Block) pair.Second;
1429 Event e = new Event ((string) $4, (string) $5, null, (int) $2, add_block, rem_block,
1430 (Attributes) $1, lexer.Location);
1432 CheckDef (current_container.AddEvent (e), e.Name);
1433 implicit_value_parameter_type = null;
1437 event_accessor_declarations
1438 : add_accessor_declaration remove_accessor_declaration
1440 $$ = new Pair ($1, $2);
1442 | remove_accessor_declaration add_accessor_declaration
1444 $$ = new Pair ($2, $1);
1448 add_accessor_declaration
1449 : opt_attributes ADD
1451 Parameter [] args = new Parameter [1];
1452 Parameter implicit_value_parameter = new Parameter (
1453 implicit_value_parameter_type, "value",
1454 Parameter.Modifier.NONE, null);
1456 args [0] = implicit_value_parameter;
1458 current_local_parameters = new Parameters (args, null, lexer.Location);
1459 lexer.EventParsing = false;
1464 lexer.EventParsing = true;
1468 remove_accessor_declaration
1469 : opt_attributes REMOVE
1471 Parameter [] args = new Parameter [1];
1472 Parameter implicit_value_parameter = new Parameter (
1473 implicit_value_parameter_type, "value",
1474 Parameter.Modifier.NONE, null);
1476 args [0] = implicit_value_parameter;
1478 current_local_parameters = new Parameters (args, null, lexer.Location);
1479 lexer.EventParsing = false;
1484 lexer.EventParsing = true;
1489 : opt_attributes opt_modifiers indexer_declarator
1492 IndexerDeclaration decl = (IndexerDeclaration) $3;
1494 implicit_value_parameter_type = decl.type;
1496 lexer.PropertyParsing = true;
1497 parsing_indexer = true;
1499 indexer_parameters = decl.param_list;
1500 $$ = lexer.Location;
1502 accessor_declarations
1504 lexer.PropertyParsing = false;
1505 parsing_indexer = false;
1509 // The signature is computed from the signature of the indexer. Look
1510 // at section 3.6 on the spec
1513 IndexerDeclaration decl = (IndexerDeclaration) $3;
1514 Pair pair = (Pair) $6;
1515 Block get_block = null;
1516 Block set_block = null;
1518 if (pair.First != null)
1519 get_block = (Block) pair.First;
1520 if (pair.Second != null)
1521 set_block = (Block) pair.Second;
1523 indexer = new Indexer (decl.type, decl.interface_type, (int) $2, decl.param_list,
1524 get_block, set_block, (Attributes) $1, (Location) $5);
1526 // Note that there is no equivalent of CheckDef for this case
1527 // We shall handle this in semantic analysis
1529 current_container.AddIndexer (indexer);
1531 current_local_parameters = null;
1532 implicit_value_parameter_type = null;
1533 indexer_parameters = null;
1538 : type THIS OPEN_BRACKET formal_parameter_list CLOSE_BRACKET
1540 $$ = new IndexerDeclaration ((string) $1, null, (Parameters) $4);
1542 | type qualified_identifier DOT THIS OPEN_BRACKET formal_parameter_list CLOSE_BRACKET
1544 $$ = new IndexerDeclaration ((string) $1, (string) $2, (Parameters) $6);
1556 string full_name = MakeName ((string) $4);
1557 Enum e = new Enum (current_container, (string) $5, (int) $2, full_name, (Attributes) $1, lexer.Location);
1559 foreach (VariableDeclaration ev in (ArrayList) $6){
1560 CheckDef (e.AddEnumMember (ev.identifier,
1561 (Expression) ev.expression_or_array_initializer,
1562 (Location) ev.Location),
1566 CheckDef (current_container.AddEnum (e), name);
1571 : /* empty */ { $$ = "System.Int32"; }
1572 | COLON type { $$ = $2; }
1576 : OPEN_BRACE opt_enum_member_declarations CLOSE_BRACE
1582 opt_enum_member_declarations
1583 : /* empty */ { $$ = new ArrayList (); }
1584 | enum_member_declarations opt_comma { $$ = $1; }
1587 enum_member_declarations
1588 : enum_member_declaration
1590 ArrayList l = new ArrayList ();
1595 | enum_member_declarations COMMA enum_member_declaration
1597 ArrayList l = (ArrayList) $1;
1605 enum_member_declaration
1606 : opt_attributes IDENTIFIER
1608 $$ = new VariableDeclaration ((string) $2, null, lexer.Location);
1610 | opt_attributes IDENTIFIER
1612 $$ = lexer.Location;
1616 $$ = new VariableDeclaration ((string) $2, $5, lexer.Location);
1620 delegate_declaration
1624 IDENTIFIER OPEN_PARENS
1625 opt_formal_parameter_list
1629 Delegate del = new Delegate ((string) $4, (int) $2,
1630 MakeName ((string) $5), (Parameters) $7,
1631 (Attributes) $1, lexer.Location);
1633 CheckDef (current_container.AddDelegate (del), del.Name);
1638 IDENTIFIER OPEN_PARENS
1639 opt_formal_parameter_list
1643 Delegate del = new Delegate ("System.Void", (int) $2, (string) $5, (Parameters) $7,
1644 (Attributes) $1, lexer.Location);
1646 CheckDef (current_container.AddDelegate (del), del.Name);
1651 : namespace_or_type_name
1654 namespace_or_type_name
1655 : qualified_identifier
1659 * Before you think of adding a return_type, notice that we have been
1660 * using two rules in the places where it matters (one rule using type
1661 * and another identical one that uses VOID as the return type). This
1662 * gets rid of a shift/reduce couple
1665 : type_name { /* class_type */
1667 This does interfaces, delegates, struct_types, class_types,
1668 parent classes, and more! 4.2
1679 $$ = new SimpleName ((string) $1, lexer.Location);
1681 | non_expression_type rank_specifier
1683 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
1685 | expression rank_specifiers
1687 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
1694 ArrayList types = new ArrayList ();
1699 | type_list COMMA type
1701 ArrayList types = (ArrayList) $1;
1709 * replaces all the productions for isolating the various
1710 * simple types, but we need this to reuse it easily in local_variable_type
1713 : OBJECT { $$ = "System.Object"; }
1714 | STRING { $$ = "System.String"; }
1715 | BOOL { $$ = "System.Boolean"; }
1716 | DECIMAL { $$ = "System.Decimal"; }
1717 | FLOAT { $$ = "System.Single"; }
1718 | DOUBLE { $$ = "System.Double"; }
1723 : SBYTE { $$ = "System.SByte"; }
1724 | BYTE { $$ = "System.Byte"; }
1725 | SHORT { $$ = "System.Int16"; }
1726 | USHORT { $$ = "System.UInt16"; }
1727 | INT { $$ = "System.Int32"; }
1728 | UINT { $$ = "System.UInt32"; }
1729 | LONG { $$ = "System.Int64"; }
1730 | ULONG { $$ = "System.UInt64"; }
1731 | CHAR { $$ = "System.Char"; }
1739 : type rank_specifiers
1741 $$ = (string) $1 + (string) $2;
1746 // Expressions, section 7.5
1754 | qualified_identifier
1756 string name = (string) $1;
1759 $$ = DecomposeQI (name, lexer.Location);
1761 | parenthesized_expression
1763 | invocation_expression
1767 | post_increment_expression
1768 | post_decrement_expression
1772 | checked_expression
1773 | unchecked_expression
1780 | LITERAL_CHARACTER { $$ = new CharLiteral ((char) lexer.Value); }
1781 | LITERAL_STRING { $$ = new StringLiteral ((string) lexer.Value); }
1782 | NULL { $$ = NullLiteral.Null; }
1786 : LITERAL_FLOAT { $$ = new FloatLiteral ((float) lexer.Value); }
1787 | LITERAL_DOUBLE { $$ = new DoubleLiteral ((double) lexer.Value); }
1788 | LITERAL_DECIMAL { $$ = new DecimalLiteral ((decimal) lexer.Value); }
1793 object v = lexer.Value;
1796 // FIXME: Possible optimization would be to
1797 // compute the *Literal objects directly in the scanner
1800 $$ = new IntLiteral ((Int32) v);
1802 $$ = new UIntLiteral ((UInt32) v);
1804 $$ = new LongLiteral ((Int64) v);
1805 else if (v is ulong)
1806 $$ = new ULongLiteral ((UInt64) v);
1808 Console.WriteLine ("OOPS. Unexpected result from scanner");
1813 : TRUE { $$ = new BoolLiteral (true); }
1814 | FALSE { $$ = new BoolLiteral (false); }
1817 parenthesized_expression
1818 : OPEN_PARENS expression CLOSE_PARENS
1823 : primary_expression DOT IDENTIFIER
1825 $$ = new MemberAccess ((Expression) $1, (string) $3, lexer.Location);
1827 | predefined_type DOT IDENTIFIER
1829 $$ = new SimpleName ((string) $1 + "." + (string) $3, lexer.Location);
1837 invocation_expression
1838 : primary_expression OPEN_PARENS opt_argument_list CLOSE_PARENS
1841 Location l = lexer.Location;
1842 Report.Error (1, l, "THIS IS CRAZY");
1844 $$ = new Invocation ((Expression) $1, (ArrayList) $3, lexer.Location);
1849 : /* empty */ { $$ = null; }
1856 ArrayList list = new ArrayList ();
1860 | argument_list COMMA argument
1862 ArrayList list = (ArrayList) $1;
1871 $$ = new Argument ((Expression) $1, Argument.AType.Expression);
1873 | REF variable_reference
1875 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
1877 | OUT variable_reference
1879 $$ = new Argument ((Expression) $2, Argument.AType.Out);
1884 : expression { note ("section 5.4"); $$ = $1; }
1888 : primary_expression OPEN_BRACKET expression_list CLOSE_BRACKET
1890 $$ = new ElementAccess ((Expression) $1, (ArrayList) $3, lexer.Location);
1892 | primary_expression rank_specifiers
1894 // So the super-trick is that primary_expression
1895 // can only be either a SimpleName or a MemberAccess.
1896 // The MemberAccess case arises when you have a fully qualified type-name like :
1898 // SimpleName is when you have
1901 Expression expr = (Expression) $1;
1902 if (!(expr is SimpleName || expr is MemberAccess)) {
1903 Location l = lexer.Location;
1904 Report.Error (-1, l, "Invalid Type definition");
1905 $$ = "System.Object";
1909 // So we extract the string corresponding to the SimpleName
1912 $$ = new SimpleName (GetQualifiedIdentifier (expr) + (string) $2, lexer.Location);
1919 ArrayList list = new ArrayList ();
1923 | expression_list COMMA expression
1925 ArrayList list = (ArrayList) $1;
1934 $$ = new This (lexer.Location);
1939 : BASE DOT IDENTIFIER
1941 $$ = new BaseAccess ((string) $3, lexer.Location);
1943 | BASE OPEN_BRACKET expression_list CLOSE_BRACKET
1945 $$ = new BaseIndexerAccess ((ArrayList) $3, lexer.Location);
1949 post_increment_expression
1950 : primary_expression OP_INC
1952 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement,
1953 (Expression) $1, lexer.Location);
1957 post_decrement_expression
1958 : primary_expression OP_DEC
1960 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement,
1961 (Expression) $1, lexer.Location);
1966 : object_or_delegate_creation_expression
1967 | array_creation_expression
1970 object_or_delegate_creation_expression
1971 : NEW type OPEN_PARENS opt_argument_list CLOSE_PARENS
1973 $$ = new New ((string) $2, (ArrayList) $4, lexer.Location);
1977 array_creation_expression
1978 : NEW type OPEN_BRACKET expression_list CLOSE_BRACKET
1980 opt_array_initializer
1982 $$ = new ArrayCreation ((string) $2, (ArrayList) $4, (string) $6, (ArrayList) $7,
1985 | NEW type rank_specifiers array_initializer
1987 $$ = new ArrayCreation ((string) $2, (string) $3, (ArrayList) $4, lexer.Location);
2007 | rank_specifiers rank_specifier
2009 $$ = (string) $2 + (string) $1;
2014 : OPEN_BRACKET opt_dim_separators CLOSE_BRACKET
2016 $$ = "[" + (string) $2 + "]";
2036 | dim_separators COMMA
2038 $$ = (string) $1 + ",";
2042 opt_array_initializer
2054 : OPEN_BRACE CLOSE_BRACE
2056 ArrayList list = new ArrayList ();
2059 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
2061 $$ = (ArrayList) $2;
2065 variable_initializer_list
2066 : variable_initializer
2068 ArrayList list = new ArrayList ();
2072 | variable_initializer_list COMMA variable_initializer
2074 ArrayList list = (ArrayList) $1;
2081 : TYPEOF OPEN_PARENS type CLOSE_PARENS
2083 $$ = new TypeOf ((string) $3, lexer.Location);
2088 : SIZEOF OPEN_PARENS type CLOSE_PARENS {
2089 $$ = new SizeOf ((string) $3);
2091 note ("Verify type is unmanaged");
2092 note ("if (5.8) builtin, yield constant expression");
2097 : CHECKED OPEN_PARENS expression CLOSE_PARENS
2099 $$ = new CheckedExpr ((Expression) $3);
2103 unchecked_expression
2104 : UNCHECKED OPEN_PARENS expression CLOSE_PARENS
2106 $$ = new UnCheckedExpr ((Expression) $3);
2111 : primary_expression
2112 | BANG prefixed_unary_expression
2114 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, lexer.Location);
2116 | TILDE prefixed_unary_expression
2118 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, lexer.Location);
2120 | OPEN_PARENS expression CLOSE_PARENS unary_expression
2122 $$ = new Cast ((Expression) $2, (Expression) $4, lexer.Location);
2124 | OPEN_PARENS non_expression_type CLOSE_PARENS prefixed_unary_expression
2126 $$ = new Cast ((Expression) $2, (Expression) $4, lexer.Location);
2131 // The idea to split this out is from Rhys' grammar
2132 // to solve the problem with casts.
2134 prefixed_unary_expression
2136 | PLUS prefixed_unary_expression
2138 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, lexer.Location);
2140 | MINUS prefixed_unary_expression
2142 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, lexer.Location);
2144 | OP_INC prefixed_unary_expression
2146 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
2147 (Expression) $2, lexer.Location);
2149 | OP_DEC prefixed_unary_expression
2151 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
2152 (Expression) $2, lexer.Location);
2154 | STAR prefixed_unary_expression
2156 $$ = new Unary (Unary.Operator.Indirection, (Expression) $2, lexer.Location);
2158 | BITWISE_AND prefixed_unary_expression
2160 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, lexer.Location);
2164 pre_increment_expression
2165 : OP_INC prefixed_unary_expression
2167 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
2168 (Expression) $2, lexer.Location);
2172 pre_decrement_expression
2173 : OP_DEC prefixed_unary_expression
2175 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
2176 (Expression) $2, lexer.Location);
2180 multiplicative_expression
2181 : prefixed_unary_expression
2182 | multiplicative_expression STAR prefixed_unary_expression
2184 $$ = new Binary (Binary.Operator.Multiply,
2185 (Expression) $1, (Expression) $3, lexer.Location);
2187 | multiplicative_expression DIV prefixed_unary_expression
2189 $$ = new Binary (Binary.Operator.Division,
2190 (Expression) $1, (Expression) $3, lexer.Location);
2192 | multiplicative_expression PERCENT prefixed_unary_expression
2194 $$ = new Binary (Binary.Operator.Modulus,
2195 (Expression) $1, (Expression) $3, lexer.Location);
2200 : multiplicative_expression
2201 | additive_expression PLUS multiplicative_expression
2203 $$ = new Binary (Binary.Operator.Addition,
2204 (Expression) $1, (Expression) $3, lexer.Location);
2206 | additive_expression MINUS multiplicative_expression
2208 $$ = new Binary (Binary.Operator.Subtraction,
2209 (Expression) $1, (Expression) $3, lexer.Location);
2214 : additive_expression
2215 | shift_expression OP_SHIFT_LEFT additive_expression
2217 $$ = new Binary (Binary.Operator.LeftShift,
2218 (Expression) $1, (Expression) $3, lexer.Location);
2220 | shift_expression OP_SHIFT_RIGHT additive_expression
2222 $$ = new Binary (Binary.Operator.RightShift,
2223 (Expression) $1, (Expression) $3, lexer.Location);
2227 relational_expression
2229 | relational_expression OP_LT shift_expression
2231 $$ = new Binary (Binary.Operator.LessThan,
2232 (Expression) $1, (Expression) $3, lexer.Location);
2234 | relational_expression OP_GT shift_expression
2236 $$ = new Binary (Binary.Operator.GreaterThan,
2237 (Expression) $1, (Expression) $3, lexer.Location);
2239 | relational_expression OP_LE shift_expression
2241 $$ = new Binary (Binary.Operator.LessThanOrEqual,
2242 (Expression) $1, (Expression) $3, lexer.Location);
2244 | relational_expression OP_GE shift_expression
2246 $$ = new Binary (Binary.Operator.GreaterThanOrEqual,
2247 (Expression) $1, (Expression) $3, lexer.Location);
2249 | relational_expression IS type
2251 $$ = new Is ((Expression) $1, (string) $3, lexer.Location);
2253 | relational_expression AS type
2255 $$ = new As ((Expression) $1, (string) $3, lexer.Location);
2260 : relational_expression
2261 | equality_expression OP_EQ relational_expression
2263 $$ = new Binary (Binary.Operator.Equality,
2264 (Expression) $1, (Expression) $3, lexer.Location);
2266 | equality_expression OP_NE relational_expression
2268 $$ = new Binary (Binary.Operator.Inequality,
2269 (Expression) $1, (Expression) $3, lexer.Location);
2274 : equality_expression
2275 | and_expression BITWISE_AND equality_expression
2277 $$ = new Binary (Binary.Operator.BitwiseAnd,
2278 (Expression) $1, (Expression) $3, lexer.Location);
2282 exclusive_or_expression
2284 | exclusive_or_expression CARRET and_expression
2286 $$ = new Binary (Binary.Operator.ExclusiveOr,
2287 (Expression) $1, (Expression) $3, lexer.Location);
2291 inclusive_or_expression
2292 : exclusive_or_expression
2293 | inclusive_or_expression BITWISE_OR exclusive_or_expression
2295 $$ = new Binary (Binary.Operator.BitwiseOr,
2296 (Expression) $1, (Expression) $3, lexer.Location);
2300 conditional_and_expression
2301 : inclusive_or_expression
2302 | conditional_and_expression OP_AND inclusive_or_expression
2304 $$ = new Binary (Binary.Operator.LogicalAnd,
2305 (Expression) $1, (Expression) $3, lexer.Location);
2309 conditional_or_expression
2310 : conditional_and_expression
2311 | conditional_or_expression OP_OR conditional_and_expression
2313 $$ = new Binary (Binary.Operator.LogicalOr,
2314 (Expression) $1, (Expression) $3, lexer.Location);
2318 conditional_expression
2319 : conditional_or_expression
2320 | conditional_or_expression INTERR expression COLON expression
2322 $$ = new Conditional ((Expression) $1, (Expression) $3, (Expression) $5, lexer.Location);
2326 assignment_expression
2327 : prefixed_unary_expression ASSIGN expression
2329 $$ = new Assign ((Expression) $1, (Expression) $3, lexer.Location);
2331 | prefixed_unary_expression OP_MULT_ASSIGN expression
2333 Location l = lexer.Location;
2335 $$ = new Assign ((Expression) $1,
2336 new Binary (Binary.Operator.Multiply,
2338 (Expression) $3, l), l);
2340 | prefixed_unary_expression OP_DIV_ASSIGN expression
2342 Location l = lexer.Location;
2344 $$ = new Assign ((Expression) $1,
2345 new Binary (Binary.Operator.Division,
2347 (Expression) $3, l), l);
2349 | prefixed_unary_expression OP_MOD_ASSIGN expression
2351 Location l = lexer.Location;
2353 $$ = new Assign ((Expression) $1,
2354 new Binary (Binary.Operator.Modulus,
2356 (Expression) $3, l), l);
2358 | prefixed_unary_expression OP_ADD_ASSIGN expression
2360 Location l = lexer.Location;
2362 $$ = new Assign ((Expression) $1,
2363 new Binary (Binary.Operator.Addition,
2365 (Expression) $3, l), l);
2367 | prefixed_unary_expression OP_SUB_ASSIGN expression
2369 Location l = lexer.Location;
2371 $$ = new Assign ((Expression) $1,
2372 new Binary (Binary.Operator.Subtraction,
2374 (Expression) $3, l), l);
2376 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
2378 Location l = lexer.Location;
2380 $$ = new Assign ((Expression) $1,
2381 new Binary (Binary.Operator.LeftShift,
2383 (Expression) $3, l), l);
2385 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
2387 Location l = lexer.Location;
2389 $$ = new Assign ((Expression) $1,
2390 new Binary (Binary.Operator.RightShift,
2392 (Expression) $3, l), l);
2394 | prefixed_unary_expression OP_AND_ASSIGN expression
2396 Location l = lexer.Location;
2398 $$ = new Assign ((Expression) $1,
2399 new Binary (Binary.Operator.BitwiseAnd,
2401 (Expression) $3, l), l);
2403 | prefixed_unary_expression OP_OR_ASSIGN expression
2405 Location l = lexer.Location;
2407 $$ = new Assign ((Expression) $1,
2408 new Binary (Binary.Operator.BitwiseOr,
2410 (Expression) $3, l), l);
2412 | prefixed_unary_expression OP_XOR_ASSIGN expression
2414 Location l = lexer.Location;
2416 $$ = new Assign ((Expression) $1,
2417 new Binary (Binary.Operator.ExclusiveOr,
2419 (Expression) $3, l), l);
2424 : conditional_expression
2425 | assignment_expression
2447 name = MakeName ((string) $4);
2449 new_class = new Class (current_container, name, (int) $2,
2450 (Attributes) $1, lexer.Location);
2451 current_container = new_class;
2452 current_container.Namespace = current_namespace;
2453 RootContext.Tree.RecordClass (name, new_class);
2459 Class new_class = (Class) current_container;
2462 new_class.Bases = (ArrayList) $6;
2464 current_container = current_container.Parent;
2465 CheckDef (current_container.AddClass (new_class), new_class.Name);
2472 : /* empty */ { $$ = (int) 0; }
2478 | modifiers modifier
2483 if ((m1 & m2) != 0) {
2484 Location l = lexer.Location;
2485 Report.Error (1004, l, "Duplicate modifier: `" + Modifiers.Name (m2) + "'");
2487 $$ = (int) (m1 | m2);
2492 : NEW { $$ = Modifiers.NEW; }
2493 | PUBLIC { $$ = Modifiers.PUBLIC; }
2494 | PROTECTED { $$ = Modifiers.PROTECTED; }
2495 | INTERNAL { $$ = Modifiers.INTERNAL; }
2496 | PRIVATE { $$ = Modifiers.PRIVATE; }
2497 | ABSTRACT { $$ = Modifiers.ABSTRACT; }
2498 | SEALED { $$ = Modifiers.SEALED; }
2499 | STATIC { $$ = Modifiers.STATIC; }
2500 | READONLY { $$ = Modifiers.READONLY; }
2501 | VIRTUAL { $$ = Modifiers.VIRTUAL; }
2502 | OVERRIDE { $$ = Modifiers.OVERRIDE; }
2503 | EXTERN { $$ = Modifiers.EXTERN; }
2504 | VOLATILE { $$ = Modifiers.VOLATILE; }
2508 : /* empty */ { $$ = null; }
2509 | class_base { $$ = $1; }
2513 : COLON type_list { $$ = $2; }
2521 // A block is "contained" on the following places:
2523 // property_declaration as part of the accessor body (get/set)
2524 // operator_declaration
2525 // constructor_declaration
2526 // destructor_declaration
2527 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
2532 current_block = new Block (current_block);
2534 opt_statement_list CLOSE_BRACE
2536 while (current_block.Implicit)
2537 current_block = current_block.Parent;
2539 current_block = current_block.Parent;
2550 | statement_list statement
2554 : declaration_statement
2556 if ((Block) $1 != current_block){
2557 current_block.AddStatement ((Statement) $1);
2558 current_block = (Block) $1;
2561 | embedded_statement
2563 Statement s = (Statement) $1;
2566 current_block.AddStatement ((Statement) $1);
2574 | expression_statement
2575 | selection_statement
2576 | iteration_statement
2580 | unchecked_statement
2588 $$ = new EmptyStatement ();
2595 LabeledStatement labeled = new LabeledStatement ((string) $1);
2597 if (!current_block.AddLabel ((string) $1, labeled)){
2598 Location l = lexer.Location;
2599 Report.Error (140, l, "The label '" + ((string) $1) + "' is a duplicate");
2601 current_block.AddStatement (labeled);
2606 declaration_statement
2607 : local_variable_declaration SEMICOLON
2609 DictionaryEntry de = (DictionaryEntry) $1;
2611 $$ = declare_local_variables ((string) de.Key, (ArrayList) de.Value, lexer.Location);
2614 | local_constant_declaration SEMICOLON
2616 DictionaryEntry de = (DictionaryEntry) $1;
2618 $$ = declare_local_constant ((string) de.Key, (VariableDeclaration) de.Value);
2623 * The following is from Rhys' grammar:
2624 * > Types in local variable declarations must be recognized as
2625 * > expressions to prevent reduce/reduce errors in the grammar.
2626 * > The expressions are converted into types during semantic analysis.
2629 : primary_expression opt_rank_specifier
2631 // FIXME: Do something smart here regarding the composition of the type.
2633 // Ok, the above "primary_expression" is there to get rid of
2634 // both reduce/reduce and shift/reduces in the grammar, it should
2635 // really just be "type_name". If you use type_name, a reduce/reduce
2636 // creeps up. If you use qualified_identifier (which is all we need
2637 // really) two shift/reduces appear.
2640 // So the super-trick is that primary_expression
2641 // can only be either a SimpleName or a MemberAccess.
2642 // The MemberAccess case arises when you have a fully qualified type-name like :
2644 // SimpleName is when you have
2647 Expression expr = (Expression) $1;
2648 if (!(expr is SimpleName || expr is MemberAccess)) {
2649 Location l = lexer.Location;
2650 Report.Error (-1, l, "Invalid Type definition");
2651 $$ = "System.Object";
2655 // So we extract the string corresponding to the SimpleName
2658 $$ = GetQualifiedIdentifier (expr) + (string) $2;
2660 | builtin_types opt_rank_specifier
2662 $$ = (string) $1 + (string) $2;
2666 // FIXME : How can the type of a local variable be void ? I don't quite see ;-)
2669 // // FIXME: this is a string that represents the type
2670 // // Figure out something to make this work.
2675 local_variable_declaration
2676 : local_variable_type variable_declarators
2678 $$ = new DictionaryEntry ($1, $2);
2682 local_constant_declaration
2683 : CONST local_variable_type constant_declarator
2685 $$ = new DictionaryEntry ($2, $3);
2689 expression_statement
2690 : statement_expression SEMICOLON
2697 // We have to do the wrapping here and not in the case above,
2698 // because statement_expression is used for example in for_statement
2700 statement_expression
2701 : invocation_expression { $$ = new StatementExpression ((ExpressionStatement) $1); }
2702 | object_creation_expression { $$ = new StatementExpression ((ExpressionStatement) $1); }
2703 | assignment_expression { $$ = new StatementExpression ((ExpressionStatement) $1); }
2704 | post_increment_expression { $$ = new StatementExpression ((ExpressionStatement) $1); }
2705 | post_decrement_expression { $$ = new StatementExpression ((ExpressionStatement) $1); }
2706 | pre_increment_expression { $$ = new StatementExpression ((ExpressionStatement) $1); }
2707 | pre_decrement_expression { $$ = new StatementExpression ((ExpressionStatement) $1); }
2709 Report.Error (1002, lexer.Location, "Expecting `;'");
2713 object_creation_expression
2714 : object_or_delegate_creation_expression
2715 { note ("complain if this is a delegate maybe?"); }
2724 : IF OPEN_PARENS boolean_expression CLOSE_PARENS
2727 $$ = new If ((Expression) $3, (Statement) $5);
2729 | IF OPEN_PARENS boolean_expression CLOSE_PARENS
2730 embedded_statement ELSE embedded_statement
2732 $$ = new If ((Expression) $3, (Statement) $5, (Statement) $7);
2737 : SWITCH OPEN_PARENS
2739 oob_stack.Push (lexer.Location);
2741 expression CLOSE_PARENS
2744 $$ = new Switch ((Expression) $4, (ArrayList) $6, (Location) oob_stack.Pop ());
2758 : /* empty */ { $$ = new ArrayList (); }
2765 ArrayList sections = new ArrayList ();
2770 | switch_sections switch_section
2772 ArrayList sections = (ArrayList) $1;
2782 current_block = new Block (current_block);
2786 while (current_block.Implicit)
2787 current_block = current_block.Parent;
2788 $$ = new SwitchSection ((ArrayList) $1, current_block);
2789 current_block = current_block.Parent;
2796 ArrayList labels = new ArrayList ();
2801 | switch_labels switch_label
2803 ArrayList labels = (ArrayList) ($1);
2811 : CASE constant_expression COLON { $$ = new SwitchLabel ((Expression) $2, lexer.Location); }
2812 | DEFAULT COLON { $$ = new SwitchLabel (null, lexer.Location); }
2823 : WHILE OPEN_PARENS boolean_expression CLOSE_PARENS embedded_statement
2825 $$ = new While ((Expression) $3, (Statement) $5);
2830 : DO embedded_statement
2831 WHILE OPEN_PARENS boolean_expression CLOSE_PARENS SEMICOLON
2833 $$ = new Do ((Statement) $2, (Expression) $5);
2839 opt_for_initializer SEMICOLON
2841 Block assign_block = new Block (current_block);
2842 current_block = assign_block;
2844 if ($3 is DictionaryEntry){
2845 DictionaryEntry de = (DictionaryEntry) $3;
2847 string type = (string) de.Key;
2848 ArrayList var_declarators = (ArrayList) de.Value;
2850 foreach (VariableDeclaration decl in var_declarators){
2852 if (!current_block.AddVariable (type, decl.identifier, current_local_parameters,
2854 Report.Error (128, decl.Location,
2855 "A local variable `" + decl.identifier + "' is already" +
2856 "defined in this scope");
2859 Location l = lexer.Location;
2861 if (decl.expression_or_array_initializer is Expression){
2862 expr = (Expression) decl.expression_or_array_initializer;
2866 ArrayList init = (ArrayList) decl.expression_or_array_initializer;
2868 string base_type = type.Substring (0, type.IndexOf ("["));
2869 string rank = type.Substring (type.IndexOf ("["));
2871 expr = new ArrayCreation (base_type, rank, init, decl.Location);
2874 LocalVariableReference var;
2875 var = new LocalVariableReference (
2876 assign_block, decl.identifier, l);
2878 Assign a = new Assign (var, expr, decl.Location);
2880 assign_block.AddStatement (new StatementExpression (a));
2887 opt_for_condition SEMICOLON
2888 opt_for_iterator CLOSE_PARENS
2891 For f = new For ((Statement) $3, (Expression) $6, (Statement) $8, (Statement) $10);
2893 current_block.AddStatement (f);
2894 while (current_block.Implicit)
2895 current_block = current_block.Parent;
2897 current_block = current_block.Parent;
2902 : /* empty */ { $$ = new EmptyStatement (); }
2907 : local_variable_declaration
2908 | statement_expression_list
2912 : /* empty */ { $$ = null; }
2913 | boolean_expression
2917 : /* empty */ { $$ = new EmptyStatement (); }
2922 : statement_expression_list
2925 statement_expression_list
2926 : statement_expression
2928 Block b = new Block (null, true);
2930 b.AddStatement ((Statement) $1);
2933 | statement_expression_list COMMA statement_expression
2935 Block b = (Block) $1;
2937 b.AddStatement ((Statement) $3);
2943 : FOREACH OPEN_PARENS type IDENTIFIER IN
2945 oob_stack.Push (lexer.Location);
2947 expression CLOSE_PARENS
2949 Block foreach_block = new Block (current_block, true);
2950 LocalVariableReference v;
2951 Location l = lexer.Location;
2953 foreach_block.AddVariable ((string) $3, (string) $4, current_local_parameters, l);
2954 v = new LocalVariableReference (foreach_block, (string) $4, l);
2956 current_block.AddStatement (foreach_block);
2957 current_block = foreach_block;
2959 oob_stack.Push (foreach_block);
2964 LocalVariableReference v = (LocalVariableReference) oob_stack.Pop ();
2965 Block foreach_block = (Block) oob_stack.Pop ();
2966 Location l = (Location) oob_stack.Pop ();
2968 $$ = new Foreach ((string) $3, v, (Expression) $7, (Statement) $10, l);
2974 | continue_statement
2983 $$ = new Break (lexer.Location);
2988 : CONTINUE SEMICOLON
2990 $$ = new Continue (lexer.Location);
2995 : GOTO IDENTIFIER SEMICOLON
2997 $$ = new Goto (current_block, (string) $2, lexer.Location);
2999 | GOTO CASE constant_expression SEMICOLON
3001 $$ = new GotoCase ((Expression) $3, lexer.Location);
3003 | GOTO DEFAULT SEMICOLON
3005 $$ = new GotoDefault (lexer.Location);
3010 : RETURN opt_expression SEMICOLON
3012 $$ = new Return ((Expression) $2, lexer.Location);
3017 : THROW opt_expression SEMICOLON
3019 $$ = new Throw ((Expression) $2, lexer.Location);
3029 : TRY block catch_clauses
3032 ArrayList s = new ArrayList ();
3034 foreach (Catch cc in (ArrayList) $3) {
3035 if (cc.Type == null)
3041 // Now s contains the list of specific catch clauses
3042 // and g contains the general one.
3044 $$ = new Try ((Block) $2, s, g, null);
3046 | TRY block opt_catch_clauses FINALLY block
3049 ArrayList s = new ArrayList ();
3051 foreach (Catch cc in (ArrayList) $3) {
3052 if (cc.Type == null)
3058 $$ = new Try ((Block) $2, s, g, (Block) $5);
3063 : /* empty */ { $$ = null; }
3070 ArrayList l = new ArrayList ();
3075 | catch_clauses catch_clause
3077 ArrayList l = (ArrayList) $1;
3085 : /* empty */ { $$ = null; }
3090 : CATCH opt_catch_args
3092 string type = null, id = null;
3095 DictionaryEntry cc = (DictionaryEntry) $2;
3096 type = (string) cc.Key;
3097 id = (string) cc.Value;
3100 ArrayList one = new ArrayList ();
3101 Location loc = lexer.Location;
3103 one.Add (new VariableDeclaration (id, null, loc));
3106 current_block = new Block (current_block);
3107 Block b = declare_local_variables (type, one, loc);
3114 string type = null, id = null;
3117 DictionaryEntry cc = (DictionaryEntry) $2;
3118 type = (string) cc.Key;
3119 id = (string) cc.Value;
3122 while (current_block != (Block) $1)
3123 current_block = current_block.Parent;
3128 $$ = new Catch (type, id , (Block) $4, lexer.Location);
3133 : /* empty */ { $$ = null; }
3138 : OPEN_PARENS type opt_identifier CLOSE_PARENS
3140 $$ = new DictionaryEntry ($2, $3);
3147 $$ = new Checked ((Block) $2);
3154 $$ = new Unchecked ((Block) $2);
3159 : LOCK OPEN_PARENS expression CLOSE_PARENS
3165 $$ = new Lock ((Expression) $3, (Statement) $6, lexer.Location);
3170 : USING OPEN_PARENS resource_acquisition CLOSE_PARENS
3172 Block assign_block = new Block (current_block);
3173 current_block = assign_block;
3175 oob_stack.Push (lexer.Location);
3177 if ($3 is DictionaryEntry){
3178 DictionaryEntry de = (DictionaryEntry) $3;
3179 Location l = lexer.Location;
3181 string type = (string) de.Key;
3182 ArrayList var_declarators = (ArrayList) de.Value;
3184 foreach (VariableDeclaration decl in var_declarators){
3185 if (!current_block.AddVariable (type, decl.identifier, current_local_parameters,
3187 Report.Error (128, decl.Location,
3188 "A local variable `" + decl.identifier + "' is already" +
3189 "defined in this scope");
3193 ArrayList vars = new ArrayList ();
3195 foreach (VariableDeclaration decl in var_declarators){
3198 if (decl.expression_or_array_initializer is Expression){
3199 expr = (Expression) decl.expression_or_array_initializer;
3203 ArrayList init = (ArrayList) decl.expression_or_array_initializer;
3205 string base_type = type.Substring (0, type.IndexOf ("["));
3206 string rank = type.Substring (type.IndexOf ("["));
3208 expr = new ArrayCreation (base_type, rank, init, decl.Location);
3211 LocalVariableReference var;
3214 var = new LocalVariableReference (assign_block, decl.identifier, l);
3215 vi = var.VariableInfo;
3218 // This is so that it is not a warning on using variables
3221 vars.Add (new DictionaryEntry (var, expr));
3223 // Assign a = new Assign (var, expr, decl.Location);
3224 // assign_block.AddStatement (new StatementExpression (a));
3226 $3 = new DictionaryEntry (type, vars);
3231 Using u = new Using ($3, (Statement) $6, (Location) oob_stack.Pop ());
3232 current_block.AddStatement (u);
3233 while (current_block.Implicit)
3234 current_block = current_block.Parent;
3236 current_block = current_block.Parent;
3240 resource_acquisition
3241 : local_variable_declaration
3248 // A class used to pass around variable declarations and constants
3250 public class VariableDeclaration {
3251 public string identifier;
3252 public object expression_or_array_initializer;
3253 public Location Location;
3255 public VariableDeclaration (string id, object eoai, Location l){
3256 this.identifier = id;
3257 this.expression_or_array_initializer = eoai;
3263 // A class used to hold info about an indexer declarator
3266 public class IndexerDeclaration {
3268 public string interface_type;
3269 public Parameters param_list;
3271 public IndexerDeclaration (string type, string interface_type, Parameters param_list)
3274 this.interface_type = interface_type;
3275 this.param_list = param_list;
3280 // A class used to hold info about an operator declarator
3283 public class OperatorDeclaration {
3284 public Operator.OpType optype;
3285 public string ret_type;
3286 public string arg1type;
3287 public string arg1name;
3288 public string arg2type;
3289 public string arg2name;
3290 public Location location;
3292 public OperatorDeclaration (Operator.OpType op, string ret_type, string arg1type, string arg1name,
3293 string arg2type, string arg2name, Location location)
3296 this.ret_type = ret_type;
3297 this.arg1type = arg1type;
3298 this.arg1name = arg1name;
3299 this.arg2type = arg2type;
3300 this.arg2name = arg2name;
3301 this.location = location;
3307 // Given the @class_name name, it creates a fully qualified name
3308 // based on the containing declaration space
3311 MakeName (string class_name)
3313 string ns = current_namespace.Name;
3314 string container_name = current_container.Name;
3316 if (container_name == ""){
3318 return ns + "." + class_name;
3322 return container_name + "." + class_name;
3326 // Used to report back to the user the result of a declaration
3327 // in the current declaration space
3330 CheckDef (AdditionResult result, string name)
3332 if (result == AdditionResult.Success)
3335 Location l = lexer.Location;
3338 case AdditionResult.NameExists:
3339 Report.Error (102, l, "The namespace `" + current_container.Name +
3340 "' already contains a definition for `"+
3346 // This is handled only for static Constructors, because
3347 // in reality we handle these by the semantic analysis later
3349 case AdditionResult.MethodExists:
3351 111, l, "Class `"+current_container.Name+
3352 "' already defines a member called '" +
3353 name + "' with the same parameter types (more than one default constructor)");
3356 case AdditionResult.EnclosingClash:
3357 Report.Error (542, l, "Member names cannot be the same as their enclosing type");
3360 case AdditionResult.NotAConstructor:
3361 Report.Error (1520, l, "Class, struct, or interface method must have a return type");
3367 CheckDef (bool result, string name)
3371 CheckDef (AdditionResult.NameExists, name);
3375 SimpleLookup (string name, Location loc)
3378 // we need to check against current_block not being null
3379 // as `expression' is allowed in argument_lists, which
3380 // do not exist inside a block.
3382 if (current_block != null){
3383 if (current_block.IsVariableDefined (name))
3384 return new LocalVariableReference (current_block, name, loc);
3387 if (current_local_parameters != null){
3389 Parameter par = current_local_parameters.GetParameterByName (name, out idx);
3391 return new ParameterReference (current_local_parameters, idx, name);
3397 Expression DecomposeQI (string name, Location loc)
3401 if (name.IndexOf ('.') == -1){
3402 o = SimpleLookup (name, loc);
3404 return new SimpleName (name, loc);
3407 int pos = name.LastIndexOf (".");
3408 string left = name.Substring (0, pos);
3409 string right = name.Substring (pos + 1);
3411 o = DecomposeQI (left, loc);
3412 return new MemberAccess (o, right, loc);
3417 // This method is used to get at the complete string representation of
3418 // a fully-qualified type name, hiding inside a MemberAccess ;-)
3419 // This is necessary because local_variable_type admits primary_expression
3420 // as the type of the variable. So we do some extra checking
3422 string GetQualifiedIdentifier (Expression expr)
3424 if (expr is SimpleName)
3425 return ((SimpleName)expr).Name;
3426 else if (expr is MemberAccess)
3427 return GetQualifiedIdentifier (((MemberAccess)expr).Expr) + "." + ((MemberAccess) expr).Identifier;
3429 throw new Exception ("Expr has to be either SimpleName or MemberAccess! (" + expr + ")");
3433 Block declare_local_variables (string type, ArrayList variable_declarators, Location loc)
3435 Block implicit_block;
3436 ArrayList inits = null;
3439 // We use the `Used' property to check whether statements
3440 // have been added to the current block. If so, we need
3441 // to create another block to contain the new declaration
3442 // otherwise, as an optimization, we use the same block to
3443 // add the declaration.
3445 // FIXME: A further optimization is to check if the statements
3446 // that were added were added as part of the initialization
3447 // below. In which case, no other statements have been executed
3448 // and we might be able to reduce the number of blocks for
3449 // situations like this:
3451 // int j = 1; int k = j + 1;
3453 if (current_block.Used)
3454 implicit_block = new Block (current_block, true);
3456 implicit_block = current_block;
3458 foreach (VariableDeclaration decl in variable_declarators){
3460 if (implicit_block.AddVariable (type, decl.identifier, current_local_parameters, decl.Location)) {
3461 if (decl.expression_or_array_initializer != null){
3463 inits = new ArrayList ();
3467 Report.Error (128, decl.Location, "A local variable `" + decl.identifier +
3468 "' is already defined in this scope");
3473 return implicit_block;
3475 foreach (VariableDeclaration decl in inits){
3479 if (decl.expression_or_array_initializer is Expression){
3480 expr = (Expression) decl.expression_or_array_initializer;
3483 ArrayList init = (ArrayList) decl.expression_or_array_initializer;
3485 string base_type = type.Substring (0, type.IndexOf ("["));
3486 string rank = type.Substring (type.IndexOf ("["));
3488 expr = new ArrayCreation (base_type, rank, init, decl.Location);
3492 LocalVariableReference var;
3493 var = new LocalVariableReference (implicit_block, decl.identifier, loc);
3495 assign = new Assign (var, expr, decl.Location);
3497 implicit_block.AddStatement (new StatementExpression (assign));
3500 return implicit_block;
3503 Block declare_local_constant (string type, VariableDeclaration decl)
3505 Block implicit_block;
3507 if (current_block.Used)
3508 implicit_block = new Block (current_block, true);
3510 implicit_block = current_block;
3512 if (!(implicit_block.AddConstant (type, decl.identifier, (Expression) decl.expression_or_array_initializer,
3513 current_local_parameters, decl.Location))){
3514 Report.Error (128, decl.Location, "A local variable `" + decl.identifier +
3515 "' is already defined in this scope");
3518 return implicit_block;
3521 void CheckAttributeTarget (string a)
3525 case "assembly" : case "field" : case "method" : case "param" : case "property" : case "type" :
3529 Location l = lexer.Location;
3530 Report.Error (658, l, "Invalid attribute target");
3536 void CheckUnaryOperator (Operator.OpType op)
3540 case Operator.OpType.LogicalNot:
3541 case Operator.OpType.OnesComplement:
3542 case Operator.OpType.Increment:
3543 case Operator.OpType.Decrement:
3544 case Operator.OpType.True:
3545 case Operator.OpType.False:
3546 case Operator.OpType.Addition:
3547 case Operator.OpType.Subtraction:
3552 Location l = lexer.Location;
3553 Report.Error (1019, l, "Overloadable unary operator expected");
3559 void CheckBinaryOperator (Operator.OpType op)
3563 case Operator.OpType.Addition:
3564 case Operator.OpType.Subtraction:
3565 case Operator.OpType.Multiply:
3566 case Operator.OpType.Division:
3567 case Operator.OpType.Modulus:
3568 case Operator.OpType.BitwiseAnd:
3569 case Operator.OpType.BitwiseOr:
3570 case Operator.OpType.ExclusiveOr:
3571 case Operator.OpType.LeftShift:
3572 case Operator.OpType.RightShift:
3573 case Operator.OpType.Equality:
3574 case Operator.OpType.Inequality:
3575 case Operator.OpType.GreaterThan:
3576 case Operator.OpType.LessThan:
3577 case Operator.OpType.GreaterThanOrEqual:
3578 case Operator.OpType.LessThanOrEqual:
3582 Location l = lexer.Location;
3583 Report.Error (1020, l, "Overloadable binary operator expected");
3589 void syntax_error (Location l, string msg)
3591 Report.Error (1003, l, "Syntax error, " + msg);
3594 void output (string s)
3596 Console.WriteLine (s);
3599 void note (string s)
3601 // Used to put annotations
3606 public Tokenizer Lexer {
3612 public CSharpParser (string name, System.IO.Stream input, ArrayList defines)
3614 current_namespace = new Namespace (null, "");
3617 current_container = RootContext.Tree.Types;
3618 current_container.Namespace = current_namespace;
3619 oob_stack = new Stack ();
3621 lexer = new Tokenizer (input, name, defines);
3624 public override int parse ()
3626 StringBuilder value = new StringBuilder ();
3630 if (yacc_verbose_flag)
3631 yyparse (lexer, new yydebug.yyDebugSimple ());
3634 } catch (Exception e){
3635 // Console.WriteLine ("Fatal error: " + name);
3636 // Console.WriteLine (lexer.location);
3639 // Please do not remove this, it is used during debugging
3642 Console.WriteLine (lexer.location + " : Parsing error ");
3643 Console.WriteLine (e);
3647 return global_errors;