3 // MonoBASIC.Parser.cs (from .jay): The Parser for the MonoBASIC compiler
\r
5 // Author: A Rafael D Teixeira (rafaelteixeirabr@hotmail.com)
\r
7 // Licensed under the terms of the GNU GPL
\r
9 // Copyright (C) 2001 A Rafael D Teixeira
\r
12 // Nearly everything
\r
15 namespace Mono.Languages.MonoBASIC
\r
19 using System.Collections;
\r
22 using Mono.Languages;
\r
23 using Mono.Languages.MonoBASIC; // To get the tokenizer
\r
26 /// The MonoBASIC Parser
\r
28 public class Parser : GenericParser {
\r
29 Namespace current_namespace;
\r
30 TypeContainer current_container;
\r
34 /// Current block is used to add statements as we find
\r
37 Block current_block;
\r
40 /// Current interface is used by the various declaration
\r
41 /// productions in the interface declaration to "add"
\r
42 /// the interfaces as we find them.
\r
44 Interface current_interface;
\r
47 /// This is used by the unary_expression code to resolve
\r
48 /// a name against a parameter.
\r
50 Parameters current_local_parameters;
\r
53 /// Using during property parsing to describe the implicit
\r
54 /// value parameter that is passed to the "set" accessor
\r
57 Parameter [] implicit_value_parameters;
\r
61 /// Used to record all types defined
\r
65 bool UseExtendedSyntax; // for ".mbs" files
\r
67 public override string[] GetExtensions()
\r
69 string [] list = { ".vb", ".mbs" };
\r
76 %token NONE /* This token is never returned by our lexer */
\r
77 %token ERROR // This is used not by the parser, but by the tokenizer.
\r
81 *These are the MonoBASIC keywords
\r
160 %token MUSTINHERIT
\r
161 %token MUSTOVERRIDE
\r
169 %token NOTINHERITABLE
\r
170 %token NOTOVERRIDABLE
\r
178 %token OVERRIDABLE
\r
190 %token REMOVEHANDLER
\r
223 /* MonoBASIC single character operators/punctuation. */
\r
224 %token OPEN_BRACKET "["
\r
225 %token CLOSE_BRACKET "]"
\r
226 %token OPEN_PARENS "("
\r
227 %token CLOSE_PARENS ")"
\r
242 %token OP_IDIV "\\"
\r
243 %token OP_CONCAT "&"
\r
245 /* MonoBASIC multi-character operators. */
\r
250 %token OP_AND //"and"
\r
251 %token OP_OR //"or"
\r
252 %token OP_XOR //"xor"
\r
253 %token OP_MODULUS //"mod"
\r
254 %token OP_MULT_ASSIGN "*="
\r
255 %token OP_DIV_ASSIGN "/="
\r
256 %token OP_IDIV_ASSIGN "\\="
\r
257 %token OP_ADD_ASSIGN "+="
\r
258 %token OP_SUB_ASSIGN "-="
\r
259 %token OP_CONCAT_ASSIGN "&="
\r
260 %token OP_EXP_ASSIGN "^="
\r
263 %token LITERAL_INTEGER "int literal"
\r
264 %token LITERAL_SINGLE "float literal"
\r
265 %token LITERAL_DOUBLE "double literal"
\r
266 %token LITERAL_DECIMAL "decimal literal"
\r
267 %token LITERAL_CHARACTER "character literal"
\r
268 %token LITERAL_STRING "string literal"
\r
272 /* Add precedence rules to solve dangling else s/r conflict */
\r
281 %left OP_SHIFT_LEFT OP_SHIFT_RIGHT
\r
283 %left STAR DIV PERCENT
\r
284 %right BITWISE_NOT CARRET UMINUS
\r
285 %nonassoc OP_INC OP_DEC
\r
287 %left OPEN_BRACKET OPEN_BRACE
\r
291 %start compilation_unit
\r
295 : opt_imports_directives
\r
296 /* opt_attributes */
\r
297 opt_namespace_member_declarations
\r
304 qualified_identifier
\r
306 | qualified_identifier DOT IDENTIFIER
\r
308 $$ = (($1).ToString ()) + "." + ($3.ToString ());
\r
312 opt_imports_directives
\r
314 | imports_directives
\r
318 : imports_directive
\r
319 | imports_directives imports_directive
\r
323 : /* imports_alias_directive
\r
324 | */ imports_namespace_directive
\r
327 imports_namespace_directive
\r
328 : IMPORTS namespace_name EOL
\r
330 current_namespace.Using ((string) $2);
\r
338 namespace_declaration
\r
339 : NAMESPACE qualified_identifier EOL
\r
341 current_namespace = new Namespace (current_namespace, (string) $2);
\r
343 opt_imports_directives
\r
344 opt_namespace_member_declarations
\r
347 current_namespace = current_namespace.Parent;
\r
352 : qualified_identifier
\r
357 opt_namespace_member_declarations
\r
359 | namespace_member_declarations
\r
362 namespace_member_declarations
\r
363 : namespace_member_declaration
\r
364 | namespace_member_declarations namespace_member_declaration
\r
367 namespace_member_declaration
\r
368 : namespace_declaration
\r
375 Class c = (Class) $1;
\r
376 mod_flags = c.ModFlags;
\r
378 } else if ($1 is Struct){
\r
379 Struct s = (Struct) $1;
\r
380 mod_flags = s.ModFlags;
\r
390 : class_declaration
\r
395 : /* opt_attributes opt_modifiers */
\r
396 CLASS IDENTIFIER /* opt_class_interfaces */ EOL
\r
399 opt_class_member_declarations
\r
405 opt_class_member_declarations
\r
407 | class_member_declarations
\r
410 class_member_declarations
\r
411 : class_member_declaration
\r
412 | class_member_declarations class_member_declaration
\r
415 class_member_declaration
\r
421 : SUB qualified_identifier OPEN_PARENS opt_formal_parameters CLOSE_PARENS EOL
\r
428 | qualified_identifier OPEN_PARENS opt_actual_parameters CLOSE_PARENS EOL
\r
431 opt_formal_parameters
\r
433 | qualified_identifier AS qualified_identifier
\r
436 opt_actual_parameters
\r
438 | qualified_identifier
\r
447 public override int parse ()
\r
449 current_namespace = new Namespace (null, "");
\r
450 this.tree = rc.Tree;
\r
451 current_container = tree.Types;
\r
452 current_container.Namespace = current_namespace;
\r
454 UseExtendedSyntax = name.EndsWith(".mbs");
\r
456 lexer = new Tokenizer (input, name);
\r
457 StringBuilder value = new StringBuilder ();
\r
462 if (yacc_verbose_flag)
\r
463 yyparse (lexer, new yydebug.yyDebugSimple ());
\r
467 catch (Exception e)
\r
469 Console.WriteLine (lexer.location + " : Parsing error ");
\r
470 Console.WriteLine (e);
\r
474 return global_errors;
\r