//
// Mono.MonoBASIC.Parser.cs (from .jay): The Parser for the MonoBASIC compiler
//
-// Author: A Rafael D Teixeira (rafaelteixeirabr@hotmail.com)
-// Anirban Bhattacharjee (banirban@novell.com)
+// Authors: A Rafael D Teixeira (rafaelteixeirabr@hotmail.com)
+// Anirban Bhattacharjee (banirban@novell.com)
+// Jambunathan K (kjambunathan@novell.com)
+// Manjula GHM (mmanjula@novell.com)
+// Sudharsan V (vsudharsan@novell.com)
//
// Licensed under the terms of the GNU GPL
//
-// Copyright (C) 2001 A Rafael D Teixeira
+// Copyright (C) 2001, 2002, 2003, 2004 A Rafael D Teixeira
+// Copyright (C) 2003, 2004 Novell
//
//
-
namespace Mono.MonoBASIC
{
using System.Text;
{
+
/// <summary>
/// Current block is used to add statements as we find
/// them.
// </summary>
Expression set_implicit_value_parameter_type;
- Location member_location;
-
// An out-of-band stack.
//
Stack oob_stack;
-
+
ArrayList current_rank_specifiers;
+ //To handle the End of a block
+ // We use grammer, priority, strings, and an integer called Parenta
+ //
+ // FIX ME: Need to implement some better method than this and in
+ // some cases parser will come out without proceeding further
+ // if it comes acorss error.
+
+ // Used to store
+ // 1) The value for corresponding blocks with which it will be accessed...
+ // In case of any more addition to end of blocks... add it at the end
+
+ public enum Start_block {
+ NOTHING,
+ FOR,
+ DO,
+ IF,
+ SUB,
+ MODULE,
+ NAMESPACE,
+ CLASS,
+ FUNCTION,
+ STRUCTURE,
+ ENUM,
+ INTERFACE,
+ PROPERTY,
+ WITH,
+ SYNCLOCK,
+ TRY,
+ WHILE,
+ SELECT,
+ SET,
+ GET
+ }
+
+ // Used to store
+ // 1) Start of block
+ // 2) End of Block
+ // In case of any more addition to end of blocks... add it at the end
+
+ public string[,] end_blocks = {
+ { "empty" , "empty" },
+ { "For" , "Next" },
+ { "Do" , "Loop" },
+ { "If" , "End If" },
+ { "Sub" , "End Sub" },
+ { "Module" , "End Module" },
+ { "NameSpace" , "End NameSpace" },
+ { "Class" , "End Class" },
+ { "Function" , "End Function" },
+ { "Structure" , "End Structure" },
+ { "Enum" , "End Enum" },
+ { "Interface" , "End Interface" },
+ { "Property" , "End Property" },
+ { "With" , "End With" },
+ { "SyncLock" , "End SyncLock" },
+ { "Try" , "End Try" },
+ { "While" , "End While" },
+ { "Select" , "End Select" },
+ { "Set" , "End Set" },
+ { "Get" , "End Get" }
+ };
+
+
+ // Used to store
+ // 1) Error number for End of block missing
+ // 2) Extra End of Block
+ // 3) Priority for the end 0f blocks
+ // In case of any more addition to end of blocks... add it at the end
+
+ public int[,] error_end_blocks = {
+ { 29999 , 29999 , 0 },
+ { 30084 , 30092 , 1 },
+ { 30083 , 30091 , 1 },
+ { 30081 , 30087 , 1 },
+ { 30289 , 30429 , 3 },
+ { 30625 , 30622 , 5 },
+ { 30626 , 30623 , 6 },
+ { 30481 , 30460 , 4 },
+ { 30027 , 30430 , 3 },
+ { 30624 , 30621 , 4 },
+ { 30185 , 30184 , 1 },
+ { 30253 , 30252 , 3 },
+ { 30025 , 30431 , 3 },
+ { 30085 , 30093 , 1 },
+ { 30675 , 30674 , 1 },
+ { 30384 , 30383 , 1 },
+ { 30082 , 30090 , 1 },
+ { 30095 , 30088 , 1 },
+ { 30633 , 30632 , 2 },
+ { 30631 , 30630 , 2 }
+ };
+
+ Stack end_of_block;
+ Stack temp_block;
+ Stack loc_end_of_block;
+ Stack loc_temp_block;
+
+ Location try_top;
+
DoOptions do_type;
//
// Switch stack.
// A stack for With expressions.
//
Stack with_stack;
-
+
+ //
+ // Hash table for const preprocessing directive
+ //
+ public static Hashtable constPreDir = new Hashtable();
static public bool InitialOptionExplicit = false;
static public bool InitialOptionStrict = false;
{
public bool CanAcceptTokens;
public bool CanSelectBlock;
-
}
State currentState;
}
}
}
+
+ bool allow_global_attribs = true;
+
+ bool expecting_global_attribs = false;
+ bool expecting_local_attribs = false;
+
+ bool local_attrib_section_added = false;
%}
%token EOF
%token ELSE
%token ELSEIF
%token END
+%token END_EOL
%token ENDIF
%token ENUM
%token EOL
;
logical_end_of_line
- : EOL
+ :
+ EOL
| logical_end_of_line pp_directive
;
compilation_unit
- : logical_end_of_line
+ : logical_end_of_line _mark_
opt_option_directives
opt_imports_directives
- opt_global_attributes
- opt_declarations
+ declarations
EOF
{
- $$=$5;
+ $$=$4;
+ }
+ | logical_end_of_line _mark_
+ opt_option_directives
+ opt_imports_directives
+ opt_attributes
+ EOF
+ {
+ /* ????? */ ;
}
-
;
opt_option_directives
: option_explicit_directive
| option_strict_directive
| option_compare_directive
+ | OPTION _mark_ logical_end_of_line
+ {
+ Report.Error(30206 ,(Location)$2, "Option must be followed by 'Compare' or 'Explicit' or 'Strict'");
+ }
+ | OPTION _mark_ IDENTIFIER logical_end_of_line
+ {
+ Report.Error(30206 ,(Location)$2, "Option must be followed by 'Compare' or 'Explicit' or 'Strict'");
+ }
;
on_off
;
option_explicit_directive
- : OPTION EXPLICIT on_off logical_end_of_line
+ : OPTION EXPLICIT _mark_ on_off logical_end_of_line
{
if (!UseExtendedSyntax)
- OptionExplicit = (bool)$3;
+ OptionExplicit = (bool)$4;
else
Report.Warning (
- 9999, lexer.Location,
+ 9999, (Location)$3,
"In MonoBASIC extended syntax explicit declaration is always required. So OPTION EXPLICIT is deprecated");
}
;
option_strict_directive
- : OPTION STRICT on_off logical_end_of_line
+ : OPTION STRICT _mark_ on_off logical_end_of_line
{
if (!UseExtendedSyntax)
- OptionStrict = (bool)$3;
+ OptionStrict = (bool)$4;
else
Report.Warning (
- 9999, lexer.Location,
+ 9999, (Location)$3,
"In MonoBASIC extended syntax strict assignability is always required. So OPTION STRICT is deprecated");
}
;
opt_declarations
: /* empty */
| declarations
- ;
+ ;
declarations
: declaration
;
declaration
- : namespace_declaration
- | type_declaration
+ : declaration_qualifiers
+ {
+ // FIXME: Need to check declaration qualifiers for multi-file compilation
+ // FIXME: Qualifiers cannot be applied to namespaces
+ allow_global_attribs = false;
+ }
+ namespace_declaration
+ |declaration_qualifiers _mark_
+ {
+ // FIXME: Need to check declaration qualifiers for multi-file compilation
+ allow_global_attribs = false;
+ }
+ type_spec_declaration
{
string name = "";
int mod_flags;
- if ($1 is Class || $1 is Struct || $1 is Module ){
- TypeContainer c = (TypeContainer) $1;
+ if ($4 is Class || $4 is Struct || $4 is Module ){
+ TypeContainer c = (TypeContainer) $4;
mod_flags = c.ModFlags;
name = c.Name;
} else
break;
- if ((mod_flags & (Modifiers.PRIVATE|Modifiers.PROTECTED)) != 0){
+ if ((mod_flags & (Modifiers.PRIVATE)) != 0){
Report.Error (
- 1527, lexer.Location,
+ 31089, (Location)$2,
"Namespace elements cannot be explicitly " +
- "declared private or protected in '" + name + "'");
+ "declared private in '" + name + "'");
+ }
+ else if ((mod_flags & (Modifiers.PROTECTED)) != 0){
+ Report.Error (
+ 31047, (Location)$2,
+ "Namespace elements cannot be explicitly " +
+ "declared protected in '" + name + "'");
}
}
;
qualified_identifier
- : identifier
+ : identifier
| qualified_identifier DOT identifier // FIXME: It should be qualified_identifier DOT identifier-or-keyword
- {
+ {
$$ = (($1).ToString ()) + "." + ($3.ToString ());
}
;
{
RootContext.SourceBeingCompiled.Imports ((string) $1, lexer.Location);
}
- | identifier ASSIGN namespace_or_type_name
+ | identifier _mark_ ASSIGN namespace_or_type_name
{
- RootContext.SourceBeingCompiled.ImportsWithAlias ((string) $1, (string) $3, lexer.Location);
+ RootContext.SourceBeingCompiled.ImportsWithAlias ((string) $1, (string) $4, (Location)$2);
}
+ | identifier _mark_ ASSIGN
+ {
+ Report.Error(30203, (Location)$2, "Alias Statement no complete: Expression Expected");
+ }
+ | _mark_ /* empty */
+ {
+ Report.Error(30203, (Location)$1, "No namespace imported: Expression Expected");
+ }
;
opt_params
- : /* empty */ { $$ = Parameters.EmptyReadOnlyParameters; }
- | OPEN_PARENS CLOSE_PARENS { $$ = Parameters.EmptyReadOnlyParameters; }
- | OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS { $$ = $2; }
- ;
+ : /* empty */ { $$ = Parameters.EmptyReadOnlyParameters; }
+ | OPEN_PARENS CLOSE_PARENS { $$ = Parameters.EmptyReadOnlyParameters; }
+ | OPEN_PARENS _mark_ opt_formal_parameter_list CLOSE_PARENS { $$ = $3; }
+ | OPEN_PARENS _mark_
+ {
+ Report.Error(30203,(Location)$2, "Identifier Expected");
+ $$ = Parameters.EmptyReadOnlyParameters;
+ }
+ | OPEN_PARENS _mark_ opt_formal_parameter_list error
+ {
+ Report.Error(30198,(Location)$2, "'(' is not having a matching ')'");
+ $$ = $3;
+ }
+ | error _mark_ opt_formal_parameter_list CLOSE_PARENS
+ {
+ Report.Error(30205,(Location)$2, "')' is not having a matching '('");
+ $$ = $3;
+ }
+ ;
-attribute_modifier
- : ASSEMBLY
- | MODULE
- | identifier
- {
- Report.Error (658, lexer.Location, "`" + (string)$1 + "' is an invalid attribute target");
- }
- ;
+opt_attributes
+ : /* empty */
+ | attribute_sections
+ {
+ $$ = $1;
+ local_attrib_section_added = false;
+ }
+ ;
-global_attribute_list
- : global_attribute
- | global_attribute_list COMMA global_attribute
- ;
+attribute_sections
+ : attribute_section
+ {
+ $$ = $1;
+ if ($1 == null) {
+ expecting_local_attribs = false;
+ expecting_global_attribs = false;
+ break;
+ }
+
+ if (expecting_local_attribs) {
+ local_attrib_section_added = true;
+ allow_global_attribs = false;
-global_attribute
- : attribute_modifier COLON attribute
- ;
+ $$ = new Attributes ((ArrayList) $1);
+ }
-global_attributes_definition
- : attr_begin global_attribute_list attr_end
- ;
+ if (expecting_global_attribs) {
+ $$ = null;
+ CodeGen.AddGlobalAttributes ((ArrayList) $1);
+ }
-global_attributes
- : global_attributes_definition
- | global_attributes global_attributes_definition
- | global_attributes end_of_stmt global_attributes_definition
- ;
+ expecting_local_attribs = false;
+ expecting_global_attribs = false;
+ }
+ | attribute_sections
+ {
+ $$ = lexer.Location;
+ }
+ attribute_section
+ {
+ $$ = $1;
+ if ($3 != null) {
+ ArrayList attrs = (ArrayList) $3;
+
+ if (expecting_local_attribs) {
+ if (local_attrib_section_added) {
+ expecting_local_attribs = false;
+ expecting_global_attribs = false;
+ Report.Error (30205, (Location) $2, "Multiple attribute sections may not be used; Coalesce multiple attribute sections in to a single attribute section");
+ break;
+ }
-opt_global_attributes
- : /* empty */
- | global_attributes end_of_stmt
- ;
+ if ($1 == null)
+ $$ = new Attributes (attrs);
+ else
+ ((Attributes) $1).Add (attrs);
-opt_attributes
- : /* empty */
- | attributes { $$ = $1; }
- ;
+ local_attrib_section_added = true;
+ allow_global_attribs = false;
+ }
-attr_begin
- : OP_LT
- ;
+ if (expecting_global_attribs) {
+ $$ = null;
+ CodeGen.AddGlobalAttributes ((ArrayList) $3);
+ }
+ }
-attr_end
- : OP_GT
+ expecting_local_attribs = false;
+ expecting_global_attribs = false;
+ }
;
-attributes
- : attr_begin attribute_list attr_end
+attribute_section
+ : OP_LT _mark_ attribute_list OP_GT opt_end_of_stmt
{
- AttributeSection sect = new AttributeSection (null, (ArrayList) $2);
- $$ = new Attributes (sect, lexer.Location);
+ $$ = null;
+ if ($3 != null) {
+ if (expecting_global_attribs && !(bool) $5) {
+ Report.Error (30205, (Location)$2, "End of statement expected");
+ break;
+ }
+
+ if (expecting_local_attribs) {
+ if ((bool) $5) {
+ Report.Error (32035, (Location)$2, "Use a line continuation after the attribute specifier to apply it to the following statement.");
+ break;
+ }
+ }
+
+ $$ = $3;
+ }
}
- | attr_begin global_attribute_list attr_end logical_end_of_line
;
+opt_end_of_stmt
+ : /* empty */ { $$ = false; }
+ | end_of_stmt { $$ = true; }
+ ;
+
attribute_list
: attribute
{
- ArrayList attrs = new ArrayList ();
- attrs.Add ($1);
-
+ ArrayList attrs = null;
+ if ($1 != null) {
+ attrs = new ArrayList ();
+ attrs.Add ($1);
+ }
$$ = attrs;
-
}
| attribute_list COMMA attribute
{
- ArrayList attrs = (ArrayList) $1;
- attrs.Add ($3);
+ ArrayList attrs = null;
+
+ if ($3 != null) {
+ attrs = ($1 == null) ? new ArrayList () : (ArrayList) $1;
+ attrs.Add ($3);
+ }
$$ = attrs;
}
;
attribute
- : attribute_name
- {
+ : namespace_or_type_name
+ {
$$ = lexer.Location;
- }
- opt_attribute_arguments
- {
- $$ = new Mono.MonoBASIC.Attribute ((string) $1, (ArrayList) $3, (Location) $2);
- }
+ }
+ opt_attribute_arguments
+ {
+ $$ = null;
+
+ if (expecting_global_attribs)
+ Report.Error (32015, (Location) $2, "Expecting Assembly or Module attribute specifiers");
+ else {
+ expecting_local_attribs = true;
+ $$ = new Attribute ((string) $1, (ArrayList) $3, (Location) $2);
+ }
+ }
+ | attribute_target_specifier
+ {
+ $$ = lexer.Location;
+ }
+ COLON
+ namespace_or_type_name
+ {
+ $$ = lexer.Location;
+ }
+ opt_attribute_arguments
+ {
+ $$ = null;
+
+ string attribute_target = (string) $1;
+ if (attribute_target != "assembly" && attribute_target != "module") {
+ Report.Error (29999, lexer.Location, "`" + (string)$1 + "' is an invalid attribute modifier");
+ break;
+ }
+ if (!allow_global_attribs) {
+ Report.Error (30637, (Location) $2, "Global attribute statements must precede any declarations in a file");
+ break;
+ }
+
+ if (expecting_local_attribs) {
+ Report.Error (30183, (Location) $2, "Global attributes cannot be combined with local attributes");
+ break;
+ }
+
+ expecting_global_attribs = true;
+ $$ = new Attribute (attribute_target, (string) $4, (ArrayList) $6, (Location) $5);
+ }
;
-attribute_name
- : namespace_or_type_name
+attribute_target_specifier
+ : ASSEMBLY { $$ = "assembly"; }
+ | MODULE { $$ = "module"; }
+ | namespace_or_type_name
;
+
opt_attribute_arguments
: /* empty */ { $$ = null; }
;
namespace_declaration
- : NAMESPACE qualified_identifier logical_end_of_line
+ : NAMESPACE _mark_ qualified_identifier logical_end_of_line
{
- current_namespace = RootContext.Tree.RecordNamespace(current_namespace, name, (string)$2);
+ push_into_stack((int)Start_block.NAMESPACE, (Location)$2);
+ current_namespace = RootContext.Tree.RecordNamespace(current_namespace, name, (string)$3);
+
}
opt_declarations
- END NAMESPACE logical_end_of_line
+ opt_end_block
+ {
+ pop_out_of_stack((int)$7, lexer.Location);
+ }
+ logical_end_of_line
{
current_namespace = current_namespace.Parent;
}
;
-type_declaration
+declaration_qualifiers
: opt_attributes
opt_modifiers
{
current_attributes = (Attributes) $1;
current_modifiers = (int) $2;
}
- type_spec_declaration
;
type_spec_declaration
;
class_declaration
- : CLASS identifier logical_end_of_line opt_inherits opt_implements
+ : CLASS identifier _mark_ end_of_stmt opt_inherits opt_implements
{
// Module members are static by default, but Class *can't* be declared static
// so we must fix it, if mbas was the one actually responsible for this
// instead of triggering an error.
+ push_into_stack((int)Start_block.CLASS, (Location)$3);
+
if (implicit_modifiers && ((current_modifiers & Modifiers.STATIC) != 0))
current_modifiers = (current_modifiers & ~Modifiers.STATIC);
name = MakeName ((string) $2);
new_class = new Class (current_container, name, current_modifiers,
- (Attributes) current_attributes, lexer.Location);
+ (Attributes) current_attributes, (Location)$3);
current_container = new_class;
current_container.Namespace = current_namespace;
RootContext.Tree.RecordDecl (name, new_class);
}
opt_class_member_declarations
- END CLASS logical_end_of_line
+ opt_end_block
+ {
+ pop_out_of_stack((int)$9, lexer.Location);
+ }
+ logical_end_of_line
{
Class new_class = (Class) current_container;
- ArrayList bases = (ArrayList) $4;
+ ArrayList bases = (ArrayList) $5;
- ArrayList ifaces = (ArrayList) $5;
+ ArrayList ifaces = (ArrayList) $6;
if (ifaces != null){
if (bases != null)
bases.AddRange(ifaces);
opt_inherits
: /* empty */ { $$ = null; }
- | INHERITS type_list logical_end_of_line { $$ = $2; }
+ | INHERITS type_list end_of_stmt { $$ = $2; }
;
opt_implements
: /* empty */ { $$ = null; }
- | IMPLEMENTS type_list logical_end_of_line { $$ = $2; }
+ | IMPLEMENTS type_list end_of_stmt { $$ = $2; }
;
opt_modifiers
;
module_declaration
- : MODULE identifier logical_end_of_line
+ : MODULE _mark_ identifier logical_end_of_line
{
+ push_into_stack((int)Start_block.MODULE, (Location)$2);
Module new_module;
string name;
- name = MakeName((string) $2);
+ name = MakeName((string) $3);
new_module = new Module(current_container,
name,
current_modifiers, // already checks then
(Attributes) current_attributes,
- lexer.Location);
+ (Location)$2);
current_container = new_module;
current_container.Namespace = current_namespace;
RootContext.Tree.RecordDecl(name, new_module);
}
opt_module_member_declarations
- END MODULE logical_end_of_line
+ opt_end_block
+ {
+ pop_out_of_stack((int)$7, lexer.Location);
+ }
+ logical_end_of_line
{
Module new_module = (Module)current_container;
;
constant_declaration
- : CONST constant_declarators logical_end_of_line
+ : CONST constant_declarators end_of_stmt
{
// Module members are static by default, but constants *can't* be declared static
// so we must fix it, if mbas was the one actually responsible for this
;
must_override_sub_declaration
- : MUSTOVERRIDE SUB identifier opt_params opt_implement_clause logical_end_of_line
+ : MUSTOVERRIDE SUB identifier opt_params opt_implement_clause _mark_ logical_end_of_line
{
if (current_container is Module)
- Report.Error (433, "Methods in a Module cannot be declared 'MustOverride'.");
+ Report.Error (30433, (Location)$6, "Methods in a Module cannot be declared 'MustOverride'.");
if (current_container is Struct)
- Report.Error (435, "Methods in a Structure cannot be declared 'MustOverride'.");
+ Report.Error (435, (Location)$6, "Methods in a Structure cannot be declared 'MustOverride'.");
current_modifiers |= Modifiers.ABSTRACT;
Method method = new Method (TypeManager.system_void_expr, (int) current_modifiers, (string) $3,
- (Parameters) $4, null, (ArrayList) $5, lexer.Location);
+ (Parameters) $4, null, (ArrayList) $5, (Location)$6);
if (!(current_container is Class))
- Report.Error (9999, "THIS SHOULD NEVER HAPPEN!");
+ Report.Error (9999, (Location)$6, "THIS SHOULD NEVER HAPPEN!");
$$ = method;
}
must_override_func_declaration
- : MUSTOVERRIDE FUNCTION identifier opt_type_character opt_params opt_type_with_ranks opt_implement_clause logical_end_of_line
+ : MUSTOVERRIDE FUNCTION identifier opt_type_character opt_params _mark_ opt_type_with_ranks opt_implement_clause logical_end_of_line
{
- Expression ftype = ($6 == null) ? (($4 == null) ? TypeManager.
- system_object_expr : (Expression) $4 ) : (Expression) $6;
+ Expression ftype = ($7 == null) ? (($4 == null) ? TypeManager.
+ system_object_expr : (Expression) $4 ) : (Expression) $7;
if (current_container is Module)
- Report.Error (433, "Methods in a Module cannot be declared 'MustOverride'.");
+ Report.Error (30433, (Location)$6,"Methods in a Module cannot be declared 'MustOverride'.");
if (current_container is Struct)
- Report.Error (435, "Methods in a Structure cannot be declared 'MustOverride'.");
+ Report.Error (435, (Location)$6,"Methods in a Structure cannot be declared 'MustOverride'.");
current_modifiers |= Modifiers.ABSTRACT;
Method method = new Method ((Expression) ftype, (int) current_modifiers,
- (string) $3,(Parameters) $5, null, (ArrayList) $7,
- lexer.Location);
+ (string) $3,(Parameters) $5, null, (ArrayList) $8,
+ (Location)$6);
if (!(current_container is Class))
- Report.Error (9999, "THIS SHOULD NEVER HAPPEN!");
+ Report.Error (9999, (Location)$6,"THIS SHOULD NEVER HAPPEN!");
$$ = method;
}
;
sub_declaration
- : SUB identifier opt_params opt_evt_handler opt_implement_clause logical_end_of_line
+ : SUB identifier _mark_ opt_params opt_evt_handler opt_implement_clause logical_end_of_line
{
- current_local_parameters = (Parameters) $3;
+ push_into_stack((int)Start_block.SUB, (Location)$3);
+ current_local_parameters = (Parameters) $4;
start_block();
// Structure members are Public by default
if ((current_container is Struct) && (current_modifiers == 0))
current_modifiers = Modifiers.PUBLIC;
- member_location = lexer.Location;
}
opt_statement_list
- END SUB logical_end_of_line
+ opt_end_block
+ {
+ pop_out_of_stack((int)$10, lexer.Location);
+ }
+ logical_end_of_line
{
Method method = new Method (TypeManager.system_void_expr, (int) current_modifiers, (string) $2,
(Parameters) current_local_parameters, (Attributes) current_attributes,
- (ArrayList) $5, member_location);
+ (ArrayList) $6, (Location)$3);
method.Block = (Block) end_block();
$$ = method;
- if ($4 != null) {
+ if ($5 != null) {
// we have an event handler to take care of
- Expression handles_exp = (Expression) $4;
- Location loc = lexer.Location;
+ Expression handles_exp = (Expression) $5;
+ Location loc = (Location)$3;
if (handles_exp is MemberAccess) {
- string evt_def = ((MemberAccess)$4).ToString();
+ string evt_def = ((MemberAccess)$5).ToString();
int pos = evt_def.LastIndexOf (".");
string evt_target = evt_def.Substring (0, pos);
bool found = false;
if (p.Name == evt_target) {
- Statement addhnd = (Statement) new AddHandler ((Expression) $4,
+ Statement addhnd = (Statement) new AddHandler ((Expression) $5,
DecomposeQI((string) $2, loc),
loc);
}
if (!found){
- Report.Error(30506, lexer.Location,
+ Report.Error(30506, (Location)$3,
evt_target + " is not declared with WithEvents");
}
} else if (handles_exp is BaseAccess) {
- string evt_id = ((BaseAccess) $4).member;
- Statement addhnd = (Statement) new AddHandler ((Expression) $4,
+ Statement addhnd = (Statement) new AddHandler ((Expression) $5,
DecomposeQI((string) $2, loc),
loc);
}
}
;
-
+
func_declaration
: FUNCTION identifier opt_type_character
- opt_params opt_type_with_ranks opt_implement_clause logical_end_of_line
+ opt_params _mark_ opt_type_with_ranks opt_implement_clause logical_end_of_line
{
+ push_into_stack((int)Start_block.FUNCTION, (Location)$5);
current_local_parameters = (Parameters) $4;
- member_location = lexer.Location;
start_block();
- Expression ftype = ($5 == null) ? (($3 == null) ? TypeManager.system_object_expr : (Expression) $3 ) : (Expression) $5;
+ Expression ftype = ($6 == null) ? (($3 == null) ? TypeManager.system_object_expr : (Expression) $3 ) : (Expression) $6;
// Structure members are Public by default
if ((current_container is Struct) && (current_modifiers == 0))
// Add local var declaration
// for return value
ArrayList retval = new ArrayList ();
- retval.Add (new VariableDeclaration ((string) $2, (Expression) ftype, lexer.Location));
- declare_local_variables ((Expression) ftype, retval, lexer.Location);
+ retval.Add (new VariableDeclaration ((string) $2, (Expression) ftype, (Location)$5));
+ declare_local_variables ((Expression) ftype, retval, (Location)$5);
}
opt_statement_list
- END FUNCTION logical_end_of_line
+ opt_end_block
{
- Expression ftype = ($5 == null) ? (($3 == null) ? TypeManager.system_object_expr : (Expression) $3 ) : (Expression) $5;
+ pop_out_of_stack((int)$11, lexer.Location);
+ }
+ logical_end_of_line
+ {
+ Expression ftype = ($6 == null) ? (($3 == null) ? TypeManager.system_object_expr : (Expression) $3 ) : (Expression) $6;
Method method = new Method ((Expression) ftype, (int) current_modifiers, (string) $2,
(Parameters) current_local_parameters, (Attributes) current_attributes,/* (Attributes) currx ent_attributes, */
- (ArrayList) $6, member_location);
+ (ArrayList) $7, (Location)$5);
method.Block = end_block();
$$ = method;
}
;
struct_declaration
- : STRUCTURE identifier logical_end_of_line
+ : STRUCTURE _mark_ identifier end_of_stmt
opt_implement_clause
{
+ push_into_stack((int)Start_block.STRUCTURE, (Location)$2);
Struct new_struct;
- string full_struct_name = MakeName ((string) $2);
+ string full_struct_name = MakeName ((string) $3);
// Module members are static by default, but structures *can't* be declared static
// so we must fix it, if mbas was the one actually responsible for this
new_struct = new Struct (current_container, full_struct_name,
(int) current_modifiers,
- (Attributes) current_attributes, lexer.Location);
+ (Attributes) current_attributes, (Location)$2);
current_container = new_struct;
current_container.Namespace = current_namespace;
RootContext.Tree.RecordDecl (full_struct_name, new_struct);
{
Struct new_struct = (Struct) current_container;
- if ($4 != null)
- new_struct.Bases = (ArrayList) $4;
+ if ($5 != null)
+ new_struct.Bases = (ArrayList) $5;
current_container = current_container.Parent;
CheckDef (current_container.AddStruct (new_struct), new_struct.Name, new_struct.Location);
$$ = new_struct;
}
- END STRUCTURE logical_end_of_line
+ opt_end_block
+ {
+ pop_out_of_stack((int)$9, lexer.Location);
+ }
+ logical_end_of_line
;
opt_struct_member_declarations
;
event_declaration
- : EVENT identifier AS type opt_implement_clause logical_end_of_line
+ : EVENT identifier _mark_ AS type opt_implement_clause logical_end_of_line
{
- VariableDeclaration var = new VariableDeclaration ((string) $2, (Expression) $4, lexer.Location);
+ VariableDeclaration var = new VariableDeclaration ((string) $2, (Expression) $5, (Location)$3);
- Event e = new Event ((Expression) $4, var.identifier,
- null, current_modifiers, null, null,
- current_attributes, (ArrayList) $5,
- lexer.Location);
+ Event e = new Event ((Expression) $5, var.identifier,
+ null, current_modifiers,
+ current_attributes, (ArrayList) $6,
+ (Location)$3);
CheckDef (current_container.AddEvent (e), e.Name, e.Location);
}
- | EVENT identifier opt_params opt_implement_clause logical_end_of_line
+ | EVENT identifier _mark_ opt_params opt_implement_clause logical_end_of_line
{
string delName = null;
- if ($4 == null) {
+ if ($5 == null) {
delName = (string) $2;
delName = delName + "EventHandler";
Mono.MonoBASIC.Delegate del = new Mono.MonoBASIC.Delegate
(current_container, TypeManager.system_void_expr,
- (int) current_modifiers, MakeName(delName), (Parameters) $3,
- (Attributes) current_attributes, lexer.Location);
+ (int) current_modifiers, MakeName(delName), (Parameters) $4,
+ (Attributes) current_attributes, (Location)$3);
del.Namespace = current_namespace;
- CheckDef (current_container.AddDelegate (del), del.Name, lexer.Location);
+ CheckDef (current_container.AddDelegate (del), del.Name, (Location)$3);
} else {
- ArrayList impls = (ArrayList) $4;
+ ArrayList impls = (ArrayList) $5;
if (impls.Count > 1) {
string expstr = "Event '" + ((Expression) impls[1]).ToString () +
"' can not be implemented with Event '" +
(string) $2 + "', since it's delegate type does not match " +
"with the delegate type of '" + ((Expression) impls[0]).ToString () + "'";
- Report.Error (31407, lexer.Location, expstr);
+ Report.Error (31407, (Location)$3, expstr);
}
Expression impl = (Expression) impls[0];
delName = impl.ToString();
delName = delName + "EventHandler";
}
- Event e = new Event (DecomposeQI (delName, lexer.Location),
+ Event e = new Event (DecomposeQI (delName, (Location)$3),
(string) $2,
- null, current_modifiers, null, null,
- current_attributes, (ArrayList) $4,
- lexer.Location);
+ null, current_modifiers,
+ current_attributes, (ArrayList) $5,
+ (Location)$3);
CheckDef (current_container.AddEvent (e), e.Name, e.Location);
}
;
enum_declaration
- : ENUM identifier opt_type_spec logical_end_of_line
+ : ENUM _mark_ identifier opt_type_spec logical_end_of_line
opt_enum_member_declarations
{
- Location enum_location = lexer.Location;
- string full_name = MakeName ((string) $2);
- Expression enum_type = ($3 == null) ? TypeManager.system_int32_expr : (Expression) $3;
- ArrayList enum_members = (ArrayList) $5;
+ push_into_stack((int)Start_block.ENUM, (Location)$2);
+ Location enum_location = (Location)$2;
+ string full_name = MakeName ((string) $3);
+ Expression enum_type = ($4 == null) ? TypeManager.system_int32_expr : (Expression) $4;
+ ArrayList enum_members = (ArrayList) $6;
if (enum_members.Count == 0)
Report.Error (30280, enum_location,
RootContext.Tree.RecordDecl (full_name, e);
}
- END ENUM logical_end_of_line
+ opt_end_block
+ {
+ pop_out_of_stack((int)$8,lexer.Location);
+ }
+ logical_end_of_line
;
opt_enum_member_declarations
;
enum_member_declaration
- : opt_attributes identifier logical_end_of_line
+ : opt_attributes identifier _mark_ logical_end_of_line
{
- $$ = new VariableDeclaration ((string) $2, null, lexer.Location, (Attributes) $1);
+ $$ = new VariableDeclaration ((string) $2, null, (Location)$3, (Attributes) $1);
}
| opt_attributes identifier
{
}
ASSIGN expression logical_end_of_line
{
- $$ = new VariableDeclaration ((string) $2, $5, lexer.Location, (Attributes) $1);
+ $$ = new VariableDeclaration ((string) $2, (Expression)$5, (Location)$3, (Attributes) $1);
}
;
interface_declaration
- : INTERFACE identifier logical_end_of_line
+ : INTERFACE _mark_ identifier logical_end_of_line
{
+ push_into_stack((int)Start_block.INTERFACE, (Location)$2);
Interface new_interface;
- string full_interface_name = MakeName ((string) $2);
+ string full_interface_name = MakeName ((string) $3);
new_interface = new Interface (current_container, full_interface_name, (int) current_modifiers,
- (Attributes) current_attributes, lexer.Location);
+ (Attributes) current_attributes, (Location)$2);
if (current_interface != null) {
- Location l = lexer.Location;
- Report.Error (-2, l, "Internal compiler error: interface inside interface");
+ Report.Error (-2, (Location)$2, "Internal compiler error: interface inside interface");
}
current_interface = new_interface;
new_interface.Namespace = current_namespace;
{
Interface new_interface = (Interface) current_interface;
- if ($5 != null)
- new_interface.Bases = (ArrayList) $5;
+ if ($6 != null)
+ new_interface.Bases = (ArrayList) $6;
current_interface = null;
CheckDef (current_container.AddInterface (new_interface),
new_interface.Name, new_interface.Location);
}
- END INTERFACE logical_end_of_line
+ opt_end_block
+ {
+ pop_out_of_stack((int)$9, lexer.Location);
+ }
+ logical_end_of_line
;
opt_interface_base
;
interface_method_declaration
- : SUB identifier opt_params logical_end_of_line
+ : SUB identifier opt_params _mark_ logical_end_of_line
{
Method method = new Method (TypeManager.system_void_expr, (int) current_modifiers, (string) $2,
- (Parameters) $3, current_attributes, null, lexer.Location);
+ (Parameters) $3, current_attributes, null, (Location)$4);
$$ = method;
}
- | FUNCTION identifier opt_type_character opt_params opt_type_with_ranks logical_end_of_line
+ | FUNCTION identifier opt_type_character opt_params _mark_ opt_type_with_ranks logical_end_of_line
{
- Expression ftype = ($5 == null) ? (($3 == null) ? TypeManager.
- system_object_expr : (Expression) $3 ) : (Expression) $5;
+ Expression ftype = ($6 == null) ? (($3 == null) ? TypeManager.
+ system_object_expr : (Expression) $3 ) : (Expression) $6;
Method method = new Method ((Expression) ftype, (int) current_modifiers,
(string) $2,(Parameters) $4, current_attributes, null,
- lexer.Location);
+ (Location)$5);
$$ = method;
}
;
interface_property_declaration
- : PROPERTY identifier opt_type_character opt_property_parameters opt_type_with_ranks logical_end_of_line
+ : PROPERTY identifier _mark_ opt_type_character opt_property_parameters opt_type_with_ranks logical_end_of_line
{
- Expression ftype = ($5 == null) ? (($3 == null) ?
- TypeManager.system_object_expr : (Expression) $3 ) : (Expression) $5;
+ Expression ftype = ($6 == null) ? (($4 == null) ?
+ TypeManager.system_object_expr : (Expression) $4 ) : (Expression) $6;
- current_local_parameters = (Parameters) $4;
+ current_local_parameters = (Parameters) $5;
if (current_local_parameters != Parameters.EmptyReadOnlyParameters) {
- get_parameters = current_local_parameters.Copy (lexer.Location);
- set_parameters = current_local_parameters.Copy (lexer.Location);
+ get_parameters = current_local_parameters.Copy ((Location)$3);
+ set_parameters = current_local_parameters.Copy ((Location)$3);
Parameter implicit_value_parameter = new Parameter (
ftype, "Value", Parameter.Modifier.NONE, null);
else
{
get_parameters = Parameters.EmptyReadOnlyParameters;
- set_parameters = new Parameters (null, null ,lexer.Location);
+ set_parameters = new Parameters (null, null ,(Location)$3);
Parameter implicit_value_parameter = new Parameter (
ftype, "Value", Parameter.Modifier.NONE, null);
Accessor set_block = new Accessor (null, null);
Property prop = new Property ((Expression) ftype, (string) $2, current_modifiers,
- get_block, set_block, current_attributes, lexer.Location,
+ get_block, set_block, current_attributes, (Location)$3,
null, get_parameters, set_parameters, null);
- CheckDef (current_interface.AddProperty (prop), prop.Name, lexer.Location);
+ CheckDef (current_interface.AddProperty (prop), prop.Name, (Location)$3);
get_implicit_value_parameter_type = null;
set_implicit_value_parameter_type = null;
;
interface_event_declaration
- : EVENT identifier AS type logical_end_of_line
+ : EVENT identifier AS _mark_ type logical_end_of_line
{
- VariableDeclaration var = new VariableDeclaration ((string) $2, (Expression) $4, lexer.Location);
+ VariableDeclaration var = new VariableDeclaration ((string) $2, (Expression) $5, (Location)$4);
- Event e = new Event ((Expression) $4, var.identifier,
- null, current_modifiers, null, null,
- current_attributes, lexer.Location);
+ Event e = new Event ((Expression) $5, var.identifier,
+ null, current_modifiers,
+ current_attributes, (Location)$4);
CheckDef (current_interface.AddEvent (e), e.Name, e.Location);
}
- | EVENT identifier opt_params logical_end_of_line
+ | EVENT identifier opt_params _mark_ logical_end_of_line
{
string delName = (string) $2;
delName = delName + "EventHandler";
Mono.MonoBASIC.Delegate del = new Mono.MonoBASIC.Delegate
(current_container, TypeManager.system_void_expr,
(int) delModifiers, MakeName(delName), (Parameters) $3,
- (Attributes) current_attributes, lexer.Location);
+ (Attributes) current_attributes, (Location)$4);
del.Namespace = current_namespace;
- CheckDef (current_interface.AddDelegate (del), del.Name, lexer.Location);
+ CheckDef (current_interface.AddDelegate (del), del.Name, (Location)$4);
- Event e = new Event (DecomposeQI (delName, lexer.Location),
+ Event e = new Event (DecomposeQI (delName, (Location)$4),
(string) $2,
- null, current_modifiers, null, null,
- current_attributes, lexer.Location);
+ null, current_modifiers,
+ current_attributes, (Location)$4);
CheckDef (current_interface.AddEvent (e), e.Name, e.Location);
}
;
abstract_propery_declaration
- : MUSTOVERRIDE PROPERTY identifier opt_type_character opt_property_parameters opt_type_with_ranks logical_end_of_line
+ : MUSTOVERRIDE PROPERTY identifier opt_type_character opt_property_parameters _mark_ opt_type_with_ranks logical_end_of_line
{
- Expression ftype = ($6 == null) ? (($4 == null) ?
- TypeManager.system_object_expr : (Expression) $4 ) : (Expression) $6;
+ Expression ftype = ($7 == null) ? (($4 == null) ?
+ TypeManager.system_object_expr : (Expression) $4 ) : (Expression) $7;
if (current_container is Module)
- Report.Error (30503, "Properties in a Module cannot be declared 'MustOverride'.");
+ Report.Error (30503, (Location) $6 , "Properties in a Module cannot be declared 'MustOverride'.");
if (current_container is Struct)
- Report.Error (435, "Methods in a Structure cannot be declared 'MustOverride'.");
+ Report.Error (435, (Location) $6 ,"Methods in a Structure cannot be declared 'MustOverride'.");
current_modifiers |= Modifiers.ABSTRACT;
null, get_parameters, set_parameters, null);
if (!(current_container is Class))
- Report.Error (9999, "THIS SHOULD NEVER HAPPEN!");
+ Report.Error (9999, (Location) $6, "THIS SHOULD NEVER HAPPEN!");
CheckDef (current_container.AddProperty (prop), prop.Name, lexer.Location);
non_abstract_propery_declaration
- : PROPERTY identifier opt_type_character opt_property_parameters opt_type_with_ranks opt_implement_clause logical_end_of_line
- {
+ : PROPERTY identifier
+ opt_type_character
+ opt_property_parameters
+ _mark_
+ opt_type_with_ranks
+ opt_implement_clause
+ {
+ push_into_stack((int)Start_block.PROPERTY, (Location)$5);
+ if ((current_modifiers & Modifiers.DEFAULT) > 0) {
+ if (current_container.DefaultPropName != null
+ && current_container.DefaultPropName != (string) $2)
+ Report.Error (30359,
+ (Location) $5,
+ "Type '" + current_container.Name +
+ "' cannot have more than one 'Default Property' ");
+
+ current_container.DefaultPropName = (string) $2;
+ }
+
get_implicit_value_parameter_type =
- ($5 == null) ? (($3 == null) ?
- TypeManager.system_object_expr : (Expression) $3 ) : (Expression) $5;
+ ($6 == null) ? (($3 == null) ?
+ TypeManager.system_object_expr : (Expression) $3 ) : (Expression) $6;
get_implicit_value_parameter_name = (string) $2;
current_local_parameters = (Parameters) $4;
if (current_local_parameters != Parameters.EmptyReadOnlyParameters) {
- get_parameters = current_local_parameters.Copy (lexer.Location);
- set_parameters = current_local_parameters.Copy (lexer.Location);
+ get_parameters = current_local_parameters.Copy ((Location)$5);
+ set_parameters = current_local_parameters.Copy ((Location)$5);
}
else
{
get_parameters = Parameters.EmptyReadOnlyParameters;
- set_parameters = new Parameters (null, null ,lexer.Location);
+ set_parameters = new Parameters (null, null ,(Location)$5);
}
lexer.PropertyParsing = true;
- $$ = lexer.Location;
+ $$ = (Location)$5;
}
+ logical_end_of_line
accessor_declarations
- END PROPERTY logical_end_of_line
+ opt_end_block
+ {
+ pop_out_of_stack((int)$11,lexer.Location);
+ }
+ logical_end_of_line
{
lexer.PropertyParsing = false;
Property prop;
- Pair pair = (Pair) $9;
+ Pair pair = (Pair) $10;
Accessor get_block = null;
Accessor set_block = null;
set_block = (Accessor) pair.Second;
}
- Location loc = lexer.Location;
+ Location loc = (Location) $5 ;
// Structure members are Public by default
if ((current_container is Struct) && (current_modifiers == 0))
prop = new Property ((Expression) get_implicit_value_parameter_type,
(string) $2, current_modifiers, get_block, set_block,
current_attributes, loc, set_implicit_value_parameter_name,
- get_parameters, set_parameters, (ArrayList) $6);
+ get_parameters, set_parameters, (ArrayList) $7);
CheckDef (current_container.AddProperty (prop), prop.Name, loc);
get_implicit_value_parameter_type = null;
implement_clause_list
: qualified_identifier
{
- ArrayList impl_list = new ArrayList ();
- impl_list.Add (DecomposeQI ((string)$1, lexer.Location));
+ ArrayList impl_list = new ArrayList ();
+ impl_list.Add (DecomposeQI ((string)$1, lexer.Location));
$$ = impl_list;
}
| implement_clause_list COMMA qualified_identifier
;
get_accessor_declaration
- : opt_attributes GET logical_end_of_line
+ : opt_attributes GET _mark_ logical_end_of_line
{
+ push_into_stack((int)Start_block.GET, (Location)$3);
if ((current_modifiers & Modifiers.WRITEONLY) != 0)
- Report.Error (30023, "'WriteOnly' properties cannot have a 'Get' accessor");
+ Report.Error (30023, (Location)$3, "'WriteOnly' properties cannot have a 'Get' accessor");
current_local_parameters = get_parameters;
// Add local var declaration
// for return value
ArrayList retval = new ArrayList ();
- retval.Add (new VariableDeclaration (get_implicit_value_parameter_name, get_implicit_value_parameter_type, lexer.Location));
+ retval.Add (new VariableDeclaration (get_implicit_value_parameter_name, get_implicit_value_parameter_type, (Location)$3));
declare_local_variables (get_implicit_value_parameter_type, retval, lexer.Location);
}
opt_statement_list
- END GET logical_end_of_line
+ opt_end_block
+ {
+ pop_out_of_stack((int)$7,lexer.Location);
+ }
+ logical_end_of_line
{
$$ = new Accessor ((Block) end_block(), (Attributes) $1);
current_local_parameters = null;
;
set_accessor_declaration
- : opt_attributes SET opt_set_parameter logical_end_of_line
+ : opt_attributes SET opt_set_parameter _mark_ logical_end_of_line
{
- if ((current_modifiers & Modifiers.READONLY) != 0)
- Report.Error (30022, "'ReadOnly' properties cannot have a 'Set' accessor");
+ push_into_stack((int)Start_block.SET, (Location)$4);
+ if ((current_modifiers & Modifiers.READONLY) != 0)
+ Report.Error (30022,
+ (Location)$4,
+ "'ReadOnly' properties cannot have a 'Set' accessor");
Parameter implicit_value_parameter = new Parameter (
set_implicit_value_parameter_type,
lexer.PropertyParsing = false;
}
opt_statement_list
- END SET logical_end_of_line
+ opt_end_block
+ {
+ pop_out_of_stack((int)$8,lexer.Location);
+ }
+
+ logical_end_of_line
{
$$ = new Accessor ((Block) end_block(), (Attributes) $1);
current_local_parameters = null;
set_implicit_value_parameter_type = (Expression) $4;
- if (set_implicit_value_parameter_type != get_implicit_value_parameter_type)
+ if (set_implicit_value_parameter_type.ToString () != get_implicit_value_parameter_type.ToString ())
Report.Error (31064,
lexer.Location,
"Set value parameter type can not be different from property type");
-
+
if ($2 != null)
set_implicit_value_parameter_name = (string) $3;
else
field_declaration
: opt_dim_stmt
- variable_declarators logical_end_of_line
+ variable_declarators end_of_stmt
{
int mod = (int) current_modifiers;
;
delegate_declaration
- : DELEGATE SUB
+ : DELEGATE SUB _mark_
identifier OPEN_PARENS
opt_formal_parameter_list
CLOSE_PARENS
logical_end_of_line
{
- Location l = lexer.Location;
+ Location l = (Location)$3;
// Module members are static by default, but delegates *can't* be declared static
// so we must fix it, if mbas was the one actually responsible for this
// instead of triggering an error.
Mono.MonoBASIC.Delegate del = new Mono.MonoBASIC.Delegate (current_container,
TypeManager.system_void_expr,
(int) current_modifiers,
- MakeName ((string) $3), (Parameters) $5,
+ MakeName ((string) $4), (Parameters) $6,
(Attributes) current_attributes, l);
del.Namespace = current_namespace;
CheckDef (current_container.AddDelegate (del), del.Name, l);
}
- | DELEGATE FUNCTION
+ | DELEGATE FUNCTION _mark_
identifier OPEN_PARENS
opt_formal_parameter_list
CLOSE_PARENS opt_type_with_ranks logical_end_of_line
{
- Location l = lexer.Location;
+ Location l = (Location)$3;
// Module members are static by default, but delegates *can't* be declared static
// so we must fix it, if mbas was the one actually responsible for this
if (implicit_modifiers && ((current_modifiers & Modifiers.STATIC) != 0))
current_modifiers = (current_modifiers & ~Modifiers.STATIC);
- Expression ftype = ($7 == null) ? TypeManager.system_object_expr : (Expression) $7;
+ Expression ftype = ($8 == null) ? TypeManager.system_object_expr : (Expression) $8;
Mono.MonoBASIC.Delegate del = new Mono.MonoBASIC.Delegate (
current_container,
- ftype, (int) current_modifiers, MakeName ((string) $3),
- (Parameters) $5, (Attributes) current_attributes, l);
+ ftype, (int) current_modifiers, MakeName ((string) $4),
+ (Parameters) $6, (Attributes) current_attributes, l);
del.Namespace = current_namespace;
CheckDef (current_container.AddDelegate (del), del.Name, l);
;
evt_handler
- : qualified_identifier
+ : qualified_identifier _mark_
{
- $$ = (Expression) DecomposeQI ((string)$1, lexer.Location);
+ $$ = (Expression) DecomposeQI ((string)$1, (Location)$2);
}
| base_access
{
$$ = $1;
}
- | ME DOT qualified_identifier
+ | ME DOT qualified_identifier _mark_
{
- $$ = (Expression) DecomposeQI ((string)$3, lexer.Location);
+ $$ = (Expression) DecomposeQI ((string)$3, (Location)$4);
}
/*| MYBASE DOT qualified_identifier
{
;
constructor_declaration
- : SUB NEW opt_params logical_end_of_line
+ : SUB _mark_ NEW opt_params logical_end_of_line
{
- current_local_parameters = (Parameters) $3;
+ push_into_stack((int)Start_block.SUB, (Location)$2);
+ current_local_parameters = (Parameters) $4;
start_block();
- oob_stack.Push (lexer.Location);
-
- Location l = (Location) oob_stack.Pop ();
- $$ = new Constructor ((string) "New", (Parameters) $3, (ConstructorInitializer) null, l);
+ $$ = new Constructor ((string) "New", (Parameters) $4, (ConstructorInitializer) null, (Location)$2);
$1 = $$;
}
opt_statement_list
{
Constructor c = (Constructor) $1;
c.Block = (Block) end_block();
+
+//To support "Sub New()" add default modifier "public"
+
+ if(current_modifiers ==0)
+ current_modifiers = Modifiers.PUBLIC;
c.ModFlags = (int) current_modifiers;
c.OptAttributes = current_attributes;
CheckDef (current_container.AddConstructor(c), c.Name, c.Location);
current_local_parameters = null;
}
- END SUB logical_end_of_line
+ opt_end_block
+ {
+ pop_out_of_stack((int)$9, lexer.Location);
+ }
+ logical_end_of_line
;
opt_formal_parameter_list
parameter
: opt_attributes
opt_parameter_modifier
- identifier opt_type_character opt_rank_specifiers opt_type_with_ranks opt_variable_initializer
+ identifier _mark_ opt_type_character opt_rank_specifiers opt_type_with_ranks opt_variable_initializer
{
Parameter.Modifier pm = (Parameter.Modifier)$2;
bool opt_parm = ((pm & Parameter.Modifier.OPTIONAL) != 0);
Expression ptype;
- if (opt_parm && ($7 == null))
- Report.Error (30812, lexer.Location, "Optional parameters must have a default value");
+ if (opt_parm && ($8 == null))
+ Report.Error (30812, (Location)$4, "Optional parameters must have a default value");
- if (!opt_parm && ($7 != null))
- Report.Error (32024, lexer.Location, "Non-Optional parameters should not have a default value");
+ if (!opt_parm && ($8 != null))
+ Report.Error (32024, (Location)$4, "Non-Optional parameters should not have a default value");
if ((pm & Parameter.Modifier.PARAMS) != 0) {
if ((pm & ~Parameter.Modifier.PARAMS) != 0)
- Report.Error (30667, lexer.Location, "ParamArray parameters must be ByVal");
+ Report.Error (30667, (Location)$4, "ParamArray parameters must be ByVal");
}
if ((pm & Parameter.Modifier.REF) !=0)
pm |= Parameter.Modifier.ISBYREF;
- if ($4 != null && $6 != null && $4 != $6)
- Report.Error (30302, lexer.Location, "Type character conflicts with declared type."); // TODO: Correct error number and message text
+ if ($5 != null && $7 != null && $5 != $7)
+ Report.Error (30302, (Location)$4, "Type character conflicts with declared type."); // TODO: Correct error number and message text
- ptype = (Expression)(($6 == null) ? (($4 == null) ? TypeManager.system_object_expr : $4) : $6);
- if ($5 != null) {
+ ptype = (Expression)(($7 == null) ? (($5 == null) ? TypeManager.system_object_expr : $5) : $7);
+ if ($6 != null) {
string t = ptype.ToString ();
if (t.IndexOf('[') >= 0)
- Report.Error (31087, lexer.Location, "Array types specified in too many places");
+ Report.Error (31087, (Location)$4, "Array types specified in too many places");
else
- ptype = DecomposeQI (t + VariableDeclaration.BuildRanks ((ArrayList) $5, true, lexer.Location), lexer.Location);
+ ptype = DecomposeQI (t + VariableDeclaration.BuildRanks ((ArrayList) $6, true, (Location)$4), (Location)$4);
}
if ((pm & Parameter.Modifier.PARAMS) != 0 && ptype.ToString ().IndexOf('[') < 0)
- Report.Error (30050, lexer.Location, "ParamArray parameters must be an array type");
+ Report.Error (30050, (Location)$4, "ParamArray parameters must be an array type");
$$ = new Parameter (ptype, (string) $3, pm,
- (Attributes) $1, (Expression) $7, opt_parm);
+ (Attributes) $1, (Expression) $8, opt_parm);
}
;
statement_list
: statement
- | statement_list end_of_stmt statement
+ | statement_list end_of_stmt
+ statement
;
-
+
statement
: declaration_statement
{
}
| embedded_statement
{
- Statement s = (Statement) $1;
-
current_block.AddStatement ((Statement) $1);
}
| labeled_statement
/* | empty_statement */
| with_statement
{
- Statement s = (Statement) $1;
-
current_block.AddStatement ((Statement) $1);
}
;
+opt_end_stmt
+ : END_EOL {$$ = new End (lexer.Location);}
+ ;
+
+
opt_raise_event_args
: /* empty */ { $$ = null; }
| OPEN_PARENS opt_argument_list CLOSE_PARENS
*/
with_statement
- : WITH expression end_of_stmt /* was : WITH qualified_identifier end_of_stmt */
+ : WITH _mark_ expression end_of_stmt /* was : WITH qualified_identifier end_of_stmt */
{
- // was : Expression e = DecomposeQI ((string) $2, lexer.Location);
- Expression e = (Expression) $2;
+ // was : Expression e = DecomposeQI ((string) $3, (Location)$2);
+ push_into_stack((int)Start_block.WITH, (Location)$2);
+ Expression e = (Expression) $3;
with_stack.Push(e);
start_block();
}
opt_statement_list
- END WITH
+ opt_end_block
{
+ pop_out_of_stack((int)$7,lexer.Location);
Block b = end_block();
with_stack.Pop();
$$ = b;
| throw_statement
| exit_statement
| yield_statement
+ | opt_end_stmt
;
goto_statement
;
throw_statement
- : THROW opt_expression
+ : THROW _mark_ opt_expression
{
- $$ = new Throw ((Expression) $2, lexer.Location);
+ $$ = new Throw ((Expression) $3, (Location)$2);
}
;
;
foreach_statement
- : FOR EACH identifier IN
- {
- oob_stack.Push (lexer.Location);
- }
+ : FOR EACH identifier _mark_ opt_type_spec IN
expression end_of_stmt
{
-
- start_block();
- Block foreach_block = current_block;
- Location l = lexer.Location;
+ Location l = (Location)$4;
+ push_into_stack((int)Start_block.FOR, l);
LocalVariableReference v = null;
VariableInfo vi;
- vi = foreach_block.GetVariableInfo ((string) $3);
- if (vi != null) {
- // Get a reference to this variable.
- v = new LocalVariableReference (foreach_block, (string) $3, l, vi, false);
+ if ($5 != null)
+ {
+ start_block();
+ VariableDeclaration decl = new VariableDeclaration ((string) $3,
+ (Expression) $5, null, (Location)$4, null);
+
+ vi = current_block.AddVariable (
+ (Expression) $5, decl.identifier, current_local_parameters, decl.Location);
+
+ Expression expr;
+ if (decl.expression_or_array_initializer is Expression)
+ expr = (Expression) decl.expression_or_array_initializer;
+ else if (decl.expression_or_array_initializer == null)
+ expr = null;
+ else
+ {
+ ArrayList init = (ArrayList) decl.expression_or_array_initializer;
+ expr = new ArrayCreation ((Expression) $5, "", init, decl.Location);
+ }
+
+ v = new LocalVariableReference (current_block, decl.identifier, l);
+
+ if (expr != null)
+ {
+ Assign a = new Assign (v, expr, decl.Location);
+ current_block.AddStatement (new StatementExpression (a, (Location)$4));
+ }
}
else
- Report.Error (451, "Name '" + (string) $3 + "' is not declared.");
-
+ {
+ vi = current_block.GetVariableInfo ((string) $3);
+
+ if (vi != null) {
+ // Get a reference to this variable.
+ v = new LocalVariableReference (current_block, (string) $3, l, vi, false);
+ }
+ else
+ Report.Error (451, (Location)$4,"Name '" + (string) $3 + "' is not declared.");
+ }
+
oob_stack.Push (v);
+ start_block();
}
opt_statement_list
- NEXT opt_identifier
- {
+ opt_end_block
+ {
+ pop_out_of_stack((int)$11,lexer.Location);
+ }
+ _mark_ opt_identifier
+ {
+ string s = $3.ToString();
+ string s1 = "";
+ if ($14 != null)
+ s1 = $14.ToString();
+ if (s1 != "" && s != s1)
+ {
+ Report.Error(30070, (Location)$13, "Next Control Variable '"+s1+"' does not match with For Loop control variable '"+s+"'");
+ }
LocalVariableReference v = (LocalVariableReference) oob_stack.Pop ();
Block foreach_block = end_block();
- Location l = (Location) oob_stack.Pop ();
Foreach f = null;
- if (v != null) {
- f = new Foreach (null, v, (Expression) $6, foreach_block, l);
- }
+ if (v != null)
+ f = new Foreach (null, v, (Expression) $7, foreach_block, (Location)$4);
- $$ = f;
+ if ($5 != null)
+ {
+ current_block.AddStatement (f);
+ $$ = end_block ();
+ }
+ else
+ $$ = f;
}
;
yield_statement
- : YIELD expression
+ : YIELD expression _mark_
{
if (!UseExtendedSyntax)
{
}
/* else
if (iterator_container == null){
- Report.Error (204, lexer.Location, "yield statement can only be used within a method, operator or property");
+ Report.Error (204, (Location)$3, "yield statement can only be used within a method, operator or property");
$$ = null;
} else {
iterator_container.SetYields ();
- $$ = new Yield ((Expression) $2, lexer.Location);
+ $$ = new Yield ((Expression) $2, (Location)$3);
} */
}
- | YIELD STOP
+ | YIELD STOP _mark_
{
if (!UseExtendedSyntax)
{
}
/* else
if (iterator_container == null){
- Report.Error (204, lexer.Location, "yield statement can only be used within a method, operator or property");
+ Report.Error (204, (Location)$3, "yield statement can only be used within a method, operator or property");
$$ = null;
} else {
iterator_container.SetYields ();
- $$ = new YieldBreak (lexer.Location);
+ $$ = new YieldBreak ((Location)$3);
} */
}
;
synclock_statement
- : SYNCLOCK expression end_of_stmt
+ : SYNCLOCK _mark_ expression end_of_stmt
{
+ push_into_stack((int)Start_block.SYNCLOCK, (Location)$2);
start_block();
}
opt_statement_list
- END SYNCLOCK
+ opt_end_block
{
- $$ = new Lock ((Expression) $2, (Statement) (Block) end_block(), lexer.Location);
+ pop_out_of_stack((int)$7,lexer.Location);
+ $$ = new Lock ((Expression) $3, (Statement) (Block) end_block(), (Location)$2);
}
;
;
try_header
- : TRY end_of_stmt
+ : TRY _mark_ end_of_stmt
{
+ push_into_stack((int)Start_block.TRY, (Location)$2);
+ try_top=(Location)$2;
start_block();
}
opt_statement_list
opt_catch_clauses
{
- tmp_catch_clauses = (ArrayList) $5;
+ tmp_catch_clauses = (ArrayList) $6;
}
;
-
+
+
+/*FIXME: Try block without a end try is throwing error at a wrong place*/
try_catch
- : try_header
- END TRY
- {
+ : try_header
+ _mark_ opt_end_block
+ {
+ pop_out_of_stack((int)$3,lexer.Location);
Catch g = null;
ArrayList s = new ArrayList ();
// and g contains the general one.
Block b = end_block();
- $$ = new Try ((Block) b, s, g, null, lexer.Location);
+ $$ = new Try ((Block) b, s, g, null, try_top);
}
;
start_block();
}
opt_statement_list
- END TRY
+ _mark_ opt_end_block
{
+ pop_out_of_stack((int)$8,lexer.Location);
Catch g = null;
ArrayList s = new ArrayList ();
ArrayList catch_list = (ArrayList) tmp_catch_clauses;
}
}
- $$ = new Try ((Block) tmp_block, s, g, (Block) end_block(), lexer.Location);
+ $$ = new Try ((Block) tmp_block, s, g, (Block) end_block(), try_top);
}
;
| identifier
;
+opt_when
+ : /* empty */ { $$ = null; }
+ | WHEN boolean_expression
+ {
+ $$ = $2;
+ }
+ ;
+
catch_clause
- : CATCH opt_catch_args end_of_stmt
+ : CATCH opt_catch_args opt_when _mark_ end_of_stmt
{
Expression type = null;
string id = null;
if (id != null){
ArrayList one = new ArrayList ();
- Location loc = lexer.Location;
+ Location loc = (Location)$4;
one.Add (new VariableDeclaration (id, type, loc));
-
$1 = current_block;
current_block = new Block (current_block);
Block b = declare_local_variables (type, one, loc);
current_block = b;
}
}
-
}
opt_statement_list {
Expression type = null;
current_block = current_block.Parent;
}
}
-
- $$ = new Catch (type, id , (Block)b_catch, lexer.Location);
+ $$ = new Catch (type, id , (Block) b_catch, (Expression) $3, (Location)$4);
}
- ;
+ ;
opt_catch_args
: /* empty */ { $$ = null; }
;
catch_args
- : identifier AS type
+ : identifier AS _mark_ type
{
- $$ = new DictionaryEntry ($3, $1);
+ $$ = new DictionaryEntry ($4, $1);
+ }
+ | error _mark_ AS type
+ {
+ Report.Error(30203, (Location)$2, "Identifier Expected");
+ $$ = null;
+ }
+ | identifier AS _mark_ error
+ {
+ Report.Error(30182, (Location)$3, "Type Expected");
+ $$ = null;
}
;
-
+
do_statement
- : DO opt_do_construct end_of_stmt
+ : DO _mark_ opt_do_construct end_of_stmt
{
+ push_into_stack((int)Start_block.DO, (Location)$2);
start_block();
- oob_stack.Push (lexer.Location);
}
opt_statement_list
- LOOP opt_do_construct
+ opt_end_block
+ {
+ pop_out_of_stack((int)$7,lexer.Location);
+ }
+ _mark_ opt_do_construct
{
- Expression t_before = (Expression) $2;
- Expression t_after = (Expression) $7;
+ Expression t_before = (Expression) $3;
+ Expression t_after = (Expression) $10;
Expression t;
if ((t_before != null) && (t_after != null))
- Report.Error (30238, "'Loop' cannot have a condition if matching 'Do' has one.");
+ Report.Error (30238, (Location)$9, "'Loop' cannot have a condition if matching 'Do' has one.");
if ((t_before == null) && (t_after == null))
t = new BoolLiteral (true);
if (((do_type == DoOptions.WHILE) && (test_type == DoOptions.TEST_BEFORE)) ||
((do_type == DoOptions.UNTIL) && (test_type == DoOptions.TEST_AFTER)))
- t = new Unary (Unary.Operator.LogicalNot, (Expression) t, lexer.Location);
+ t = new Unary (Unary.Operator.LogicalNot, (Expression) t, (Location)$2);
- $$ = new Do ((Statement) end_block(), (Expression) t, test_type, lexer.Location);
+ $$ = new Do ((Statement) end_block(), (Expression) t, test_type, (Location)$2);
}
;
while_statement
: WHILE
{
+ push_into_stack((int)Start_block.WHILE, lexer.Location);
start_block();
oob_stack.Push (lexer.Location);
}
boolean_expression end_of_stmt
opt_statement_list
- END WHILE
- {
+ opt_end_block
+ {
Location l = (Location) oob_stack.Pop ();
+ pop_out_of_stack((int)$6,lexer.Location);
Block b = end_block();
Expression e = (Expression) $3;
$$ = new While ((Expression) e, (Statement) b, l);
;
for_statement
- : FOR identifier opt_type_spec ASSIGN expression TO expression opt_step end_of_stmt
+ : FOR _mark_ identifier opt_type_spec ASSIGN expression TO expression opt_step end_of_stmt
{
- if ($3 != null)
+ push_into_stack((int)Start_block.FOR, (Location)$2);
+ if ($4 != null)
{
start_block();
ArrayList VarDeclaration = new ArrayList ();
- VarDeclaration.Add (new VariableDeclaration ((string) $2,
- (Expression) $3, null, lexer.Location, null));
+ VarDeclaration.Add (new VariableDeclaration ((string) $3,
+ (Expression) $4, null, (Location)$2, null));
- DictionaryEntry de = new DictionaryEntry (DecomposeQI("_local_vars_", lexer.Location), VarDeclaration);
- Block b = declare_local_variables ((Expression) de.Key, (ArrayList) de.Value, lexer.Location);
+ DictionaryEntry de = new DictionaryEntry (DecomposeQI("_local_vars_", (Location)$2), VarDeclaration);
+ Block b = declare_local_variables ((Expression) de.Key, (ArrayList) de.Value, (Location)$2);
current_block = b;
}
- oob_stack.Push (lexer.Location);
start_block();
}
opt_statement_list
- NEXT opt_identifier
- {
- Block inner_statement = end_block();\r
- Location l = (Location) oob_stack.Pop ();\r
- Expression for_var = (Expression) DecomposeQI ((string)$2, l);\r
- \r
- Expression assign_expr = new Assign (for_var, (Expression) $5, l);\r
- Expression test_expr = new Binary (Binary.Operator.LessThanOrEqual,\r
- for_var, (Expression) $7, l);\r
- Expression step_expr = new Assign (for_var, (Expression) new Binary (Binary.Operator.Addition,\r
- for_var, (Expression) $8, l), l);\r
-\r
- Statement assign_stmt = new StatementExpression ((ExpressionStatement) assign_expr, l);\r
- Statement step_stmt = new StatementExpression ((ExpressionStatement) step_expr, l);\r
-\r
- For f = new For (assign_stmt, test_expr, step_stmt, inner_statement, l);
- if ($3 != null)
- {
- current_block.AddStatement (f);
- $$ = end_block();
- }
- else
- $$ = f;
- }
+ opt_end_block
+ {
+ pop_out_of_stack((int)$13,lexer.Location);
+ }
+ _mark_ opt_identifier
+ {
+ string s = $3.ToString();
+ string s1 = "";
+ if ($16 != null)
+ s1 = $16.ToString();
+ if (s1 != "" && s != s1) {
+ Report.Error(30070, (Location)$15, "Next Control Variable '"+s1+"' does not match with For Loop control variable '"+s+"'");
+ }
+
+ Block inner_statement = end_block();
+ Location l = (Location)$2;
+ Expression for_var = (Expression) DecomposeQI ((string)$3, l);
+
+ For f = new For (for_var, (Expression) $6, (Expression) $8, (Expression) $9, inner_statement, l);
+ if ($4 != null)
+ {
+ current_block.AddStatement (f);
+ $$ = end_block();
+ }
+ else
+ $$ = f;
+ }
;
opt_step
;
if_statement
- : if_statement_open opt_then if_statement_rest
- {
- $$ = $3;
- }
+ : if_statement_open opt_then end_of_stmt opt_statement_list
+ {
+ push_into_stack((int)Start_block.IF, (Location)$1);
+ }
+ if_statement_rest
+ {
+ $$ = $6;
+ }
| if_statement_open THEN pre_embedded_statement opt_else_pre_embedded_statement
{
if ($4 == null)
$$ = new If ((Expression) tmp_expr, (Statement) tmp_block, end_block(), l);
}
}
- | if_statement_open THEN else_pre_embedded_statement
+ | if_statement_open THEN else_pre_embedded_statement
{
Location l = (Location) oob_stack.Pop ();
tmp_expr = (Expression)expr_stack.Pop();
pre_embedded_statement
: embedded_statement
{
- Statement s = (Statement) $1;
-
current_block.AddStatement ((Statement) $1);
}
;
tmp_blocks.Push(bl);
start_block();
- Statement s = (Statement) $2;
current_block.AddStatement ((Statement) $2);
}
;
-
+
+/*FIXME:if without end if not working. Error line shown is nor correct*/
if_statement_open
- : IF boolean_expression
+ : IF _mark_
{
oob_stack.Push (lexer.Location);
+ }
+ boolean_expression
+ {
start_block();
- tmp_expr = (Expression) $2;
+ tmp_expr = (Expression) $4;
expr_stack.Push(tmp_expr);
+ $$ = (Location)$2;
}
;
;
if_statement_rest
- : end_of_stmt
- opt_statement_list
- END IF
+ :
+ opt_end_block
{
Location l = (Location) oob_stack.Pop ();
- Expression expr = (Expression)expr_stack.Pop();
+ pop_out_of_stack((int)$1,lexer.Location);
+ Expression expr = (Expression)expr_stack.Pop();
$$ = new If ((Expression) expr, (Statement) end_block(), l);
}
- | end_of_stmt
- opt_statement_list
+ |
ELSE end_of_stmt
{
Block bl = end_block();
- tmp_blocks.Push(bl);
+ tmp_blocks.Push(bl);
start_block();
}
opt_statement_list
- END IF
+ opt_end_block
{
Location l = (Location) oob_stack.Pop ();
+ pop_out_of_stack((int)$5,lexer.Location);
tmp_expr = (Expression)expr_stack.Pop();
tmp_block = (Block) tmp_blocks.Pop();
$$ = new If ((Expression) tmp_expr, (Statement) tmp_block, (Statement) end_block(), l);
}
- | end_of_stmt
- opt_statement_list
- ELSEIF boolean_expression opt_then
+ |
+ opt_elseif boolean_expression opt_then
{
- tmp_expr = (Expression) $4;
+ tmp_expr = (Expression) $2;
expr_stack.Push(tmp_expr);
tmp_block = end_block();
tmp_blocks.Push(tmp_block);
start_block();
}
- else_if_statement_rest
+ end_of_stmt opt_statement_list
+ else_if_statement_rest
{
Statement stmt = (Statement) statement_stack.Pop();
Block bl = (Block) tmp_blocks.Pop();
else_if_statement_rest
- : end_of_stmt
- opt_statement_list
- END IF
- {
- Location l = (Location) oob_stack.Pop ();
- oob_stack.Push (l);
- Expression expr = (Expression)expr_stack.Pop();
- Statement stmt = (Statement) new If ((Expression) expr, (Statement) end_block(), l);
- statement_stack.Push(stmt);
- }
- | end_of_stmt
- opt_statement_list
+ :
ELSE end_of_stmt
{
Block bl = end_block();
start_block();
}
opt_statement_list
- END IF
+ opt_end_block
{
Location l = (Location) oob_stack.Pop ();
+ pop_out_of_stack((int)$5,lexer.Location);
oob_stack.Push (l);
Expression expr = (Expression)expr_stack.Pop();
Block bl = (Block)tmp_blocks.Pop();
Statement stmt = (Statement) new If ((Expression) expr, (Statement) bl , (Statement) end_block(), l);
statement_stack.Push(stmt);
}
- | end_of_stmt
- opt_statement_list
- ELSEIF boolean_expression opt_then
+ |
+ opt_elseif boolean_expression opt_then
{
- expr_stack.Push((Expression) $4);
+ expr_stack.Push((Expression) $2);
Block bl = end_block();
tmp_blocks.Push(bl);
start_block();
}
- else_if_statement_rest
+ end_of_stmt opt_statement_list
+ else_if_statement_rest
{
Location l = (Location) oob_stack.Pop ();
oob_stack.Push (l);
Statement stmt = (Statement) new If ((Expression) expr, (Statement) bl, tmp_stmt , l);
statement_stack.Push(stmt);
}
+ |
+ opt_end_block
+ {
+ Location l = (Location) oob_stack.Pop ();
+ pop_out_of_stack((int)$1,lexer.Location);
+ oob_stack.Push (l);
+ Expression expr = (Expression)expr_stack.Pop();
+ Statement stmt = (Statement) new If ((Expression) expr, (Statement) end_block(), l);
+ statement_stack.Push(stmt);
+ }
;
-
+
+/*FIXME:Select without an expression is showing a parser error instead of a expression missing error*/
select_statement
- : SELECT opt_case expression end_of_stmt
+ : SELECT
+ _mark_ opt_case expression end_of_stmt
{
+ push_into_stack((int)Start_block.SELECT, (Location)$2);
oob_stack.Push (lexer.Location);
switch_stack.Push (current_block);
}
opt_case_sections
- END SELECT
- {
- $$ = new Switch ((Expression) $3, (ArrayList) $6, (Location) oob_stack.Pop ());
+ opt_end_block
+ {
+ pop_out_of_stack((int)$8,lexer.Location);
current_block = (Block) switch_stack.Pop ();
+ $$ = new Switch ((Expression) $4, (ArrayList) $7, (Location) oob_stack.Pop ());
}
;
topmost.statements.Add (new Break (lexer.Location));
$$ = new SwitchSection ((ArrayList) $2, topmost);
}
- | CASE ELSE ends
+ | CASE ELSE ends
/* FIXME: we should somehow flag an error
(BC30321 'Case' cannot follow a 'Case Else'
in the same 'Select' statement.)
topmost.statements.Add (new Break (lexer.Location));
ArrayList a = new ArrayList();
- a.Add (new SwitchLabel (null, lexer.Location));
+ a.Add (new SwitchLabel (null, SwitchLabel.LabelType.Else, Binary.Operator.TOP, lexer.Location));
$$ = new SwitchSection ((ArrayList) a, topmost);
}
;
: case_clause
{
ArrayList labels = new ArrayList ();
-
labels.Add ($1);
$$ = labels;
}
| case_clauses COMMA case_clause
{
ArrayList labels = (ArrayList) ($1);
- labels.Add ($2);
+ labels.Add ($3);
$$ = labels;
}
case_clause
: opt_is comparison_operator expression
+ {
+ $$ = new SwitchLabel ((Expression) $3, SwitchLabel.LabelType.Operator, (Binary.Operator) $2, lexer.Location);
+ }
| expression
{
- $$ = new SwitchLabel ((Expression) $1, lexer.Location);
+ $$ = new SwitchLabel ((Expression) $1, SwitchLabel.LabelType.Label, Binary.Operator.TOP, lexer.Location);
}
+ | expression TO expression
+ {
+ $$ = new SwitchLabel ((Expression) $1, (Expression) $3, SwitchLabel.LabelType.Range,
+ Binary.Operator.TOP, lexer.Location);
+ }
+
;
opt_is
;
comparison_operator
- : OP_LT
+ : OP_LT
+ {
+ $$ = Binary.Operator.LessThan;
+ }
| OP_GT
+ {
+ $$ = Binary.Operator.GreaterThan;
+ }
+ | OP_GE
+ {
+ $$ = Binary.Operator.GreaterThanOrEqual;
+ }
| OP_LE
+ {
+ $$ = Binary.Operator.LessThanOrEqual;
+ }
| OP_NE
- /*| OP_EQ */
+ {
+ $$ = Binary.Operator.Inequality;
+ }
+ | ASSIGN
+ {
+ $$ = Binary.Operator.Equality;
+ }
;
opt_case
;
object_creation_expression
- : NEW type OPEN_PARENS opt_argument_list CLOSE_PARENS
+ : NEW type OPEN_PARENS _mark_ opt_argument_list CLOSE_PARENS
{
- $$ = new New ((Expression) $2, (ArrayList) $4, lexer.Location);
+ $$ = new New ((Expression) $2, (ArrayList) $5, (Location)$4);
}
- | NEW type
+ | NEW type _mark_
{
- $$ = new New ((Expression) $2, new ArrayList(), lexer.Location);
+ $$ = new New ((Expression) $2, new ArrayList(), (Location)$3);
}
;
array_creation_expression
- : object_creation_expression opt_rank_specifiers array_initializer
+ : object_creation_expression opt_rank_specifiers _mark_ array_initializer
{
New n = (New) $1;
ArrayList dims = new ArrayList();
Expression atype = n.RequestedType;
if ($2 != null)
- atype = DecomposeQI (atype.ToString () + VariableDeclaration.BuildRanks ((ArrayList)$2, true, lexer.Location), lexer.Location);
+ atype = DecomposeQI (atype.ToString () + VariableDeclaration.BuildRanks ((ArrayList)$2, true, (Location)$3), (Location)$3);
- ArrayList init = (ArrayList) $3;
+ ArrayList init = (ArrayList) $4;
if (init.Count == 0)
init = null;
if (VariableDeclaration.IndexesSpecifiedInRank(dims)) {
VariableDeclaration.VBFixIndexList (ref dims);
- $$ = new ArrayCreation (atype, dims, "", init, lexer.Location);
+ $$ = new ArrayCreation (atype, dims, "", init, (Location)$3);
}
else
{
string rank = VariableDeclaration.BuildRank (dims);
- $$ = new ArrayCreation (atype, rank, (ArrayList) $3, lexer.Location);
+ $$ = new ArrayCreation (atype, rank, (ArrayList) $4, (Location)$3);
}
//Console.WriteLine ("Creating a new array of type " + (atype.ToString()) + " with rank '" + dims + "'");
}
;
declaration_statement
- : local_variable_declaration
+ : _mark_ local_variable_declaration
{
- if ($1 != null){
- DictionaryEntry de = (DictionaryEntry) $1;
+ if ($2 != null){
+ DictionaryEntry de = (DictionaryEntry) $2;
- $$ = declare_local_variables ((Expression) de.Key, (ArrayList) de.Value, lexer.Location);
+ $$ = declare_local_variables ((Expression) de.Key, (ArrayList) de.Value, (Location)$1);
}
}
| local_constant_declaration
{
- if ($1 != null){
+ if ($1!= null){
DictionaryEntry de = (DictionaryEntry) $1;
$$ = declare_local_constant ((Expression) de.Key, (ArrayList) de.Value);
;
local_variable_declaration
- : DIM variable_declarators
+ : DIM _mark_ variable_declarators
{
- $$ = new DictionaryEntry (DecomposeQI("_local_vars_", lexer.Location), $2);
+ $$ = new DictionaryEntry (DecomposeQI("_local_vars_", (Location)$2), $3);
}
;
;
constant_declarator
- : variable_name opt_type_decl opt_variable_initializer
+ : _mark_ variable_name opt_type_decl opt_variable_initializer
{
- VarName vname = (VarName) $1;
+ VarName vname = (VarName) $2;
string varname = (string) vname.Name;
current_rank_specifiers = (ArrayList) vname.Rank;
- object varinit = $3;
- ArrayList a_dims = null;
+ object varinit = $4;
if (varinit == null)
Report.Error (
- 30438, lexer.Location, "Constant should have a value"
+ 30438, (Location)$1, "Constant should have a value"
);
- if (vname.Type != null && $2 != null)
+ if (vname.Type != null && $3 != null)
Report.Error (
- 30302, lexer.Location,
+ 30302, (Location)$1,
"Type character cannot be used with explicit type declaration" );
- Expression vartype = ($2 == null) ? ((vname.Type == null) ? TypeManager.system_object_expr : (Expression) vname.Type ) : (Expression) $2;
+ Expression vartype = ($3 == null) ? ((vname.Type == null) ? TypeManager.system_object_expr : (Expression) vname.Type ) : (Expression) $3;
if (current_rank_specifiers != null)
{
- Report.Error (30424, lexer.Location, "Constant doesn't support array");
+ Report.Error (30424, (Location)$1, "Constant doesn't support array");
$$ = null;
}
else
- $$ = new VariableDeclaration (varname, vartype, varinit, lexer.Location, null);
+ $$ = new VariableDeclaration (varname, vartype, varinit, (Location)$1, null);
}
;
;
variable_declarator
- : variable_names opt_type_decl opt_variable_initializer
+ : _mark_ variable_names opt_type_decl opt_variable_initializer
{
- ArrayList names = (ArrayList) $1;
- object varinit = $3;
+ ArrayList names = (ArrayList) $2;
+ object varinit = $4;
ArrayList VarDeclarations = new ArrayList();
Expression vartype;
ArrayList a_dims = null;
if ((names.Count > 1) && (varinit != null))
Report.Error (
- 30671, lexer.Location,
+ 30671, (Location)$1,
"Multiple variables with single type can not have " +
"a explicit initialization" );
string varname = (string) vname.Name;
current_rank_specifiers = (ArrayList) vname.Rank;
a_dims = null;
- varinit = $3;
+ varinit = $4;
- if(vname.Type != null && $2 != null)
+ if(vname.Type != null && $3 != null)
Report.Error (
- 30302, lexer.Location,
+ 30302, (Location)$1,
"Type character cannot be used with explicit type declaration" );
// Some checking is required for particularly weird declarations
// like Dim a As Integer(,)
- if ($2 is Pair) {
- vartype = (Expression) ((Pair) $2).First;
+ if ($3 is Pair) {
+ vartype = (Expression) ((Pair) $3).First;
- /*if ($3 != null && $3 is ArrayList)
+ /*if ($4 != null && $4 is ArrayList)
Report.Error (205, "End of statement expected.");*/
- ArrayList args = (ArrayList) ((Pair) $2).Second;
+ ArrayList args = (ArrayList) ((Pair) $3).Second;
if (current_rank_specifiers != null)
- Report.Error (31087, lexer.Location,
+ Report.Error (31087, (Location)$1,
"Array types specified in too many places");
if (VariableDeclaration.IndexesSpecifiedInRank (args))
- Report.Error (30638, "Array bounds cannot appear in type specifiers.");
+ Report.Error (30638, (Location)$1,"Array bounds cannot appear in type specifiers.");
current_rank_specifiers = new ArrayList ();
current_rank_specifiers.Add (args);
}
else
- vartype = ($2 == null) ? ((vname.Type == null) ? TypeManager.system_object_expr : (Expression) vname.Type ) : (Expression) $2;
+ vartype = ($3 == null) ? ((vname.Type == null) ? TypeManager.system_object_expr : (Expression) vname.Type ) : (Expression) $3;
// if the variable is an array with explicit bound
// and having explicit initialization throw exception
if (!((Expression)expr is EmptyExpression ))
{
Report.Error (
- 30672, lexer.Location,
+ 30672, (Location)$1,
"Array declared with explicit bound " +
" can not have explicit initialization");
broken = true;
if (VariableDeclaration.IndexesSpecified(current_rank_specifiers)) {
a_dims = (ArrayList) current_rank_specifiers;
VariableDeclaration.VBFixIndexLists (ref a_dims);
- varinit = VariableDeclaration.BuildArrayCreator(vartype, a_dims, (ArrayList) varinit, lexer.Location);
+ varinit = VariableDeclaration.BuildArrayCreator(vartype, a_dims, (ArrayList) varinit, (Location)$1);
}
- vartype = DecomposeQI (vartype.ToString() + VariableDeclaration.BuildRanks (current_rank_specifiers, false, lexer.Location), lexer.Location);
+ vartype = DecomposeQI (vartype.ToString() + VariableDeclaration.BuildRanks (current_rank_specifiers, false, (Location)$1), (Location)$1);
}
if (vartype is New) {
if (varinit != null) {
- Report.Error (30205, lexer.Location, "End of statement expected");
+ Report.Error (30205, (Location)$1, "End of statement expected");
$$ = null;
}
else
vartype = ((New)vartype).RequestedType;
}
}
- VarDeclarations.Add (new VariableDeclaration (varname, vartype, varinit, lexer.Location, null));
+ VarDeclarations.Add (new VariableDeclaration (varname, vartype, varinit, (Location)$1, null));
}// end of for
$$ = VarDeclarations;
}
opt_type_with_ranks
: opt_type_spec
- | AS type rank_specifiers
+ | AS type _mark_ rank_specifiers
{
- $$ = DecomposeQI ($2.ToString() + VariableDeclaration.BuildRanks ((ArrayList)$3, true, lexer.Location), lexer.Location);
+ $$ = DecomposeQI ($2.ToString() + VariableDeclaration.BuildRanks ((ArrayList)$4, true, (Location)$3), (Location)$3);
}
;
variable_initializer
: expression
{
- $$ = $1;
+ Expression etmp = (Expression) $1;
+ etmp = SetValueRequiredFlag (etmp);
+ $$ = etmp;
}
| array_initializer
{
| parenthesized_expression
| this_access
| base_access
- | qualified_identifier
+ | qualified_identifier opt_type_character _mark_
{
string name = (string) $1;
- $$ = DecomposeQI (name, lexer.Location);
+ $$ = DecomposeQI (name, (Location)$3);
}
| get_type_expression
| member_access
//| element_access
| new_expression
| cast_expression
+ | error _mark_
+ { Report.Error(30201,(Location)$2,"Expression expected"); $$ = (Expression)null;}
;
literal
else if (v is long)
$$ = new LongLiteral ((Int64)v);
else
- Console.WriteLine ("OOPS. Unexpected result from scanner");
+ Console.WriteLine ("Unexpected result from scanner");
}
;
;
member_access
- : primary_expression DOT identifier
+ : primary_expression DOT _mark_ identifier
{
if ($1 != null) {
- string id_name = (string)$3;
+ string id_name = (string)$4;
if (id_name.ToUpper() == "NEW")
id_name = ".ctor";
- $$ = new MemberAccess ((Expression) $1, id_name, lexer.Location);
+ $$ = new MemberAccess ((Expression) $1, id_name, (Location)$3);
}
else
{
if (with_stack.Count > 0) {
Expression e = (Expression) with_stack.Peek();
- $$ = new MemberAccess (e, (string) $3, lexer.Location);
+ $$ = new MemberAccess (e, (string) $4, (Location)$3);
}
else
{
}
}
}
-/* | primary_expression DOT NEW
+/* | primary_expression DOT _mark_ NEW
{
- $$ = new MemberAccess ((Expression) $1, (string) ".ctor", lexer.Location);
+ $$ = new MemberAccess ((Expression) $1, (string) ".ctor", (Location)$3);
} */
- | predefined_type DOT identifier
+ | predefined_type DOT _mark_ identifier
{
if ($1 != null)
- $$ = new MemberAccess ((Expression) $1, (string) $3, lexer.Location);
+ $$ = new MemberAccess ((Expression) $1, (string) $4, (Location)$3);
else
{
if (with_stack.Count > 0) {
Expression e = (Expression) with_stack.Peek();
- $$ = new MemberAccess (e, (string) $3, lexer.Location);
+ $$ = new MemberAccess (e, (string) $4, (Location)$3);
}
else
{
;
invocation_expression
- : primary_expression OPEN_PARENS opt_argument_list CLOSE_PARENS
+// To support Mid$()
+ : primary_expression opt_dolar_sign OPEN_PARENS opt_argument_list _mark_ CLOSE_PARENS
{
if ($1 == null) {
- Location l = lexer.Location;
+ Location l = (Location)$5;
Report.Error (1, l, "THIS IS CRAZY");
}
- $$ = new Invocation ((Expression) $1, (ArrayList) $3, lexer.Location);
-// Console.WriteLine ("Invocation: {0} with {1} arguments", $1, ($3 != null) ? ((ArrayList) $3).Count : 0);
+ $$ = new Invocation ((Expression) $1, (ArrayList) $4, (Location)$5);
+ // Console.WriteLine ("Invocation: {0} with {1} arguments", $1, ($4 != null) ? ((ArrayList) $4).Count : 0);
}
- | CALL primary_expression OPEN_PARENS opt_argument_list CLOSE_PARENS
+ | CALL primary_expression OPEN_PARENS opt_argument_list _mark_ CLOSE_PARENS
{
if ($2 == null) {
- Location l = lexer.Location;
+ Location l = (Location)$5;
Report.Error (1, l, "THIS IS CRAZY");
}
- $$ = new Invocation ((Expression) $2, (ArrayList) $3, lexer.Location);
+ $$ = new Invocation ((Expression) $2, (ArrayList) $3, (Location)$5);
// Console.WriteLine ("Invocation: {0} with {1} arguments", $2, ($3 != null) ? ((ArrayList) $3).Count : 0);
}
+ | primary_expression EXCLAMATION _mark_ identifier // FIXME : This should be identifier-or-keyword
+ {
+ if ($1 == null) {
+ Location l = (Location)$3;
+ Report.Error (1, l, "THIS IS CRAZY");
+ }
+
+ ArrayList args = new ArrayList ();
+ Expression etmp = new StringLiteral ((string)$4);
+
+ args.Add (new Argument (etmp, Argument.AType.Expression));
+ $$ = new Invocation ((Expression) $1, args, (Location)$3);
+ }
;
-
+
+opt_dolar_sign
+ : DOLAR_SIGN
+ | /*empty*/
+ ;
+
base_access
: MYBASE DOT IDENTIFIER
{
{
$$ = new Argument ((Expression) $2, Argument.AType.AddressOf);
}
+ | identifier ATTR_ASSIGN expression
+ {
+ $$ = new Argument ((string) $1, (Expression) $3, Argument.AType.Expression);
+ }
;
variable_reference
expression
- : conditional_xor_expression { $$ = $1; }
+ : conditional_xor_expression { $$ = $1; }
/*| assignment_expression*/
;
}
| MYCLASS
{
- // FIXME: This is actually somewhat different from Me
- // because it is for accessing static (classifier) methods/properties/fields
- $$ = new This (current_block, lexer.Location);
+ $$ = new This (This.TypeOfAccess.MyClass, current_block, lexer.Location);
}
;
| COBJ { $$ = TypeManager.system_object_expr; }
| CSHORT { $$ = TypeManager.system_int16_expr; }
| CSNG { $$ = TypeManager.system_single_expr; }
- | CSTR { $$ = TypeManager.system_string_expr; }
+ | CSTR { $$ = TypeManager.system_string_expr; }
;
get_type_expression
- : GETTYPE OPEN_PARENS type CLOSE_PARENS
+ : GETTYPE OPEN_PARENS _mark_ type CLOSE_PARENS
{
- $$ = new TypeOf ((Expression) $3, lexer.Location);
+ $$ = new TypeOf ((Expression) $4, (Location)$3);
}
;
exponentiation_expression
- : primary_expression
- | exponentiation_expression OP_EXP primary_expression
+ : prefixed_unary_expression
+ | exponentiation_expression OP_EXP _mark_ primary_expression
{
- //TODO
+ $$ = new Binary (Binary.Operator.Exponentiation,
+ (Expression) $1, (Expression) $4, (Location)$3);
}
;
prefixed_unary_expression
- : exponentiation_expression
- | PLUS prefixed_unary_expression
+ : primary_expression
+ | PLUS _mark_ prefixed_unary_expression
{
//FIXME: Is this rule correctly defined ?
- $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, lexer.Location);
+ $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $3, (Location)$2);
}
- | MINUS prefixed_unary_expression
+ | MINUS _mark_ prefixed_unary_expression
{
//FIXME: Is this rule correctly defined ?
- $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, lexer.Location);
+ $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $3, (Location)$2);
}
;
multiplicative_expression
- : prefixed_unary_expression
- | multiplicative_expression STAR prefixed_unary_expression
+ : exponentiation_expression
+ | multiplicative_expression STAR _mark_ prefixed_unary_expression
{
$$ = new Binary (Binary.Operator.Multiply,
- (Expression) $1, (Expression) $3, lexer.Location);
+ (Expression) $1, (Expression) $4, (Location)$3);
}
- | multiplicative_expression DIV prefixed_unary_expression
+ | multiplicative_expression DIV _mark_ prefixed_unary_expression
{
$$ = new Binary (Binary.Operator.Division,
- (Expression) $1, (Expression) $3, lexer.Location);
+ (Expression) $1, (Expression) $4, (Location)$3);
}
;
integer_division_expression
: multiplicative_expression
- | integer_division_expression OP_IDIV multiplicative_expression
+ | integer_division_expression OP_IDIV _mark_ multiplicative_expression
{
//FIXME: Is this right ?
- $$ = new Binary (Binary.Operator.Division,
- (Expression) $1, (Expression) $3, lexer.Location);
+ $$ = new Binary (Binary.Operator.IntDivision,
+ (Expression) $1, (Expression) $4, (Location)$3);
}
;
mod_expression
: integer_division_expression
- | mod_expression MOD integer_division_expression
+ | mod_expression MOD _mark_ integer_division_expression
{
$$ = new Binary (Binary.Operator.Modulus,
- (Expression) $1, (Expression) $3, lexer.Location);
+ (Expression) $1, (Expression) $4, (Location)$3);
}
;
additive_expression
: mod_expression
- | additive_expression PLUS mod_expression
+ | additive_expression PLUS _mark_ mod_expression
{
$$ = new Binary (Binary.Operator.Addition,
- (Expression) $1, (Expression) $3, lexer.Location);
+ (Expression) $1, (Expression) $4, (Location)$3);
}
- | additive_expression MINUS mod_expression
+ | additive_expression MINUS _mark_ mod_expression
{
$$ = new Binary (Binary.Operator.Subtraction,
- (Expression) $1, (Expression) $3, lexer.Location);
+ (Expression) $1, (Expression) $4, (Location)$3);
}
;
concat_expression
: additive_expression
- | concat_expression OP_CONCAT additive_expression
+ | concat_expression OP_CONCAT _mark_ additive_expression
{
// FIXME: This should only work for String expressions
// We probably need to use something from the runtime
- $$ = new Binary (Binary.Operator.Addition,
- (Expression) $1, (Expression) $3, lexer.Location);
+ $$ = new StringConcat((Location)$3,
+ (Expression) $1, (Expression) $4);
}
;
+
shift_expression
: concat_expression
- | shift_expression OP_SHIFT_LEFT concat_expression
+ | shift_expression OP_SHIFT_LEFT _mark_ concat_expression
{
- // TODO
+ $$ = new Binary(Binary.Operator.LeftShift, (Expression) $1, (Expression) $4, (Location)$3);
}
- | shift_expression OP_SHIFT_RIGHT concat_expression
+ | shift_expression OP_SHIFT_RIGHT _mark_ concat_expression
{
- //TODO
+ $$ = new Binary(Binary.Operator.RightShift, (Expression) $1, (Expression) $4, (Location)$3);
}
;
relational_expression
: shift_expression
- | relational_expression ASSIGN shift_expression
+ | relational_expression LIKE _mark_ shift_expression
+ {
+ $$ = new Binary (Binary.Operator.Like,
+ (Expression) $1, (Expression) $4, (Location)$3);
+ }
+ | relational_expression ASSIGN _mark_ shift_expression
{
$$ = new Binary (Binary.Operator.Equality,
- (Expression) $1, (Expression) $3, lexer.Location);
+ (Expression) $1, (Expression) $4, (Location)$3);
}
- | relational_expression OP_NE shift_expression
+ | relational_expression OP_NE _mark_ shift_expression
{
$$ = new Binary (Binary.Operator.Inequality,
- (Expression) $1, (Expression) $3, lexer.Location);
+ (Expression) $1, (Expression) $4, (Location)$3);
}
- | relational_expression OP_LT shift_expression
+ | relational_expression OP_LT _mark_ shift_expression
{
$$ = new Binary (Binary.Operator.LessThan,
- (Expression) $1, (Expression) $3, lexer.Location);
+ (Expression) $1, (Expression) $4, (Location)$3);
}
- | relational_expression OP_GT shift_expression
+ | relational_expression OP_GT _mark_ shift_expression
{
$$ = new Binary (Binary.Operator.GreaterThan,
- (Expression) $1, (Expression) $3, lexer.Location);
+ (Expression) $1, (Expression) $4, (Location)$3);
}
- | relational_expression OP_LE shift_expression
+ | relational_expression OP_LE _mark_ shift_expression
{
$$ = new Binary (Binary.Operator.LessThanOrEqual,
- (Expression) $1, (Expression) $3, lexer.Location);
+ (Expression) $1, (Expression) $4, (Location)$3);
}
- | relational_expression OP_GE shift_expression
+ | relational_expression OP_GE _mark_ shift_expression
{
$$ = new Binary (Binary.Operator.GreaterThanOrEqual,
- (Expression) $1, (Expression) $3, lexer.Location);
+ (Expression) $1, (Expression) $4, (Location)$3);
}
- | relational_expression IS shift_expression
+ | relational_expression IS _mark_ shift_expression
{
- //FIXME: Should be a different op for reference equality but allows tests to use Is
- $$ = new Binary (Binary.Operator.Equality,
- (Expression) $1, (Expression) $3, lexer.Location);
+ $$ = new Binary (Binary.Operator.Is,
+ (Expression) $1, (Expression) $4, (Location)$3);
}
- | TYPEOF shift_expression IS type
+ | TYPEOF shift_expression _mark_ IS type
{
//FIXME: Is this rule correctly defined ?
- $$ = new Is ((Expression) $2, (Expression) $4, lexer.Location);
+ $$ = new Is ((Expression) $2, (Expression) $5, (Location)$3);
}
;
negation_expression
: relational_expression
- | NOT negation_expression
+ | NOT _mark_ negation_expression
{
//FIXME: Is this rule correctly defined ?
- $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, lexer.Location);
+ $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $3, (Location)$2);
}
;
conditional_and_expression
: negation_expression
- | conditional_and_expression AND negation_expression
+ | conditional_and_expression AND _mark_ negation_expression
{
- $$ = new Binary (Binary.Operator.LogicalAnd,
- (Expression) $1, (Expression) $3, lexer.Location);
+ $$ = new Binary (Binary.Operator.BitwiseAnd,
+ (Expression) $1, (Expression) $4, (Location)$3);
}
- | conditional_and_expression ANDALSO negation_expression
+ | conditional_and_expression ANDALSO _mark_ negation_expression
{ // FIXME: this is likely to be broken
$$ = new Binary (Binary.Operator.LogicalAnd,
- (Expression) $1, (Expression) $3, lexer.Location);
+ (Expression) $1, (Expression) $4, (Location)$3);
}
;
conditional_or_expression
: conditional_and_expression
- | conditional_or_expression OR conditional_and_expression
+ | conditional_or_expression OR _mark_ conditional_and_expression
{
- $$ = new Binary (Binary.Operator.LogicalOr,
- (Expression) $1, (Expression) $3, lexer.Location);
+ $$ = new Binary (Binary.Operator.BitwiseOr,
+ (Expression) $1, (Expression) $4, (Location)$3);
}
- | conditional_or_expression ORELSE conditional_and_expression
+ | conditional_or_expression ORELSE _mark_ conditional_and_expression
{ // FIXME: this is likely to be broken
$$ = new Binary (Binary.Operator.LogicalOr,
- (Expression) $1, (Expression) $3, lexer.Location);
+ (Expression) $1, (Expression) $4, (Location)$3);
}
;
conditional_xor_expression
: conditional_or_expression
- | conditional_xor_expression XOR conditional_or_expression
+ | conditional_xor_expression XOR _mark_ conditional_or_expression
{
- $$ = new Binary (Binary.Operator.ExclusiveOr,
- (Expression) $1, (Expression) $3, lexer.Location);
+ $$ = new Binary (Binary.Operator.ExclusiveOr,
+ (Expression) $1, (Expression) $4, (Location)$3);
}
;
assignment_expression
- : prefixed_unary_expression ASSIGN expression
+ : prefixed_unary_expression ASSIGN _mark_ expression
{
- $$ = new Assign ((Expression) $1, (Expression) $3, lexer.Location);
+ $$ = new Assign ((Expression) $1, (Expression) $4, (Location)$3);
}
- | prefixed_unary_expression STAR ASSIGN expression
+ | prefixed_unary_expression OP_EXP ASSIGN _mark_ expression
{
- Location l = lexer.Location;
-
+ Location l = (Location)$4;
$$ = new CompoundAssign (
- Binary.Operator.Multiply, (Expression) $1, (Expression) $4, l);
+ Binary.Operator.Exponentiation, (Expression) $1, (Expression) $5, l);
}
- | prefixed_unary_expression DIV ASSIGN expression
+ | prefixed_unary_expression STAR ASSIGN _mark_ expression
{
- Location l = lexer.Location;
-
+ Location l = (Location)$4;
$$ = new CompoundAssign (
- Binary.Operator.Division, (Expression) $1, (Expression) $4, l);
+ Binary.Operator.Multiply, (Expression) $1, (Expression) $5, l);
}
- | prefixed_unary_expression PLUS ASSIGN expression
+ | prefixed_unary_expression DIV ASSIGN _mark_ expression
{
- Location l = lexer.Location;
-
+ Location l = (Location)$4;
$$ = new CompoundAssign (
- Binary.Operator.Addition, (Expression) $1, (Expression) $4, l);
+ Binary.Operator.Division, (Expression) $1, (Expression) $5, l);
}
- | prefixed_unary_expression MINUS ASSIGN expression
+ | prefixed_unary_expression PLUS ASSIGN _mark_ expression
{
- Location l = lexer.Location;
-
+ Location l = (Location)$4;
$$ = new CompoundAssign (
- Binary.Operator.Subtraction, (Expression) $1, (Expression) $4, l);
+ Binary.Operator.Addition, (Expression) $1, (Expression) $5, l);
}
- | prefixed_unary_expression OP_SHIFT_LEFT ASSIGN expression
+ | prefixed_unary_expression MINUS ASSIGN _mark_ expression
{
- Location l = lexer.Location;
-
+ Location l = (Location)$4;
$$ = new CompoundAssign (
- Binary.Operator.LeftShift, (Expression) $1, (Expression) $4, l);
+ Binary.Operator.Subtraction, (Expression) $1, (Expression) $5, l);
}
- | prefixed_unary_expression OP_SHIFT_RIGHT ASSIGN expression
+ | prefixed_unary_expression OP_SHIFT_LEFT ASSIGN _mark_ expression
{
- Location l = lexer.Location;
-
+ Location l = (Location)$4;
$$ = new CompoundAssign (
- Binary.Operator.RightShift, (Expression) $1, (Expression) $4, l);
+ Binary.Operator.LeftShift, (Expression) $1, (Expression) $5, l);
}
- | prefixed_unary_expression OP_CONCAT ASSIGN expression
+ | prefixed_unary_expression OP_SHIFT_RIGHT ASSIGN _mark_ expression
{
- Location l = lexer.Location;
-
- // FIXME should be strings only
+ Location l = (Location)$4;
$$ = new CompoundAssign (
- Binary.Operator.Addition, (Expression) $1, (Expression) $4, l);
+ Binary.Operator.RightShift, (Expression) $1, (Expression) $5, l);
}
- | prefixed_unary_expression OP_EXP ASSIGN expression
+ | prefixed_unary_expression OP_CONCAT ASSIGN _mark_ expression
{
- Location l = lexer.Location;
+ Location l = (Location)$4;
- /* TODO: $$ = new CompoundAssign (
- Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $4, l); */
+ // FIXME should be strings only
+ $$ = new CompoundAssign (
+ Binary.Operator.Addition, (Expression) $1, (Expression) $5, l);
}
- | prefixed_unary_expression ASSIGN ADDRESSOF expression
+ | prefixed_unary_expression ASSIGN ADDRESSOF _mark_ expression
{
ArrayList args = new ArrayList();
- Argument arg = new Argument ((Expression) $4, Argument.AType.Expression);
+ Argument arg = new Argument ((Expression) $5, Argument.AType.Expression);
args.Add (arg);
- New n = new New ((Expression) $1, (ArrayList) args, lexer.Location);
+ New n = new New ((Expression) $1, (ArrayList) args, (Location)$4);
n.isDelegate = true;
- $$ = new Assign ((Expression) $1, (Expression) n, lexer.Location);
+ $$ = new Assign ((Expression) $1, (Expression) n, (Location)$4);
}
;
;
boolean_expression
- : expression
+ : expression
+ {
+ Expression expr = (Expression) $1;
+ expr = SetValueRequiredFlag (expr);
+ $$ = expr;
+ }
;
type
| DOUBLE { $$ = TypeManager.system_double_expr; }
;
+directive_exp
+ : boolean_literal
+ | constant_expression _mark_ //FIXME: Fix for binary expression
+ {
+ Expression exp = (Expression) $1;
+ if(exp is SimpleName) {
+ string key = ((SimpleName)exp).Name;
+ if(constPreDir.Contains(key)) {
+ $$ = new BoolLiteral ((bool)constPreDir [key]);
+ }
+ }
+ else {
+ object o = ((Constant) exp).GetValue ();
+ bool temp = Convert.ToBoolean(o);
+ $$ = new BoolLiteral ((bool)temp);
+ // Report.Error (30580, (Location)$2, "value of Const used is not set");
+ }
+ }
+ ;
+
pp_directive
- : HASH IDENTIFIER OPEN_PARENS LITERAL_STRING COMMA LITERAL_INTEGER CLOSE_PARENS EOL
+ : HASH IDENTIFIER OPEN_PARENS LITERAL_STRING COMMA LITERAL_INTEGER CLOSE_PARENS _mark_ EOL
{
if(tokenizerController.IsAcceptingTokens)
{
if(in_external_source)
- Report.Error (30580, lexer.Location, "#ExternalSource directives may not be nested");
+ Report.Error (30580, (Location)$8, "#ExternalSource directives may not be nested");
else {
in_external_source = true;
}
}
}
- | HASH IDENTIFIER LITERAL_STRING EOL
+ | HASH IDENTIFIER LITERAL_STRING _mark_ EOL
{
if(tokenizerController.IsAcceptingTokens)
{
- string id = ($2 as string);
-
if(!($2 as string).ToLower().Equals("region"))
- Report.Error (30205, lexer.Location, "Invalid Pre-processor directive");
+ Report.Error (30205, (Location)$4, "Invalid Pre-processor directive");
else
{
++in_marked_region;
}
}
}
- | HASH END IDENTIFIER EOL
+ | HASH END IDENTIFIER _mark_ EOL
{
if(tokenizerController.IsAcceptingTokens)
{
if( ($3 as string).ToLower().Equals("externalsource")) {
if(!in_external_source)
- Report.Error (30578, lexer.Location, "'#End ExternalSource' must be preceded by a matching '#ExternalSource'");
+ Report.Error (30578, (Location)$4, "'#End ExternalSource' must be preceded by a matching '#ExternalSource'");
else {
in_external_source = false;
lexer.EffectiveSource = lexer.Source;
if(in_marked_region > 0)
--in_marked_region;
else
- Report.Error (30205, lexer.Location, "'#End Region' must be preceded by a matching '#Region'");
+ Report.Error (30205, (Location)$4, "'#End Region' must be preceded by a matching '#Region'");
}
else {
- Report.Error (29999, lexer.Location, "Unrecognized Pre-Processor statement");
+ Report.Error (29999, (Location)$4, "Unrecognized Pre-Processor statement");
}
}
}
- | HASH CONST IDENTIFIER ASSIGN boolean_literal EOL
+ | HASH CONST IDENTIFIER ASSIGN constant_expression _mark_ EOL
{
- if(tokenizerController.IsAcceptingTokens)
{
- //TODO;
+ Expression express = (Expression) $5;
+ if (express is Binary) {
+ // FIXME
+ // TODO
+ }
+ object o = ((Constant) express).GetValue ();
+ bool temp = Convert.ToBoolean(o);
+ constPreDir.Add($3,temp);
}
}
- | HASH IF
+ | HASH IF _mark_
{
IfElseStateMachine.Token tok = IfElseStateMachine.Token.IF;
ifElseStateMachine.HandleToken(tok);
}
catch(ApplicationException) {
- throw new MBASException(ifElseStateMachine.Error, lexer.Location, ifElseStateMachine.ErrString);
+ throw new MBASException(ifElseStateMachine.Error, (Location)$3, ifElseStateMachine.ErrString);
}
}
- boolean_literal opt_then EOL
+ directive_exp opt_then EOL
{
- HandleConditionalDirective(IfElseStateMachine.Token.IF, (BoolLiteral)$4);
+ //FIXME: Fix for constant expression
+
+ HandleConditionalDirective(IfElseStateMachine.Token.IF, (BoolLiteral)$5);
}
- | HASH ELSEIF
+ | HASH opt_elseif _mark_
{
IfElseStateMachine.Token tok = IfElseStateMachine.Token.ELSEIF;
try {
ifElseStateMachine.HandleToken(tok);
}
catch(ApplicationException) {
- throw new MBASException(ifElseStateMachine.Error, lexer.Location, ifElseStateMachine.ErrString);
+ throw new MBASException(ifElseStateMachine.Error, (Location)$3, ifElseStateMachine.ErrString);
}
}
- boolean_literal opt_then EOL
- {
- HandleConditionalDirective(IfElseStateMachine.Token.ELSEIF, (BoolLiteral)$4);
+ directive_exp opt_then EOL
+ {
+ //FIXME: Fix for constant expression
+
+ HandleConditionalDirective(IfElseStateMachine.Token.ELSEIF, (BoolLiteral)$5);
}
- | HASH ELSE
+ | HASH ELSE _mark_
{
IfElseStateMachine.Token tok = IfElseStateMachine.Token.ELSE;
try {
ifElseStateMachine.HandleToken(tok);
}
catch(ApplicationException) {
- throw new MBASException(ifElseStateMachine.Error, lexer.Location, ifElseStateMachine.ErrString);
+ throw new MBASException(ifElseStateMachine.Error, (Location)$3, ifElseStateMachine.ErrString);
}
}
EOL
{
HandleConditionalDirective(IfElseStateMachine.Token.ELSE, new BoolLiteral(true));
}
- | HASH END IF
+ | HASH END IF _mark_
{
+ /*FIXME: IF without ENDIF not working properly. Error line is not diplayed properly*/
+
IfElseStateMachine.Token tok = IfElseStateMachine.Token.ENDIF;
try {
ifElseStateMachine.HandleToken(tok);
}
catch(ApplicationException) {
- throw new MBASException(ifElseStateMachine.Error, lexer.Location, ifElseStateMachine.ErrString);
+ throw new MBASException(ifElseStateMachine.Error, (Location)$4, ifElseStateMachine.ErrString);
}
}
EOL
{
HandleConditionalDirective(IfElseStateMachine.Token.ENDIF, new BoolLiteral(false));
}
- | HASH error EOL
+ | HASH error _mark_ EOL
{
if(tokenizerController.IsAcceptingTokens)
- Report.Error(2999, lexer.Location, "Unrecognized Pre-Processor statement");
+ Report.Error(29999, (Location)$3, "Unrecognized Pre-Processor statement");
else
- Report.Warning (9999, lexer.Location, "Unrecognized Pre-Processor statement");
+ Report.Warning (29999, (Location)$3,"Unrecognized Pre-Processor statement");
}
;
+// Utility rule to save location information
+_mark_
+ : /* empty */
+ { $$ = lexer.Location; if (yyToken == Token.EOL) { $$ = new Location (lexer.Location.Row - 1, lexer.Location.Col); } }
+ ;
+
+// Changed to accept "Else If" also along with "ElseIf"
+opt_elseif
+ : ELSEIF
+ | ELSE IF
+ ;
+
+// Changed so as to check if every block is closed or not...
+opt_end_block
+ : opt_block_types
+ {
+ $$ = 2 + (int)$1 ;
+ }
+ | NEXT
+ {$$ = 1;}
+ | LOOP
+ {$$ = 2;}
+ | EOF
+ {$$ = Token.EOF;}
+ ;
+
+opt_block_types
+ : END IF
+ {$$ = 1;}
+ | END SUB
+ {$$ = 2;}
+ | END MODULE
+ {$$ = 3;}
+ | END NAMESPACE
+ {$$ = 4;}
+ | END CLASS
+ {$$ = 5;}
+ | END FUNCTION
+ {$$ = 6;}
+ | END STRUCTURE
+ {$$ = 7;}
+ | END ENUM
+ {$$ = 8;}
+ | END INTERFACE
+ {$$ = 9;}
+ | END PROPERTY
+ {$$ = 10;}
+ | END WITH
+ {$$ = 11;}
+ | END SYNCLOCK
+ {$$ = 12;}
+ | END TRY
+ {$$ = 13;}
+ | END WHILE
+ {$$ = 14;}
+ | END SELECT
+ {$$ = 15;}
+ | END SET
+ {$$ = 16;}
+ | END GET
+ {$$ = 17;}
+ /*In case of any new end block please add it here.. after END_GET as single token... and please continue the numbering from 17...*/
+ ;
+
%%
foreach (VariableDeclaration decl in variable_declarators){
Expression type = decl.type;
- if (implicit_block.AddVariable (type, decl.identifier, current_local_parameters, decl.Location) != null) {
+ if (implicit_block.AddVariable (type, decl.identifier, current_local_parameters, loc) != null) {
if (decl.expression_or_array_initializer != null){
if (inits == null)
inits = new ArrayList ();
public static void FixupArrayTypes (ArrayList vars)
{
- int varcount = vars.Count;
string dims;
foreach (VariableDeclaration var in vars) {
return (res);
}
+void push_into_stack(int BlockStart, Location l)
+{
+ end_of_block.Push(BlockStart);
+ loc_end_of_block.Push(l);
+}
+
+void pop_out_of_stack(int BlockEnd, Location l)
+{
+ if(BlockEnd != Token.EOF) {
+ int current = (int)end_of_block.Pop();
+ Location current_loc = (Location)loc_end_of_block.Pop();
+ if(BlockEnd != current) {
+ // Block end is missing
+ // eg: For 'Sub' BlockEnd should be 'End Sub'
+
+ if(error_end_blocks[BlockEnd,2] > error_end_blocks[current,2]) {
+ while(error_end_blocks[BlockEnd,2] > error_end_blocks[current,2])
+ {
+ if(error_end_blocks[BlockEnd,2] > error_end_blocks[current,2])
+ Report.Error(error_end_blocks[current,0],current_loc,"'"+end_blocks[current,0]+"' is not having matching '"+end_blocks[current,1]+"'");
+ current = (int)end_of_block.Pop();
+ current_loc = (Location)loc_end_of_block.Pop();
+ }
+ }
+
+ // Extra end is present, but works for lesser priority
+ // (for priority see opt_end_block opt_block_types return values
+ // eg: 'EndIf' without 'If' inside 'Sub'
+ // Also certain other errors like 'Sub' having a 'End Module' etc
+ // can be handled here
+
+ if(error_end_blocks[BlockEnd,2] < error_end_blocks[current,2]) {
+ Report.Error(error_end_blocks[BlockEnd,1],l,"'"+end_blocks[BlockEnd,1]+"' is not having a corresponding '"+end_blocks[BlockEnd,0]+"'");
+ end_of_block.Push(current);
+ loc_end_of_block.Push(current_loc);
+ }
+ // Extra end is present but with equal priorty
+
+ if((error_end_blocks[BlockEnd,2] == error_end_blocks[current,2]) && BlockEnd != current) {
+ while((error_end_blocks[BlockEnd,2] == error_end_blocks[current,2]) && BlockEnd != current) {
+ temp_block.Push(current);
+ loc_temp_block.Push(current_loc);
+ current = (int)end_of_block.Pop();
+ current_loc = (Location)loc_end_of_block.Pop();
+ }
+
+ if(BlockEnd == current) {
+ while(temp_block.Count !=0)
+ {
+ int lapse = (int) temp_block.Pop();
+ Location lapse_location = (Location)loc_temp_block.Pop();
+ Report.Error(error_end_blocks[lapse,0],lapse_location,"'"+end_blocks[lapse,0]+"' is not having matching '"+end_blocks[lapse,1]+"'");
+ }
+ }
+
+ else {
+ Report.Error(error_end_blocks[BlockEnd,1],l,"'"+end_blocks[BlockEnd,1]+"' is not having a corresponding '"+end_blocks[BlockEnd,0]+"'");
+ end_of_block.Push(current);
+ loc_end_of_block.Push(current_loc);
+ while(temp_block.Count !=0) {
+ int lapse = (int) temp_block.Pop();
+ Location lapse_location = (Location)loc_temp_block.Pop();
+ end_of_block.Push(lapse);
+ loc_end_of_block.Push(lapse_location);
+ }
+ }
+ }
+ }
+ }
+ else {
+ while(end_of_block.Count !=0) {
+ int lapse = (int) end_of_block.Pop();
+ Location lapse_location = (Location)loc_end_of_block.Pop();
+ Report.Error(error_end_blocks[lapse,0],lapse_location,"'"+end_blocks[lapse,0]+"' is not having matching '"+end_blocks[lapse,1]+"'");
+ }
+ }
+}
+
private void AddHandler (Expression evt_definition, Expression handler_exp)
{
AddHandler (current_block, evt_definition, handler_exp);
}
+/*
void CheckAttributeTarget (string a)
{
switch (a) {
break;
}
}
+*/
private void AddHandler (Block b, Expression evt_id, Expression handles_exp)
{
- Expression evt_target;
Location loc = lexer.Location;
Statement addhnd = (Statement) new AddHandler (evt_id,
handles_exp,
loc);
-
b.AddStatement (addhnd);
}
private void RemoveHandler (Block b, Expression evt_definition, Expression handler_exp)
{
- Expression evt_target;
Location loc = lexer.Location;
Statement rmhnd = (Statement) new RemoveHandler (evt_definition,
return ci;
}
+/*
void Error_ExpectingTypeName (Location l, Expression expr)
{
if (expr is Invocation){
Report.Error (-1, l, "Invalid Type definition");
}
}
+*/
+
+public static Expression SetLeftHandFlag (Expression expr) {
+ if (expr is Invocation) {
+ Invocation e = (Invocation) expr;
+ e.IsLeftHand = true;
+ return e;
+ } else if (expr is MemberAccess) {
+ MemberAccess e = (MemberAccess) expr;
+ e.IsLeftHand = true;
+ return e;
+ }
+
+ return expr;
+}
+
+public static Expression SetValueRequiredFlag (Expression expr) {
+ if (expr is Invocation) {
+ Invocation e = (Invocation) expr;
+ e.IsRetvalRequired = true;
+ expr = e;
+ return expr;
+ }
+ if (expr is Binary) {
+ Binary binary = (Binary) expr;
+ binary.Left = SetValueRequiredFlag (binary.Left);
+ binary.Right = SetValueRequiredFlag (binary.Right);
+ return binary;
+ }
+ if (expr is Unary) {
+ Unary unary = (Unary) expr;
+ unary.Expr = SetValueRequiredFlag (unary.Expr);
+ return unary;
+ }
+ return expr;
+}
+/*
static bool AlwaysAccept (MemberInfo m, object filterCriteria) {
return true;
}
+*/
private void ReportError9998()
{
tmp_blocks = new Stack();
with_stack = new Stack();
statement_stack = new Stack();
+ end_of_block = new Stack ();
+ loc_end_of_block = new Stack ();
+ temp_block = new Stack();
+ loc_temp_block = new Stack();
+
+ allow_global_attribs = true;
+ expecting_global_attribs = false;
+ expecting_local_attribs = false;
+ local_attrib_section_added = false;
UseExtendedSyntax = name.EndsWith(".mbs");
OptionExplicit = InitialOptionExplicit || UseExtendedSyntax;
ifElseStateMachine = new IfElseStateMachine();
tokenizerController = new TokenizerController(lexer);
- StringBuilder value = new StringBuilder ();
try {
- if (yacc_verbose_flag)
+ if (yacc_verbose_flag > 0)
yyparse (lexer, new yydebug.yyDebugSimple ());
else {
yyparse (lexer);