3 // Mono.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.MonoBASIC
\r
19 using System.Collections;
\r
20 using Mono.Languages;
\r
24 /// The MonoBASIC Parser
\r
26 public class Parser : GenericParser
\r
31 /// Current block is used to add statements as we find
\r
34 Block current_block;
\r
37 /// Current interface is used by the various declaration
\r
38 /// productions in the interface declaration to "add"
\r
39 /// the interfaces as we find them.
\r
41 Interface current_interface;
\r
44 /// This is used by the unary_expression code to resolve
\r
45 /// a name against a parameter.
\r
47 Parameters current_local_parameters;
\r
50 /// Using during property parsing to describe the implicit
\r
51 /// value parameter that is passed to the "set" accessor
\r
54 Parameter [] implicit_value_parameters;
\r
57 bool UseExtendedSyntax; // for ".mbs" files
\r
59 public override string[] extensions()
\r
61 string [] list = { ".vb", ".mbs" };
\r
68 %token NONE /* This token is never returned by our lexer */
\r
69 %token ERROR // This is used not by the parser, but by the tokenizer.
\r
73 *These are the MonoBASIC keywords
\r
113 %token DESCRIPTION // MonoBASIC extension
\r
153 %token MUSTINHERIT
\r
154 %token MUSTOVERRIDE
\r
162 %token NOTINHERITABLE
\r
163 %token NOTOVERRIDABLE
\r
171 %token OVERRIDABLE
\r
173 %token PARAMETER // MonoBASIC extension
\r
184 %token REMOVEHANDLER
\r
200 %token SUMMARY // MonoBASIC extension
\r
218 /* MonoBASIC single character operators/punctuation. */
\r
219 %token OPEN_BRACKET "["
\r
220 %token CLOSE_BRACKET "]"
\r
221 %token OPEN_PARENS "("
\r
222 %token CLOSE_PARENS ")"
\r
237 %token OP_IDIV "\\"
\r
238 %token OP_CONCAT "&"
\r
240 /* MonoBASIC multi-character operators. */
\r
245 %token OP_AND //"and"
\r
246 %token OP_OR //"or"
\r
247 %token OP_XOR //"xor"
\r
248 %token OP_MODULUS //"mod"
\r
249 %token OP_MULT_ASSIGN "*="
\r
250 %token OP_DIV_ASSIGN "/="
\r
251 %token OP_IDIV_ASSIGN "\\="
\r
252 %token OP_ADD_ASSIGN "+="
\r
253 %token OP_SUB_ASSIGN "-="
\r
254 %token OP_CONCAT_ASSIGN "&="
\r
255 %token OP_EXP_ASSIGN "^="
\r
258 %token LITERAL_INTEGER "int literal"
\r
259 %token LITERAL_SINGLE "float literal"
\r
260 %token LITERAL_DOUBLE "double literal"
\r
261 %token LITERAL_DECIMAL "decimal literal"
\r
262 %token LITERAL_CHARACTER "character literal"
\r
263 %token LITERAL_STRING "string literal"
\r
267 /* Add precedence rules to solve dangling else s/r conflict */
\r
276 %left OP_SHIFT_LEFT OP_SHIFT_RIGHT
\r
278 %left STAR DIV PERCENT
\r
279 %right BITWISE_NOT CARRET UMINUS
\r
280 %nonassoc OP_INC OP_DEC
\r
282 %left OPEN_BRACKET OPEN_BRACE
\r
286 %start compilation_unit
\r
290 : opt_imports_directives
\r
306 | declarations declaration
\r
310 : namespace_declaration
\r
317 Class c = (Class) $1;
318 mod_flags = c.ModFlags;
320 } else if ($1 is Struct){
321 Struct s = (Struct) $1;
322 mod_flags = s.ModFlags;
327 if ((mod_flags & (Modifiers.PRIVATE|Modifiers.PROTECTED)) != 0){
329 1527, lexer.Location,
330 "Namespace elements cannot be explicitly " +
331 "declared private or protected in '" + name + "'");
336 qualified_identifier
\r
338 | qualified_identifier DOT IDENTIFIER
\r
340 $$ = (($1).ToString ()) + "." + ($3.ToString ());
\r
343 opt_imports_directives
\r
345 | imports_directives
\r
349 : imports_directive
\r
350 | imports_directives imports_directive
\r
354 : /* imports_alias_directive
\r
355 | */ imports_namespace_directive
\r
358 imports_namespace_directive
\r
359 : IMPORTS qualified_identifier EOL
\r
361 current_namespace.Using ((string) $2);
\r
369 namespace_declaration
\r
370 : NAMESPACE qualified_identifier EOL
\r
372 current_namespace = RootContext.Tree.RecordNamespace(current_namespace, name, (string)$2);
374 opt_imports_directives
\r
378 current_namespace = current_namespace.Parent;
\r
383 : class_declaration
\r
384 | module_declaration
\r
385 // | struct_declaration
386 // | interface_declaration
387 // | enum_declaration
388 // | delegate_declaration
392 : /* opt_attributes opt_modifiers */
\r
393 CLASS IDENTIFIER /* opt_class_interfaces */ EOL
\r
396 opt_class_member_declarations
\r
402 opt_module_modifiers
\r
403 : /* empty */ { $$ = (int) 0; }
\r
404 | PUBLIC { $$ = Modifiers.PUBLIC; }
\r
405 | FRIEND { $$ = Modifiers.INTERNAL; }
\r
409 : opt_attributes opt_module_modifiers
\r
410 MODULE IDENTIFIER EOL
\r
415 name = MakeName((string) $4);
416 new_module = new Module(current_container,
421 current_container = new_module;
422 current_container.Namespace = current_namespace;
423 RootContext.Tree.RecordDecl(name, new_module);
425 opt_class_member_declarations
\r
428 Module new_module = (Module)current_container;
430 current_container = current_container.Parent;
431 CheckDef (current_container.AddClass(new_module), new_module.Name, new_module.Location);
437 opt_class_member_declarations
\r
439 | class_member_declarations
\r
442 class_member_declarations
\r
443 : class_member_declaration
\r
444 | class_member_declarations class_member_declaration
\r
447 class_member_declaration
\r
448 : /* type_declaration
\r
449 | */ sub_declaration
\r
453 : SUB qualified_identifier OPEN_PARENS opt_formal_parameters CLOSE_PARENS EOL
\r
460 | qualified_identifier OPEN_PARENS opt_actual_parameters CLOSE_PARENS EOL
\r
463 opt_formal_parameters
\r
465 | qualified_identifier AS qualified_identifier
\r
468 opt_actual_parameters
\r
470 | qualified_identifier
\r
479 public Tokenizer Lexer {
\r
485 public override int parse ()
\r
487 current_namespace = new Namespace (null, "");
\r
488 current_container = RootContext.Tree.Types;
\r
489 current_container.Namespace = current_namespace;
\r
491 UseExtendedSyntax = name.EndsWith(".mbs");
\r
493 lexer = new Tokenizer (input, name, defines);
\r
494 StringBuilder value = new StringBuilder ();
\r
499 if (yacc_verbose_flag)
\r
500 yyparse (lexer, new yydebug.yyDebugSimple ());
\r
504 catch (Exception e)
\r
506 Console.WriteLine (lexer.location + " : Parsing error ");
\r
507 Console.WriteLine (e);
\r
511 return global_errors;
\r