3 // Mono.MonoBASIC.Parser.cs (from .jay): The Parser for the MonoBASIC compiler
5 // Authors: A Rafael D Teixeira (rafaelteixeirabr@hotmail.com)
6 // Anirban Bhattacharjee (banirban@novell.com)
7 // Jambunathan K (kjambunathan@novell.com)
8 // Manjula GHM (mmanjula@novell.com)
9 // Sudharsan V (vsudharsan@novell.com)
11 // Licensed under the terms of the GNU GPL
13 // Copyright (C) 2001, 2002, 2003, 2004 A Rafael D Teixeira
14 // Copyright (C) 2003, 2004 Novell
17 namespace Mono.MonoBASIC
21 using System.Reflection;
22 using System.Collections;
26 public class MBASException : ApplicationException
31 public MBASException(int code, Location loc, string text) : base(text)
39 /// The MonoBASIC Parser
42 public class Parser : GenericParser
48 /// Current block is used to add statements as we find
54 /// Tmp block is used to store block endings in if/select's
59 /// Tmp block is used to store tmp copies of expressions
64 /// Tmp catch is used to store catch clauses in try..catch..finally
66 ArrayList tmp_catch_clauses;
69 /// Current interface is used by the various declaration
70 /// productions in the interface declaration to "add"
71 /// the interfaces as we find them.
73 Interface current_interface;
76 /// This is used by the unary_expression code to resolve
77 /// a name against a parameter.
79 Parameters current_local_parameters;
82 /// This are used when parsing parameters in property
85 Parameters set_parameters;
86 Parameters get_parameters;
89 /// This is used by the sub_header parser to store modifiers
90 /// to be passed to sub/constructor
92 int current_modifiers;
95 /// This is used by the sub_header parser to store attributes
96 /// to be passed to sub/constructor
98 Attributes current_attributes;
101 /// Using during property parsing to describe the implicit
102 /// value parameter that is passed to the "set" accessor
105 string get_implicit_value_parameter_name;
108 // Using during property parsing to describe the implicit
109 // value parameter that is passed to the "set" and "get"accesor
110 // methods (properties and indexers).
112 Expression get_implicit_value_parameter_type;
115 /// Using during property parsing to describe the implicit
116 /// value parameter that is passed to the "set" accessor
119 string set_implicit_value_parameter_name;
122 // Using during property parsing to describe the implicit
123 // value parameter that is passed to the "set" and "get"accesor
124 // methods (properties and indexers).
126 Expression set_implicit_value_parameter_type;
128 // An out-of-band stack.
132 ArrayList current_rank_specifiers;
134 //To handle the End of a block
135 // We use grammer, priority, strings, and an integer called Parenta
137 // FIX ME: Need to implement some better method than this and in
138 // some cases parser will come out without proceeding further
139 // if it comes acorss error.
141 public string[] end_blocks = {"Nothing", "Next", "Loop", "End If", "End Sub", "End Module", "End Namespace", "End Class", "End Function", "End Structure", "End Enum", "End Interface", "End Property", "End With", "End Synclock", "End Try", "End While", "End Select", "End Set", "End Get"};
143 public string[] open_blocks = {"Block", "For", "Do", "If", "Sub", "Module", "Namespace", "Class", "Function", "Structure", "Enum", "Interface", "Property", "With", "Synclock", "Try", "While", "Select", "Set", "Get","\nCompilation failed"};
145 public int[] error_numbers = {29999, 30092, 30091, 30087, 30429, 30622, 30623, 30460, 30430, 30621, 30184, 30252, 30431, 30093, 30674, 30383, 30090, 30088, 30632, 30630, 29999};
147 public int[] end_priority = {0,1,1,1,2,3,4,3,2,3,1,2,2,1,1,1,1,1,1,1,1};
158 // Expression stack for nested ifs
162 Stack statement_stack;
164 // A stack for With expressions.
169 static public bool InitialOptionExplicit = false;
170 static public bool InitialOptionStrict = false;
171 static public bool InitialOptionCompareBinary = true;
172 static public ArrayList ImportsList = null;
176 bool OptionCompareBinary;
178 static public bool UseExtendedSyntax; // for ".mbs" files
180 bool implicit_modifiers;
182 public override string[] extensions()
184 string [] list = { ".vb", ".mbs" };
188 bool in_external_source = false;
189 int in_marked_region = 0;
191 TokenizerController tokenizerController;
192 IfElseStateMachine ifElseStateMachine;
195 public class IfElseStateMachine {
219 public static Hashtable errStrings = new Hashtable();
222 static int[,] errTable = new int[(int)State.MAX, (int)Token.MAX];
224 static IfElseStateMachine()
226 // FIXME: Fix both the error nos and the error strings.
227 // Currently the error numbers and the error strings are
228 // just placeholders for getting the state-machine going.
230 errStrings.Add(0, "");
231 errStrings.Add(30012, "#If must end with a matching #End If");
232 errStrings.Add(30013, "#ElseIf, #Else or #End If must be preceded by a matching #If");
233 errStrings.Add(30014, "#ElseIf must be preceded by a matching #If or #ElseIf");
234 errStrings.Add(30028, "#Else must be preceded by a matching #If or #ElseIf");
235 errStrings.Add(32030, "#ElseIf cannot follow #Else as part of #If block");
237 errTable[(int)State.START, (int)Token.IF] = 0;
238 errTable[(int)State.START, (int)Token.ELSEIF] = 30014;
239 errTable[(int)State.START, (int)Token.ELSE] = 30028;
240 errTable[(int)State.START, (int)Token.ENDIF] = 30013;
241 errTable[(int)State.START, (int)Token.EOF] = 0;
243 errTable[(int)State.IF_SEEN, (int)Token.IF] = 0;
244 errTable[(int)State.IF_SEEN, (int)Token.ELSEIF] = 0;
245 errTable[(int)State.IF_SEEN, (int)Token.ELSE] = 0;
246 errTable[(int)State.IF_SEEN, (int)Token.ENDIF] = 0;
247 errTable[(int)State.IF_SEEN, (int)Token.EOF] = 30012;
249 errTable[(int)State.ELSEIF_SEEN, (int)Token.IF] = 0;
250 errTable[(int)State.ELSEIF_SEEN, (int)Token.ELSEIF] = 0;
251 errTable[(int)State.ELSEIF_SEEN, (int)Token.ELSE] = 0;
252 errTable[(int)State.ELSEIF_SEEN, (int)Token.ENDIF] = 0;
253 errTable[(int)State.ELSEIF_SEEN, (int)Token.EOF] = 30012;
255 errTable[(int)State.ELSE_SEEN, (int)Token.IF] = 0;
256 errTable[(int)State.ELSE_SEEN, (int)Token.ELSEIF] = 32030;
257 errTable[(int)State.ELSE_SEEN, (int)Token.ELSE] = 32030;
258 errTable[(int)State.ELSE_SEEN, (int)Token.ENDIF] = 0;
259 errTable[(int)State.ELSE_SEEN, (int)Token.EOF] = 30012;
261 errTable[(int)State.ENDIF_SEEN, (int)Token.IF] = 0;
262 errTable[(int)State.ENDIF_SEEN, (int)Token.ELSEIF] = 30014;
263 errTable[(int)State.ENDIF_SEEN, (int)Token.ELSE] = 30028;
264 errTable[(int)State.ENDIF_SEEN, (int)Token.ENDIF] = 30013;
265 errTable[(int)State.ENDIF_SEEN, (int)Token.EOF] = 0;
268 public IfElseStateMachine()
272 stateStack = new Stack();
273 stateStack.Push(state);
276 // The parameter here need not be qualified with IfElseStateMachine
277 // But it hits a bug in mcs. So temporarily scoping it so that builds
280 public void HandleToken(IfElseStateMachine.Token tok)
282 err = (int) errTable[(int)state, (int)tok];
285 throw new ApplicationException("Unexpected pre-processor directive #"+tok);
287 if(tok == Token.IF) {
288 stateStack.Push(state);
291 else if(tok == Token.ENDIF) {
292 state = (State)stateStack.Pop();
304 public string ErrString {
306 return (string) errStrings[err];
312 public class TokenizerController {
316 public bool CanAcceptTokens;
317 public bool CanSelectBlock;
324 public TokenizerController(Tokenizer lexer)
327 stateStack = new Stack();
329 currentState.CanAcceptTokens = true;
330 currentState.CanSelectBlock = true;
332 stateStack.Push(currentState);
337 return (State)stateStack.Peek();
341 public bool IsAcceptingTokens {
343 return currentState.CanAcceptTokens;
347 public void PositionCursorAtNextPreProcessorDirective()
349 lexer.PositionCursorAtNextPreProcessorDirective();
352 public void PositionTokenizerCursor(IfElseStateMachine.Token tok, BoolLiteral expr)
354 if(tok == IfElseStateMachine.Token.ENDIF) {
355 currentState = (State)stateStack.Pop();
357 if(currentState.CanAcceptTokens)
360 PositionCursorAtNextPreProcessorDirective();
365 if(tok == IfElseStateMachine.Token.IF) {
366 stateStack.Push(currentState);
368 currentState.CanAcceptTokens = parentState.CanAcceptTokens;
369 currentState.CanSelectBlock = true;
372 if(parentState.CanAcceptTokens &&
373 currentState.CanSelectBlock && (bool)(expr.GetValue()) ) {
375 currentState.CanAcceptTokens = true;
376 currentState.CanSelectBlock = false;
380 currentState.CanAcceptTokens = false;
381 PositionCursorAtNextPreProcessorDirective();
387 bool allow_global_attribs = true;
389 bool expecting_global_attribs = false;
390 bool expecting_local_attribs = false;
392 bool local_attrib_section_added = false;
396 %token NONE /* This token is never returned by our lexer */
397 %token ERROR // This is used not by the parser, but by the tokenizer.
401 *These are the MonoBASIC keywords
493 %token NOTINHERITABLE
494 %token NOTOVERRIDABLE
550 %token YIELD // MonoBASIC extension
554 /* MonoBASIC single character operators/punctuation. */
556 %token OPEN_BRACKET "["
557 %token CLOSE_BRACKET "]"
558 %token OPEN_PARENS "("
559 %token OPEN_BRACE "{"
560 %token CLOSE_BRACE "}"
561 %token CLOSE_PARENS ")"
575 %token OP_IDIV "\\" //FIXME: This should be "\"
577 %token EXCLAMATION "!"
580 %token LONGTYPECHAR "&"
582 %token SINGLETYPECHAR "!"
583 %token NUMBER_SIGN "#"
584 %token DOLAR_SIGN "$"
586 %token ATTR_ASSIGN ":="
588 /* MonoBASIC multi-character operators. */
593 //%token OP_MODULUS //"mod"
595 /* VB.NET 2003 new bit-shift operators */
596 %token OP_SHIFT_LEFT "<<"
597 %token OP_SHIFT_RIGHT ">>"
600 %token LITERAL_INTEGER "int literal"
601 %token LITERAL_SINGLE "float literal"
602 %token LITERAL_DOUBLE "double literal"
603 %token LITERAL_DECIMAL "decimal literal"
604 %token LITERAL_CHARACTER "character literal"
605 %token LITERAL_STRING "string literal"
606 %token LITERAL_DATE "datetime literal"
610 /* Add precedence rules to solve dangling else s/r conflict */
619 %left OP_SHIFT_LEFT OP_SHIFT_RIGHT
621 %left STAR DIV PERCENT
622 %right BITWISE_NOT CARRET UMINUS
623 %nonassoc OP_INC OP_DEC
625 %left OPEN_BRACKET OPEN_BRACE
630 %start compilation_unit
634 : logical_end_of_line
641 | logical_end_of_line pp_directive
645 : logical_end_of_line _mark_
646 opt_option_directives
647 opt_imports_directives
653 | logical_end_of_line _mark_
654 opt_option_directives
655 opt_imports_directives
663 opt_option_directives
670 | option_directives option_directive
674 : option_explicit_directive
675 | option_strict_directive
676 | option_compare_directive
677 | OPTION _mark_ logical_end_of_line
679 Report.Error(30206 ,(Location)$2, "Option must be followed by 'Compare' or 'Explicit' or 'Strict'");
681 | OPTION _mark_ IDENTIFIER logical_end_of_line
683 Report.Error(30206 ,(Location)$2, "Option must be followed by 'Compare' or 'Explicit' or 'Strict'");
713 option_explicit_directive
714 : OPTION EXPLICIT _mark_ on_off logical_end_of_line
716 if (!UseExtendedSyntax)
717 OptionExplicit = (bool)$4;
721 "In MonoBASIC extended syntax explicit declaration is always required. So OPTION EXPLICIT is deprecated");
726 option_strict_directive
727 : OPTION STRICT _mark_ on_off logical_end_of_line
729 if (!UseExtendedSyntax)
730 OptionStrict = (bool)$4;
734 "In MonoBASIC extended syntax strict assignability is always required. So OPTION STRICT is deprecated");
738 option_compare_directive
739 : OPTION COMPARE text_or_binary logical_end_of_line
741 OptionCompareBinary = (bool)$3;
752 | declarations declaration
756 : declaration_qualifiers
758 // FIXME: Need to check declaration qualifiers for multi-file compilation
759 // FIXME: Qualifiers cannot be applied to namespaces
760 allow_global_attribs = false;
762 namespace_declaration
763 |declaration_qualifiers _mark_
765 // FIXME: Need to check declaration qualifiers for multi-file compilation
766 allow_global_attribs = false;
768 type_spec_declaration
773 if ($4 is Class || $4 is Struct || $4 is Module ){
774 TypeContainer c = (TypeContainer) $4;
775 mod_flags = c.ModFlags;
780 if ((mod_flags & (Modifiers.PRIVATE)) != 0){
783 "Namespace elements cannot be explicitly " +
784 "declared private in '" + name + "'");
786 else if ((mod_flags & (Modifiers.PROTECTED)) != 0){
789 "Namespace elements cannot be explicitly " +
790 "declared protected in '" + name + "'");
805 : PERCENT { $$ = TypeManager.system_int32_expr; }
806 | LONGTYPECHAR { $$ = TypeManager.system_int64_expr; }
807 | AT_SIGN { $$ = TypeManager.system_decimal_expr; }
808 | SINGLETYPECHAR { $$ = TypeManager.system_single_expr; }
809 | NUMBER_SIGN { $$ = TypeManager.system_double_expr; }
810 | DOLAR_SIGN { $$ = TypeManager.system_string_expr; }
814 : /* empty */ { $$ = null; }
815 | type_character { $$ = $1; }
821 | qualified_identifier DOT identifier // FIXME: It should be qualified_identifier DOT identifier-or-keyword
823 $$ = (($1).ToString ()) + "." + ($3.ToString ());
827 opt_imports_directives
834 | imports_directives imports_directive
838 : IMPORTS imports_terms logical_end_of_line
843 | imports_terms COMMA imports_term
847 : namespace_or_type_name
849 RootContext.SourceBeingCompiled.Imports ((string) $1, lexer.Location);
851 | identifier _mark_ ASSIGN namespace_or_type_name
853 RootContext.SourceBeingCompiled.ImportsWithAlias ((string) $1, (string) $4, (Location)$2);
855 | identifier _mark_ ASSIGN
857 Report.Error(30203, (Location)$2, "Alias Statement no complete: Expression Expected");
861 Report.Error(30203, (Location)$1, "No namespace imported: Expression Expected");
866 : /* empty */ { $$ = Parameters.EmptyReadOnlyParameters; }
867 | OPEN_PARENS CLOSE_PARENS { $$ = Parameters.EmptyReadOnlyParameters; }
868 | OPEN_PARENS _mark_ opt_formal_parameter_list CLOSE_PARENS { $$ = $3; }
871 Report.Error(30203,(Location)$2, "Identifier Expected");
872 $$ = Parameters.EmptyReadOnlyParameters;
874 | OPEN_PARENS _mark_ opt_formal_parameter_list
876 Report.Error(30198,(Location)$2, "'(' is not having a matching ')'");
879 | _mark_ opt_formal_parameter_list CLOSE_PARENS
881 Report.Error(30205,(Location)$1, "')' is not having a matching '('");
891 local_attrib_section_added = false;
900 expecting_local_attribs = false;
901 expecting_global_attribs = false;
905 if (expecting_local_attribs) {
906 local_attrib_section_added = true;
907 allow_global_attribs = false;
909 $$ = new Attributes ((ArrayList) $1);
912 if (expecting_global_attribs) {
914 CodeGen.AddGlobalAttributes ((ArrayList) $1);
917 expecting_local_attribs = false;
918 expecting_global_attribs = false;
928 ArrayList attrs = (ArrayList) $3;
930 if (expecting_local_attribs) {
931 if (local_attrib_section_added) {
932 expecting_local_attribs = false;
933 expecting_global_attribs = false;
934 Report.Error (30205, (Location) $2, "Multiple attribute sections may not be used; Coalesce multiple attribute sections in to a single attribute section");
939 $$ = new Attributes (attrs);
941 ((Attributes) $1).Add (attrs);
943 local_attrib_section_added = true;
944 allow_global_attribs = false;
947 if (expecting_global_attribs) {
949 CodeGen.AddGlobalAttributes ((ArrayList) $3);
953 expecting_local_attribs = false;
954 expecting_global_attribs = false;
959 : OP_LT attribute_list OP_GT opt_end_of_stmt
963 if (expecting_global_attribs && !(bool) $4) {
964 Report.Error (30205, lexer.Location, "End of statement expected");
968 if (expecting_local_attribs) {
970 Report.Error (32035, lexer.Location, "Use a line continuation after the attribute specifier to apply it to the following statement.");
981 : /* empty */ { $$ = false; }
982 | end_of_stmt { $$ = true; }
988 ArrayList attrs = null;
990 attrs = new ArrayList ();
995 | attribute_list COMMA attribute
997 ArrayList attrs = null;
1000 attrs = ($1 == null) ? new ArrayList () : (ArrayList) $1;
1009 : namespace_or_type_name
1011 $$ = lexer.Location;
1013 opt_attribute_arguments
1017 if (expecting_global_attribs)
1018 Report.Error (32015, (Location) $2, "Expecting Assembly or Module attribute specifiers");
1020 expecting_local_attribs = true;
1021 $$ = new Attribute ((string) $1, (ArrayList) $3, (Location) $2);
1024 | attribute_target_specifier
1026 $$ = lexer.Location;
1029 namespace_or_type_name
1031 $$ = lexer.Location;
1033 opt_attribute_arguments
1037 string attribute_target = (string) $1;
1038 if (attribute_target != "assembly" && attribute_target != "module") {
1039 Report.Error (29999, lexer.Location, "`" + (string)$1 + "' is an invalid attribute modifier");
1042 if (!allow_global_attribs) {
1043 Report.Error (30637, (Location) $2, "Global attribute statements must precede any declarations in a file");
1047 if (expecting_local_attribs) {
1048 Report.Error (30183, (Location) $2, "Global attributes cannot be combined with local attributes");
1052 expecting_global_attribs = true;
1053 $$ = new Attribute (attribute_target, (string) $4, (ArrayList) $6, (Location) $5);
1057 attribute_target_specifier
1058 : ASSEMBLY { $$ = "assembly"; }
1059 | MODULE { $$ = "module"; }
1060 | namespace_or_type_name
1064 opt_attribute_arguments
1065 : /* empty */ { $$ = null; }
1066 | OPEN_PARENS opt_attribute_arguments_list CLOSE_PARENS
1072 opt_attribute_arguments_list
1074 | attribute_arguments_list
1077 attribute_arguments_list
1078 : positional_argument_list
1080 ArrayList args = new ArrayList ();
1085 | positional_argument_list COMMA named_argument_list
1087 ArrayList args = new ArrayList ();
1093 | named_argument_list
1095 ArrayList args = new ArrayList ();
1103 positional_argument_list
1104 : constant_expression
1106 ArrayList args = new ArrayList ();
1107 args.Add (new Argument ((Expression) $1, Argument.AType.Expression));
1111 | positional_argument_list COMMA constant_expression
1113 ArrayList args = (ArrayList) $1;
1114 args.Add (new Argument ((Expression) $3, Argument.AType.Expression));
1123 ArrayList args = new ArrayList ();
1128 | named_argument_list COMMA named_argument
1130 ArrayList args = (ArrayList) $1;
1138 : identifier ATTR_ASSIGN constant_expression //FIXME: It should be identifier_or_keyword ATTR_ASSIGN constant_expression
1140 $$ = new DictionaryEntry (
1142 new Argument ((Expression) $3, Argument.AType.Expression));
1146 namespace_declaration
1147 : NAMESPACE _mark_ qualified_identifier logical_end_of_line
1149 current_namespace = RootContext.Tree.RecordNamespace(current_namespace, name, (string)$3);
1156 if (end_priority[6]>=end_priority[i] && i!=6)
1158 Report.Error(error_numbers[i],lexer.Location,"'"+end_blocks[i]+"' found without a matching '"+open_blocks[i]+"'"+open_blocks[20]);
1159 Environment.Exit(1);
1161 if (i!=6 && Parent!=6)
1163 Report.Error(30626,(Location)$2,"'NameSpace' is not having a matching 'End NameSpace'");
1173 current_namespace = current_namespace.Parent;
1177 declaration_qualifiers
1181 current_attributes = (Attributes) $1;
1182 current_modifiers = (int) $2;
1186 type_spec_declaration
1188 | module_declaration
1189 | interface_declaration
1190 | delegate_declaration
1191 | struct_declaration
1196 : CLASS identifier _mark_ end_of_stmt opt_inherits opt_implements
1198 // Module members are static by default, but Class *can't* be declared static
1199 // so we must fix it, if mbas was the one actually responsible for this
1200 // instead of triggering an error.
1201 if (implicit_modifiers && ((current_modifiers & Modifiers.STATIC) != 0))
1202 current_modifiers = (current_modifiers & ~Modifiers.STATIC);
1207 name = MakeName ((string) $2);
1208 new_class = new Class (current_container, name, current_modifiers,
1209 (Attributes) current_attributes, (Location)$3);
1211 current_container = new_class;
1212 current_container.Namespace = current_namespace;
1213 RootContext.Tree.RecordDecl (name, new_class);
1215 opt_class_member_declarations
1219 if (end_priority[7]>=end_priority[i] && i!=7)
1221 Report.Error(error_numbers[i],lexer.Location,"'"+end_blocks[i]+"' found without a matching '"+open_blocks[i]+"'"+open_blocks[20]);
1222 Environment.Exit(1);
1224 if (i!=7 && Parent!=7)
1226 Report.Error(30481,(Location)$3,"'Class' is not having a matching 'End Class'");
1236 Class new_class = (Class) current_container;
1238 ArrayList bases = (ArrayList) $5;
1240 ArrayList ifaces = (ArrayList) $6;
1241 if (ifaces != null){
1243 bases.AddRange(ifaces);
1247 new_class.Bases = bases;
1249 current_container = current_container.Parent;
1250 CheckDef (current_container.AddClass (new_class), new_class.Name, new_class.Location);
1257 : /* empty */ { $$ = null; }
1258 | INHERITS type_list end_of_stmt { $$ = $2; }
1262 : /* empty */ { $$ = null; }
1263 | IMPLEMENTS type_list end_of_stmt { $$ = $2; }
1267 : /* empty */ { $$ = (int) 0; current_modifiers = 0; }
1268 | modifiers { $$ = $1; current_modifiers = (int) $1; }
1273 | modifiers modifier
1278 if ((m1 & m2) != 0) {
1279 Location l = lexer.Location;
1280 Report.Error (1004, l, "Duplicate modifier: `" + Modifiers.Name (m2) + "'");
1282 $$ = (int) (m1 | m2);
1287 : PUBLIC { $$ = Modifiers.PUBLIC; }
1288 | PROTECTED { $$ = Modifiers.PROTECTED; }
1289 | PRIVATE { $$ = Modifiers.PRIVATE; }
1290 | SHARED { $$ = Modifiers.STATIC; }
1291 | FRIEND { $$ = Modifiers.INTERNAL; }
1292 | NOTINHERITABLE { $$ = Modifiers.SEALED; }
1293 | OVERRIDABLE { $$ = Modifiers.VIRTUAL; }
1294 | NOTOVERRIDABLE { $$ = Modifiers.NONVIRTUAL; }
1295 | OVERRIDES { $$ = Modifiers.OVERRIDE; }
1296 | OVERLOADS { $$ = Modifiers.NEW; }
1297 | SHADOWS { $$ = Modifiers.SHADOWS; }
1298 | MUSTINHERIT { $$ = Modifiers.ABSTRACT; }
1299 | READONLY { $$ = Modifiers.READONLY; }
1300 | DEFAULT { $$ = Modifiers.DEFAULT; }
1301 | WRITEONLY { $$ = Modifiers.WRITEONLY; }
1305 : MODULE _mark_ identifier logical_end_of_line
1309 name = MakeName((string) $3);
1310 new_module = new Module(current_container,
1312 current_modifiers, // already checks then
1313 (Attributes) current_attributes,
1315 current_container = new_module;
1316 current_container.Namespace = current_namespace;
1317 RootContext.Tree.RecordDecl(name, new_module);
1319 opt_module_member_declarations
1323 if (end_priority[5]>=end_priority[i] && i!=5)
1325 Report.Error(error_numbers[i],lexer.Location,"'"+end_blocks[i]+"' found without a matching '"+open_blocks[i]+"'"+open_blocks[20]);
1326 Environment.Exit(1);
1328 if (i!=5 && Parent!=5)
1330 Report.Error(30625,(Location)$2,"'Module' is not having a matching 'End Module'");
1340 Module new_module = (Module)current_container;
1342 current_container = current_container.Parent;
1343 CheckDef (current_container.AddClass(new_module), new_module.Name, new_module.Location);
1345 TypeManager.AddStandardModule(new_module);
1351 opt_module_member_declarations
1353 | module_member_declarations
1356 module_member_declarations
1357 : module_member_declaration
1358 | module_member_declarations module_member_declaration
1361 module_member_declaration
1365 current_attributes = (Attributes) $1;
1366 current_modifiers = ((int)$2) | Modifiers.STATIC;
1367 bool explicit_static = (((int) $2 & Modifiers.STATIC) > 0);
1368 implicit_modifiers = (!explicit_static);
1370 module_member_declarator
1372 implicit_modifiers = false;
1377 module_member_declarator
1378 : constructor_declaration
1379 | method_declaration
1381 Method method = (Method) $1;
1382 CheckDef (current_container.AddMethod (method), method.Name, method.Location);
1385 | withevents_declaration /* This is a field but must be treated specially, see below */
1386 | constant_declaration
1387 | property_declaration
1389 | type_spec_declaration
1392 constant_declaration
1393 : CONST constant_declarators end_of_stmt
1395 // Module members are static by default, but constants *can't* be declared static
1396 // so we must fix it, if mbas was the one actually responsible for this
1397 // instead of triggering an error.
1398 if (implicit_modifiers && ((current_modifiers & Modifiers.STATIC) != 0))
1399 current_modifiers = (current_modifiers & ~Modifiers.STATIC);
1401 int mod = (int) current_modifiers;
1403 // Structure members are Public by default
1404 if ((current_container is Struct) && (mod == 0))
1405 mod = Modifiers.PUBLIC;
1407 ArrayList consts = (ArrayList) $2;
1408 if(consts.Count > 0)
1410 VariableDeclaration.FixupTypes ((ArrayList) $2);
1411 VariableDeclaration.FixupArrayTypes ((ArrayList) $2);
1413 foreach (VariableDeclaration var in (ArrayList) $2){
1414 Location l = var.Location;
1415 Const vconstant = new Const ((Expression)var.type, (String)var.identifier,
1416 (Expression)var.expression_or_array_initializer,
1417 mod, (Attributes) null, l);
1419 CheckDef (current_container.AddConstant (vconstant), vconstant.Name, l);
1425 opt_class_member_declarations
1427 | class_member_declarations
1430 class_member_declarations
1431 : class_member_declaration
1432 | class_member_declarations class_member_declaration
1435 class_member_declaration
1439 current_attributes = (Attributes) $1;
1440 current_modifiers = (int) $2;
1442 class_member_declarator
1448 class_member_declarator
1449 : constructor_declaration
1450 | method_declaration
1452 Method method = (Method) $1;
1453 CheckDef (current_container.AddMethod (method), method.Name, method.Location);
1456 | constant_declaration
1457 | property_declaration
1459 | withevents_declaration /* This is a field but must be treated specially, see below */
1460 | type_spec_declaration
1467 | must_override_declaration
1470 must_override_declaration
1471 : must_override_sub_declaration
1472 | must_override_func_declaration
1475 must_override_sub_declaration
1476 : MUSTOVERRIDE SUB identifier opt_params opt_implement_clause _mark_ logical_end_of_line
1478 if (current_container is Module)
1479 Report.Error (30433, (Location)$6, "Methods in a Module cannot be declared 'MustOverride'.");
1481 if (current_container is Struct)
1482 Report.Error (435, (Location)$6, "Methods in a Structure cannot be declared 'MustOverride'.");
1484 current_modifiers |= Modifiers.ABSTRACT;
1486 Method method = new Method (TypeManager.system_void_expr, (int) current_modifiers, (string) $3,
1487 (Parameters) $4, null, (ArrayList) $5, (Location)$6);
1489 if (!(current_container is Class))
1490 Report.Error (9999, (Location)$6, "THIS SHOULD NEVER HAPPEN!");
1497 must_override_func_declaration
1498 : MUSTOVERRIDE FUNCTION identifier opt_type_character opt_params _mark_ opt_type_with_ranks opt_implement_clause logical_end_of_line
1500 Expression ftype = ($7 == null) ? (($4 == null) ? TypeManager.
1501 system_object_expr : (Expression) $4 ) : (Expression) $7;
1503 if (current_container is Module)
1504 Report.Error (30433, (Location)$6,"Methods in a Module cannot be declared 'MustOverride'.");
1506 if (current_container is Struct)
1507 Report.Error (435, (Location)$6,"Methods in a Structure cannot be declared 'MustOverride'.");
1509 current_modifiers |= Modifiers.ABSTRACT;
1511 Method method = new Method ((Expression) ftype, (int) current_modifiers,
1512 (string) $3,(Parameters) $5, null, (ArrayList) $8,
1515 if (!(current_container is Class))
1516 Report.Error (9999, (Location)$6,"THIS SHOULD NEVER HAPPEN!");
1523 : SUB identifier _mark_ opt_params opt_evt_handler opt_implement_clause logical_end_of_line
1525 current_local_parameters = (Parameters) $4;
1528 // Structure members are Public by default
1529 if ((current_container is Struct) && (current_modifiers == 0))
1530 current_modifiers = Modifiers.PUBLIC;
1537 if (end_priority[4]>=end_priority[i] && i!=4)
1539 Report.Error(error_numbers[i],lexer.Location,"'"+end_blocks[i]+"' found without a matching '"+open_blocks[i]+"'"+open_blocks[20]);
1540 Environment.Exit(1);
1542 if (i!=4 && Parent!=4)
1544 Report.Error(30289,(Location)$3,"'Sub' is not having a matching 'End Sub'");
1554 Method method = new Method (TypeManager.system_void_expr, (int) current_modifiers, (string) $2,
1555 (Parameters) current_local_parameters, (Attributes) current_attributes,
1556 (ArrayList) $6, (Location)$3);
1558 method.Block = (Block) end_block();
1562 // we have an event handler to take care of
1564 Expression handles_exp = (Expression) $5;
1565 Location loc = (Location)$3;
1567 if (handles_exp is MemberAccess) {
1568 string evt_def = ((MemberAccess)$5).ToString();
1569 int pos = evt_def.LastIndexOf (".");
1570 string evt_target = evt_def.Substring (0, pos);
1573 if (current_container.Properties != null) {
1574 foreach (Property p in current_container.Properties) {
1575 if (p.Name == evt_target) {
1578 Statement addhnd = (Statement) new AddHandler ((Expression) $5,
1579 DecomposeQI((string) $2, loc),
1582 current_container.AddEventHandler (addhnd);
1590 Report.Error(30506, (Location)$3,
1591 evt_target + " is not declared with WithEvents");
1593 } else if (handles_exp is BaseAccess) {
1594 Statement addhnd = (Statement) new AddHandler ((Expression) $5,
1595 DecomposeQI((string) $2, loc),
1598 current_container.AddEventHandler (addhnd);
1606 : FUNCTION identifier opt_type_character
1607 opt_params _mark_ opt_type_with_ranks opt_implement_clause logical_end_of_line
1609 current_local_parameters = (Parameters) $4;
1612 Expression ftype = ($6 == null) ? (($3 == null) ? TypeManager.system_object_expr : (Expression) $3 ) : (Expression) $6;
1614 // Structure members are Public by default
1615 if ((current_container is Struct) && (current_modifiers == 0))
1616 current_modifiers = Modifiers.PUBLIC;
1617 // Add local var declaration
1619 ArrayList retval = new ArrayList ();
1620 retval.Add (new VariableDeclaration ((string) $2, (Expression) ftype, (Location)$5));
1621 declare_local_variables ((Expression) ftype, retval, (Location)$5);
1627 if (end_priority[8]>=end_priority[i] && i!=8)
1629 Report.Error(error_numbers[i],lexer.Location,"'"+end_blocks[i]+"' found without a matching '"+open_blocks[i]+"'"+open_blocks[20]);
1630 Environment.Exit(1);
1632 if (i!=8 && Parent!=8)
1634 Report.Error(30027,(Location)$5,"'Function' is not having a matching 'End Function'");
1644 Expression ftype = ($6 == null) ? (($3 == null) ? TypeManager.system_object_expr : (Expression) $3 ) : (Expression) $6;
1646 Method method = new Method ((Expression) ftype, (int) current_modifiers, (string) $2,
1647 (Parameters) current_local_parameters, (Attributes) current_attributes,/* (Attributes) currx ent_attributes, */
1648 (ArrayList) $7, (Location)$5);
1649 method.Block = end_block();
1655 : STRUCTURE _mark_ identifier end_of_stmt
1656 opt_implement_clause
1659 string full_struct_name = MakeName ((string) $3);
1661 // Module members are static by default, but structures *can't* be declared static
1662 // so we must fix it, if mbas was the one actually responsible for this
1663 // instead of triggering an error.
1664 if (implicit_modifiers && ((current_modifiers & Modifiers.STATIC) != 0))
1665 current_modifiers = (current_modifiers & ~Modifiers.STATIC);
1667 new_struct = new Struct (current_container, full_struct_name,
1668 (int) current_modifiers,
1669 (Attributes) current_attributes, (Location)$2);
1670 current_container = new_struct;
1671 current_container.Namespace = current_namespace;
1672 RootContext.Tree.RecordDecl (full_struct_name, new_struct);
1674 opt_struct_member_declarations
1676 Struct new_struct = (Struct) current_container;
1679 new_struct.Bases = (ArrayList) $5;
1681 current_container = current_container.Parent;
1682 CheckDef (current_container.AddStruct (new_struct), new_struct.Name, new_struct.Location);
1688 if (end_priority[9]>=end_priority[i] && i!=9)
1690 Report.Error(error_numbers[i],lexer.Location,"'"+end_blocks[i]+"' found without a matching '"+open_blocks[i]+"'"+open_blocks[20]);
1691 Environment.Exit(1);
1693 if (i!=9 && Parent!=9)
1696 Report.Error(30624,(Location)$2,"'Structure' is not having a matching 'End Structure'");
1707 opt_struct_member_declarations
1709 | struct_member_declarations
1712 struct_member_declarations
1713 : struct_member_declaration
1714 | struct_member_declarations struct_member_declaration
1717 struct_member_declaration
1719 struct_member_declarator
1722 struct_member_declarator
1724 | constant_declaration
1725 | constructor_declaration
1726 | method_declaration
1728 Method method = (Method) $1;
1729 CheckDef (current_container.AddMethod (method), method.Name, method.Location);
1731 | property_declaration
1733 | type_spec_declaration
1736 * This is only included so we can flag error 575:
1737 * destructors only allowed on class types
1739 //| destructor_declaration
1743 : EVENT identifier _mark_ AS type opt_implement_clause logical_end_of_line
1745 VariableDeclaration var = new VariableDeclaration ((string) $2, (Expression) $5, (Location)$3);
1747 Event e = new Event ((Expression) $5, var.identifier,
1748 null, current_modifiers,
1749 current_attributes, (ArrayList) $6,
1752 CheckDef (current_container.AddEvent (e), e.Name, e.Location);
1754 | EVENT identifier _mark_ opt_params opt_implement_clause logical_end_of_line
1756 string delName = null;
1759 delName = (string) $2;
1760 delName = delName + "EventHandler";
1761 Mono.MonoBASIC.Delegate del = new Mono.MonoBASIC.Delegate
1762 (current_container, TypeManager.system_void_expr,
1763 (int) current_modifiers, MakeName(delName), (Parameters) $4,
1764 (Attributes) current_attributes, (Location)$3);
1766 del.Namespace = current_namespace;
1767 CheckDef (current_container.AddDelegate (del), del.Name, (Location)$3);
1769 ArrayList impls = (ArrayList) $5;
1770 if (impls.Count > 1) {
1771 string expstr = "Event '" + ((Expression) impls[1]).ToString () +
1772 "' can not be implemented with Event '" +
1773 (string) $2 + "', since it's delegate type does not match " +
1774 "with the delegate type of '" + ((Expression) impls[0]).ToString () + "'";
1775 Report.Error (31407, (Location)$3, expstr);
1777 Expression impl = (Expression) impls[0];
1778 delName = impl.ToString();
1779 delName = delName.Substring (delName.LastIndexOf(".") + 1);
1780 delName = delName + "EventHandler";
1783 Event e = new Event (DecomposeQI (delName, (Location)$3),
1785 null, current_modifiers,
1786 current_attributes, (ArrayList) $5,
1789 CheckDef (current_container.AddEvent (e), e.Name, e.Location);
1794 : ENUM _mark_ identifier opt_type_spec logical_end_of_line
1795 opt_enum_member_declarations
1797 Location enum_location = (Location)$2;
1798 string full_name = MakeName ((string) $3);
1799 Expression enum_type = ($4 == null) ? TypeManager.system_int32_expr : (Expression) $4;
1800 ArrayList enum_members = (ArrayList) $6;
1802 if (enum_members.Count == 0)
1803 Report.Error (30280, enum_location,
1804 "Enum can not have empty member list");
1806 // Module members are static by default, but enums *can't* be declared static
1807 // so we must fix it if mbas was the one actually responsible for this
1808 // instead of triggering an error.
1809 if (implicit_modifiers && ((current_modifiers & Modifiers.STATIC) != 0))
1810 current_modifiers = (current_modifiers & ~Modifiers.STATIC);
1812 Mono.MonoBASIC.Enum e = new Mono.MonoBASIC.Enum (current_container, enum_type,
1813 (int) current_modifiers, full_name,
1814 (Attributes) current_attributes, enum_location);
1816 foreach (VariableDeclaration ev in enum_members) {
1817 Location loc = (Location) ev.Location;
1819 CheckDef (e.AddEnumMember (ev.identifier,
1820 (Expression) ev.expression_or_array_initializer,
1821 loc, ev.OptAttributes), ev.identifier, loc);
1824 e.Namespace = current_namespace;
1826 CheckDef (current_container.AddEnum (e), full_name, enum_location);
1827 RootContext.Tree.RecordDecl (full_name, e);
1833 if (end_priority[10]>=end_priority[i] && i!=10)
1835 Report.Error(error_numbers[i],lexer.Location,"'"+end_blocks[i]+"' found without a matching '"+open_blocks[i]+"'"+open_blocks[20]);
1836 Environment.Exit(1);
1838 if (i!=10 && Parent!=10)
1840 Report.Error(30185,(Location)$2,"'ENUM' is not having a matching 'End ENUM'");
1851 opt_enum_member_declarations
1852 : /* empty */ { $$ = new ArrayList (); }
1853 | enum_member_declarations { $$ = $1; }
1856 enum_member_declarations
1857 : enum_member_declaration
1859 ArrayList l = new ArrayList ();
1864 | enum_member_declarations enum_member_declaration
1866 ArrayList l = (ArrayList) $1;
1874 enum_member_declaration
1875 : opt_attributes identifier _mark_ logical_end_of_line
1877 $$ = new VariableDeclaration ((string) $2, null, (Location)$3, (Attributes) $1);
1879 | opt_attributes identifier
1881 $$ = lexer.Location;
1883 ASSIGN expression logical_end_of_line
1885 $$ = new VariableDeclaration ((string) $2, (Expression)$5, (Location)$3, (Attributes) $1);
1889 interface_declaration
1890 : INTERFACE _mark_ identifier logical_end_of_line
1892 Interface new_interface;
1893 string full_interface_name = MakeName ((string) $3);
1895 new_interface = new Interface (current_container, full_interface_name, (int) current_modifiers,
1896 (Attributes) current_attributes, (Location)$2);
1897 if (current_interface != null) {
1898 Report.Error (-2, (Location)$2, "Internal compiler error: interface inside interface");
1900 current_interface = new_interface;
1901 new_interface.Namespace = current_namespace;
1902 RootContext.Tree.RecordDecl (full_interface_name, new_interface);
1907 Interface new_interface = (Interface) current_interface;
1910 new_interface.Bases = (ArrayList) $6;
1912 current_interface = null;
1913 CheckDef (current_container.AddInterface (new_interface),
1914 new_interface.Name, new_interface.Location);
1920 if (end_priority[11]>=end_priority[i] && i!=11)
1922 Report.Error(error_numbers[i],lexer.Location,"'"+end_blocks[i]+"' found without a matching '"+open_blocks[i]+"'"+open_blocks[20]);
1923 Environment.Exit(1);
1925 if (i!=11 && Parent!=11)
1927 Report.Error(30253,(Location)$2,"'INTERFACE' is not having a matching 'End INTERFACE'");
1939 : /* empty */ { $$ = null; }
1945 | interface_bases interface_base
1947 ArrayList bases = (ArrayList) $1;
1948 bases.AddRange ((ArrayList) $2);
1954 : INHERITS type_list logical_end_of_line { $$ = $2; }
1958 : opt_interface_member_declarations
1961 opt_interface_member_declarations
1963 | interface_member_declarations
1966 interface_member_declarations
1967 : interface_member_declaration
1968 | interface_member_declarations interface_member_declaration
1971 interface_member_declaration
1975 current_attributes = (Attributes) $1;
1976 current_modifiers = ((int)$2) | Modifiers.ABSTRACT;
1978 interface_member_declarator
1984 interface_member_declarator
1985 : interface_method_declaration
1987 Method m = (Method) $1;
1988 CheckDef (current_interface.AddMethod (m), m.Name, m.Location);
1990 | interface_property_declaration
1991 | interface_event_declaration
1994 interface_method_declaration
1995 : SUB identifier opt_params _mark_ logical_end_of_line
1997 Method method = new Method (TypeManager.system_void_expr, (int) current_modifiers, (string) $2,
1998 (Parameters) $3, current_attributes, null, (Location)$4);
2002 | FUNCTION identifier opt_type_character opt_params _mark_ opt_type_with_ranks logical_end_of_line
2004 Expression ftype = ($6 == null) ? (($3 == null) ? TypeManager.
2005 system_object_expr : (Expression) $3 ) : (Expression) $6;
2007 Method method = new Method ((Expression) ftype, (int) current_modifiers,
2008 (string) $2,(Parameters) $4, current_attributes, null,
2015 interface_property_declaration
2016 : PROPERTY identifier _mark_ opt_type_character opt_property_parameters opt_type_with_ranks logical_end_of_line
2018 Expression ftype = ($6 == null) ? (($4 == null) ?
2019 TypeManager.system_object_expr : (Expression) $4 ) : (Expression) $6;
2021 current_local_parameters = (Parameters) $5;
2022 if (current_local_parameters != Parameters.EmptyReadOnlyParameters) {
2023 get_parameters = current_local_parameters.Copy ((Location)$3);
2024 set_parameters = current_local_parameters.Copy ((Location)$3);
2026 Parameter implicit_value_parameter = new Parameter (
2027 ftype, "Value", Parameter.Modifier.NONE, null);
2029 set_parameters.AppendParameter (implicit_value_parameter);
2033 get_parameters = Parameters.EmptyReadOnlyParameters;
2034 set_parameters = new Parameters (null, null ,(Location)$3);
2036 Parameter implicit_value_parameter = new Parameter (
2037 ftype, "Value", Parameter.Modifier.NONE, null);
2039 set_parameters.AppendParameter (implicit_value_parameter);
2041 lexer.PropertyParsing = true;
2043 Accessor get_block = new Accessor (null, null);
2044 Accessor set_block = new Accessor (null, null);
2046 Property prop = new Property ((Expression) ftype, (string) $2, current_modifiers,
2047 get_block, set_block, current_attributes, (Location)$3,
2048 null, get_parameters, set_parameters, null);
2050 CheckDef (current_interface.AddProperty (prop), prop.Name, (Location)$3);
2052 get_implicit_value_parameter_type = null;
2053 set_implicit_value_parameter_type = null;
2054 get_parameters = null;
2055 set_parameters = null;
2056 current_local_parameters = null;
2060 interface_event_declaration
2061 : EVENT identifier AS _mark_ type logical_end_of_line
2063 VariableDeclaration var = new VariableDeclaration ((string) $2, (Expression) $5, (Location)$4);
2065 Event e = new Event ((Expression) $5, var.identifier,
2066 null, current_modifiers,
2067 current_attributes, (Location)$4);
2069 CheckDef (current_interface.AddEvent (e), e.Name, e.Location);
2072 | EVENT identifier opt_params _mark_ logical_end_of_line
2074 string delName = (string) $2;
2075 delName = delName + "EventHandler";
2076 int delModifiers = (current_modifiers & ~Modifiers.ABSTRACT);
2077 Mono.MonoBASIC.Delegate del = new Mono.MonoBASIC.Delegate
2078 (current_container, TypeManager.system_void_expr,
2079 (int) delModifiers, MakeName(delName), (Parameters) $3,
2080 (Attributes) current_attributes, (Location)$4);
2082 del.Namespace = current_namespace;
2083 CheckDef (current_interface.AddDelegate (del), del.Name, (Location)$4);
2085 Event e = new Event (DecomposeQI (delName, (Location)$4),
2087 null, current_modifiers,
2088 current_attributes, (Location)$4);
2090 CheckDef (current_interface.AddEvent (e), e.Name, e.Location);
2094 property_declaration
2095 : abstract_propery_declaration
2096 | non_abstract_propery_declaration
2099 abstract_propery_declaration
2100 : MUSTOVERRIDE PROPERTY identifier opt_type_character opt_property_parameters _mark_ opt_type_with_ranks logical_end_of_line
2102 Expression ftype = ($7 == null) ? (($4 == null) ?
2103 TypeManager.system_object_expr : (Expression) $4 ) : (Expression) $7;
2105 if (current_container is Module)
2106 Report.Error (30503, (Location) $6 , "Properties in a Module cannot be declared 'MustOverride'.");
2108 if (current_container is Struct)
2109 Report.Error (435, (Location) $6 ,"Methods in a Structure cannot be declared 'MustOverride'.");
2111 current_modifiers |= Modifiers.ABSTRACT;
2113 current_local_parameters = (Parameters) $5;
2114 if (current_local_parameters != Parameters.EmptyReadOnlyParameters) {
2115 get_parameters = current_local_parameters.Copy (lexer.Location);
2116 set_parameters = current_local_parameters.Copy (lexer.Location);
2118 Parameter implicit_value_parameter = new Parameter (
2119 ftype, "Value", Parameter.Modifier.NONE, null);
2121 set_parameters.AppendParameter (implicit_value_parameter);
2125 get_parameters = Parameters.EmptyReadOnlyParameters;
2126 set_parameters = new Parameters (null, null ,lexer.Location);
2128 Parameter implicit_value_parameter = new Parameter (
2129 ftype, "Value", Parameter.Modifier.NONE, null);
2131 set_parameters.AppendParameter (implicit_value_parameter);
2133 lexer.PropertyParsing = true;
2135 Accessor get_block = new Accessor (null, null);
2136 Accessor set_block = new Accessor (null, null);
2138 Property prop = new Property ((Expression) ftype, (string) $3, current_modifiers,
2139 get_block, set_block, current_attributes, lexer.Location,
2140 null, get_parameters, set_parameters, null);
2142 if (!(current_container is Class))
2143 Report.Error (9999, (Location) $6, "THIS SHOULD NEVER HAPPEN!");
2145 CheckDef (current_container.AddProperty (prop), prop.Name, lexer.Location);
2147 get_implicit_value_parameter_type = null;
2148 set_implicit_value_parameter_type = null;
2149 get_parameters = null;
2150 set_parameters = null;
2151 current_local_parameters = null;
2156 non_abstract_propery_declaration
2157 : PROPERTY identifier
2159 opt_property_parameters
2162 opt_implement_clause
2164 if ((current_modifiers & Modifiers.DEFAULT) > 0) {
2165 if (current_container.DefaultPropName != null
2166 && current_container.DefaultPropName != (string) $2)
2167 Report.Error (30359,
2169 "Type '" + current_container.Name +
2170 "' cannot have more than one 'Default Property' ");
2172 current_container.DefaultPropName = (string) $2;
2175 get_implicit_value_parameter_type =
2176 ($6 == null) ? (($3 == null) ?
2177 TypeManager.system_object_expr : (Expression) $3 ) : (Expression) $6;
2178 get_implicit_value_parameter_name = (string) $2;
2180 current_local_parameters = (Parameters) $4;
2181 if (current_local_parameters != Parameters.EmptyReadOnlyParameters) {
2182 get_parameters = current_local_parameters.Copy ((Location)$5);
2183 set_parameters = current_local_parameters.Copy ((Location)$5);
2187 get_parameters = Parameters.EmptyReadOnlyParameters;
2188 set_parameters = new Parameters (null, null ,(Location)$5);
2190 lexer.PropertyParsing = true;
2195 accessor_declarations
2199 if (end_priority[12]>=end_priority[i] && i!=12)
2201 Report.Error(error_numbers[i],lexer.Location,"'"+end_blocks[i]+"' found without a matching '"+open_blocks[i]+"'"+open_blocks[20]);
2202 Environment.Exit(1);
2204 if (i!=12 && Parent!=12)
2206 Report.Error(30025,(Location)$5,"'Property' is not having a matching 'End Property'");
2216 lexer.PropertyParsing = false;
2219 Pair pair = (Pair) $10;
2221 Accessor get_block = null;
2222 Accessor set_block = null;
2224 if (pair.First != null){
2225 get_block = (Accessor) pair.First;
2228 if (pair.Second != null) {
2229 set_block = (Accessor) pair.Second;
2232 Location loc = (Location) $5 ;
2234 // Structure members are Public by default
2235 if ((current_container is Struct) && (current_modifiers == 0))
2236 current_modifiers = Modifiers.PUBLIC;
2238 prop = new Property ((Expression) get_implicit_value_parameter_type,
2239 (string) $2, current_modifiers, get_block, set_block,
2240 current_attributes, loc, set_implicit_value_parameter_name,
2241 get_parameters, set_parameters, (ArrayList) $7);
2243 CheckDef (current_container.AddProperty (prop), prop.Name, loc);
2244 get_implicit_value_parameter_type = null;
2245 set_implicit_value_parameter_type = null;
2246 get_parameters = null;
2247 set_parameters = null;
2248 current_local_parameters = null;
2252 opt_property_parameters
2255 $$ = Parameters.EmptyReadOnlyParameters;
2257 | OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2263 opt_implement_clause
2268 | IMPLEMENTS implement_clause_list
2274 implement_clause_list
2275 : qualified_identifier
2277 ArrayList impl_list = new ArrayList ();
2278 impl_list.Add (DecomposeQI ((string)$1, lexer.Location));
2281 | implement_clause_list COMMA qualified_identifier
2283 ArrayList impl_list = (ArrayList) $1;
2284 impl_list.Add (DecomposeQI ((string)$3, lexer.Location));
2290 accessor_declarations
2291 : get_accessor_declaration opt_set_accessor_declaration
2293 $$ = new Pair ($1, $2);
2295 | set_accessor_declaration opt_get_accessor_declaration
2297 $$ = new Pair ($2, $1);
2301 opt_get_accessor_declaration
2302 : /* empty */ { $$ = null; }
2303 | get_accessor_declaration
2306 opt_set_accessor_declaration
2307 : /* empty */ { $$ = null; }
2308 | set_accessor_declaration
2311 get_accessor_declaration
2312 : opt_attributes GET _mark_ logical_end_of_line
2314 if ((current_modifiers & Modifiers.WRITEONLY) != 0)
2315 Report.Error (30023, (Location)$3, "'WriteOnly' properties cannot have a 'Get' accessor");
2317 current_local_parameters = get_parameters;
2319 lexer.PropertyParsing = false;
2322 // Add local var declaration
2324 ArrayList retval = new ArrayList ();
2325 retval.Add (new VariableDeclaration (get_implicit_value_parameter_name, get_implicit_value_parameter_type, (Location)$3));
2326 declare_local_variables (get_implicit_value_parameter_type, retval, lexer.Location);
2332 if (end_priority[19]>=end_priority[i] && i!=19)
2334 Report.Error(error_numbers[i],lexer.Location,"'"+end_blocks[i]+"' found without a matching '"+open_blocks[i]+"'"+open_blocks[20]);
2335 Environment.Exit(1);
2337 if (i!=19 && Parent!=19)
2339 Report.Error(30631,(Location)$3,"'GET' is not having a matching 'End Get'");
2349 $$ = new Accessor ((Block) end_block(), (Attributes) $1);
2350 current_local_parameters = null;
2351 lexer.PropertyParsing = true;
2355 set_accessor_declaration
2356 : opt_attributes SET opt_set_parameter _mark_ logical_end_of_line
2358 if ((current_modifiers & Modifiers.READONLY) != 0)
2359 Report.Error (30022,
2361 "'ReadOnly' properties cannot have a 'Set' accessor");
2363 Parameter implicit_value_parameter = new Parameter (
2364 set_implicit_value_parameter_type,
2365 set_implicit_value_parameter_name,
2366 Parameter.Modifier.NONE, null);
2368 current_local_parameters = set_parameters;
2369 current_local_parameters.AppendParameter (implicit_value_parameter);
2372 lexer.PropertyParsing = false;
2378 if (end_priority[18]>=end_priority[i] && i!=18)
2380 Report.Error(error_numbers[i],lexer.Location,"'"+end_blocks[i]+"' found without a matching '"+open_blocks[i]+"'"+open_blocks[20]);
2381 Environment.Exit(1);
2383 if (i!=18 && Parent!=18)
2385 Report.Error(30633,(Location)$4,"'SET' is not having a matching 'End Set'");
2396 $$ = new Accessor ((Block) end_block(), (Attributes) $1);
2397 current_local_parameters = null;
2398 lexer.PropertyParsing = true;
2405 set_implicit_value_parameter_type = (Expression) get_implicit_value_parameter_type; // TypeManager.system_object_expr;
2406 set_implicit_value_parameter_name = "Value";
2408 |OPEN_PARENS CLOSE_PARENS
2410 set_implicit_value_parameter_type = (Expression) get_implicit_value_parameter_type;
2411 set_implicit_value_parameter_name = "Value";
2413 | OPEN_PARENS opt_parameter_modifier opt_identifier opt_type_with_ranks CLOSE_PARENS
2415 Parameter.Modifier pm = (Parameter.Modifier)$2;
2416 if ((pm | Parameter.Modifier.VAL) != 0)
2417 Report.Error (31065,
2419 "Set cannot have a paremeter modifier other than 'ByVal'");
2421 set_implicit_value_parameter_type = (Expression) $4;
2423 if (set_implicit_value_parameter_type.ToString () != get_implicit_value_parameter_type.ToString ())
2424 Report.Error (31064,
2426 "Set value parameter type can not be different from property type");
2429 set_implicit_value_parameter_name = (string) $3;
2431 set_implicit_value_parameter_name = "Value";
2437 variable_declarators end_of_stmt
2439 int mod = (int) current_modifiers;
2441 VariableDeclaration.FixupTypes ((ArrayList) $2);
2442 VariableDeclaration.FixupArrayTypes ((ArrayList) $2);
2444 if (current_container is Module)
2445 mod = mod | Modifiers.STATIC;
2447 // Structure members are Public by default
2448 if ((current_container is Struct) && (mod == 0))
2449 mod = Modifiers.PUBLIC;
2451 if ((mod & Modifiers.Accessibility) == 0)
2452 mod |= Modifiers.PRIVATE;
2454 foreach (VariableDeclaration var in (ArrayList) $2){
2455 Location l = var.Location;
2456 Field field = new Field (var.type, mod, var.identifier,
2457 var.expression_or_array_initializer,
2458 (Attributes) null, l);
2460 CheckDef (current_container.AddField (field), field.Name, l);
2465 withevents_declaration
2466 : opt_dim_stmt WITHEVENTS variable_declarators logical_end_of_line
2468 // Module members are static by default, but delegates *can't* be declared static
2469 // so we must fix it, if mbas was the one actually responsible for this
2470 // instead of triggering an error.
2471 if (implicit_modifiers && ((current_modifiers & Modifiers.STATIC) != 0))
2472 current_modifiers = (current_modifiers & ~Modifiers.STATIC);
2474 /* WithEvents Fields must be resolved into properties
2475 with a bit of magic behind the scenes */
2477 VariableDeclaration.FixupTypes ((ArrayList) $3);
2479 foreach (VariableDeclaration var in (ArrayList) $3) {
2480 // 1 - We create a private field
2481 Location l = var.Location;
2483 if ((current_modifiers & Modifiers.STATIC) > 0)
2484 Report.Error (30234, l, "'Static' is not valid on a WithEvents declaration.");
2486 Field field = new Field (var.type, Modifiers.PRIVATE, "_" + var.identifier,
2487 var.expression_or_array_initializer,
2488 (Attributes) null, l);
2490 CheckDef (current_container.AddField (field), field.Name, l);
2492 // 2 - Public property
2494 prop = BuildSimpleProperty (var.type, (string) var.identifier,
2495 field, (int) current_modifiers,
2496 (Attributes) current_attributes, l);
2498 CheckDef (current_container.AddProperty (prop), prop.Name, l);
2508 delegate_declaration
2509 : DELEGATE SUB _mark_
2510 identifier OPEN_PARENS
2511 opt_formal_parameter_list
2515 Location l = (Location)$3;
2516 // Module members are static by default, but delegates *can't* be declared static
2517 // so we must fix it, if mbas was the one actually responsible for this
2518 // instead of triggering an error.
2519 if (implicit_modifiers && ((current_modifiers & Modifiers.STATIC) != 0))
2520 current_modifiers = (current_modifiers & ~Modifiers.STATIC);
2522 Mono.MonoBASIC.Delegate del = new Mono.MonoBASIC.Delegate (current_container,
2523 TypeManager.system_void_expr,
2524 (int) current_modifiers,
2525 MakeName ((string) $4), (Parameters) $6,
2526 (Attributes) current_attributes, l);
2528 del.Namespace = current_namespace;
2529 CheckDef (current_container.AddDelegate (del), del.Name, l);
2531 | DELEGATE FUNCTION _mark_
2532 identifier OPEN_PARENS
2533 opt_formal_parameter_list
2534 CLOSE_PARENS opt_type_with_ranks logical_end_of_line
2536 Location l = (Location)$3;
2538 // Module members are static by default, but delegates *can't* be declared static
2539 // so we must fix it, if mbas was the one actually responsible for this
2540 // instead of triggering an error.
2541 if (implicit_modifiers && ((current_modifiers & Modifiers.STATIC) != 0))
2542 current_modifiers = (current_modifiers & ~Modifiers.STATIC);
2544 Expression ftype = ($8 == null) ? TypeManager.system_object_expr : (Expression) $8;
2546 Mono.MonoBASIC.Delegate del = new Mono.MonoBASIC.Delegate (
2548 ftype, (int) current_modifiers, MakeName ((string) $4),
2549 (Parameters) $6, (Attributes) current_attributes, l);
2551 del.Namespace = current_namespace;
2552 CheckDef (current_container.AddDelegate (del), del.Name, l);
2557 : /* empty */ { $$ = null; }
2558 | HANDLES evt_handler { $$ = $2; }
2562 : qualified_identifier
2564 $$ = (Expression) DecomposeQI ((string)$1, lexer.Location);
2570 | ME DOT qualified_identifier
2572 $$ = (Expression) DecomposeQI ((string)$3, lexer.Location);
2574 /*| MYBASE DOT qualified_identifier
2576 // FIXME: this is blatantly wrong and crash-prone
2577 $$ = (Expression) DecomposeQI ("MyBase." + (string)$4, lexer.Location);
2581 constructor_declaration
2582 : SUB _mark_ NEW opt_params logical_end_of_line
2584 current_local_parameters = (Parameters) $4;
2586 oob_stack.Push (lexer.Location);
2588 Location l = (Location) oob_stack.Pop ();
2589 $$ = new Constructor ((string) "New", (Parameters) $4, (ConstructorInitializer) null, l);
2594 Constructor c = (Constructor) $1;
2595 c.Block = (Block) end_block();
2596 c.ModFlags = (int) current_modifiers;
2597 c.OptAttributes = current_attributes;
2599 c.Initializer = CheckConstructorInitializer (ref c.Block.statements);
2601 CheckDef (current_container.AddConstructor(c), c.Name, c.Location);
2602 current_local_parameters = null;
2607 if (end_priority[4]>=end_priority[i] && i!=4)
2609 Report.Error(error_numbers[i],lexer.Location,"'"+end_blocks[i]+"' found without a matching '"+open_blocks[i]+"'"+open_blocks[20]);
2610 Environment.Exit(1);
2612 if (i!=4 && Parent!=4)
2614 Report.Error(30289,(Location)$2,"'Sub' is not having a matching 'End Sub'");
2625 opt_formal_parameter_list
2628 $$ = Parameters.EmptyReadOnlyParameters;
2630 | formal_parameter_list
2633 //Parameter p = ((Parameters) $1).FixedParameters[0];
2637 formal_parameter_list
2640 ArrayList pars_list = (ArrayList) $1;
2641 Parameter [] pars = null;
2642 Parameter array_parameter = null;
2643 int non_array_count = pars_list.Count;
2644 if (pars_list.Count > 0 && (((Parameter) pars_list [pars_list.Count - 1]).ModFlags & Parameter.Modifier.PARAMS) != 0) {
2645 array_parameter = (Parameter) pars_list [pars_list.Count - 1];
2646 non_array_count = pars_list.Count - 1;
2648 foreach (Parameter par in pars_list)
2649 if (par != array_parameter && (par.ModFlags & Parameter.Modifier.PARAMS) != 0) {
2650 Report.Error (30192, lexer.Location, "ParamArray parameters must be last");
2651 non_array_count = 0;
2652 array_parameter = null;
2655 if (non_array_count > 0) {
2656 pars = new Parameter [non_array_count];
2657 pars_list.CopyTo (0, pars, 0, non_array_count);
2659 $$ = new Parameters (pars, array_parameter, lexer.Location);
2666 ArrayList pars = new ArrayList ();
2671 | parameters COMMA parameter
2673 ArrayList pars = (ArrayList) $1;
2682 opt_parameter_modifier
2683 identifier _mark_ opt_type_character opt_rank_specifiers opt_type_with_ranks opt_variable_initializer
2685 Parameter.Modifier pm = (Parameter.Modifier)$2;
2686 bool opt_parm = ((pm & Parameter.Modifier.OPTIONAL) != 0);
2689 if (opt_parm && ($8 == null))
2690 Report.Error (30812, (Location)$4, "Optional parameters must have a default value");
2692 if (!opt_parm && ($8 != null))
2693 Report.Error (32024, (Location)$4, "Non-Optional parameters should not have a default value");
2695 if ((pm & Parameter.Modifier.PARAMS) != 0) {
2696 if ((pm & ~Parameter.Modifier.PARAMS) != 0)
2697 Report.Error (30667, (Location)$4, "ParamArray parameters must be ByVal");
2700 if ((pm & Parameter.Modifier.REF) !=0)
2701 pm |= Parameter.Modifier.ISBYREF;
2703 if ($5 != null && $7 != null && $5 != $7)
2704 Report.Error (30302, (Location)$4, "Type character conflicts with declared type."); // TODO: Correct error number and message text
2706 ptype = (Expression)(($7 == null) ? (($5 == null) ? TypeManager.system_object_expr : $5) : $7);
2708 string t = ptype.ToString ();
2709 if (t.IndexOf('[') >= 0)
2710 Report.Error (31087, (Location)$4, "Array types specified in too many places");
2712 ptype = DecomposeQI (t + VariableDeclaration.BuildRanks ((ArrayList) $6, true, (Location)$4), (Location)$4);
2714 if ((pm & Parameter.Modifier.PARAMS) != 0 && ptype.ToString ().IndexOf('[') < 0)
2715 Report.Error (30050, (Location)$4, "ParamArray parameters must be an array type");
2716 $$ = new Parameter (ptype, (string) $3, pm,
2717 (Attributes) $1, (Expression) $8, opt_parm);
2721 opt_parameter_modifier
2722 : /* empty */ { $$ = Parameter.Modifier.VAL; }
2723 | parameter_modifiers { $$ = $1; }
2727 : parameter_modifiers parameter_modifier { $$ = (Parameter.Modifier)$1 | (Parameter.Modifier)$2; }
2728 | parameter_modifier { $$ = $1; }
2732 : BYREF { $$ = Parameter.Modifier.REF | Parameter.Modifier.ISBYREF; }
2733 | BYVAL { $$ = Parameter.Modifier.VAL; }
2734 | OPTIONAL { $$ = Parameter.Modifier.OPTIONAL; }
2735 | PARAM_ARRAY { $$ = Parameter.Modifier.PARAMS; }
2740 | statement_list end_of_stmt
2745 | statement_list end_of_stmt
2750 : declaration_statement
2752 if ($1 != null && (Block) $1 != current_block){
2753 current_block.AddStatement ((Statement) $1);
2754 current_block = (Block) $1;
2757 | embedded_statement
2759 current_block.AddStatement ((Statement) $1);
2762 | ADDHANDLER prefixed_unary_expression COMMA ADDRESSOF evt_handler
2764 AddHandler ((Expression) $2, (Expression) $5);
2766 | REMOVEHANDLER prefixed_unary_expression COMMA ADDRESSOF evt_handler
2768 RemoveHandler ((Expression) $2, (Expression) $5);
2770 | RAISEEVENT identifier opt_raise_event_args //OPEN_PARENS opt_argument_list CLOSE_PARENS
2772 RaiseEvent ((string) $2, (ArrayList) $3);
2774 /* | array_handling_statement */
2775 /* | empty_statement */
2778 current_block.AddStatement ((Statement) $1);
2782 opt_raise_event_args
2783 : /* empty */ { $$ = null; }
2784 | OPEN_PARENS opt_argument_list CLOSE_PARENS
2801 LabeledStatement labeled = new LabeledStatement ((string) $1, lexer.Location);
2803 if (!current_block.AddLabel ((string) $1, labeled)){
2804 Location l = lexer.Location;
2805 Report.Error (140, l, "The label '" + ((string) $1) + "' is a duplicate");
2807 current_block.AddStatement (labeled);
2811 LabeledStatement labeled = new LabeledStatement ((string) $1, lexer.Location);
2813 if (!current_block.AddLabel ((string) $1, labeled)){
2814 Location l = lexer.Location;
2815 Report.Error (140, l, "The label '" + ((string) $1) + "' is a duplicate");
2817 current_block.AddStatement (labeled);
2823 : expression_statement
2824 | selection_statement
2825 | iteration_statement
2827 | synclock_statement
2829 | array_handling_statement
2835 $$ = new EmptyStatement ();
2841 : WITH _mark_ expression end_of_stmt /* was : WITH qualified_identifier end_of_stmt */
2843 // was : Expression e = DecomposeQI ((string) $3, (Location)$2);
2844 Expression e = (Expression) $3;
2852 if (end_priority[13]>=end_priority[i] && i!=13)
2854 Report.Error(error_numbers[i],lexer.Location,"'"+end_blocks[i]+"' found without a matching '"+open_blocks[i]+"'"+open_blocks[20]);
2855 Environment.Exit(1);
2857 if (i!=13 && Parent!=13)
2859 Report.Error(30085,(Location)$2,"'With' is not having a matching 'End With'");
2866 Block b = end_block();
2873 array_handling_statement
2879 : REDIM opt_preserve redim_clauses
2881 ArrayList list = (ArrayList) $3;
2882 ReDim r = new ReDim (list, (bool) $2, lexer.Location);
2889 : /* empty */ { $$ = false; }
2890 | PRESERVE { $$ = true; }
2896 ArrayList clauses = new ArrayList ();
2901 | redim_clauses COMMA redim_clause
2903 ArrayList clauses = (ArrayList) ($1);
2911 : invocation_expression
2913 Invocation i = (Invocation) $1;
2914 RedimClause rc = new RedimClause (i.expr, i.Arguments);
2920 : ERASE erase_clauses
2922 ArrayList list = (ArrayList) $2;
2923 foreach(Expression e in list)
2925 Erase r = new Erase (e, lexer.Location);
2934 ArrayList clauses = new ArrayList ();
2939 | erase_clauses COMMA erase_clause
2941 ArrayList clauses = (ArrayList) ($1);
2949 : primary_expression
2954 | continue_statement
2955 | */return_statement
2965 $$ = new Goto (current_block, (string) $2, lexer.Location);
2970 : THROW opt_expression
2972 $$ = new Throw ((Expression) $2, lexer.Location);
2979 $$ = new Exit ((ExitType)$2, lexer.Location);
2984 : DO { $$ = ExitType.DO; }
2985 | FOR { $$ = ExitType.FOR; }
2986 | WHILE { $$ = ExitType.WHILE; }
2987 | SELECT { $$ = ExitType.SELECT; }
2988 | SUB { $$ = ExitType.SUB; }
2989 | FUNCTION { $$ = ExitType.FUNCTION; }
2990 | PROPERTY { $$ = ExitType.PROPERTY; }
2991 | TRY { $$ = ExitType.TRY; }
2994 : RETURN opt_expression
2996 $$ = new Return ((Expression) $2, lexer.Location);
3008 : FOR EACH identifier _mark_ opt_type_spec IN
3009 expression end_of_stmt
3011 Location l = (Location)$4;
3012 LocalVariableReference v = null;
3018 VariableDeclaration decl = new VariableDeclaration ((string) $3,
3019 (Expression) $5, null, (Location)$4, null);
3021 vi = current_block.AddVariable (
3022 (Expression) $5, decl.identifier, current_local_parameters, decl.Location);
3025 if (decl.expression_or_array_initializer is Expression)
3026 expr = (Expression) decl.expression_or_array_initializer;
3027 else if (decl.expression_or_array_initializer == null)
3031 ArrayList init = (ArrayList) decl.expression_or_array_initializer;
3032 expr = new ArrayCreation ((Expression) $5, "", init, decl.Location);
3035 v = new LocalVariableReference (current_block, decl.identifier, l);
3039 Assign a = new Assign (v, expr, decl.Location);
3040 current_block.AddStatement (new StatementExpression (a, (Location)$4));
3045 vi = current_block.GetVariableInfo ((string) $3);
3048 // Get a reference to this variable.
3049 v = new LocalVariableReference (current_block, (string) $3, l, vi, false);
3052 Report.Error (451, (Location)$4,"Name '" + (string) $3 + "' is not declared.");
3062 if (end_priority[1]>=end_priority[i] && i!=1)
3064 Report.Error(error_numbers[i],lexer.Location,"'"+end_blocks[i]+"' found without a matching '"+open_blocks[i]+"'"+open_blocks[20]);
3065 Environment.Exit(1);
3067 if (i!=1 && Parent!=1)
3069 Report.Error(30084,(Location)$4,"'For' is not having a matching 'Next'");
3077 _mark_ opt_identifier
3079 string s = $3.ToString();
3082 s1 = $14.ToString();
3083 if (s1 != "" && s != s1)
3085 Report.Error(30070, (Location)$13, "Next Control Variable '"+s1+"' does not match with For Loop control variable '"+s+"'");
3087 LocalVariableReference v = (LocalVariableReference) oob_stack.Pop ();
3088 Block foreach_block = end_block();
3092 f = new Foreach (null, v, (Expression) $7, foreach_block, (Location)$4);
3096 current_block.AddStatement (f);
3105 : YIELD expression _mark_
3107 if (!UseExtendedSyntax)
3113 if (iterator_container == null){
3114 Report.Error (204, (Location)$3, "yield statement can only be used within a method, operator or property");
3117 iterator_container.SetYields ();
3118 $$ = new Yield ((Expression) $2, (Location)$3);
3123 if (!UseExtendedSyntax)
3129 if (iterator_container == null){
3130 Report.Error (204, (Location)$3, "yield statement can only be used within a method, operator or property");
3133 iterator_container.SetYields ();
3134 $$ = new YieldBreak ((Location)$3);
3140 : SYNCLOCK _mark_ expression end_of_stmt
3148 if (end_priority[14]>=end_priority[i] && i!=14)
3150 Report.Error(error_numbers[i],lexer.Location,"'"+end_blocks[i]+"' found without a matching '"+open_blocks[i]+"'"+open_blocks[20]);
3151 Environment.Exit(1);
3153 if (i!=14 && Parent!=14)
3155 Report.Error(30675,(Location)$2,"'Synclock' is not having a matching 'End SyncLock'");
3162 $$ = new Lock ((Expression) $3, (Statement) (Block) end_block(), (Location)$2);
3172 : TRY _mark_ end_of_stmt
3174 try_top=(Location)$2;
3180 tmp_catch_clauses = (ArrayList) $6;
3185 /*FIXME: Try block without a end try is throwing error at a wrong place*/
3188 _mark_ opt_end_block
3191 if (end_priority[15]>=end_priority[i] && i!=15)
3193 Report.Error(error_numbers[i],lexer.Location,"'"+end_blocks[i]+"' found without a matching '"+open_blocks[i]+"'"+open_blocks[20]);
3194 Environment.Exit(1);
3196 if (i!=15 && Parent!=15)
3198 Report.Error(30384,try_top,"'Try' is not having a matching 'End Try'");
3206 ArrayList s = new ArrayList ();
3208 foreach (Catch cc in (ArrayList) tmp_catch_clauses) {
3215 // Now s contains the list of specific catch clauses
3216 // and g contains the general one.
3217 Block b = end_block();
3219 $$ = new Try ((Block) b, s, g, null, try_top);
3226 tmp_block = end_block();
3233 _mark_ opt_end_block
3236 if (end_priority[15]>=end_priority[i] && i!=15)
3238 Report.Error(error_numbers[i],lexer.Location,"'"+end_blocks[i]+"' found without a matching '"+open_blocks[i]+"'"+open_blocks[20]);
3239 Environment.Exit(1);
3241 if (i!=15 && Parent!=15)
3243 Report.Error(30384,try_top,"'Try' is not having a matching 'End Try'");
3252 ArrayList s = new ArrayList ();
3253 ArrayList catch_list = (ArrayList) tmp_catch_clauses;
3255 if (catch_list != null){
3256 foreach (Catch cc in catch_list) {
3264 $$ = new Try ((Block) tmp_block, s, g, (Block) end_block(), try_top);
3270 : /* empty */ { $$ = null; }
3277 ArrayList l = new ArrayList ();
3282 | catch_clauses catch_clause
3284 ArrayList l = (ArrayList) $1;
3292 : /* empty */ { $$ = null; }
3297 : /* empty */ { $$ = null; }
3298 | WHEN boolean_expression
3305 : CATCH opt_catch_args opt_when _mark_ end_of_stmt
3307 Expression type = null;
3311 DictionaryEntry cc = (DictionaryEntry) $2;
3312 type = (Expression) cc.Key;
3313 id = (string) cc.Value;
3316 ArrayList one = new ArrayList ();
3317 Location loc = (Location)$4;
3319 one.Add (new VariableDeclaration (id, type, loc));
3322 current_block = new Block (current_block);
3323 Block b = declare_local_variables (type, one, loc);
3328 opt_statement_list {
3329 Expression type = null;
3331 Block b_catch = current_block;
3334 DictionaryEntry cc = (DictionaryEntry) $2;
3335 type = (Expression) cc.Key;
3336 id = (string) cc.Value;
3340 // FIXME: I can change this for an assignment.
3342 while (current_block != (Block) $1)
3343 current_block = current_block.Parent;
3346 $$ = new Catch (type, id , (Block) b_catch, (Expression) $3, (Location)$4);
3351 : /* empty */ { $$ = null; }
3356 : identifier AS _mark_ type
3358 $$ = new DictionaryEntry ($4, $1);
3362 Report.Error(30203, (Location)$1, "Identifier Expected");
3365 | identifier AS _mark_
3367 Report.Error(30182, (Location)$3, "Type Expected");
3374 : DO _mark_ opt_do_construct end_of_stmt
3382 if (end_priority[2]>=end_priority[i] && i!=2)
3384 Report.Error(error_numbers[i],lexer.Location,"'"+end_blocks[i]+"' found without a matching '"+open_blocks[i]+"'"+open_blocks[20]);
3385 Environment.Exit(1);
3387 if (i!=2 && Parent!=2)
3389 Report.Error(30083,(Location)$2,"'Do' is not having a matching 'Loop'");
3397 _mark_ opt_do_construct
3399 Expression t_before = (Expression) $3;
3400 Expression t_after = (Expression) $10;
3403 if ((t_before != null) && (t_after != null))
3404 Report.Error (30238, (Location)$9, "'Loop' cannot have a condition if matching 'Do' has one.");
3406 if ((t_before == null) && (t_after == null))
3407 t = new BoolLiteral (true);
3409 t = (t_before != null) ? t_before : t_after;
3411 DoOptions test_type = (t_before != null) ? DoOptions.TEST_BEFORE : DoOptions.TEST_AFTER;
3413 if (((do_type == DoOptions.WHILE) && (test_type == DoOptions.TEST_BEFORE)) ||
3414 ((do_type == DoOptions.UNTIL) && (test_type == DoOptions.TEST_AFTER)))
3415 t = new Unary (Unary.Operator.LogicalNot, (Expression) t, (Location)$2);
3417 $$ = new Do ((Statement) end_block(), (Expression) t, test_type, (Location)$2);
3422 : /* empty */ { $$ = null; }
3423 | while_or_until boolean_expression
3425 do_type = (DoOptions)$1;
3426 $$ = (Expression) $2;
3431 : WHILE { $$ = DoOptions.WHILE; }
3432 | UNTIL { $$ = DoOptions.UNTIL; }
3439 oob_stack.Push (lexer.Location);
3441 boolean_expression end_of_stmt
3445 Location l = (Location) oob_stack.Pop ();
3447 if (end_priority[16]>=end_priority[i] && i!=16)
3449 Report.Error(error_numbers[i],lexer.Location,"'"+end_blocks[i]+"' found without a matching '"+open_blocks[i]+"'"+open_blocks[20]);
3450 Environment.Exit(1);
3452 if (i!=16 && Parent!=16)
3454 Report.Error(30082,l,"'While' is not having a matching 'End While'");
3461 Block b = end_block();
3462 Expression e = (Expression) $3;
3463 $$ = new While ((Expression) e, (Statement) b, l);
3468 : FOR _mark_ identifier opt_type_spec ASSIGN expression TO expression opt_step end_of_stmt
3473 ArrayList VarDeclaration = new ArrayList ();
3474 VarDeclaration.Add (new VariableDeclaration ((string) $3,
3475 (Expression) $4, null, (Location)$2, null));
3477 DictionaryEntry de = new DictionaryEntry (DecomposeQI("_local_vars_", (Location)$2), VarDeclaration);
3478 Block b = declare_local_variables ((Expression) de.Key, (ArrayList) de.Value, (Location)$2);
3487 if (end_priority[1]>=end_priority[i] && i!=1)
3489 Report.Error(error_numbers[i],lexer.Location,"'"+end_blocks[i]+"' found without a matching '"+open_blocks[i]+"'"+open_blocks[20]);
3490 Environment.Exit(1);
3492 if (i!=1 && Parent!=1)
3494 Report.Error(30084,(Location)$2,"'For' is not having a matching 'Next'");
3502 _mark_ opt_identifier
3504 string s = $3.ToString();
3507 s1 = $16.ToString();
3508 if (s1 != "" && s != s1)
3510 Report.Error(30070, (Location)$15, "Next Control Variable '"+s1+"' does not match with For Loop control variable '"+s+"'");
3513 Block inner_statement = end_block();
3514 Location l = (Location)$2;
3515 Expression for_var = (Expression) DecomposeQI ((string)$3, l);
3517 Expression assign_expr = new Assign (for_var, (Expression) $6, l);
3518 Expression test_expr = new Binary (Binary.Operator.LessThanOrEqual,
3519 for_var, (Expression) $8, l);
3520 Expression step_expr = new Assign (for_var, (Expression) new Binary (Binary.Operator.Addition,
3521 for_var, (Expression) $9, l), l);
3523 Statement assign_stmt = new StatementExpression ((ExpressionStatement) assign_expr, l);
3524 Statement step_stmt = new StatementExpression ((ExpressionStatement) step_expr, l);
3526 For f = new For (assign_stmt, test_expr, step_stmt, inner_statement, l);
3529 current_block.AddStatement (f);
3538 : /* empty */ { $$ = new IntLiteral ((Int32) 1); }
3539 | STEP expression { $$ = $2; }
3548 : if_statement_open opt_then end_of_stmt opt_statement_list if_statement_rest
3552 | if_statement_open THEN pre_embedded_statement opt_else_pre_embedded_statement
3556 Location l = (Location) oob_stack.Pop ();
3557 tmp_expr = (Expression)expr_stack.Pop();
3558 $$ = new If ((Expression) tmp_expr, end_block(), l);
3562 Location l = (Location) oob_stack.Pop ();
3563 tmp_expr = (Expression)expr_stack.Pop();
3564 tmp_block = (Block) tmp_blocks.Pop ();
3565 $$ = new If ((Expression) tmp_expr, (Statement) tmp_block, end_block(), l);
3568 | if_statement_open THEN else_pre_embedded_statement
3570 Location l = (Location) oob_stack.Pop ();
3571 tmp_expr = (Expression)expr_stack.Pop();
3572 tmp_block = (Block) tmp_blocks.Pop ();
3573 $$ = new If ((Expression) tmp_expr, (Statement) tmp_block, end_block(), l);
3577 pre_embedded_statement
3578 : embedded_statement
3580 current_block.AddStatement ((Statement) $1);
3584 opt_else_pre_embedded_statement
3586 | else_pre_embedded_statement
3589 else_pre_embedded_statement
3592 Block bl = end_block();
3593 tmp_blocks.Push(bl);
3597 | ELSE embedded_statement
3599 Block bl = end_block();
3600 tmp_blocks.Push(bl);
3603 current_block.AddStatement ((Statement) $2);
3607 /*FIXME:if without end if not working. Error line shown is nor correct*/
3611 oob_stack.Push (lexer.Location);
3616 tmp_expr = (Expression) $3;
3617 expr_stack.Push(tmp_expr);
3630 Location l = (Location) oob_stack.Pop ();
3632 if (end_priority[3]>=end_priority[i] && i!=3)
3634 Report.Error(error_numbers[i],lexer.Location,"'"+end_blocks[i]+"' found without a matching '"+open_blocks[i]+"'"+open_blocks[20]);
3635 Environment.Exit(1);
3637 if (i!=3 && Parent!=3)
3639 Report.Error(30081,l,"'If' is not having a matching 'EndIf'");
3646 Expression expr = (Expression)expr_stack.Pop();
3647 $$ = new If ((Expression) expr, (Statement) end_block(), l);
3652 Block bl = end_block();
3653 tmp_blocks.Push(bl);
3659 Location l = (Location) oob_stack.Pop ();
3661 if (end_priority[3]>=end_priority[i] && i!=3)
3663 Report.Error(error_numbers[i],lexer.Location,"'"+end_blocks[i]+"' found without a matching '"+open_blocks[i]+"'"+open_blocks[20]);
3664 Environment.Exit(1);
3666 if (i!=3 && Parent!=3)
3668 Report.Error(30081,l,"'If' is not having a matching 'EndIf'");
3675 tmp_expr = (Expression)expr_stack.Pop();
3676 tmp_block = (Block) tmp_blocks.Pop();
3677 $$ = new If ((Expression) tmp_expr, (Statement) tmp_block, (Statement) end_block(), l);
3680 opt_elseif boolean_expression opt_then
3682 tmp_expr = (Expression) $2;
3683 expr_stack.Push(tmp_expr);
3684 tmp_block = end_block();
3685 tmp_blocks.Push(tmp_block);
3688 end_of_stmt opt_statement_list
3689 else_if_statement_rest
3691 Statement stmt = (Statement) statement_stack.Pop();
3692 Block bl = (Block) tmp_blocks.Pop();
3693 Expression expr = (Expression)expr_stack.Pop();
3694 Location l = (Location) oob_stack.Pop ();
3695 $$ = (Statement) new If ((Expression) expr, (Statement) bl , stmt , l);
3700 else_if_statement_rest
3704 Block bl = end_block();
3705 tmp_blocks.Push(bl);
3711 Location l = (Location) oob_stack.Pop ();
3713 if (end_priority[3]>=end_priority[i] && i!=3)
3715 Report.Error(error_numbers[i],lexer.Location,"'"+end_blocks[i]+"' found without a matching '"+open_blocks[i]+"'"+open_blocks[20]);
3716 Environment.Exit(1);
3718 if (i!=3 && Parent!=3)
3720 Report.Error(30081,l,"'If' is not having a matching 'EndIf'");
3728 Expression expr = (Expression)expr_stack.Pop();
3729 Block bl = (Block)tmp_blocks.Pop();
3730 Statement stmt = (Statement) new If ((Expression) expr, (Statement) bl , (Statement) end_block(), l);
3731 statement_stack.Push(stmt);
3734 opt_elseif boolean_expression opt_then
3736 expr_stack.Push((Expression) $2);
3737 Block bl = end_block();
3738 tmp_blocks.Push(bl);
3741 end_of_stmt opt_statement_list
3742 else_if_statement_rest
3744 Location l = (Location) oob_stack.Pop ();
3746 Statement tmp_stmt = (Statement)statement_stack.Pop();
3747 Block bl = (Block) tmp_blocks.Pop();
3748 Expression expr = (Expression)expr_stack.Pop();
3749 Statement stmt = (Statement) new If ((Expression) expr, (Statement) bl, tmp_stmt , l);
3750 statement_stack.Push(stmt);
3755 Location l = (Location) oob_stack.Pop ();
3757 if (end_priority[3]>=end_priority[i] && i!=3)
3759 Report.Error(error_numbers[i],lexer.Location,"'"+end_blocks[i]+"' found without a matching '"+open_blocks[i]+"'"+open_blocks[20]);
3760 Environment.Exit(1);
3762 if (i!=3 && Parent!=3)
3764 Report.Error(30081,l,"'If' is not having a matching 'EndIf'");
3772 Expression expr = (Expression)expr_stack.Pop();
3773 Statement stmt = (Statement) new If ((Expression) expr, (Statement) end_block(), l);
3774 statement_stack.Push(stmt);
3778 /*FIXME:Select without an expression is showing a parser error instead of a expression missing error*/
3781 _mark_ opt_case expression end_of_stmt
3783 oob_stack.Push (lexer.Location);
3784 switch_stack.Push (current_block);
3790 if (end_priority[17]>=end_priority[i] && i!=17)
3792 Report.Error(error_numbers[i],lexer.Location,"'"+end_blocks[i]+"' found without a matching '"+open_blocks[i]+"'"+open_blocks[20]);
3793 Environment.Exit(1);
3795 if (i!=17 && Parent!=17)
3797 Report.Error(30095,(Location)$2,"'Select' is not having a matching 'End Select'");
3804 current_block = (Block) switch_stack.Pop ();
3805 $$ = new Switch ((Expression) $4, (ArrayList) $7, (Location) oob_stack.Pop ());
3810 : /* empty */ { $$ = null; }
3811 | case_sections { $$ = $1; }
3815 : case_sections case_section
3817 ArrayList sections = (ArrayList) $1;
3824 ArrayList sections = new ArrayList ();
3838 : CASE case_clauses ends
3844 //Block topmost = current_block;
3845 Block topmost = end_block();
3847 while (topmost.Implicit)
3848 topmost = topmost.Parent;
3850 // FIXME: This is a horrible hack which MUST go
3851 topmost.statements.Add (new Break (lexer.Location));
3852 $$ = new SwitchSection ((ArrayList) $2, topmost);
3855 /* FIXME: we should somehow flag an error
3856 (BC30321 'Case' cannot follow a 'Case Else'
3857 in the same 'Select' statement.)
3858 if Case Else is not the last of the Case clauses
3865 //Block topmost = current_block;
3866 Block topmost = end_block();
3868 while (topmost.Implicit)
3869 topmost = topmost.Parent;
3871 // FIXME: This is a horrible hack which MUST go
3872 topmost.statements.Add (new Break (lexer.Location));
3874 ArrayList a = new ArrayList();
3875 a.Add (new SwitchLabel (null, lexer.Location));
3876 $$ = new SwitchSection ((ArrayList) a, topmost);
3883 if ($1 is ArrayList) //From expression TO expression
3887 ArrayList labels = new ArrayList ();
3893 | case_clauses COMMA case_clause
3895 ArrayList labels = (ArrayList) ($1);
3903 : opt_is comparison_operator expression
3906 $$ = new SwitchLabel ((Expression) $1, lexer.Location);
3908 | expression TO expression
3910 //FIXME: need to handle when expressions are character strings.
3911 Constant start = (Constant) $1;
3912 Constant end = (Constant) $3;
3913 int i = 0, s = 0, e = 0;
3914 Location l = lexer.Location ;
3915 ArrayList labels = new ArrayList ();
3918 s = (int) start.GetValue ();
3920 e = (int) end.GetValue ();
3921 for(i = s; i <= e; i++) {
3922 labels.Add(new SwitchLabel ((Expression)new IntLiteral(i), l));
3947 expression_statement
3948 : statement_expression
3955 statement_expression
3956 : invocation_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3957 | object_creation_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3958 | assignment_expression { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
3961 object_creation_expression
3962 : NEW type OPEN_PARENS _mark_ opt_argument_list CLOSE_PARENS
3964 $$ = new New ((Expression) $2, (ArrayList) $5, (Location)$4);
3968 $$ = new New ((Expression) $2, new ArrayList(), (Location)$3);
3972 array_creation_expression
3973 : object_creation_expression opt_rank_specifiers array_initializer
3976 ArrayList dims = new ArrayList();
3978 if (n.Arguments != null) {
3979 foreach (Argument a in n.Arguments) {
3984 Expression atype = n.RequestedType;
3987 atype = DecomposeQI (atype.ToString () + VariableDeclaration.BuildRanks ((ArrayList)$2, true, lexer.Location), lexer.Location);
3989 ArrayList init = (ArrayList) $3;
3990 if (init.Count == 0)
3993 if (VariableDeclaration.IndexesSpecifiedInRank(dims)) {
3994 VariableDeclaration.VBFixIndexList (ref dims);
3995 $$ = new ArrayCreation (atype, dims, "", init, lexer.Location);
3999 string rank = VariableDeclaration.BuildRank (dims);
4000 $$ = new ArrayCreation (atype, rank, (ArrayList) $3, lexer.Location);
4002 //Console.WriteLine ("Creating a new array of type " + (atype.ToString()) + " with rank '" + dims + "'");
4007 : object_creation_expression
4008 | array_creation_expression
4011 declaration_statement
4012 : _mark_ local_variable_declaration
4015 DictionaryEntry de = (DictionaryEntry) $2;
4017 $$ = declare_local_variables ((Expression) de.Key, (ArrayList) de.Value, (Location)$1);
4020 | local_constant_declaration
4023 DictionaryEntry de = (DictionaryEntry) $1;
4025 $$ = declare_local_constant ((Expression) de.Key, (ArrayList) de.Value);
4030 local_variable_declaration
4031 : DIM _mark_ variable_declarators
4033 $$ = new DictionaryEntry (DecomposeQI("_local_vars_", (Location)$2), $3);
4038 local_constant_declaration
4039 : CONST constant_declarators
4042 $$ = new DictionaryEntry (DecomposeQI("_local_consts_", lexer.Location), $2);
4048 constant_declarators
4049 : constant_declarator
4051 ArrayList decl = new ArrayList ();
4057 | constant_declarators COMMA constant_declarator
4059 ArrayList decls = (ArrayList) $1;
4068 : _mark_ variable_name opt_type_decl opt_variable_initializer
4070 VarName vname = (VarName) $2;
4071 string varname = (string) vname.Name;
4072 current_rank_specifiers = (ArrayList) vname.Rank;
4073 object varinit = $4;
4075 if (varinit == null)
4077 30438, (Location)$1, "Constant should have a value"
4080 if (vname.Type != null && $3 != null)
4082 30302, (Location)$1,
4083 "Type character cannot be used with explicit type declaration" );
4085 Expression vartype = ($3 == null) ? ((vname.Type == null) ? TypeManager.system_object_expr : (Expression) vname.Type ) : (Expression) $3;
4087 if (current_rank_specifiers != null)
4089 Report.Error (30424, (Location)$1, "Constant doesn't support array");
4093 $$ = new VariableDeclaration (varname, vartype, varinit, (Location)$1, null);
4097 variable_declarators
4098 : variable_declarator
4100 ArrayList decl = new ArrayList ();
4101 decl.AddRange ((ArrayList) $1);
4104 | variable_declarators COMMA variable_declarator
4106 ArrayList decls = (ArrayList) $1;
4107 decls.AddRange ((ArrayList) $3);
4113 : _mark_ variable_names opt_type_decl opt_variable_initializer
4115 ArrayList names = (ArrayList) $2;
4116 object varinit = $4;
4117 ArrayList VarDeclarations = new ArrayList();
4119 ArrayList a_dims = null;
4121 if ((names.Count > 1) && (varinit != null))
4123 30671, (Location)$1,
4124 "Multiple variables with single type can not have " +
4125 "a explicit initialization" );
4128 foreach (VarName vname in names)
4130 string varname = (string) vname.Name;
4131 current_rank_specifiers = (ArrayList) vname.Rank;
4135 if(vname.Type != null && $3 != null)
4137 30302, (Location)$1,
4138 "Type character cannot be used with explicit type declaration" );
4140 // Some checking is required for particularly weird declarations
4141 // like Dim a As Integer(,)
4143 vartype = (Expression) ((Pair) $3).First;
4145 /*if ($4 != null && $4 is ArrayList)
4146 Report.Error (205, "End of statement expected.");*/
4148 ArrayList args = (ArrayList) ((Pair) $3).Second;
4149 if (current_rank_specifiers != null)
4150 Report.Error (31087, (Location)$1,
4151 "Array types specified in too many places");
4153 if (VariableDeclaration.IndexesSpecifiedInRank (args))
4154 Report.Error (30638, "Array bounds cannot appear in type specifiers.");
4156 current_rank_specifiers = new ArrayList ();
4157 current_rank_specifiers.Add (args);
4160 vartype = ($3 == null) ? ((vname.Type == null) ? TypeManager.system_object_expr : (Expression) vname.Type ) : (Expression) $3;
4162 // if the variable is an array with explicit bound
4163 // and having explicit initialization throw exception
4164 if (current_rank_specifiers != null && varinit != null)
4166 bool broken = false;
4167 foreach (ArrayList exprs in current_rank_specifiers)
4169 foreach (Expression expr in exprs)
4171 if (!((Expression)expr is EmptyExpression ))
4174 30672, (Location)$1,
4175 "Array declared with explicit bound " +
4176 " can not have explicit initialization");
4187 Check for a declaration like Dim a(2) or Dim a(2,3)
4188 If this is the case, we must generate an ArrayCreationExpression
4189 and, in case, add the initializer after the array has been created.
4191 if (VariableDeclaration.IsArrayDecl (this)) {
4192 if (VariableDeclaration.IndexesSpecified(current_rank_specifiers)) {
4193 a_dims = (ArrayList) current_rank_specifiers;
4194 VariableDeclaration.VBFixIndexLists (ref a_dims);
4195 varinit = VariableDeclaration.BuildArrayCreator(vartype, a_dims, (ArrayList) varinit, (Location)$1);
4197 vartype = DecomposeQI (vartype.ToString() + VariableDeclaration.BuildRanks (current_rank_specifiers, false, (Location)$1), (Location)$1);
4200 if (vartype is New) {
4201 if (varinit != null) {
4202 Report.Error (30205, (Location)$1, "End of statement expected");
4208 vartype = ((New)vartype).RequestedType;
4211 VarDeclarations.Add (new VariableDeclaration (varname, vartype, varinit, (Location)$1, null));
4213 $$ = VarDeclarations;
4220 ArrayList list = new ArrayList ();
4224 | variable_names COMMA variable_name
4226 ArrayList list = (ArrayList) $1;
4233 : identifier opt_type_character opt_array_name_modifier
4235 $$ = new VarName ($1, $2, $3);
4246 $$ = (Expression) $2;
4252 | AS type rank_specifiers
4254 $$ = DecomposeQI ($2.ToString() + VariableDeclaration.BuildRanks ((ArrayList)$3, true, lexer.Location), lexer.Location);
4259 : opt_type_with_ranks
4265 New n = new New ((Expression)$3, null, lexer.Location);
4266 $$ = (Expression) n;
4268 | AS NEW type OPEN_PARENS opt_argument_list CLOSE_PARENS
4270 New n = new New ((Expression)$3, (ArrayList) $5, lexer.Location);
4271 $$ = (Expression) n;
4273 /*| AS NEW type OPEN_PARENS ADDRESSOF expression CLOSE_PARENS
4275 ArrayList args = new ArrayList();
4276 Argument arg = new Argument ((Expression) $6, Argument.AType.Expression);
4279 New n = new New ((Expression)$3, (ArrayList) args, lexer.Location);
4280 $$ = (Expression) n;
4284 opt_array_name_modifier
4285 : /* empty */ { $$ = null; }
4286 | array_type_modifier { $$ = $1; }
4290 : rank_specifiers { $$ = $1; }
4293 opt_variable_initializer
4294 : /* empty */ { $$ = null; }
4295 | ASSIGN variable_initializer { $$ = $2; }
4298 variable_initializer
4311 : OPEN_BRACE CLOSE_BRACE
4313 ArrayList list = new ArrayList ();
4316 | OPEN_BRACE variable_initializer_list CLOSE_BRACE
4318 $$ = (ArrayList) $2;
4322 variable_initializer_list
4323 : variable_initializer
4325 ArrayList list = new ArrayList ();
4329 | variable_initializer_list COMMA variable_initializer
4331 ArrayList list = (ArrayList) $1;
4352 ArrayList rs = new ArrayList();
4356 | rank_specifiers rank_specifier
4358 ArrayList rs = (ArrayList) $1;
4365 : OPEN_PARENS opt_dim_specifiers CLOSE_PARENS
4374 ArrayList ds = new ArrayList();
4375 ds.Add (new EmptyExpression());
4380 ArrayList ds = new ArrayList();
4381 ds.Add ((Expression) $1);
4384 | opt_dim_specifiers COMMA expression
4386 ArrayList ds = (ArrayList) $1;
4387 ds.Add ((Expression) $3);
4390 | opt_dim_specifiers COMMA
4392 ArrayList ds = (ArrayList) $1;
4393 ds.Add (new EmptyExpression());
4403 | parenthesized_expression
4406 | qualified_identifier
4408 string name = (string) $1;
4409 $$ = DecomposeQI (name, lexer.Location);
4411 | get_type_expression
4413 | invocation_expression
4418 { Report.Error(30201,(Location)$1,"Expression expected"); $$ = (Expression)null;}
4426 | LITERAL_DATE { $$ = new DateLiteral ((DateTime)lexer.Value); }
4427 | LITERAL_CHARACTER { $$ = new CharLiteral ((char) lexer.Value); }
4428 | LITERAL_STRING { $$ = new StringLiteral ((string) lexer.Value); }
4429 | NOTHING { $$ = NullLiteral.Null; }
4433 : LITERAL_SINGLE { $$ = new FloatLiteral ((float) lexer.Value); }
4434 | LITERAL_DOUBLE { $$ = new DoubleLiteral ((double) lexer.Value); }
4435 | LITERAL_DECIMAL { $$ = new DecimalLiteral ((decimal) lexer.Value); }
4440 object v = lexer.Value;
4443 $$ = new IntLiteral ((Int32)v);
4444 else if (v is short)
4445 $$ = new ShortLiteral ((Int16)v);
4447 $$ = new LongLiteral ((Int64)v);
4449 Console.WriteLine ("Unexpected result from scanner");
4455 : TRUE { $$ = new BoolLiteral (true); }
4456 | FALSE { $$ = new BoolLiteral (false); }
4459 parenthesized_expression
4460 : OPEN_PARENS expression CLOSE_PARENS
4465 : primary_expression DOT identifier
4468 string id_name = (string)$3;
4469 if (id_name.ToUpper() == "NEW")
4471 $$ = new MemberAccess ((Expression) $1, id_name, lexer.Location);
4475 if (with_stack.Count > 0) {
4476 Expression e = (Expression) with_stack.Peek();
4477 $$ = new MemberAccess (e, (string) $3, lexer.Location);
4485 /* | primary_expression DOT NEW
4487 $$ = new MemberAccess ((Expression) $1, (string) ".ctor", lexer.Location);
4489 | predefined_type DOT identifier
4492 $$ = new MemberAccess ((Expression) $1, (string) $3, lexer.Location);
4495 if (with_stack.Count > 0) {
4496 Expression e = (Expression) with_stack.Peek();
4497 $$ = new MemberAccess (e, (string) $3, lexer.Location);
4511 invocation_expression
4512 : primary_expression OPEN_PARENS opt_argument_list _mark_ CLOSE_PARENS
4515 Location l = (Location)$4;
4516 Report.Error (1, l, "THIS IS CRAZY");
4518 $$ = new Invocation ((Expression) $1, (ArrayList) $3, (Location)$4);
4519 // Console.WriteLine ("Invocation: {0} with {1} arguments", $1, ($3 != null) ? ((ArrayList) $3).Count : 0);
4522 // To support Mid$()
4523 | primary_expression DOLAR_SIGN OPEN_PARENS opt_argument_list _mark_ CLOSE_PARENS
4526 Location l = (Location)$5;
4527 Report.Error (1, l, "THIS IS CRAZY");
4529 $$ = new Invocation ((Expression) $1, (ArrayList) $4, (Location)$5);
4530 // Console.WriteLine ("Invocation: {0} with {1} arguments", $1, ($4 != null) ? ((ArrayList) $4).Count : 0);
4532 | CALL primary_expression OPEN_PARENS opt_argument_list _mark_ CLOSE_PARENS
4535 Location l = (Location)$5;
4536 Report.Error (1, l, "THIS IS CRAZY");
4538 $$ = new Invocation ((Expression) $2, (ArrayList) $3, (Location)$5);
4539 // Console.WriteLine ("Invocation: {0} with {1} arguments", $2, ($3 != null) ? ((ArrayList) $3).Count : 0);
4544 : MYBASE DOT IDENTIFIER
4546 string id_name = (string) $3;
4547 if (id_name.ToUpper() == "NEW")
4549 $$ = new BaseAccess (id_name, lexer.Location);
4553 $$ = new BaseAccess ("New", lexer.Location);
4561 The 'argument' rule returns an 'empty' argument
4562 of type NoArg (used for default arguments in invocations)
4563 if no arguments are actually passed.
4565 If there is only one argument and it is o type NoArg,
4566 we return a null (empty) list
4568 ArrayList args = (ArrayList) $1;
4569 if (args.Count == 1 &&
4570 ((Argument)args[0]).ArgType == Argument.AType.NoArg)
4580 ArrayList list = new ArrayList ();
4584 | argument_list COMMA argument
4586 ArrayList list = (ArrayList) $1;
4595 $$ = new Argument ((Expression) $1, Argument.AType.Expression);
4597 | BYREF variable_reference
4599 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
4603 $$ = new Argument (new EmptyExpression (), Argument.AType.NoArg);
4605 | ADDRESSOF expression
4607 $$ = new Argument ((Expression) $2, Argument.AType.AddressOf);
4612 : expression {/* note ("section 5.4"); */ $$ = $1; }
4617 : conditional_xor_expression { $$ = $1; }
4618 /*| assignment_expression*/
4629 $$ = new This (current_block, lexer.Location);
4633 // FIXME: This is actually somewhat different from Me
4634 // because it is for accessing static (classifier) methods/properties/fields
4635 $$ = new This (current_block, lexer.Location);
4640 : DIRECTCAST OPEN_PARENS expression COMMA type CLOSE_PARENS
4644 | CTYPE OPEN_PARENS expression COMMA type CLOSE_PARENS
4646 $$ = new Cast ((Expression) $5, (Expression) $3, lexer.Location);
4648 | cast_operator OPEN_PARENS expression CLOSE_PARENS
4650 $$ = new Cast ((Expression) $1, (Expression) $3, lexer.Location);
4655 : CBOOL { $$ = TypeManager.system_boolean_expr; }
4656 | CBYTE { $$ = TypeManager.system_byte_expr; }
4657 | CCHAR { $$ = TypeManager.system_char_expr; }
4658 | CDATE { $$ = TypeManager.system_date_expr; }
4659 | CDBL { $$ = TypeManager.system_double_expr; }
4660 | CDEC { $$ = TypeManager.system_decimal_expr; }
4661 | CINT { $$ = TypeManager.system_int32_expr; }
4662 | CLNG { $$ = TypeManager.system_int64_expr; }
4663 | COBJ { $$ = TypeManager.system_object_expr; }
4664 | CSHORT { $$ = TypeManager.system_int16_expr; }
4665 | CSNG { $$ = TypeManager.system_single_expr; }
4666 | CSTR { $$ = TypeManager.system_string_expr; }
4670 : GETTYPE OPEN_PARENS _mark_ type CLOSE_PARENS
4672 $$ = new TypeOf ((Expression) $4, (Location)$3);
4676 exponentiation_expression
4677 : primary_expression
4678 | exponentiation_expression OP_EXP _mark_ primary_expression
4680 $$ = new Exponentiation ((Location)$3, (Expression) $1, (Expression) $4);
4684 prefixed_unary_expression
4685 : exponentiation_expression
4686 | PLUS _mark_ prefixed_unary_expression
4688 //FIXME: Is this rule correctly defined ?
4689 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $3, (Location)$2);
4691 | MINUS _mark_ prefixed_unary_expression
4693 //FIXME: Is this rule correctly defined ?
4694 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $3, (Location)$2);
4698 multiplicative_expression
4699 : prefixed_unary_expression
4700 | multiplicative_expression STAR _mark_ prefixed_unary_expression
4702 $$ = new Binary (Binary.Operator.Multiply,
4703 (Expression) $1, (Expression) $4, (Location)$3);
4705 | multiplicative_expression DIV _mark_ prefixed_unary_expression
4707 $$ = new Binary (Binary.Operator.Division,
4708 (Expression) $1, (Expression) $4, (Location)$3);
4712 integer_division_expression
4713 : multiplicative_expression
4714 | integer_division_expression OP_IDIV _mark_ multiplicative_expression
4716 //FIXME: Is this right ?
4717 $$ = new Binary (Binary.Operator.IntDivision,
4718 (Expression) $1, (Expression) $4, (Location)$3);
4723 : integer_division_expression
4724 | mod_expression MOD _mark_ integer_division_expression
4726 $$ = new Binary (Binary.Operator.Modulus,
4727 (Expression) $1, (Expression) $4, (Location)$3);
4733 | additive_expression PLUS _mark_ mod_expression
4735 $$ = new Binary (Binary.Operator.Addition,
4736 (Expression) $1, (Expression) $4, (Location)$3);
4738 | additive_expression MINUS _mark_ mod_expression
4740 $$ = new Binary (Binary.Operator.Subtraction,
4741 (Expression) $1, (Expression) $4, (Location)$3);
4746 : additive_expression
4747 | concat_expression OP_CONCAT _mark_ additive_expression
4749 // FIXME: This should only work for String expressions
4750 // We probably need to use something from the runtime
4751 $$ = new StringConcat((Location)$3,
4752 (Expression) $1, (Expression) $4);
4759 | shift_expression OP_SHIFT_LEFT _mark_ concat_expression
4761 $$ = new Binary(Binary.Operator.LeftShift, (Expression) $1, (Expression) $4, (Location)$3);
4763 | shift_expression OP_SHIFT_RIGHT _mark_ concat_expression
4765 $$ = new Binary(Binary.Operator.RightShift, (Expression) $1, (Expression) $4, (Location)$3);
4769 relational_expression
4771 | relational_expression _mark_ LIKE shift_expression
4773 $$ = new Binary (Binary.Operator.Like,
4774 (Expression) $1, (Expression) $4, (Location)$2);
4776 | relational_expression ASSIGN _mark_ shift_expression
4778 $$ = new Binary (Binary.Operator.Equality,
4779 (Expression) $1, (Expression) $4, (Location)$3);
4781 | relational_expression OP_NE _mark_ shift_expression
4783 $$ = new Binary (Binary.Operator.Inequality,
4784 (Expression) $1, (Expression) $4, (Location)$3);
4786 | relational_expression OP_LT _mark_ shift_expression
4788 $$ = new Binary (Binary.Operator.LessThan,
4789 (Expression) $1, (Expression) $4, (Location)$3);
4791 | relational_expression OP_GT _mark_ shift_expression
4793 $$ = new Binary (Binary.Operator.GreaterThan,
4794 (Expression) $1, (Expression) $4, (Location)$3);
4796 | relational_expression OP_LE _mark_ shift_expression
4798 $$ = new Binary (Binary.Operator.LessThanOrEqual,
4799 (Expression) $1, (Expression) $4, (Location)$3);
4801 | relational_expression OP_GE _mark_ shift_expression
4803 $$ = new Binary (Binary.Operator.GreaterThanOrEqual,
4804 (Expression) $1, (Expression) $4, (Location)$3);
4806 | relational_expression IS _mark_ shift_expression
4808 $$ = new Binary (Binary.Operator.Is,
4809 (Expression) $1, (Expression) $4, (Location)$3);
4811 | TYPEOF shift_expression _mark_ IS type
4813 //FIXME: Is this rule correctly defined ?
4814 $$ = new Is ((Expression) $2, (Expression) $5, (Location)$3);
4819 : relational_expression
4820 | NOT _mark_ negation_expression
4822 //FIXME: Is this rule correctly defined ?
4823 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $3, (Location)$2);
4827 conditional_and_expression
4828 : negation_expression
4829 | conditional_and_expression AND _mark_ negation_expression
4831 $$ = new Binary (Binary.Operator.BitwiseAnd,
4832 (Expression) $1, (Expression) $4, (Location)$3);
4834 | conditional_and_expression ANDALSO _mark_ negation_expression
4835 { // FIXME: this is likely to be broken
4836 $$ = new Binary (Binary.Operator.LogicalAnd,
4837 (Expression) $1, (Expression) $4, (Location)$3);
4841 conditional_or_expression
4842 : conditional_and_expression
4843 | conditional_or_expression OR _mark_ conditional_and_expression
4845 $$ = new Binary (Binary.Operator.BitwiseOr,
4846 (Expression) $1, (Expression) $4, (Location)$3);
4848 | conditional_or_expression ORELSE _mark_ conditional_and_expression
4849 { // FIXME: this is likely to be broken
4850 $$ = new Binary (Binary.Operator.LogicalOr,
4851 (Expression) $1, (Expression) $4, (Location)$3);
4855 conditional_xor_expression
4856 : conditional_or_expression
4857 | conditional_xor_expression XOR _mark_ conditional_or_expression
4859 $$ = new Binary (Binary.Operator.ExclusiveOr,
4860 (Expression) $1, (Expression) $4, (Location)$3);
4864 assignment_expression
4865 : prefixed_unary_expression ASSIGN _mark_ expression
4867 $$ = new Assign ((Expression) $1, (Expression) $4, (Location)$3);
4869 | prefixed_unary_expression STAR ASSIGN _mark_ expression
4871 Location l = (Location)$4;
4873 $$ = new CompoundAssign (
4874 Binary.Operator.Multiply, (Expression) $1, (Expression) $5, l);
4876 | prefixed_unary_expression DIV ASSIGN _mark_ expression
4878 Location l = (Location)$4;
4880 $$ = new CompoundAssign (
4881 Binary.Operator.Division, (Expression) $1, (Expression) $5, l);
4883 | prefixed_unary_expression PLUS ASSIGN _mark_ expression
4885 Location l = (Location)$4;
4887 $$ = new CompoundAssign (
4888 Binary.Operator.Addition, (Expression) $1, (Expression) $5, l);
4890 | prefixed_unary_expression MINUS ASSIGN _mark_ expression
4892 Location l = (Location)$4;
4894 $$ = new CompoundAssign (
4895 Binary.Operator.Subtraction, (Expression) $1, (Expression) $5, l);
4897 | prefixed_unary_expression OP_SHIFT_LEFT ASSIGN _mark_ expression
4899 Location l = (Location)$4;
4901 $$ = new CompoundAssign (
4902 Binary.Operator.LeftShift, (Expression) $1, (Expression) $5, l);
4904 | prefixed_unary_expression OP_SHIFT_RIGHT ASSIGN _mark_ expression
4906 Location l = (Location)$4;
4908 $$ = new CompoundAssign (
4909 Binary.Operator.RightShift, (Expression) $1, (Expression) $5, l);
4911 | prefixed_unary_expression OP_CONCAT ASSIGN _mark_ expression
4913 Location l = (Location)$4;
4915 // FIXME should be strings only
4916 $$ = new CompoundAssign (
4917 Binary.Operator.Addition, (Expression) $1, (Expression) $5, l);
4919 | prefixed_unary_expression OP_EXP ASSIGN _mark_ expression
4921 /*Location l = (Location)$4;
4923 TODO: $$ = new CompoundAssign (
4924 Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $5, l); */
4926 | prefixed_unary_expression ASSIGN ADDRESSOF _mark_ expression
4928 ArrayList args = new ArrayList();
4929 Argument arg = new Argument ((Expression) $5, Argument.AType.Expression);
4932 New n = new New ((Expression) $1, (ArrayList) args, (Location)$4);
4933 n.isDelegate = true;
4934 $$ = new Assign ((Expression) $1, (Expression) n, (Location)$4);
4947 : namespace_or_type_name
4949 $$ = DecomposeQI ((string) $1, lexer.Location);
4958 ArrayList types = new ArrayList ();
4963 | type_list COMMA type
4965 ArrayList types = (ArrayList) $1;
4972 namespace_or_type_name
4973 : qualified_identifier
4977 : OBJECT { $$ = TypeManager.system_object_expr; }
4983 | BOOLEAN { $$ = TypeManager.system_boolean_expr; }
4984 | DATE { $$ = TypeManager.system_date_expr; }
4985 | CHAR { $$ = TypeManager.system_char_expr; }
4986 | STRING { $$ = TypeManager.system_string_expr; }
4992 | floating_point_type
4993 | DECIMAL { $$ = TypeManager.system_decimal_expr; }
4998 | BYTE { $$ = TypeManager.system_byte_expr; }
4999 | SHORT { $$ = TypeManager.system_int16_expr; }
5000 | INTEGER { $$ = TypeManager.system_int32_expr; }
5001 | LONG { $$ = TypeManager.system_int64_expr; }
5005 : SINGLE { $$ = TypeManager.system_single_expr; }
5006 | DOUBLE { $$ = TypeManager.system_double_expr; }
5010 : HASH IDENTIFIER OPEN_PARENS LITERAL_STRING COMMA LITERAL_INTEGER CLOSE_PARENS _mark_ EOL
5012 if(tokenizerController.IsAcceptingTokens)
5014 if(in_external_source)
5015 Report.Error (30580, (Location)$8, "#ExternalSource directives may not be nested");
5017 in_external_source = true;
5019 lexer.EffectiveSource = (string) $4;
5020 lexer.EffectiveLine = (int) $6;
5024 | HASH IDENTIFIER LITERAL_STRING _mark_ EOL
5026 if(tokenizerController.IsAcceptingTokens)
5028 if(!($2 as string).ToLower().Equals("region"))
5029 Report.Error (30205, (Location)$4, "Invalid Pre-processor directive");
5036 | HASH END IDENTIFIER _mark_ EOL
5038 if(tokenizerController.IsAcceptingTokens)
5040 if( ($3 as string).ToLower().Equals("externalsource")) {
5041 if(!in_external_source)
5042 Report.Error (30578, (Location)$4, "'#End ExternalSource' must be preceded by a matching '#ExternalSource'");
5044 in_external_source = false;
5045 lexer.EffectiveSource = lexer.Source;
5046 lexer.EffectiveLine = lexer.Line;
5049 else if(($3 as string).ToLower().Equals("region")) {
5050 if(in_marked_region > 0)
5053 Report.Error (30205, (Location)$4, "'#End Region' must be preceded by a matching '#Region'");
5056 Report.Error (29999, (Location)$4, "Unrecognized Pre-Processor statement");
5060 | HASH CONST IDENTIFIER ASSIGN boolean_literal _mark_ EOL
5062 if(tokenizerController.IsAcceptingTokens)
5070 IfElseStateMachine.Token tok = IfElseStateMachine.Token.IF;
5073 ifElseStateMachine.HandleToken(tok);
5075 catch(ApplicationException) {
5076 throw new MBASException(ifElseStateMachine.Error, (Location)$3, ifElseStateMachine.ErrString);
5079 boolean_literal opt_then EOL
5081 HandleConditionalDirective(IfElseStateMachine.Token.IF, (BoolLiteral)$5);
5083 | HASH opt_elseif _mark_
5085 IfElseStateMachine.Token tok = IfElseStateMachine.Token.ELSEIF;
5087 ifElseStateMachine.HandleToken(tok);
5089 catch(ApplicationException) {
5090 throw new MBASException(ifElseStateMachine.Error, (Location)$3, ifElseStateMachine.ErrString);
5093 boolean_literal opt_then EOL
5095 HandleConditionalDirective(IfElseStateMachine.Token.ELSEIF, (BoolLiteral)$5);
5099 IfElseStateMachine.Token tok = IfElseStateMachine.Token.ELSE;
5101 ifElseStateMachine.HandleToken(tok);
5103 catch(ApplicationException) {
5104 throw new MBASException(ifElseStateMachine.Error, (Location)$3, ifElseStateMachine.ErrString);
5109 HandleConditionalDirective(IfElseStateMachine.Token.ELSE, new BoolLiteral(true));
5111 | HASH END IF _mark_
5113 /*FIXME: IF without ENDIF not working properly. Error line is not diplayed properly*/
5115 IfElseStateMachine.Token tok = IfElseStateMachine.Token.ENDIF;
5117 ifElseStateMachine.HandleToken(tok);
5119 catch(ApplicationException) {
5120 throw new MBASException(ifElseStateMachine.Error, (Location)$4, ifElseStateMachine.ErrString);
5125 HandleConditionalDirective(IfElseStateMachine.Token.ENDIF, new BoolLiteral(false));
5127 | HASH error _mark_ EOL
5129 if(tokenizerController.IsAcceptingTokens)
5130 Report.Error(29999, (Location)$3, "Unrecognized Pre-Processor statement");
5132 Report.Warning (29999, (Location)$3,"Unrecognized Pre-Processor statement");
5137 // Utility rule to save location information
5140 { $$ = lexer.Location; if (yyToken == Token.EOL) { $$ = new Location (lexer.Location.Row - 1, lexer.Location.Col); } }
5143 // Changed to accept "Else If" also along with "ElseIf"
5149 // Changed so as to check if every block is closed or not...
5151 : END opt_block_types
5205 public Tokenizer Lexer {
5211 public static Expression DecomposeQI (string name, Location loc)
5215 if (name.IndexOf ('.') == -1){
5216 return new SimpleName (name, loc);
5218 int pos = name.LastIndexOf (".");
5219 string left = name.Substring (0, pos);
5220 string right = name.Substring (pos + 1);
5222 o = DecomposeQI (left, loc);
5224 return new MemberAccess (o, right, loc);
5228 Block declare_local_variables (Expression dummy_type, ArrayList variable_declarators, Location loc)
5230 Block implicit_block;
5231 ArrayList inits = null;
5234 // We use the `Used' property to check whether statements
5235 // have been added to the current block. If so, we need
5236 // to create another block to contain the new declaration
5237 // otherwise, as an optimization, we use the same block to
5238 // add the declaration.
5240 // FIXME: A further optimization is to check if the statements
5241 // that were added were added as part of the initialization
5242 // below. In which case, no other statements have been executed
5243 // and we might be able to reduce the number of blocks for
5244 // situations like this:
5246 // int j = 1; int k = j + 1;
5249 VariableDeclaration.FixupTypes (variable_declarators);
5251 if (current_block.Used) {
5252 implicit_block = new Block (current_block, true, loc, Location.Null);
5253 implicit_block.AddChildVariableNames (current_block);
5255 implicit_block = current_block;
5257 foreach (VariableDeclaration decl in variable_declarators){
5258 Expression type = decl.type;
5259 if (implicit_block.AddVariable (type, decl.identifier, current_local_parameters, loc) != null) {
5260 if (decl.expression_or_array_initializer != null){
5262 inits = new ArrayList ();
5269 return implicit_block;
5271 foreach (VariableDeclaration decl in inits){
5274 Expression type = decl.type;
5276 if ((decl.expression_or_array_initializer is Expression) ||
5277 (decl.expression_or_array_initializer is New)) {
5278 expr = (Expression) decl.expression_or_array_initializer;
5280 ArrayList init = (ArrayList) decl.expression_or_array_initializer;
5282 expr = new ArrayCreation (type, "", init, decl.Location);
5285 LocalVariableReference var;
5286 var = new LocalVariableReference (implicit_block, decl.identifier, loc);
5288 assign = new Assign (var, expr, decl.Location);
5290 implicit_block.AddStatement (new StatementExpression (assign, lexer.Location));
5293 return implicit_block;
5296 Block declare_local_constant (Expression dummy_type, ArrayList variable_declarators)
5298 Block implicit_block;
5299 VariableDeclaration.FixupTypes (variable_declarators);
5301 if (current_block.Used)
5302 implicit_block = new Block (current_block, true);
5304 implicit_block = current_block;
5306 foreach (VariableDeclaration decl in variable_declarators){
5307 Expression type = decl.type;
5308 implicit_block.AddConstant (type, decl.identifier, (Expression) decl.expression_or_array_initializer,
5309 current_local_parameters, decl.Location);
5312 return implicit_block;
5320 public VarName (object n, object t, object r)
5330 // A class used to pass around variable declarations and constants
5332 public class VariableDeclaration {
5333 public string identifier;
5334 public object expression_or_array_initializer;
5335 public Location Location;
5336 public Attributes OptAttributes;
5337 public Expression type;
5338 public ArrayList dims;
5340 public VariableDeclaration (string id, Expression t, object eoai, Location l, Attributes opt_attrs)
5342 this.identifier = id;
5343 this.expression_or_array_initializer = eoai;
5345 this.OptAttributes = opt_attrs;
5350 public VariableDeclaration (string id, object eoai, Location l) : this (id, eoai, l, null)
5354 public VariableDeclaration (string id, Expression t, Location l) : this (id, t, null, l, null)
5358 public VariableDeclaration (string id, object eoai, Location l, Attributes opt_attrs) : this
5359 (id, TypeManager.system_object_expr, eoai, l, opt_attrs)
5363 public static ArrayCreation BuildArrayCreator (Expression vartype, ArrayList a_dims, ArrayList varinit, Location l)
5365 // FIXME : This is broken: only the first rank is parsed
5366 return new ArrayCreation (vartype, (ArrayList) a_dims[0], "", varinit, l);
5369 public static void FixupTypes (ArrayList vars)
5371 int varcount = vars.Count;
5372 VariableDeclaration last_var = (VariableDeclaration) vars[varcount - 1];
5374 if (last_var.type == null)
5375 last_var.type = TypeManager.system_object_expr;
5377 Expression cur_type = last_var.type;
5378 int n = varcount - 1;
5381 VariableDeclaration var = (VariableDeclaration) vars[n--];
5382 if (var.type == null)
5383 var.type = cur_type;
5385 cur_type = var.type;
5389 public static bool IndexesSpecifiedInRank (ArrayList IndexList)
5393 if (IndexList != null) {
5394 foreach (Expression e in IndexList)
5395 if (!(e is EmptyExpression)) {
5404 public static bool IndexesSpecified (ArrayList ranks)
5408 if (ranks != null) {
5409 foreach (ArrayList IndexList in ranks) {
5410 if (IndexesSpecifiedInRank (IndexList)) {
5419 public static string StripDims (string varname, ref string d)
5421 string res = varname;
5424 if (varname.IndexOf("[") >= 0) {
5425 dres = varname.Substring(varname.IndexOf("["), (varname.LastIndexOf("]") - varname.IndexOf("["))+1);
5426 res = varname.Substring(0, varname.IndexOf("["));
5432 public static string StripDims (string varname)
5436 return (StripDims(varname, ref dres));
5439 public static string StripIndexesFromDims (string dims)
5441 StringBuilder sb = new StringBuilder();
5443 foreach (char c in dims)
5444 if (c == ',' || c == ']' || c == '[')
5447 return sb.ToString();
5450 public static string BuildRank (ArrayList rank)
5453 return BuildRank(rank, out allEmpty);
5456 public static string BuildRank (ArrayList rank, out bool allEmpty)
5463 foreach (object e in rank) {
5464 if (!(e is EmptyExpression))
5475 public static string BuildRanks (ArrayList rank_specifiers, bool mustBeEmpty, Location loc)
5479 bool allEmpty = true;
5480 foreach (ArrayList rank in rank_specifiers) {
5482 res = BuildRank (rank, out tmp) + res;
5486 if (!allEmpty && mustBeEmpty)
5487 Report.Error (30638, loc, "Array bounds cannot appear in type specifiers.");
5492 public static void VBFixIndexList (ref ArrayList IndexList)
5494 if (IndexList != null) {
5495 for (int x = 0; x < IndexList.Count; x++) {
5496 Expression e = (Expression) IndexList[x];
5497 if (!(e is EmptyExpression)) {
5498 IndexList[x] = new Binary (Binary.Operator.Addition, e, new IntLiteral(1), Location.Null);
5504 public static bool IsArrayDecl (Parser t)
5506 // return (varname.IndexOf("[") >= 0);
5507 return (t.current_rank_specifiers != null);
5510 public static void VBFixIndexLists (ref ArrayList ranks)
5512 if (ranks != null) {
5513 for (int x = 0; x < ranks.Count; x++) {
5514 ArrayList IndexList = (ArrayList) ranks[x];
5515 VBFixIndexList (ref IndexList);
5520 public static void FixupArrayTypes (ArrayList vars)
5524 foreach (VariableDeclaration var in vars) {
5525 if (var.identifier.EndsWith(",")) {
5526 dims = "[" + var.identifier.Substring(var.identifier.IndexOf (","),
5527 var.identifier.LastIndexOf(",")) + "]";
5528 var.identifier = var.identifier.Substring (0, var.identifier.IndexOf (","));
5529 var.type = new ComposedCast (var.type, (string) dims, var.Location);
5536 public Property BuildSimpleProperty (Expression p_type, string name,
5537 Field p_fld, int mod_flags,
5538 Attributes attrs, Location loc)
5541 Block get_block, set_block;
5542 Accessor acc_set, acc_get;
5543 StatementExpression a_set;
5548 Parameter implicit_value_parameter = new Parameter (p_type, "value", Parameter.Modifier.NONE, null);
5549 args = new Parameter [1];
5550 args [0] = implicit_value_parameter;
5552 Parameters set_params = new Parameters (args, null, loc);
5553 a_set = new StatementExpression ((ExpressionStatement) new Assign ((Expression) DecomposeQI(p_fld.Name, loc),
5554 (Expression) new SimpleName("value", loc), loc), loc);
5556 set_block = new Block (current_block, set_params, loc, Location.Null);
5557 set_block.AddStatement ((Statement) a_set);
5558 acc_set = new Accessor (set_block, attrs);
5561 a_get = (Statement) new Return ((Expression) DecomposeQI(p_fld.Name, loc), loc);
5562 get_block = new Block (current_block, null, loc, Location.Null);
5563 get_block.AddStatement ((Statement) a_get);
5564 acc_get = new Accessor (get_block, attrs);
5566 p = new Property (p_type, name, mod_flags, (Accessor) acc_get, (Accessor) acc_set, attrs, loc);
5573 current_block = new Block (current_block, current_local_parameters,
5574 lexer.Location, Location.Null);
5581 while (current_block.Implicit)
5582 current_block = current_block.Parent;
5584 res = current_block;
5586 current_block.SetEndLocation (lexer.Location);
5587 current_block = current_block.Parent;
5592 private void AddHandler (Expression evt_definition, Expression handler_exp)
5594 AddHandler (current_block, evt_definition, handler_exp);
5597 void CheckAttributeTarget (string a)
5601 case "assembly" : case "field" : case "method" : case "param" : case "property" : case "type" :
5605 Location l = lexer.Location;
5606 Report.Error (658, l, "`" + a + "' is an invalid attribute target");
5611 private void AddHandler (Block b, Expression evt_id, Expression handles_exp)
5613 Location loc = lexer.Location;
5615 Statement addhnd = (Statement) new AddHandler (evt_id,
5618 b.AddStatement (addhnd);
5621 private void RaiseEvent (string evt_name, ArrayList args)
5623 Location loc = lexer.Location;
5625 Invocation evt_call = new Invocation (DecomposeQI(evt_name, loc), args, lexer.Location);
5626 Statement s = (Statement)(new StatementExpression ((ExpressionStatement) evt_call, loc));
5627 current_block.AddStatement (s);
5630 private void RemoveHandler (Block b, Expression evt_definition, Expression handler_exp)
5632 Location loc = lexer.Location;
5634 Statement rmhnd = (Statement) new RemoveHandler (evt_definition,
5637 b.AddStatement (rmhnd);
5641 // This method is used to get at the complete string representation of
5642 // a fully-qualified type name, hiding inside a MemberAccess ;-)
5643 // This is necessary because local_variable_type admits primary_expression
5644 // as the type of the variable. So we do some extra checking
5646 string GetQualifiedIdentifier (Expression expr)
5648 if (expr is SimpleName)
5649 return ((SimpleName)expr).Name;
5650 else if (expr is MemberAccess)
5651 return GetQualifiedIdentifier (((MemberAccess)expr).Expr) + "." + ((MemberAccess) expr).Identifier;
5653 throw new Exception ("Expr has to be either SimpleName or MemberAccess! (" + expr + ")");
5657 private void RemoveHandler (Expression evt_definition, Expression handler_exp)
5659 RemoveHandler (current_block, evt_definition, handler_exp);
5662 private ConstructorInitializer CheckConstructorInitializer (ref ArrayList s)
5664 ConstructorInitializer ci = null;
5667 if (s[0] is StatementExpression && ((StatementExpression) s[0]).expr is Invocation) {
5668 Invocation i = (Invocation) ((StatementExpression) s[0]).expr;
5670 if (i.expr is BaseAccess) {
5671 BaseAccess ba = (BaseAccess) i.expr;
5672 if (ba.member == "New" || ba.member == ".ctor") {
5673 ci = new ConstructorBaseInitializer (i.Arguments, current_local_parameters, lexer.Location);
5677 if (i.expr.ToString() == "Mono.MonoBASIC.This..ctor") {
5678 ci = new ConstructorThisInitializer (i.Arguments, current_local_parameters, lexer.Location);
5686 void Error_ExpectingTypeName (Location l, Expression expr)
5688 if (expr is Invocation){
5689 Report.Error (1002, l, "; expected");
5691 Report.Error (-1, l, "Invalid Type definition");
5695 static bool AlwaysAccept (MemberInfo m, object filterCriteria) {
5699 private void ReportError9998()
5701 Report.Error (29998, lexer.Location, "This construct is only available in MonoBASIC extended syntax.");
5704 protected override int parse ()
5706 RootContext.InitializeImports(ImportsList);
5707 current_namespace = new Namespace (null, RootContext.RootNamespace);
5708 current_container = RootContext.Tree.Types;
5709 current_container.Namespace = current_namespace;
5710 oob_stack = new Stack ();
5711 switch_stack = new Stack ();
5712 expr_stack = new Stack ();
5713 tmp_blocks = new Stack();
5714 with_stack = new Stack();
5715 statement_stack = new Stack();
5717 allow_global_attribs = true;
5718 expecting_global_attribs = false;
5719 expecting_local_attribs = false;
5720 local_attrib_section_added = false;
5722 UseExtendedSyntax = name.EndsWith(".mbs");
5723 OptionExplicit = InitialOptionExplicit || UseExtendedSyntax;
5724 OptionStrict = InitialOptionStrict || UseExtendedSyntax;
5725 OptionCompareBinary = InitialOptionCompareBinary;
5727 lexer = new Tokenizer (input, name, defines);
5729 ifElseStateMachine = new IfElseStateMachine();
5730 tokenizerController = new TokenizerController(lexer);
5733 if (yacc_verbose_flag > 0)
5734 yyparse (lexer, new yydebug.yyDebugSimple ());
5740 catch(MBASException e) {
5741 Report.Error(e.code, e.loc, e.Message);
5743 catch (Exception e) {
5744 if (Report.Stacktrace)
5745 Console.WriteLine(e);
5746 Report.Error (29999, lexer.Location, "Parsing error");
5749 RootContext.VerifyImports();
5751 return Report.Errors;
5757 ifElseStateMachine.HandleToken(IfElseStateMachine.Token.EOF);
5759 catch(ApplicationException) {
5760 throw new MBASException(ifElseStateMachine.Error, lexer.Location, ifElseStateMachine.ErrString);
5763 if(in_external_source)
5764 Report.Error (30579, lexer.Location, "'#ExternalSource' directives must end with matching '#End ExternalSource'");
5766 if(in_marked_region > 0)
5767 Report.Error (30205, lexer.Location, "'#Region' directive must be followed by a matching '#End Region'");
5770 void HandleConditionalDirective(IfElseStateMachine.Token tok, BoolLiteral expr)
5773 tokenizerController.PositionTokenizerCursor(tok, expr);
5775 catch(ApplicationException) {
5776 tok = IfElseStateMachine.Token.EOF;
5778 ifElseStateMachine.HandleToken(tok);
5780 catch(ApplicationException) {
5781 throw new MBASException(ifElseStateMachine.Error, lexer.Location, ifElseStateMachine.ErrString);