// Switch stack.
//
Stack switch_stack;
+
+ static public bool InitialOptionExplicit = false;
+ static public bool InitialOptionStrict = false;
+ static public bool InitialOptionCompareBinary = true;
+
+ bool OptionExplicit;
+ bool OptionStrict;
+ bool OptionCompareBinary;
bool UseExtendedSyntax; // for ".mbs" files
%token AS
%token ASSEMBLY
%token AUTO
+%token BINARY
%token BOOLEAN
%token BYREF
%token BYTE
%token CLASS
%token CLNG
%token COBJ
-//%token COMPARE
+%token COMPARE
%token CONST
%token CSHORT
%token CSNG
%token ERROR
%token EVENT
%token EXIT
-//%token EXPLICIT
+%token EXPLICIT
%token FALSE
%token FINALLY
%token FOR
%token NOTINHERITABLE
%token NOTOVERRIDABLE
%token OBJECT
+%token OFF
%token ON
%token OPTION
%token OPTIONAL
%token STATIC
%token STEP
%token STOP
+%token STRICT
%token STRING
%token STRUCTURE
%token SUB
%token SUMMARY // MonoBASIC extension
%token SYNCLOCK
+%token TEXT
%token THEN
%token THROW
%token TO
%%
compilation_unit
- : opt_imports_directives
+ : opt_option_directives
+ opt_imports_directives
opt_attributes
opt_declarations
EOF
{
- $$ = $3;
+ $$ = $4;
}
;
+opt_option_directives
+ : /* empty */
+ | option_directives
+ ;
+
+option_directives
+ : option_directive
+ | option_directives option_directive
+ ;
+
+option_directive
+ : option_explicit_directive
+ | option_strict_directive
+ | option_compare_directive
+ ;
+
+on_off
+ : /* empty */
+ {
+ $$ = (object)true;
+ }
+ | ON
+ {
+ $$ = (object)true;
+ }
+ | OFF
+ {
+ $$ = (object)false;
+ }
+ ;
+
+text_or_binary
+ : BINARY
+ {
+ $$ = (object)true;
+ }
+ | TEXT
+ {
+ $$ = (object)false;
+ }
+ ;
+
+option_explicit_directive
+ : OPTION EXPLICIT on_off EOL
+ {
+ if (!UseExtendedSyntax)
+ OptionExplicit = (bool)$3;
+ else
+ Report.Warning (
+ 9999, lexer.Location,
+ "In MonoBASIC extended syntax explicit declaration is always required. So OPTION EXPLICIT is deprecated");
+ }
+ ;
+
+
+option_strict_directive
+ : OPTION STRICT on_off EOL
+ {
+ if (!UseExtendedSyntax)
+ OptionStrict = (bool)$3;
+ else
+ Report.Warning (
+ 9999, lexer.Location,
+ "In MonoBASIC extended syntax strict assignability is always required. So OPTION STRICT is deprecated");
+ }
+ ;
+
+option_compare_directive
+ : OPTION COMPARE text_or_binary EOL
+ {
+ OptionCompareBinary = (bool)$3;
+ }
+ ;
+
opt_declarations
: /* empty */
| declarations
}
;
-qualified_identifier
+identifier
: IDENTIFIER
- | qualified_identifier DOT IDENTIFIER
+ | BINARY
+ | TEXT
+ | COMPARE
+ | EXPLICIT
+ | OFF
+ ;
+
+qualified_identifier
+ : identifier
+ | qualified_identifier DOT identifier
{
$$ = (($1).ToString ()) + "." + ($3.ToString ());
}
;
attribute_target
- : IDENTIFIER
+ : identifier
{
CheckAttributeTarget ((string) $1);
$$ = $1;
;
named_argument
- : IDENTIFIER ATTR_ASSIGN expression
+ : identifier ATTR_ASSIGN expression
{
$$ = new DictionaryEntry (
(string) $1,
;
class_declaration
- : CLASS IDENTIFIER EOL opt_class_base
+ : CLASS identifier EOL opt_class_base
{
Class new_class;
string name;
;
module_declaration
- : MODULE IDENTIFIER EOL
+ : MODULE identifier EOL
{
Module new_module;
string name;
;
sub_declaration
- : SUB IDENTIFIER OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS opt_evt_handler opt_implement_clause EOL
+ : SUB identifier OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS opt_evt_handler opt_implement_clause EOL
{
current_local_parameters = (Parameters) $4;
;
func_declaration
- : FUNCTION IDENTIFIER
+ : FUNCTION identifier
OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS AS type opt_implement_clause EOL
{
;
struct_declaration
- : STRUCTURE IDENTIFIER EOL
+ : STRUCTURE identifier EOL
opt_implement_clause
{
Struct new_struct;
;
event_declaration
- : EVENT IDENTIFIER AS type EOL
+ : EVENT identifier AS type EOL
{
VariableDeclaration var = new VariableDeclaration ((string) $2, (Expression) $4, lexer.Location);
CheckDef (current_container.AddEvent (e), e.Name, e.Location);
}
- | EVENT IDENTIFIER OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS EOL
- {
- throw new NotSupportedException();
- }
+// | EVENT identifier OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS EOL
+// {
+// throw new NotSupportedException();
+// }
;
enum_declaration
- : ENUM IDENTIFIER opt_type_spec EOL
+ : ENUM identifier opt_type_spec EOL
opt_enum_member_declarations
{
Location enum_location = lexer.Location;
;
enum_member_declaration
- : opt_attributes IDENTIFIER EOL
+ : opt_attributes identifier EOL
{
$$ = new VariableDeclaration ((string) $2, null, lexer.Location, (Attributes) $1);
}
- | opt_attributes IDENTIFIER
+ | opt_attributes identifier
{
$$ = lexer.Location;
}
;
interface_declaration
- : INTERFACE IDENTIFIER EOL
+ : INTERFACE identifier EOL
{
Interface new_interface;
string full_interface_name = MakeName ((string) $2);
;
interface_method_declaration
- : SUB IDENTIFIER
+ : SUB identifier
OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS EOL
{
$$ = new InterfaceMethod (TypeManager.system_void_expr, (string) $2, false,
(Parameters) $4, current_attributes, lexer.Location);
}
- | FUNCTION IDENTIFIER
+ | FUNCTION identifier
OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS AS type
{
$$ = new InterfaceMethod (
;
interface_property_declaration
- : PROPERTY IDENTIFIER
+ : PROPERTY identifier
OPEN_PARENS
opt_formal_parameter_list
CLOSE_PARENS opt_type_spec EOL
;
interface_event_declaration
- : opt_attributes opt_new EVENT type IDENTIFIER EOL
+ : opt_attributes opt_new EVENT type identifier EOL
{
$$ = new InterfaceEvent ((Expression) $4, (string) $5, (bool) $2, (Attributes) $1,
lexer.Location);
;
property_declaration
- : PROPERTY IDENTIFIER opt_property_parameters AS type opt_implement_clause EOL
+ : PROPERTY identifier opt_property_parameters AS type opt_implement_clause EOL
{
get_implicit_value_parameter_type = (Expression) $5;
get_implicit_value_parameter_name = (string) $2;
delegate_declaration
: DELEGATE SUB
- IDENTIFIER OPEN_PARENS
+ identifier OPEN_PARENS
opt_formal_parameter_list
CLOSE_PARENS
EOL
CheckDef (current_container.AddDelegate (del), del.Name, l);
}
| DELEGATE FUNCTION
- IDENTIFIER OPEN_PARENS
+ identifier OPEN_PARENS
opt_formal_parameter_list
CLOSE_PARENS AS type
{
fixed_parameter
: opt_attributes
opt_parameter_modifier
- IDENTIFIER opt_type_spec opt_variable_initializer
+ identifier opt_type_spec opt_variable_initializer
{
Parameter.Modifier pm = (Parameter.Modifier)$2;
bool opt_parm = ((pm & Parameter.Modifier.OPTIONAL) != 0);
;
parameter_array
- : PARAM_ARRAY IDENTIFIER opt_parens AS type
+ : PARAM_ARRAY identifier opt_parens AS type
{
$$ = new Parameter ((Expression) $5, (string) $2, Parameter.Modifier.PARAMS, null);
// note ("type must be a single-dimension array type");
{
AddHandler ((Expression) $2, (string) $5);
}
- | RAISEEVENT IDENTIFIER OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
+ | RAISEEVENT identifier OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
{
RaiseEvent ((string) $2, (ArrayList) $4);
}
;
labeled_statement
- : IDENTIFIER COLON
+ : identifier COLON
{
LabeledStatement labeled = new LabeledStatement ((string) $1, lexer.Location);
opt_identifier
: /* empty */ { $$ = null; }
- | IDENTIFIER
+ | identifier
;
catch_clause
;
catch_args
- : IDENTIFIER AS type
+ : identifier AS type
{
$$ = new DictionaryEntry ($3, $1);
}
;
constant_declarator
- : IDENTIFIER ASSIGN constant_expression
+ : identifier ASSIGN constant_expression
{
$$ = new VariableDeclaration ((string) $1, $3, lexer.Location);
}
;
variable_identifier
- : IDENTIFIER opt_array_name_modifier
+ : identifier opt_array_name_modifier
{
$$ = $1;
if ($2 != null)
;
member_access
- : primary_expression DOT IDENTIFIER
+ : primary_expression DOT identifier
{
$$ = new MemberAccess ((Expression) $1, (string) $3, lexer.Location);
}
- | predefined_type DOT IDENTIFIER
+ | predefined_type DOT identifier
{
$$ = new MemberAccess ((Expression) $1, (string) $3, lexer.Location);
}
}
$$ = new Invocation ((Expression) $1, (ArrayList) $3, lexer.Location);
}
- | MYBASE DOT IDENTIFIER OPEN_PARENS opt_expression_list CLOSE_PARENS
+ | MYBASE DOT identifier OPEN_PARENS opt_expression_list CLOSE_PARENS
{
BaseAccess ba = new BaseAccess ((string) $3, lexer.Location);
$$ = new Invocation ((Expression) ba, (ArrayList) $5, lexer.Location);
switch_stack = new Stack ();
UseExtendedSyntax = name.EndsWith(".mbs");
+ OptionExplicit = InitialOptionExplicit || UseExtendedSyntax;
+ OptionStrict = InitialOptionStrict || UseExtendedSyntax;
+ OptionCompareBinary = InitialOptionCompareBinary;
lexer = new Tokenizer (input, name, defines);
StringBuilder value = new StringBuilder ();
keywords.Add ("as", Token.AS);
keywords.Add ("assembly", Token.ASSEMBLY);
keywords.Add ("auto", Token.AUTO);
+ keywords.Add ("binary", Token.BINARY);
keywords.Add ("boolean", Token.BOOLEAN);
keywords.Add ("byref", Token.BYREF);
keywords.Add ("byte", Token.BYTE);
keywords.Add ("class", Token.CLASS);
keywords.Add ("clng", Token.CLNG);
keywords.Add ("cobj", Token.COBJ);
- //keywords.Add ("compare", Token.COMPARE);
+ keywords.Add ("compare", Token.COMPARE);
keywords.Add ("const", Token.CONST);
keywords.Add ("cshort", Token.CSHORT);
keywords.Add ("csng", Token.CSNG);
keywords.Add ("error", Token.ERROR);
keywords.Add ("event", Token.EVENT);
keywords.Add ("exit", Token.EXIT);
- //keywords.Add ("explicit", Token.EXPLICIT);
+ keywords.Add ("explicit", Token.EXPLICIT);
keywords.Add ("false", Token.FALSE);
keywords.Add ("finally", Token.FINALLY);
keywords.Add ("for", Token.FOR);
keywords.Add ("notinheritable", Token.NOTINHERITABLE);
keywords.Add ("notoverridable", Token.NOTOVERRIDABLE);
keywords.Add ("object", Token.OBJECT);
+ keywords.Add ("off", Token.OFF);
keywords.Add ("on", Token.ON);
keywords.Add ("option", Token.OPTION);
keywords.Add ("optional", Token.OPTIONAL);
keywords.Add ("static", Token.STATIC);
keywords.Add ("step", Token.STEP);
keywords.Add ("stop", Token.STOP);
+ keywords.Add ("strict", Token.STRICT);
keywords.Add ("string", Token.STRING);
keywords.Add ("structure", Token.STRUCTURE);
keywords.Add ("sub", Token.SUB);
keywords.Add ("synclock", Token.SYNCLOCK);
+ keywords.Add ("text", Token.TEXT);
keywords.Add ("then", Token.THEN);
keywords.Add ("throw", Token.THROW);
keywords.Add ("to", Token.TO);
string id;
if ((id = GetIdentifier(c)) == null)
break;
+ val = id;
if (is_keyword(id))
return getKeyword(id);
- val = id;
return Token.IDENTIFIER;
}