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
28 Namespace current_namespace;
\r
29 TypeContainer current_container;
\r
33 /// Current block is used to add statements as we find
\r
36 Block current_block;
\r
39 /// Current interface is used by the various declaration
\r
40 /// productions in the interface declaration to "add"
\r
41 /// the interfaces as we find them.
\r
43 Interface current_interface;
\r
46 /// This is used by the unary_expression code to resolve
\r
47 /// a name against a parameter.
\r
49 Parameters current_local_parameters;
\r
52 /// Using during property parsing to describe the implicit
\r
53 /// value parameter that is passed to the "set" accessor
\r
56 Parameter [] implicit_value_parameters;
\r
59 bool UseExtendedSyntax; // for ".mbs" files
\r
61 public override string[] extensions()
\r
63 string [] list = { ".vb", ".mbs" };
\r
70 %token NONE /* This token is never returned by our lexer */
\r
71 %token ERROR // This is used not by the parser, but by the tokenizer.
\r
75 *These are the MonoBASIC keywords
\r
115 %token DESCRIPTION // MonoBASIC extension
\r
155 %token MUSTINHERIT
\r
156 %token MUSTOVERRIDE
\r
164 %token NOTINHERITABLE
\r
165 %token NOTOVERRIDABLE
\r
173 %token OVERRIDABLE
\r
175 %token PARAMETER // MonoBASIC extension
\r
186 %token REMOVEHANDLER
\r
202 %token SUMMARY // MonoBASIC extension
\r
220 /* MonoBASIC single character operators/punctuation. */
\r
221 %token OPEN_BRACKET "["
\r
222 %token CLOSE_BRACKET "]"
\r
223 %token OPEN_PARENS "("
\r
224 %token CLOSE_PARENS ")"
\r
239 %token OP_IDIV "\\"
\r
240 %token OP_CONCAT "&"
\r
242 /* MonoBASIC multi-character operators. */
\r
247 %token OP_AND //"and"
\r
248 %token OP_OR //"or"
\r
249 %token OP_XOR //"xor"
\r
250 %token OP_MODULUS //"mod"
\r
251 %token OP_MULT_ASSIGN "*="
\r
252 %token OP_DIV_ASSIGN "/="
\r
253 %token OP_IDIV_ASSIGN "\\="
\r
254 %token OP_ADD_ASSIGN "+="
\r
255 %token OP_SUB_ASSIGN "-="
\r
256 %token OP_CONCAT_ASSIGN "&="
\r
257 %token OP_EXP_ASSIGN "^="
\r
260 %token LITERAL_INTEGER "int literal"
\r
261 %token LITERAL_SINGLE "float literal"
\r
262 %token LITERAL_DOUBLE "double literal"
\r
263 %token LITERAL_DECIMAL "decimal literal"
\r
264 %token LITERAL_CHARACTER "character literal"
\r
265 %token LITERAL_STRING "string literal"
\r
269 /* Add precedence rules to solve dangling else s/r conflict */
\r
278 %left OP_SHIFT_LEFT OP_SHIFT_RIGHT
\r
280 %left STAR DIV PERCENT
\r
281 %right BITWISE_NOT CARRET UMINUS
\r
282 %nonassoc OP_INC OP_DEC
\r
284 %left OPEN_BRACKET OPEN_BRACE
\r
288 %start compilation_unit
\r
292 : opt_imports_directives
\r
308 | declarations declaration
\r
312 : namespace_declaration
\r
313 | module_declaration
\r
314 | class_declaration
\r
317 qualified_identifier
\r
319 | qualified_identifier DOT IDENTIFIER
\r
321 $$ = (($1).ToString ()) + "." + ($3.ToString ());
\r
324 opt_imports_directives
\r
326 | imports_directives
\r
330 : imports_directive
\r
331 | imports_directives imports_directive
\r
335 : /* imports_alias_directive
\r
336 | */ imports_namespace_directive
\r
339 imports_namespace_directive
\r
340 : IMPORTS namespace_name EOL
\r
342 current_namespace.Using ((string) $2);
\r
350 namespace_declaration
\r
351 : NAMESPACE qualified_identifier EOL
\r
353 current_namespace = new Namespace (current_namespace, (string) $2);
\r
355 opt_imports_directives
\r
356 opt_namespace_member_declarations
\r
359 current_namespace = current_namespace.Parent;
\r
364 : qualified_identifier
\r
367 opt_namespace_member_declarations
\r
369 | namespace_member_declarations
\r
372 namespace_member_declarations
\r
373 : namespace_member_declaration
\r
374 | namespace_member_declarations namespace_member_declaration
\r
377 namespace_member_declaration
\r
378 : namespace_declaration
\r
379 | module_declaration
\r
380 | class_declaration
\r
382 /* | type_declaration
\r
388 Class c = (Class) $1;
\r
389 mod_flags = c.ModFlags;
\r
391 } else if ($1 is Struct){
\r
392 Struct s = (Struct) $1;
\r
393 mod_flags = s.ModFlags;
\r
403 | class_declaration
\r
409 : /* opt_attributes opt_modifiers */
\r
410 CLASS IDENTIFIER /* opt_class_interfaces */ EOL
\r
413 opt_class_member_declarations
\r
420 : /* opt_attributes opt_modifiers */
\r
421 MODULE IDENTIFIER EOL
\r
424 opt_class_member_declarations
\r
430 opt_class_member_declarations
\r
432 | class_member_declarations
\r
435 class_member_declarations
\r
436 : class_member_declaration
\r
437 | class_member_declarations class_member_declaration
\r
440 class_member_declaration
\r
441 : /* type_declaration
\r
442 | */ sub_declaration
\r
446 : SUB qualified_identifier OPEN_PARENS opt_formal_parameters CLOSE_PARENS EOL
\r
453 | qualified_identifier OPEN_PARENS opt_actual_parameters CLOSE_PARENS EOL
\r
456 opt_formal_parameters
\r
458 | qualified_identifier AS qualified_identifier
\r
461 opt_actual_parameters
\r
463 | qualified_identifier
\r
472 public Tokenizer Lexer {
\r
478 public override int parse ()
\r
480 current_namespace = new Namespace (null, "");
\r
481 current_container = RootContext.Tree.Types;
\r
482 current_container.Namespace = current_namespace;
\r
484 UseExtendedSyntax = name.EndsWith(".mbs");
\r
486 lexer = new Tokenizer (input, name, defines);
\r
487 StringBuilder value = new StringBuilder ();
\r
492 if (yacc_verbose_flag)
\r
493 yyparse (lexer, new yydebug.yyDebugSimple ());
\r
497 catch (Exception e)
\r
499 Console.WriteLine (lexer.location + " : Parsing error ");
\r
500 Console.WriteLine (e);
\r
504 return global_errors;
\r