Browse files

Move to old-code

svn path=/old-code/; revision=156236
  • Loading branch information...
1 parent 49c1f52 commit 13243bc72cd536dfae56536a63d97d658d055f4f @migueldeicaza migueldeicaza committed Apr 27, 2010
Showing with 12,472 additions and 0 deletions.
  1. +5 −0 monotalk/AUTHORS
  2. +64 −0 monotalk/ChangeLog
  3. +17 −0 monotalk/Indexer/App.cs
  4. +58 −0 monotalk/Indexer/Indexer.cs
  5. +24 −0 monotalk/Indexer/Makefile
  6. +181 −0 monotalk/Indexer/SourceDB.cs
  7. +3,421 −0 monotalk/Indexer/cs-parser.cs
  8. +1,904 −0 monotalk/Indexer/cs-parser.jay
  9. +1,869 −0 monotalk/Indexer/cs-tokenizer.cs
  10. +61 −0 monotalk/Indexer/genericparser.cs
  11. +128 −0 monotalk/Indexer/location.cs
  12. +359 −0 monotalk/Indexer/report.cs
  13. +11 −0 monotalk/Makefile
  14. +11 −0 monotalk/NEWS
  15. +1 −0 monotalk/ObjectBrowser/.cvsignore
  16. +219 −0 monotalk/ObjectBrowser/DemoApp.cs
  17. +283 −0 monotalk/ObjectBrowser/FindBar.cs
  18. +35 −0 monotalk/ObjectBrowser/Hierarchy.cs
  19. +70 −0 monotalk/ObjectBrowser/Makefile
  20. +320 −0 monotalk/ObjectBrowser/MemberRecord.cs
  21. +360 −0 monotalk/ObjectBrowser/MemberRecordFactory.cs
  22. +162 −0 monotalk/ObjectBrowser/MemberView.cs
  23. +712 −0 monotalk/ObjectBrowser/ObjectBrowser.cs
  24. +14 −0 monotalk/ObjectBrowser/README
  25. +12 −0 monotalk/ObjectBrowser/TypePool.cs
  26. +414 −0 monotalk/ObjectBrowser/demoapp.glade
  27. +55 −0 monotalk/ObjectBrowser/objectbrowser.schema
  28. +1 −0 monotalk/README
  29. +1 −0 monotalk/SourceView/.cvsignore
  30. +125 −0 monotalk/SourceView/Config.cs
  31. +98 −0 monotalk/SourceView/DemoApp.cs
  32. +473 −0 monotalk/SourceView/Highlights.cs
  33. +25 −0 monotalk/SourceView/Makefile
  34. +126 −0 monotalk/SourceView/Pattern.cs
  35. +129 −0 monotalk/SourceView/SourceView.cs
  36. +23 −0 monotalk/SourceView/Style.cs
  37. +191 −0 monotalk/SourceView/demoapp.glade
  38. +74 −0 monotalk/SourceView/sourceview.config
  39. +74 −0 monotalk/SourceView/sourceview.dark.config
  40. +49 −0 monotalk/SourceView/sourceview.glade
  41. +312 −0 monotalk/SourceView/svconftool
  42. +1 −0 monotalk/art/.cvsignore
  43. BIN monotalk/art/about.png
  44. BIN monotalk/art/abstract.png
  45. BIN monotalk/art/class.png
  46. BIN monotalk/art/constructor.png
  47. BIN monotalk/art/enum.png
  48. BIN monotalk/art/event.png
  49. BIN monotalk/art/field.png
  50. BIN monotalk/art/interface.png
  51. BIN monotalk/art/method.png
  52. BIN monotalk/art/prop-read-only.png
  53. BIN monotalk/art/prop-read-write.png
  54. BIN monotalk/art/prop-write-only.png
  55. BIN monotalk/art/sealed.png
  56. BIN monotalk/art/transparent.png
View
5 monotalk/AUTHORS
@@ -0,0 +1,5 @@
+Radek Doulik rodo@matfyz.cz
+
+Contributors:
+
+Gonzalo Paniagua Javier gonzalo@ximian.com
View
64 monotalk/ChangeLog
@@ -0,0 +1,64 @@
+2003-02-20 Radek Doulik <rodo@ximian.com>
+
+ * ObjectBrowser/ObjectBrowser.cs: don't hardcode SourceView font,
+ it could be set from gtkrc
+
+2003-01-23 Gonzalo Paniagua Javier <gonzalo@ximian.com>
+
+ * ObjectBrowser/DemoApp.cs: use [GladeWidget] for window.
+
+ * ObjectBrowser/demoapp.glade: connected delete_event.
+
+2003-01-23 Radek Doulik <rodo@ximian.com>
+
+ * ObjectBrowser/ObjectBrowser.cs: nest types only under types in
+ the same assembly
+
+2002-12-08 Radek Doulik <rodo@ximian.com>
+
+ * ObjectBrowser/FindBar.cs: filter SpecialNames
+
+2003-01-15 Gonzalo Paniagua Javier <gonzalo@ximian.com>
+
+ * ObjectBrowser/FindBar.cs: unambiguated Thread to make it compile with
+ latest mcs.
+
+2002-12-03 Gonzalo Paniagua Javier <gonzalo@ximian.com>
+
+ * ObjectBrowser/MemberView.cs: avoid critical message when refreshing
+ the members view.
+
+2002-11-21 Radek Doulik <rodo@ximian.com>
+
+ * ObjectBrowser/DemoApp.cs: added View/Full Type Names check menu
+ item
+
+ * ObjectBrowser/MemberRecord.cs: added TypeAliases::FullNames
+ field, specifies if to return full type names
+
+2002-11-20 Radek Doulik <rodo@ximian.com>
+
+ * ObjectBrowser/MemberRecord.cs: use patch from Gonzalo, slightly
+ modified, it introduces short type aliases, I made it work with
+ arrays as well and extracted to TypeAliases class with
+ indexer. Also parameter names are displayed now.
+
+2002-11-19 Radek Doulik <rodo@ximian.com>
+
+ * ObjectBrowser/DemoApp.cs: load assembly from path as well as by
+ name
+ try LoadFrom before Load, suggested by Gonzalo
+
+ * ObjectBrowser/ObjectBrowser.cs: show only public members by
+ default, set type and flags just to 'all' factory, which forwards
+ it to others
+
+ * ObjectBrowser/MemberRecordFactory.cs: fixed Load methods to
+ detect type == null, implemented AllRecordFactory::Flags property
+
+ * ObjectBrowser/MemberRecord.cs: implemented EventRecord::Label
+ prop, fixed empty constructors to play nice with fixed mcs
+
+ * ObjectBrowser/DemoApp.cs: derive from Gnome.Program, use glade
+ for UI, added View menu with scope changing check and radio items
+
View
17 monotalk/Indexer/App.cs
@@ -0,0 +1,17 @@
+using System;
+using Monotalk.Indexer;
+
+public class App
+{
+ public static int Main (string[] args)
+ {
+ Indexer indexer = new Indexer ();
+
+ foreach (string filename in args) {
+ Console.WriteLine ("\nparse: " + filename);
+ indexer.Parse (filename);
+ }
+
+ return 0;
+ }
+}
View
58 monotalk/Indexer/Indexer.cs
@@ -0,0 +1,58 @@
+namespace Monotalk.Indexer
+{
+ using System;
+ using System.IO;
+ using System.Collections;
+
+ using Monotalk;
+ using Monotalk.CSharp;
+
+ public class Indexer
+ {
+ public SourceDB db = new SourceDB ();
+ Hashtable fileIDs = new Hashtable ();
+ Hashtable fileNames = new Hashtable ();
+ int files = 0;
+
+ public string this [int ID] {
+ get {
+ return (string) fileNames [ID];
+ }
+ }
+
+ public void Parse (string filename)
+ {
+ CSharpParser parser;
+ ArrayList defines = new ArrayList ();
+ Stream input;
+ int id;
+
+ if (fileIDs [filename] == null) {
+ fileIDs [filename] = (object)files;
+ id = (int)fileIDs [filename];
+ fileNames [id] = filename;
+ files ++;
+ } else
+ id = (int) fileIDs [filename];
+
+ try {
+ input = File.OpenRead (filename);
+ } catch {
+ Console.WriteLine ("Source file '" + filename + "' could not be opened");
+ return;
+ }
+
+ StreamReader reader = new StreamReader (input);
+
+ parser = new CSharpParser (reader, filename, defines, db, id);
+ //parser.yacc_verbose = yacc_verbose;
+ try {
+ parser.parse ();
+ } catch (Exception ex) {
+ Console.WriteLine ("Compilation aborted: " + ex);
+ } finally {
+ input.Close ();
+ }
+ }
+ }
+}
View
24 monotalk/Indexer/Makefile
@@ -0,0 +1,24 @@
+MCS=mcs
+
+ASSEMBLIES=
+
+SOURCES=\
+ cs-tokenizer.cs \
+ cs-parser.cs \
+ genericparser.cs \
+ location.cs \
+ report.cs \
+ App.cs \
+ Indexer.cs \
+ SourceDB.cs \
+
+all: indexer.exe
+
+indexer.exe: $(SOURCES)
+ $(MCS) -o $@ $(ASSEMBLIES) $(SOURCES)
+
+clean:
+ rm -f *.exe
+
+cs-parser.cs: cs-parser.jay
+ ./jay -ctv < skeleton.cs $^ > $@ || (rm $@; exit 1)
View
181 monotalk/Indexer/SourceDB.cs
@@ -0,0 +1,181 @@
+using Monotalk.CSharp;
+
+namespace Monotalk.Indexer
+{
+ using System;
+ using System.Collections;
+
+ public class Part
+ {
+ public int fileID;
+ public int startRow, endRow, startCol, endCol;
+
+ public Part (int id, int sr, int er)
+ {
+ fileID = id;
+ startRow = sr;
+ endRow = er;
+ }
+
+ public Part (int id, TokenValue tv)
+ {
+ fileID = id;
+ startRow = tv.sRow;
+ endRow = tv.eRow;
+ }
+ }
+
+ public class MemberDB
+ {
+ Hashtable members;
+
+ public MemberDB ()
+ {
+ members = new Hashtable ();
+ }
+
+ public Part this [string member] {
+ set {
+ members [member] = value;
+ }
+ get {
+ return (Part) members [member];
+ }
+ }
+ }
+
+ public class TypeRecord
+ {
+ public string name;
+ public MemberDB db;
+ public Part part;
+
+ public TypeRecord (string type)
+ {
+ db = new MemberDB ();
+ name = type;
+ }
+
+ public TypeRecord (string type, Part p) : this (type)
+ {
+ part = p;
+ }
+
+ public MemberDB MemberDB {
+ get {
+ return db;
+ }
+ }
+ }
+
+ public class TypeDB
+ {
+ Hashtable types;
+
+ public TypeDB ()
+ {
+ types = new Hashtable ();
+ }
+
+ public TypeRecord this [string type] {
+ set {
+ types [type] = value;
+ }
+ get {
+ return (TypeRecord) types [type];
+ }
+ }
+ }
+
+ public class SourceDB
+ {
+ private Hashtable namespaces;
+ private int types = 0;
+ private int members = 0;
+
+ public SourceDB ()
+ {
+ namespaces = new Hashtable ();
+ }
+
+ public int Members {
+ get {
+ return members;
+ }
+ }
+
+ public int Types {
+ get {
+ return types;
+ }
+ }
+
+ public TypeDB this [string Namespace] {
+ set {
+ namespaces [Namespace] = value;
+ }
+ get {
+ return (TypeDB) namespaces [Namespace];
+ }
+ }
+
+ public Part LookupMember (string Namespace, string type, string member)
+ {
+ TypeDB tdb = namespaces [Namespace] as TypeDB;
+
+ Console.WriteLine ("lookup {0}.{1}.{2}", Namespace, type, member);
+ if (tdb != null) {
+ TypeRecord tr = tdb [type];
+ if (tr != null)
+ return tr.MemberDB [member];
+ }
+
+ return null;
+ }
+
+ public Part LookupType (string Namespace, string type)
+ {
+ TypeDB tdb = namespaces [Namespace] as TypeDB;
+
+ Console.WriteLine ("lookup namespace: {0} type: {1}", Namespace, type);
+ if (tdb != null) {
+ TypeRecord tr = tdb [type];
+ if (tr != null)
+ return tr.part;
+ }
+
+ return null;
+ }
+
+ public void AddMember (string Namespace, string type, string member, Part part)
+ {
+ TypeDB tdb = this [Namespace] as TypeDB;
+
+ Console.WriteLine ("add {0}.{1}.{2}", Namespace, type, member);
+ if (tdb == null)
+ tdb = this [Namespace] = new TypeDB ();
+ TypeRecord tr = tdb [type];
+ if (tr == null) {
+ tr = tdb [type] = new TypeRecord (type);
+ types ++;
+ }
+ if (tr.MemberDB [member] == null)
+ members ++;
+ tr.MemberDB [member] = part;
+ }
+
+ public void AddType (string Namespace, string type, Part part)
+ {
+ TypeDB tdb = this [Namespace] as TypeDB;
+
+ Console.WriteLine ("add type namespace: {0} type: {1}", Namespace, type);
+ if (tdb == null)
+ tdb = this [Namespace] = new TypeDB ();
+ TypeRecord tr = tdb [type];
+ if (tr == null)
+ tdb [type] = new TypeRecord (type, part);
+ else
+ tr.part = part;
+ }
+ }
+}
View
3,421 monotalk/Indexer/cs-parser.cs
3,421 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
1,904 monotalk/Indexer/cs-parser.jay
@@ -0,0 +1,1904 @@
+%{
+//
+// cs-parser.jay: The Parser for the C# compiler
+//
+// Authors: Miguel de Icaza (miguel@gnu.org)
+// Ravi Pratap (ravi@ximian.com)
+// Radek Doulik (rodo@matfyz.cz)
+//
+// Licensed under the terms of the GNU GPL
+//
+// (C) 2001 Ximian, Inc (http://www.ximian.com)
+// (C) 2003 Radek Doulik
+
+using System.Text;
+using System.IO;
+using System;
+
+namespace Monotalk.CSharp
+{
+ using System.Collections;
+ using Monotalk.Languages;
+ using Monotalk.Indexer;
+
+ /// <summary>
+ /// The C# Parser
+ /// </summary>
+ public class CSharpParser : GenericParser
+ {
+
+ Stack Namespaces;
+ string Namespace;
+
+ Stack Types;
+ string type;
+
+ Stack Rows;
+
+ SourceDB db;
+ int fileID;
+
+ bool modStatic;
+%}
+
+%token EOF
+%token NONE /* This token is never returned by our lexer */
+%token ERROR // This is used not by the parser, but by the tokenizer.
+ // do not remove.
+
+/*
+ *These are the C# keywords
+ */
+%token ABSTRACT
+%token AS
+%token ADD
+%token ASSEMBLY
+%token BASE
+%token BOOL
+%token BREAK
+%token BYTE
+%token CASE
+%token CATCH
+%token CHAR
+%token CHECKED
+%token <TokenValue> CLASS
+%token CONST
+%token CONTINUE
+%token DECIMAL
+%token DEFAULT
+%token DELEGATE
+%token DO
+%token DOUBLE
+%token ELSE
+%token ENUM
+%token EVENT
+%token EXPLICIT
+%token EXTERN
+%token FALSE
+%token FINALLY
+%token FIXED
+%token FLOAT
+%token FOR
+%token FOREACH
+%token GOTO
+%token IF
+%token IMPLICIT
+%token IN
+%token <TokenValue> INT
+%token INTERFACE
+%token INTERNAL
+%token IS
+%token LOCK
+%token LONG
+%token NAMESPACE
+%token NEW
+%token NULL
+%token OBJECT
+%token OPERATOR
+%token OUT
+%token OVERRIDE
+%token PARAMS
+%token PRIVATE
+%token PROTECTED
+%token PUBLIC
+%token READONLY
+%token REF
+%token RETURN
+%token REMOVE
+%token SBYTE
+%token SEALED
+%token SHORT
+%token SIZEOF
+%token STACKALLOC
+%token STATIC
+%token STRING
+%token STRUCT
+%token SWITCH
+%token THIS
+%token THROW
+%token TRUE
+%token TRY
+%token TYPEOF
+%token UINT
+%token ULONG
+%token UNCHECKED
+%token UNSAFE
+%token USHORT
+%token USING
+%token VIRTUAL
+%token <TokenValue> VOID
+%token VOLATILE
+%token WHILE
+
+/* simple tokens defined in tokenizer because we need position info for them */
+%token <TokenValue> OPEN_BRACE
+%token <TokenValue> CLOSE_BRACE
+%token <TokenValue> OPEN_PARENS
+%token <TokenValue> CLOSE_PARENS
+%token <TokenValue> OPEN_BRACKET
+%token <TokenValue> CLOSE_BRACKET
+%token <TokenValue> SEMICOLON
+%token <TokenValue> COLON
+
+/* C# keywords which are not really keywords */
+%token GET "get"
+%token SET "set"
+
+/* C# single character operators/punctuation. */
+%token DOT "."
+%token COMMA ","
+%token TILDE "~"
+
+%token PLUS "+"
+%token MINUS "-"
+%token BANG "!"
+%token ASSIGN "="
+%token OP_LT "<"
+%token OP_GT ">"
+%token BITWISE_AND "&"
+%token BITWISE_OR "|"
+%token STAR "*"
+%token PERCENT "%"
+%token DIV "/"
+%token CARRET "^"
+%token INTERR "?"
+
+/* C# multi-character operators. */
+%token OP_INC "++"
+%token OP_DEC "--"
+%token OP_SHIFT_LEFT "<<"
+%token OP_SHIFT_RIGHT ">>"
+%token OP_LE "<="
+%token OP_GE ">="
+%token OP_EQ "=="
+%token OP_NE "!="
+%token OP_AND "&&"
+%token OP_OR "||"
+%token OP_MULT_ASSIGN "*="
+%token OP_DIV_ASSIGN "/="
+%token OP_MOD_ASSIGN "%="
+%token OP_ADD_ASSIGN "+="
+%token OP_SUB_ASSIGN "-="
+%token OP_SHIFT_LEFT_ASSIGN "<<="
+%token OP_SHIFT_RIGHT_ASSIGN ">>="
+%token OP_AND_ASSIGN "&="
+%token OP_XOR_ASSIGN "^="
+%token OP_OR_ASSIGN "|="
+%token OP_PTR "->"
+
+/* Numbers */
+%token LITERAL_INTEGER "int literal"
+%token LITERAL_FLOAT "float literal"
+%token LITERAL_DOUBLE "double literal"
+%token LITERAL_DECIMAL "decimal literal"
+%token LITERAL_CHARACTER "character literal"
+%token LITERAL_STRING "string literal"
+
+%token <TokenValue> IDENTIFIER
+
+/* Add precedence rules to solve dangling else s/r conflict */
+%nonassoc LOWPREC
+%nonassoc IF
+%nonassoc ELSE
+%right ASSIGN
+%left OP_OR
+%left OP_AND
+%left BITWISE_OR
+%left BITWISE_AND
+%left OP_SHIFT_LEFT OP_SHIFT_RIGHT
+%left PLUS MINUS
+%left STAR DIV PERCENT
+%right BANG CARRET UMINUS
+%nonassoc OP_INC OP_DEC
+%left OPEN_PARENS
+%left OPEN_BRACKET OPEN_BRACE
+%left DOT
+%nonassoc HIGHPREC
+
+/* type non terminals to avoid casting */
+%type <TokenValue> attribute_section attribute_sections builtin_types class_body constructor_body constructor_declaration constructor_declarator dim_separators fixed_parameter fixed_parameters formal_parameter_list integral_type method_body method_header member_name modifier modifiers opt_attributes opt_constructor_initializer opt_dim_separators opt_modifiers opt_formal_parameter_list opt_rank_specifier opt_semicolon qualified_identifier parameter_array rank_specifier rank_specifiers type variable_declarator variable_declarators variable_initializer
+%start compilation_unit
+%%
+
+compilation_unit
+ : outer_declarations opt_EOF
+ | outer_declarations attribute_sections opt_EOF
+ | attribute_sections opt_EOF
+ | opt_EOF /* allow empty files */
+ ;
+
+opt_EOF
+ : /* empty */
+ | EOF
+ ;
+
+outer_declarations
+ : outer_declaration
+ | outer_declarations outer_declaration
+ ;
+
+outer_declaration
+ : using_directive
+ | namespace_member_declaration
+ ;
+
+using_directives
+ : using_directive
+ | using_directives using_directive
+ ;
+
+using_directive
+ : using_alias_directive
+ | using_namespace_directive
+ ;
+
+using_alias_directive
+ : USING IDENTIFIER ASSIGN
+ namespace_or_type_name SEMICOLON
+ ;
+
+using_namespace_directive
+ : USING namespace_name SEMICOLON
+ ;
+
+//
+// Strictly speaking, namespaces don't have attributes but
+// we parse global attributes along with namespace declarations and then
+// detach them
+//
+namespace_declaration
+ : opt_attributes NAMESPACE qualified_identifier
+ {
+ Namespace = Namespace + (Namespace.Length > 0 ? "." : "") + $3.val.s;
+ Namespaces.Push ($3.val.s.Length);
+ }
+ namespace_body opt_semicolon
+ {
+ int idx = (int) Namespaces.Pop ();
+ Namespace = Namespace.Remove (Namespace.Length - idx, idx);
+ }
+ ;
+
+opt_semicolon
+ : { $$ = new TokenValue (); }
+ | SEMICOLON
+ ;
+
+opt_comma
+ : /* empty */
+ | COMMA
+ ;
+
+qualified_identifier
+ : IDENTIFIER
+ | qualified_identifier DOT IDENTIFIER {
+ $<TokenValue>$.val = $1.val.s + "." + $3.val.s; }
+ ;
+
+
+namespace_name
+ : namespace_or_type_name
+ ;
+
+namespace_body
+ : OPEN_BRACE
+ opt_using_directives
+ opt_namespace_member_declarations
+ CLOSE_BRACE
+ {
+ }
+ ;
+
+opt_using_directives
+ : /* empty */
+ | using_directives
+ ;
+
+opt_namespace_member_declarations
+ : /* empty */
+ | namespace_member_declarations
+ ;
+
+namespace_member_declarations
+ : namespace_member_declaration
+ | namespace_member_declarations namespace_member_declaration
+ ;
+
+namespace_member_declaration
+ : type_declaration
+ | namespace_declaration
+ ;
+
+type_declaration
+ : class_declaration
+ | struct_declaration
+ | interface_declaration
+ | enum_declaration
+ | delegate_declaration
+//
+// Enable this when we have handled all errors, because this acts as a generic fallback
+//
+// | error {
+// Report.Error (1518, lexer.Location, "Expected class, struct, interface, enum or delegate");
+// }
+ ;
+
+//
+// Attributes 17.2
+//
+
+opt_attributes
+ : /* empty */ { $$ = new TokenValue (); }
+ | attribute_sections
+ ;
+
+attribute_sections
+ : attribute_section
+ | attribute_sections attribute_section
+ {
+ $1.Update ($2);
+ }
+ ;
+
+attribute_section
+ : OPEN_BRACKET attribute_target_specifier attribute_list opt_comma CLOSE_BRACKET
+ {
+ $1.Update ($5);
+ }
+ | OPEN_BRACKET attribute_list opt_comma CLOSE_BRACKET
+ {
+ $1.Update ($4);
+ }
+ ;
+
+attribute_target_specifier
+ : attribute_target COLON
+ {
+ $$ = $1;
+ }
+ ;
+
+attribute_target
+ : IDENTIFIER
+ {
+ $$ = $1;
+ }
+ | EVENT { $$ = "event"; }
+ | RETURN { $$ = "return"; }
+ ;
+
+attribute_list
+ : attribute
+ | attribute_list COMMA attribute
+ ;
+
+attribute
+ : attribute_name
+ opt_attribute_arguments
+ ;
+
+attribute_name
+ : type_name { /* reserved attribute name or identifier: 17.4 */ }
+ ;
+
+opt_attribute_arguments
+ : /* empty */ { $$ = null; }
+ | OPEN_PARENS attribute_arguments CLOSE_PARENS
+ ;
+
+
+attribute_arguments
+ : opt_positional_argument_list
+ | positional_argument_list COMMA named_argument_list
+ | named_argument_list
+ ;
+
+
+opt_positional_argument_list
+ : /* empty */ { $$ = null; }
+ | positional_argument_list
+ ;
+
+positional_argument_list
+ : expression
+ | positional_argument_list COMMA expression
+ ;
+
+named_argument_list
+ : named_argument
+ | named_argument_list COMMA named_argument
+ ;
+
+named_argument
+ : IDENTIFIER ASSIGN expression
+ ;
+
+
+class_body
+ : OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
+ {
+ $1.Update ($3);
+ }
+ ;
+
+opt_class_member_declarations
+ : /* empty */
+ | class_member_declarations
+ ;
+
+class_member_declarations
+ : class_member_declaration
+ | class_member_declarations
+ class_member_declaration
+ ;
+
+class_member_declaration
+ : constant_declaration // done
+ | field_declaration // done
+ | method_declaration // done
+ | property_declaration // done
+ | event_declaration // done
+ | indexer_declaration // done
+ | operator_declaration // done
+ | constructor_declaration // done
+ | destructor_declaration // done
+ | type_declaration
+ ;
+
+struct_declaration
+ : opt_attributes
+ opt_modifiers
+ STRUCT IDENTIFIER
+ opt_class_base
+ struct_body
+ opt_semicolon
+ ;
+
+struct_body
+ : OPEN_BRACE opt_struct_member_declarations CLOSE_BRACE
+ ;
+
+opt_struct_member_declarations
+ : /* empty */
+ | struct_member_declarations
+ ;
+
+struct_member_declarations
+ : struct_member_declaration
+ | struct_member_declarations struct_member_declaration
+ ;
+
+struct_member_declaration
+ : constant_declaration
+ | field_declaration
+ | method_declaration
+ | property_declaration
+ | event_declaration
+ | indexer_declaration
+ | operator_declaration
+ | constructor_declaration
+ | type_declaration
+
+ /*
+ * This is only included so we can flag error 575:
+ * destructors only allowed on class types
+ */
+ | destructor_declaration
+ ;
+
+constant_declaration
+ : opt_attributes
+ opt_modifiers
+ CONST
+ type
+ constant_declarators
+ SEMICOLON
+ ;
+
+constant_declarators
+ : constant_declarator
+ | constant_declarators COMMA constant_declarator
+ ;
+
+constant_declarator
+ : IDENTIFIER ASSIGN constant_expression
+ ;
+
+field_declaration
+ : opt_attributes
+ opt_modifiers
+ type
+ variable_declarators
+ SEMICOLON
+ {
+ $1.Update ($2);
+ $1.Update ($3);
+ $1.Update ($5);
+ //Console.WriteLine ("fi {0}", $2);
+ foreach (string name in $4.val.s.Split (','))
+ db.AddMember (Namespace, type, name, new Part (fileID, $1));
+ }
+ ;
+
+variable_declarators
+ : variable_declarator
+ | variable_declarators COMMA variable_declarator
+ {
+ $1.Update ($3, $1.val.s + "," + $3.val.s);
+ }
+ ;
+
+variable_declarator
+ : IDENTIFIER ASSIGN variable_initializer
+ {
+ $1.Update ($3);
+ }
+ | IDENTIFIER
+ ;
+
+variable_initializer
+ : expression
+ | array_initializer
+ | STACKALLOC type OPEN_BRACKET expression CLOSE_BRACKET
+ ;
+
+method_declaration
+ : method_header
+ method_body
+ {
+ $1.Update ($2);
+ db.AddMember (Namespace, type, $1, new Part (fileID, $1));
+ }
+ ;
+
+opt_error_modifier
+ : /* empty */
+ | modifiers
+ ;
+
+method_header
+ : opt_attributes
+ opt_modifiers
+ type
+ member_name
+ OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
+ {
+ $1.Update ($2);
+ $1.Update ($3);
+ $1.Update ($7, $4.val.s + " (" + $6.val.s + "), " + $3.val.s);
+ }
+ | opt_attributes
+ opt_modifiers
+ VOID
+ member_name
+ OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
+ {
+ $1.Update ($2);
+ $1.Update ($3);
+ $1.Update ($7, $4.val.s + " (" + $6.val.s + "), void");
+ }
+ ;
+
+method_body
+ : block
+ | SEMICOLON
+ ;
+
+opt_formal_parameter_list
+ : /* empty */ { $$ = new TokenValue (); }
+ | formal_parameter_list
+ ;
+
+formal_parameter_list
+ : fixed_parameters
+ | fixed_parameters COMMA parameter_array { $<TokenValue>$.val = $1.val.s + ", " + $3.val.s; }
+ | parameter_array
+ ;
+
+fixed_parameters
+ : fixed_parameter
+ | fixed_parameters COMMA fixed_parameter { $<TokenValue>$.val = $1.val.s + ", " + $3.val.s; }
+ ;
+
+fixed_parameter
+ : opt_attributes
+ opt_parameter_modifier
+ type
+ IDENTIFIER
+ {
+ $<TokenValue>$.val = $3.val.s + " " + $4.val.s;
+ }
+ ;
+
+opt_parameter_modifier
+ : /* empty */ { $$ = new TokenValue (); }
+ | parameter_modifier
+ ;
+
+parameter_modifier
+ : REF
+ | OUT
+ ;
+
+parameter_array
+ : opt_attributes PARAMS type IDENTIFIER
+ ;
+
+member_name
+ : qualified_identifier
+ ;
+
+property_declaration
+ : opt_attributes
+ opt_modifiers
+ type
+ member_name
+ {
+ Rows.Push (lexer.Location.Row);
+ }
+ OPEN_BRACE
+ {
+ lexer.PropertyParsing = true;
+ }
+ accessor_declarations
+ {
+ lexer.PropertyParsing = false;
+ }
+ CLOSE_BRACE
+ {
+ db.AddMember (Namespace, type, $3.val.s + " " + $4.val.s, new Part (fileID, (int) Rows.Pop (), lexer.Location.Row));
+ }
+ ;
+
+accessor_declarations
+ : get_accessor_declaration opt_set_accessor_declaration
+ | set_accessor_declaration opt_get_accessor_declaration
+ ;
+
+opt_get_accessor_declaration
+ : /* empty */ { $$ = null; }
+ | get_accessor_declaration
+ ;
+
+opt_set_accessor_declaration
+ : /* empty */ { $$ = null; }
+ | set_accessor_declaration
+ ;
+
+get_accessor_declaration
+ : opt_attributes GET
+ {
+ lexer.PropertyParsing = false;
+ }
+ accessor_body
+ {
+ lexer.PropertyParsing = true;
+ }
+ ;
+
+set_accessor_declaration
+ : opt_attributes SET
+ {
+ lexer.PropertyParsing = false;
+ }
+ accessor_body
+ {
+ lexer.PropertyParsing = true;
+ }
+ ;
+
+accessor_body
+ : block
+ | SEMICOLON { $$ = null; }
+ ;
+
+interface_declaration
+ : opt_attributes
+ opt_modifiers
+ INTERFACE IDENTIFIER
+ opt_interface_base
+ interface_body opt_semicolon
+ ;
+
+opt_interface_base
+ : /* empty */ { $$ = null; }
+ | interface_base
+ ;
+
+interface_base
+ : COLON interface_type_list { $$ = $2; }
+ ;
+
+interface_type_list
+ : interface_type
+ | interface_type_list COMMA interface_type
+ ;
+
+interface_body
+ : OPEN_BRACE
+ opt_interface_member_declarations
+ CLOSE_BRACE
+ ;
+
+opt_interface_member_declarations
+ : /* empty */
+ | interface_member_declarations
+ ;
+
+interface_member_declarations
+ : interface_member_declaration
+ | interface_member_declarations interface_member_declaration
+ ;
+
+interface_member_declaration
+ : interface_method_declaration
+ | interface_property_declaration
+ | interface_event_declaration
+ | interface_indexer_declaration
+ ;
+
+opt_new
+ : /* empty */ { $$ = false; }
+ | NEW { $$ = true; }
+ ;
+
+interface_method_declaration
+ : opt_attributes opt_new type IDENTIFIER
+ OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
+ SEMICOLON
+ | opt_attributes opt_new VOID IDENTIFIER
+ OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
+ SEMICOLON
+ ;
+
+interface_property_declaration
+ : opt_attributes
+ opt_new
+ type IDENTIFIER
+ OPEN_BRACE
+ { lexer.PropertyParsing = true; }
+ interface_accesors
+ { lexer.PropertyParsing = false; }
+ CLOSE_BRACE
+ ;
+
+interface_accesors
+ : opt_attributes GET SEMICOLON { $$ = 1; }
+ | opt_attributes SET SEMICOLON { $$ = 2; }
+ | opt_attributes GET SEMICOLON opt_attributes SET SEMICOLON
+ { $$ = 3; }
+ | opt_attributes SET SEMICOLON opt_attributes GET SEMICOLON
+ { $$ = 3; }
+ ;
+
+interface_event_declaration
+ : opt_attributes opt_new EVENT type IDENTIFIER SEMICOLON
+ ;
+
+interface_indexer_declaration
+ : opt_attributes opt_new type THIS
+ OPEN_BRACKET formal_parameter_list CLOSE_BRACKET
+ OPEN_BRACE
+ { lexer.PropertyParsing = true; }
+ interface_accesors
+ { lexer.PropertyParsing = false; }
+ CLOSE_BRACE
+ ;
+
+operator_declaration
+ : opt_attributes opt_modifiers operator_declarator operator_body
+ ;
+
+operator_body
+ : block
+ | SEMICOLON { $$ = null; }
+ ;
+operator_declarator
+ : type OPERATOR overloadable_operator
+ OPEN_PARENS type IDENTIFIER CLOSE_PARENS
+ | type OPERATOR overloadable_operator
+ OPEN_PARENS
+ type IDENTIFIER COMMA
+ type IDENTIFIER
+ CLOSE_PARENS
+ | conversion_operator_declarator
+ ;
+
+overloadable_operator
+// Unary operators:
+ : BANG
+ | TILDE
+ | OP_INC
+ | OP_DEC
+ | TRUE
+ | FALSE
+// Unary and binary:
+ | PLUS
+ | MINUS
+// Binary:
+ | STAR
+ | DIV
+ | PERCENT
+ | BITWISE_AND
+ | BITWISE_OR
+ | CARRET
+ | OP_SHIFT_LEFT
+ | OP_SHIFT_RIGHT
+ | OP_EQ
+ | OP_NE
+ | OP_GT
+ | OP_LT
+ | OP_GE
+ | OP_LE
+ ;
+
+conversion_operator_declarator
+ : IMPLICIT OPERATOR type OPEN_PARENS type IDENTIFIER CLOSE_PARENS
+ | EXPLICIT OPERATOR type OPEN_PARENS type IDENTIFIER CLOSE_PARENS
+ | IMPLICIT error
+ | EXPLICIT error
+ ;
+
+constructor_declaration
+ : opt_attributes
+ opt_modifiers
+ constructor_declarator
+ constructor_body
+ {
+ $1.Update ($2);
+ $1.Update ($3);
+ $1.Update ($4);
+ db.AddMember (Namespace, type, $3, new Part (fileID, $1));
+ }
+ ;
+
+constructor_declarator
+ : IDENTIFIER
+ OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
+ opt_constructor_initializer
+ {
+ $1.Update ($4);
+ $1.Update ($5, (modStatic ? ".cctor" : ".ctor") + " (" + $3.val.s + ")");
+ }
+ ;
+
+constructor_body
+ : block
+ | SEMICOLON
+ ;
+
+opt_constructor_initializer
+ : /* empty */ { $$ = new TokenValue (); }
+ | constructor_initializer
+ ;
+
+constructor_initializer
+ : COLON BASE OPEN_PARENS opt_argument_list CLOSE_PARENS
+ {
+ $1.Update ($5);
+ }
+ | COLON THIS OPEN_PARENS opt_argument_list CLOSE_PARENS
+ {
+ $1.Update ($5);
+ }
+ ;
+
+destructor_declaration
+ : opt_attributes TILDE IDENTIFIER OPEN_PARENS CLOSE_PARENS block
+ ;
+
+event_declaration
+ : opt_attributes
+ opt_modifiers
+ EVENT type variable_declarators SEMICOLON
+ | opt_attributes
+ opt_modifiers
+ EVENT type member_name
+ OPEN_BRACE
+ {
+ lexer.EventParsing = true;
+ }
+ event_accessor_declarations
+ {
+ lexer.EventParsing = false;
+ }
+ CLOSE_BRACE
+ ;
+
+event_accessor_declarations
+ : add_accessor_declaration remove_accessor_declaration
+ | remove_accessor_declaration add_accessor_declaration
+ ;
+
+add_accessor_declaration
+ : opt_attributes ADD
+ {
+ lexer.EventParsing = false;
+ }
+ block
+ {
+ lexer.EventParsing = true;
+ }
+ ;
+
+remove_accessor_declaration
+ : opt_attributes REMOVE
+ {
+ lexer.EventParsing = false;
+ }
+ block
+ {
+ lexer.EventParsing = true;
+ }
+ ;
+
+indexer_declaration
+ : opt_attributes opt_modifiers indexer_declarator
+ OPEN_BRACE
+ {
+ lexer.PropertyParsing = true;
+ }
+ accessor_declarations
+ {
+ lexer.PropertyParsing = false;
+ }
+ CLOSE_BRACE
+ ;
+
+indexer_declarator
+ : type THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
+ | type qualified_identifier DOT THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
+ ;
+
+enum_declaration
+ : opt_attributes
+ opt_modifiers
+ ENUM IDENTIFIER
+ opt_enum_base
+ enum_body
+ opt_semicolon
+ ;
+
+opt_enum_base
+ : /* empty */
+ | COLON type
+ ;
+
+enum_body
+ : OPEN_BRACE opt_enum_member_declarations CLOSE_BRACE
+ ;
+
+opt_enum_member_declarations
+ : /* empty */
+ | enum_member_declarations opt_comma
+ ;
+
+enum_member_declarations
+ : enum_member_declaration
+ | enum_member_declarations COMMA enum_member_declaration
+ ;
+
+enum_member_declaration
+ : opt_attributes IDENTIFIER
+ | opt_attributes IDENTIFIER
+ ASSIGN expression
+ ;
+
+delegate_declaration
+ : opt_attributes
+ opt_modifiers
+ DELEGATE type
+ IDENTIFIER OPEN_PARENS
+ opt_formal_parameter_list
+ CLOSE_PARENS
+ SEMICOLON
+ | opt_attributes
+ opt_modifiers
+ DELEGATE VOID
+ IDENTIFIER OPEN_PARENS
+ opt_formal_parameter_list
+ CLOSE_PARENS
+ SEMICOLON
+ ;
+
+type_name
+ : namespace_or_type_name
+ ;
+
+namespace_or_type_name
+ : qualified_identifier
+ ;
+
+/*
+ * Before you think of adding a return_type, notice that we have been
+ * using two rules in the places where it matters (one rule using type
+ * and another identical one that uses VOID as the return type). This
+ * gets rid of a shift/reduce couple
+ */
+type
+ : type_name
+ | builtin_types
+ | array_type
+ | pointer_type
+ ;
+
+
+pointer_type
+ : type STAR
+ | VOID STAR
+ ;
+
+non_expression_type
+ : builtin_types
+ | non_expression_type rank_specifier
+ | non_expression_type STAR
+ | expression rank_specifiers
+ | expression STAR
+
+ //
+ // We need this because the parser will happily go and reduce IDENTIFIER STAR
+ // through this different path
+ //
+ | multiplicative_expression STAR
+ ;
+
+type_list
+ : type
+ | type_list COMMA type
+ ;
+
+/*
+ * replaces all the productions for isolating the various
+ * simple types, but we need this to reuse it easily in local_variable_type
+ */
+builtin_types
+ : OBJECT
+ | STRING
+ | BOOL
+ | DECIMAL
+ | FLOAT
+ | DOUBLE
+ | integral_type
+ ;
+
+integral_type
+ : SBYTE
+ | BYTE
+ | SHORT
+ | USHORT
+ | INT
+ | UINT
+ | LONG
+ | ULONG
+ | CHAR
+ | VOID
+ ;
+
+interface_type
+ : type_name
+ ;
+
+array_type
+ : type rank_specifiers { $<TokenValue>$.val = $1.val.s + $2.val.s; }
+ ;
+
+//
+// Expressions, section 7.5
+//
+primary_expression
+ : literal
+
+ | qualified_identifier
+ | parenthesized_expression
+ | member_access
+ | invocation_expression
+ | element_access
+ | this_access
+ | base_access
+ | post_increment_expression
+ | post_decrement_expression
+ | new_expression
+ | typeof_expression
+ | sizeof_expression
+ | checked_expression
+ | unchecked_expression
+ | pointer_member_access
+ ;
+
+literal
+ : boolean_literal
+ | integer_literal
+ | real_literal
+ | LITERAL_CHARACTER
+ | LITERAL_STRING
+ | NULL
+ ;
+
+real_literal
+ : LITERAL_FLOAT
+ | LITERAL_DOUBLE
+ | LITERAL_DECIMAL
+ ;
+
+integer_literal
+ : LITERAL_INTEGER
+ ;
+
+boolean_literal
+ : TRUE
+ | FALSE
+ ;
+
+parenthesized_expression
+ : OPEN_PARENS expression CLOSE_PARENS
+ ;
+
+member_access
+ : primary_expression DOT IDENTIFIER
+ | predefined_type DOT IDENTIFIER
+ ;
+
+predefined_type
+ : builtin_types
+ ;
+
+invocation_expression
+ : primary_expression OPEN_PARENS opt_argument_list CLOSE_PARENS
+ ;
+
+opt_argument_list
+ : /* empty */ { $$ = null; }
+ | argument_list
+ ;
+
+argument_list
+ : argument
+ | argument_list COMMA argument
+ ;
+
+argument
+ : expression
+ | REF variable_reference
+ | OUT variable_reference
+ ;
+
+variable_reference
+ : expression { note ("section 5.4"); $$ = $1; }
+ ;
+
+element_access
+ : primary_expression OPEN_BRACKET expression_list CLOSE_BRACKET
+ | primary_expression rank_specifiers
+ ;
+
+expression_list
+ : expression
+ | expression_list COMMA expression
+ ;
+
+this_access
+ : THIS
+ ;
+
+base_access
+ : BASE DOT IDENTIFIER
+ | BASE OPEN_BRACKET expression_list CLOSE_BRACKET
+ ;
+
+post_increment_expression
+ : primary_expression OP_INC
+ ;
+
+post_decrement_expression
+ : primary_expression OP_DEC
+ ;
+
+new_expression
+ : object_or_delegate_creation_expression
+ | array_creation_expression
+ ;
+
+object_or_delegate_creation_expression
+ : NEW type OPEN_PARENS opt_argument_list CLOSE_PARENS
+ ;
+
+array_creation_expression
+ : NEW type OPEN_BRACKET expression_list CLOSE_BRACKET
+ opt_rank_specifier
+ opt_array_initializer
+ | NEW type rank_specifiers array_initializer
+ | NEW type error
+ ;
+
+opt_rank_specifier
+ : /* empty */ { $$ = new TokenValue (); }
+ | rank_specifiers
+ ;
+
+rank_specifiers
+ : rank_specifier opt_rank_specifier
+ {
+ $<TokenValue>$.val = $2.val.s + $1.val.s;
+ }
+ ;
+
+rank_specifier
+ : OPEN_BRACKET opt_dim_separators CLOSE_BRACKET
+ {
+ $<TokenValue>$.val.s = "[" + $2.val.s + "]";
+ }
+ ;
+
+opt_dim_separators
+ : /* empty */ { $$ = new TokenValue (); }
+ | dim_separators
+ ;
+
+dim_separators
+ : COMMA { $<TokenValue>$.val = ","; }
+ | dim_separators COMMA
+ {
+ $<TokenValue>$.val = $1.val.s + ",";
+ }
+ ;
+
+opt_array_initializer
+ : /* empty */
+ | array_initializer
+ ;
+
+array_initializer
+ : OPEN_BRACE CLOSE_BRACE
+ | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
+ ;
+
+variable_initializer_list
+ : variable_initializer
+ | variable_initializer_list COMMA variable_initializer
+ ;
+
+typeof_expression
+ : TYPEOF OPEN_PARENS type CLOSE_PARENS
+ ;
+
+sizeof_expression
+ : SIZEOF OPEN_PARENS type CLOSE_PARENS
+ ;
+
+checked_expression
+ : CHECKED OPEN_PARENS expression CLOSE_PARENS
+ ;
+
+unchecked_expression
+ : UNCHECKED OPEN_PARENS expression CLOSE_PARENS
+ ;
+
+pointer_member_access
+ : primary_expression OP_PTR IDENTIFIER
+
+unary_expression
+ : primary_expression
+ | BANG prefixed_unary_expression
+ | TILDE prefixed_unary_expression
+ | cast_expression
+ ;
+
+cast_expression
+ : OPEN_PARENS expression CLOSE_PARENS unary_expression
+ | OPEN_PARENS non_expression_type CLOSE_PARENS prefixed_unary_expression
+ ;
+
+ //
+ // The idea to split this out is from Rhys' grammar
+ // to solve the problem with casts.
+ //
+prefixed_unary_expression
+ : unary_expression
+ | PLUS prefixed_unary_expression
+ | MINUS prefixed_unary_expression
+ | OP_INC prefixed_unary_expression
+ | OP_DEC prefixed_unary_expression
+ | STAR prefixed_unary_expression
+ | BITWISE_AND prefixed_unary_expression
+ ;
+
+pre_increment_expression
+ : OP_INC prefixed_unary_expression
+ ;
+
+pre_decrement_expression
+ : OP_DEC prefixed_unary_expression
+ ;
+
+multiplicative_expression
+ : prefixed_unary_expression
+ | multiplicative_expression STAR prefixed_unary_expression
+ | multiplicative_expression DIV prefixed_unary_expression
+ | multiplicative_expression PERCENT prefixed_unary_expression
+ ;
+
+additive_expression
+ : multiplicative_expression
+ | additive_expression PLUS multiplicative_expression
+ | additive_expression MINUS multiplicative_expression
+ ;
+
+shift_expression
+ : additive_expression
+ | shift_expression OP_SHIFT_LEFT additive_expression
+ | shift_expression OP_SHIFT_RIGHT additive_expression
+ ;
+
+relational_expression
+ : shift_expression
+ | relational_expression OP_LT shift_expression
+ | relational_expression OP_GT shift_expression
+ | relational_expression OP_LE shift_expression
+ | relational_expression OP_GE shift_expression
+ | relational_expression IS type
+ | relational_expression AS type
+ ;
+
+equality_expression
+ : relational_expression
+ | equality_expression OP_EQ relational_expression
+ | equality_expression OP_NE relational_expression
+ ;
+
+and_expression
+ : equality_expression
+ | and_expression BITWISE_AND equality_expression
+ ;
+
+exclusive_or_expression
+ : and_expression
+ | exclusive_or_expression CARRET and_expression
+ ;
+
+inclusive_or_expression
+ : exclusive_or_expression
+ | inclusive_or_expression BITWISE_OR exclusive_or_expression
+ ;
+
+conditional_and_expression
+ : inclusive_or_expression
+ | conditional_and_expression OP_AND inclusive_or_expression
+ ;
+
+conditional_or_expression
+ : conditional_and_expression
+ | conditional_or_expression OP_OR conditional_and_expression
+ ;
+
+conditional_expression
+ : conditional_or_expression
+ | conditional_or_expression INTERR expression COLON expression
+ ;
+
+assignment_expression
+ : prefixed_unary_expression ASSIGN expression
+ | prefixed_unary_expression OP_MULT_ASSIGN expression
+ | prefixed_unary_expression OP_DIV_ASSIGN expression
+ | prefixed_unary_expression OP_MOD_ASSIGN expression
+ | prefixed_unary_expression OP_ADD_ASSIGN expression
+ | prefixed_unary_expression OP_SUB_ASSIGN expression
+ | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
+ | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
+ | prefixed_unary_expression OP_AND_ASSIGN expression
+ | prefixed_unary_expression OP_OR_ASSIGN expression
+ | prefixed_unary_expression OP_XOR_ASSIGN expression
+ ;
+
+expression
+ : conditional_expression
+ | assignment_expression
+ ;
+
+constant_expression
+ : expression
+ ;
+
+boolean_expression
+ : expression
+ ;
+
+//
+// 10 classes
+//
+class_declaration
+ : opt_attributes
+ opt_modifiers
+ CLASS IDENTIFIER
+ opt_class_base
+ {
+ Types.Push (type);
+ type += (type.Length > 0 ? "." : "") + $4.val.s;
+ }
+ class_body
+ opt_semicolon
+ {
+ $1.Update ($2);
+ $1.Update ($3);
+ $1.Update ($7);
+ $1.Update ($8);
+ db.AddType (Namespace, type, new Part (fileID, $1));
+ type = (string) Types.Pop ();
+ }
+ ;
+
+opt_modifiers
+ : /* empty */ { $$ = new TokenValue (); modStatic = false; }
+ | modifiers
+ {
+ modStatic = $1.val.s.IndexOf ("static") >= 0;
+ }
+ ;
+
+modifiers
+ : modifier
+ | modifiers modifier { $<TokenValue>$.val = $1.val.s + " " + $2.val.s; }
+ ;
+
+modifier
+ : NEW
+ | PUBLIC
+ | PROTECTED
+ | INTERNAL
+ | PRIVATE
+ | ABSTRACT
+ | SEALED
+ | STATIC
+ | READONLY
+ | VIRTUAL
+ | OVERRIDE
+ | EXTERN
+ | VOLATILE
+ | UNSAFE
+ ;
+
+opt_class_base
+ : /* empty */ { $$ = new TokenValue (); }
+ | class_base
+ ;
+
+class_base
+ : COLON type_list { $$ = $2; }
+ ;
+
+//
+// Statements (8.2)
+//
+
+//
+// A block is "contained" on the following places:
+// method_body
+// property_declaration as part of the accessor body (get/set)
+// operator_declaration
+// constructor_declaration
+// destructor_declaration
+// event_declaration as part of add_accessor_declaration or remove_accessor_declaration
+//
+block
+ : OPEN_BRACE
+ opt_statement_list CLOSE_BRACE
+ {
+ $1.Update ($3);
+ }
+ ;
+
+opt_statement_list
+ : /* empty */
+ | statement_list
+ ;
+
+statement_list
+ : statement
+ | statement_list statement
+ ;
+
+statement
+ : declaration_statement
+ | embedded_statement
+ | labeled_statement
+ ;
+
+embedded_statement
+ : block
+ | empty_statement
+ | expression_statement
+ | selection_statement
+ | iteration_statement
+ | jump_statement
+ | try_statement
+ | checked_statement
+ | unchecked_statement
+ | lock_statement
+ | using_statement
+ | unsafe_statement
+ | fixed_statement
+ ;
+
+empty_statement
+ : SEMICOLON
+ ;
+
+labeled_statement
+ : IDENTIFIER COLON
+ statement
+ ;
+
+declaration_statement
+ : local_variable_declaration SEMICOLON
+ | local_constant_declaration SEMICOLON
+ ;
+
+/*
+ * The following is from Rhys' grammar:
+ * > Types in local variable declarations must be recognized as
+ * > expressions to prevent reduce/reduce errors in the grammar.
+ * > The expressions are converted into types during semantic analysis.
+ */
+local_variable_type
+ : primary_expression opt_rank_specifier
+ | builtin_types opt_rank_specifier
+ ;
+
+local_variable_pointer_type
+ : primary_expression STAR
+ | builtin_types STAR
+ | VOID STAR
+ | local_variable_pointer_type STAR
+ ;
+
+local_variable_declaration
+ : local_variable_type variable_declarators
+ | local_variable_pointer_type opt_rank_specifier variable_declarators
+ ;
+
+local_constant_declaration
+ : CONST local_variable_type constant_declarator
+ ;
+
+expression_statement
+ : statement_expression SEMICOLON
+ {
+ $$ = $1;
+ }
+ ;
+
+ //
+ // We have to do the wrapping here and not in the case above,
+ // because statement_expression is used for example in for_statement
+ //
+statement_expression
+ : invocation_expression
+ | object_creation_expression
+ | assignment_expression
+ | post_increment_expression
+ | post_decrement_expression
+ | pre_increment_expression
+ | pre_decrement_expression
+ | error
+ ;
+
+object_creation_expression
+ : object_or_delegate_creation_expression
+ { note ("complain if this is a delegate maybe?"); }
+ ;
+
+selection_statement
+ : if_statement
+ | switch_statement
+ ;
+
+if_statement
+ : if_statement_open if_statement_rest
+ {
+ $$ = $2;
+ }
+ ;
+
+if_statement_open
+ : IF OPEN_PARENS
+ ;
+
+if_statement_rest
+ : boolean_expression CLOSE_PARENS
+ embedded_statement
+ | boolean_expression CLOSE_PARENS
+ embedded_statement ELSE embedded_statement
+ ;
+
+switch_statement
+ : SWITCH OPEN_PARENS
+ expression CLOSE_PARENS
+ switch_block
+ ;
+
+switch_block
+ : OPEN_BRACE
+ opt_switch_sections
+ CLOSE_BRACE
+ {
+ $$ = $2;
+ }
+ ;
+
+opt_switch_sections
+ : /* empty */
+ | switch_sections
+ ;
+
+switch_sections
+ : switch_section
+ | switch_sections switch_section
+ ;
+
+switch_section
+ : switch_labels
+ statement_list
+ ;
+
+switch_labels
+ : switch_label
+ | switch_labels switch_label
+ ;
+
+switch_label
+ : CASE constant_expression COLON
+ | DEFAULT COLON
+ | error
+ ;
+
+iteration_statement
+ : while_statement
+ | do_statement
+ | for_statement
+ | foreach_statement
+ ;
+
+while_statement
+ : WHILE OPEN_PARENS
+ boolean_expression CLOSE_PARENS embedded_statement
+ ;
+
+do_statement
+ : DO embedded_statement
+ WHILE OPEN_PARENS
+ boolean_expression CLOSE_PARENS SEMICOLON
+ ;
+
+for_statement
+ : FOR OPEN_PARENS
+ opt_for_initializer SEMICOLON
+ opt_for_condition SEMICOLON
+ opt_for_iterator CLOSE_PARENS
+ embedded_statement
+ ;
+
+opt_for_initializer
+ : /* empty */
+ | for_initializer
+ ;
+
+for_initializer
+ : local_variable_declaration
+ | statement_expression_list
+ ;
+
+opt_for_condition
+ : /* empty */
+ | boolean_expression
+ ;
+
+opt_for_iterator
+ : /* empty */
+ | for_iterator
+ ;
+
+for_iterator
+ : statement_expression_list
+ ;
+
+statement_expression_list
+ : statement_expression
+ | statement_expression_list COMMA statement_expression
+ ;
+
+foreach_statement
+ : FOREACH OPEN_PARENS type IDENTIFIER IN
+ expression CLOSE_PARENS
+ embedded_statement
+ ;
+
+jump_statement
+ : break_statement
+ | continue_statement
+ | goto_statement
+ | return_statement
+ | throw_statement
+ ;
+
+break_statement
+ : BREAK SEMICOLON
+ ;
+
+continue_statement
+ : CONTINUE SEMICOLON
+ ;
+
+goto_statement
+ : GOTO IDENTIFIER SEMICOLON
+ | GOTO CASE constant_expression SEMICOLON
+ | GOTO DEFAULT SEMICOLON
+ ;
+
+return_statement
+ : RETURN opt_expression SEMICOLON
+ ;
+
+throw_statement
+ : THROW opt_expression SEMICOLON
+ ;
+
+opt_expression
+ : /* empty */
+ | expression
+ ;
+
+try_statement
+ : TRY block catch_clauses
+ | TRY block opt_catch_clauses FINALLY block
+ | TRY block error
+ ;
+
+opt_catch_clauses
+ : /* empty */ { $$ = null; }
+ | catch_clauses
+ ;
+
+catch_clauses
+ : catch_clause
+ | catch_clauses catch_clause
+ ;
+
+opt_identifier
+ : /* empty */ { $$ = null; }
+ | IDENTIFIER
+ ;
+
+catch_clause
+ : CATCH opt_catch_args
+ block
+ ;
+
+opt_catch_args
+ : /* empty */ { $$ = null; }
+ | catch_args
+ ;
+
+catch_args
+ : OPEN_PARENS type opt_identifier CLOSE_PARENS
+ ;
+
+checked_statement
+ : CHECKED block
+ ;
+
+unchecked_statement
+ : UNCHECKED block
+ ;
+
+unsafe_statement
+ : UNSAFE
+ block
+ ;
+
+fixed_statement
+ : FIXED OPEN_PARENS
+ type fixed_pointer_declarators
+ CLOSE_PARENS
+ embedded_statement
+ ;
+
+fixed_pointer_declarators
+ : fixed_pointer_declarator
+ | fixed_pointer_declarators COMMA fixed_pointer_declarator
+ ;
+
+fixed_pointer_declarator
+ : IDENTIFIER ASSIGN expression
+ ;
+
+lock_statement
+ : LOCK OPEN_PARENS expression CLOSE_PARENS
+ embedded_statement
+ ;
+
+using_statement
+ : USING OPEN_PARENS resource_acquisition CLOSE_PARENS
+ embedded_statement
+ ;
+
+resource_acquisition
+ : local_variable_declaration
+ | expression
+ ;
+
+%%
+
+void output (string s)
+{
+ Console.WriteLine (s);
+}
+
+void note (string s)
+{
+ // Used to put annotations
+}
+
+Tokenizer lexer;
+
+public Tokenizer Lexer {
+ get {
+ return lexer;
+ }
+}
+
+public CSharpParser (StreamReader reader, string name, ArrayList defines, SourceDB sdb, int FileID)
+{
+ fileID = FileID;
+ lexer = new Tokenizer (reader, name, defines);
+ db = sdb;
+
+ Namespaces = new Stack ();
+ Namespace = "";
+
+ Types = new Stack ();
+ type = "";
+
+ Rows = new Stack ();
+
+ modStatic = false;
+}
+
+public override void parse ()
+{
+ try {
+ if (yacc_verbose_flag)
+ yyparse (lexer, new yydebug.yyDebugSimple ());
+ else
+ yyparse (lexer);
+ Tokenizer tokenizer = lexer as Tokenizer;
+ tokenizer.cleanup ();
+ } catch (Exception e){
+ // Please do not remove this, it is used during debugging
+ // of the grammar
+ //
+ //Report.Error (-25, lexer.Location, ": Parsing error ");
+ Console.WriteLine (e);
+ }
+}
+
+/* end end end */
+}
View
1,869 monotalk/Indexer/cs-tokenizer.cs
@@ -0,0 +1,1869 @@
+//
+// cs-tokenizer.cs: The Tokenizer for the C# compiler
+// This also implements the preprocessor
+//
+// Author: Miguel de Icaza (miguel@gnu.org)
+//
+// Licensed under the terms of the GNU GPL
+//
+// (C) 2001, 2002 Ximian, Inc (http://www.ximian.com)
+//
+
+/*
+ * TODO:
+ * Make sure we accept the proper Unicode ranges, per the spec.
+ * Report error 1032
+*/
+
+using System;
+using System.Text;
+using System.Collections;
+using System.IO;
+using System.Globalization;
+using System.Reflection;
+using System.Runtime.InteropServices;
+
+namespace Monotalk.CSharp
+{
+ /// <summary>
+ /// Tokenizer for C# source code.
+ /// </summary>
+
+ [StructLayout(LayoutKind.Explicit)]
+ public struct valUnion
+ {
+ [FieldOffset(0)] public object o;
+ [FieldOffset(0)] public string s;
+
+ public valUnion (object obj)
+ {
+ s = "";
+ o = obj;
+ }
+
+ public valUnion (string str)
+ {
+ o = s = str;
+ }
+
+ static public implicit operator valUnion (string str)
+ {
+ return new valUnion (str);
+ }
+
+ static public implicit operator valUnion (char c)
+ {
+ return new valUnion (c);
+ }
+
+ static public implicit operator valUnion (decimal d)
+ {
+ return new valUnion (d);
+ }
+
+ static public implicit operator valUnion (ulong ul)
+ {
+ return new valUnion (ul);
+ }
+
+ static public implicit operator valUnion (float f)
+ {
+ return new valUnion (f);
+ }
+
+ static public implicit operator valUnion (double f)
+ {
+ return new valUnion (f);
+ }
+ }
+
+ public class TokenValue : Object
+ {
+ public valUnion val;
+ public int sRow, eRow, sCol, eCol;
+
+ public TokenValue ()
+ {
+ val = new valUnion ("");
+ sRow = eRow = -1;
+ }
+
+ static public implicit operator string (TokenValue v)
+ {
+ return v.val.s;
+ }
+
+ public void Update (TokenValue a)
+ {
+ if (sRow == -1)
+ sRow = a.sRow;
+ else if (a.sRow != -1 && a.sRow < sRow)
+ sRow = a.sRow;
+ if (eRow == -1)
+ eRow = a.eRow;
+ else if (a.eRow != -1 && a.eRow > eRow)
+ eRow = a.eRow;
+ }
+
+ public void Update (TokenValue a, string s)
+ {
+ val = s;
+ Update (a);
+ }
+ }
+
+ public class Tokenizer : yyParser.yyInput
+ {
+ StreamReader reader;
+ public string ref_name;
+ public int ref_line = 1;
+ public int line = 1;
+ public int col = 1;
+ public int current_token;
+ bool handle_get_set = false;
+ bool handle_remove_add = false;
+ bool handle_assembly = false;
+
+ //
+ // Whether tokens have been seen on this line
+ //
+ bool tokens_seen = false;
+
+ //
+ // Whether a token has been seen on the file
+ // This is needed because `define' is not allowed to be used
+ // after a token has been seen.
+ //
+ bool any_token_seen = false;
+ static Hashtable tokenValues;
+
+ private static Hashtable TokenValueName
+ {
+ get {
+ if (tokenValues == null)
+ tokenValues = GetTokenValueNameHash ();
+
+ return tokenValues;
+ }
+ }
+
+ private static Hashtable GetTokenValueNameHash ()
+ {
+ Type t = typeof (Token);
+ FieldInfo [] fields = t.GetFields ();
+ Hashtable hash = new Hashtable ();
+ foreach (FieldInfo field in fields) {
+ if (field.IsLiteral && field.IsStatic && field.FieldType == typeof (int))
+ hash.Add (field.GetValue (null), field.Name);
+ }
+ return hash;
+ }
+
+ //
+ // Returns a verbose representation of the current location
+ //
+ public string location {
+ get {
+ string det;
+
+ if (current_token == Token.ERROR)
+ det = "detail: " + error_details;
+ else
+ det = "";
+
+ // return "Line: "+line+" Col: "+col + "\n" +
+ // "VirtLine: "+ref_line +
+ // " Token: "+current_token + " " + det;
+ string current_token_name = TokenValueName [current_token] as string;
+ if (current_token_name == null)
+ current_token_name = current_token.ToString ();
+
+ return String.Format ("{0} ({1},{2}), Token: {3} {4}", ref_name,
+ ref_line,
+ col,
+ current_token_name,
+ det);
+ }
+ }
+
+ public bool PropertyParsing {
+ get {
+ return handle_get_set;
+ }
+
+ set {
+ handle_get_set = value;
+ }
+ }
+
+ public bool AssemblyTargetParsing {
+ get {
+ return handle_assembly;
+ }
+
+ set {
+ handle_assembly = value;
+ }
+ }
+
+ public bool EventParsing {
+ get {
+ return handle_remove_add;
+ }
+
+ set {
+ handle_remove_add = value;
+ }
+ }
+
+ //
+ // Class variables
+ //
+ static Hashtable keywords;
+ static NumberStyles styles;
+ static NumberFormatInfo csharp_format_info;
+
+ //
+ // Values for the associated token returned
+ //
+ int putback_char;
+ TokenValue val;
+
+ //
+ // Pre-processor
+ //
+ Hashtable defines;
+
+ const int TAKING = 1;
+ const int TAKEN_BEFORE = 2;
+ const int ELSE_SEEN = 4;
+ const int PARENT_TAKING = 8;
+ const int REGION = 16;
+
+ //
+ // pre-processor if stack state:
+ //
+ Stack ifstack;
+
+ static System.Text.StringBuilder string_builder;
+
+ const int max_id_size = 512;
+ static char [] id_builder = new char [max_id_size];
+
+ const int max_number_size = 128;
+ static char [] number_builder = new char [max_number_size];
+ static int number_pos;
+
+ //
+ // Details about the error encoutered by the tokenizer
+ //
+ string error_details;
+
+ public string error {
+ get {
+ return error_details;
+ }
+ }
+
+ public int Line {
+ get {
+ return ref_line;
+ }
+ }
+
+ public int Col {
+ get {
+ return col;
+ }
+ }
+
+ static void InitTokens ()
+ {
+ keywords = new Hashtable ();
+
+ keywords.Add ("abstract", Token.ABSTRACT);
+ keywords.Add ("as", Token.AS);
+ keywords.Add ("add", Token.ADD);
+ keywords.Add ("assembly", Token.ASSEMBLY);
+ keywords.Add ("base", Token.BASE);
+ keywords.Add ("bool", Token.BOOL);
+ keywords.Add ("break", Token.BREAK);
+ keywords.Add ("byte", Token.BYTE);
+ keywords.Add ("case", Token.CASE);
+ keywords.Add ("catch", Token.CATCH);
+ keywords.Add ("char", Token.CHAR);
+ keywords.Add ("checked", Token.CHECKED);
+ keywords.Add ("class", Token.CLASS);
+ keywords.Add ("const", Token.CONST);
+ keywords.Add ("continue", Token.CONTINUE);
+ keywords.Add ("decimal", Token.DECIMAL);
+ keywords.Add ("default", Token.DEFAULT);
+ keywords.Add ("delegate", Token.DELEGATE);
+ keywords.Add ("do", Token.DO);
+ keywords.Add ("double", Token.DOUBLE);
+ keywords.Add ("else", Token.ELSE);
+ keywords.Add ("enum", Token.ENUM);
+ keywords.Add ("event", Token.EVENT);
+ keywords.Add ("explicit", Token.EXPLICIT);
+ keywords.Add ("extern", Token.EXTERN);
+ keywords.Add ("false", Token.FALSE);
+ keywords.Add ("finally", Token.FINALLY);
+ keywords.Add ("fixed", Token.FIXED);
+ keywords.Add ("float", Token.FLOAT);
+ keywords.Add ("for", Token.FOR);
+ keywords.Add ("foreach", Token.FOREACH);
+ keywords.Add ("goto", Token.GOTO);
+ keywords.Add ("get", Token.GET);
+ keywords.Add ("if", Token.IF);
+ keywords.Add ("implicit", Token.IMPLICIT);
+ keywords.Add ("in", Token.IN);
+ keywords.Add ("int", Token.INT);
+ keywords.Add ("interface", Token.INTERFACE);
+ keywords.Add ("internal", Token.INTERNAL);
+ keywords.Add ("is", Token.IS);
+ keywords.Add ("lock", Token.LOCK);
+ keywords.Add ("long", Token.LONG);
+ keywords.Add ("namespace", Token.NAMESPACE);
+ keywords.Add ("new", Token.NEW);
+ keywords.Add ("null", Token.NULL);
+ keywords.Add ("object", Token.OBJECT);
+ keywords.Add ("operator", Token.OPERATOR);
+ keywords.Add ("out", Token.OUT);
+ keywords.Add ("override", Token.OVERRIDE);
+ keywords.Add ("params", Token.PARAMS);
+ keywords.Add ("private", Token.PRIVATE);
+ keywords.Add ("protected", Token.PROTECTED);
+ keywords.Add ("public", Token.PUBLIC);
+ keywords.Add ("readonly", Token.READONLY);
+ keywords.Add ("ref", Token.REF);
+ keywords.Add ("remove", Token.REMOVE);
+ keywords.Add ("return", Token.RETURN);
+ keywords.Add ("sbyte", Token.SBYTE);
+ keywords.Add ("sealed", Token.SEALED);
+ keywords.Add ("set", Token.SET);
+ keywords.Add ("short", Token.SHORT);
+ keywords.Add ("sizeof", Token.SIZEOF);
+ keywords.Add ("stackalloc", Token.STACKALLOC);
+ keywords.Add ("static", Token.STATIC);
+ keywords.Add ("string", Token.STRING);
+ keywords.Add ("struct", Token.STRUCT);
+ keywords.Add ("switch", Token.SWITCH);
+ keywords.Add ("this", Token.THIS);
+ keywords.Add ("throw", Token.THROW);
+ keywords.Add ("true", Token.TRUE);
+ keywords.Add ("try", Token.TRY);
+ keywords.Add ("typeof", Token.TYPEOF);
+ keywords.Add ("uint", Token.UINT);
+ keywords.Add ("ulong", Token.ULONG);
+ keywords.Add ("unchecked", Token.UNCHECKED);
+ keywords.Add ("unsafe", Token.UNSAFE);
+ keywords.Add ("ushort", Token.USHORT);
+ keywords.Add ("using", Token.USING);
+ keywords.Add ("virtual", Token.VIRTUAL);
+ keywords.Add ("void", Token.VOID);
+ keywords.Add ("volatile", Token.VOLATILE);
+ keywords.Add ("while", Token.WHILE);
+ }
+
+ //
+ // Class initializer
+ //
+ static Tokenizer ()
+ {
+ InitTokens ();
+ csharp_format_info = NumberFormatInfo.InvariantInfo;
+ styles = NumberStyles.Float;
+
+ string_builder = new System.Text.StringBuilder ();
+ }
+
+ int GetKeyword (string name)
+ {
+ object o = keywords [name];
+
+ //Console.WriteLine ("name: {0}", name);
+
+ if (o == null)
+ return -1;
+
+ int res = (int) o;
+
+ if (handle_get_set == false && (res == Token.GET || res == Token.SET))
+ return -1;
+ if (handle_remove_add == false && (res == Token.REMOVE || res == Token.ADD))
+ return -1;
+ if (handle_assembly == false && res == Token.ASSEMBLY)
+ return -1;
+ return res;
+
+ }
+
+ public Location Location {
+ get {
+ return new Location (ref_line);
+ }
+ }
+
+ void define (string def)
+ {
+ /*if (!RootContext.AllDefines.Contains (def)){
+ RootContext.AllDefines [def] = true;
+ }*/
+ if (defines.Contains (def))
+ return;
+ defines [def] = true;
+ }
+
+ public Tokenizer (StreamReader input, string fname, ArrayList defs)
+ {
+ this.ref_name = fname;
+ reader = input;
+
+ putback_char = -1;
+
+ if (defs != null){
+ defines = new Hashtable ();
+ foreach (string def in defs)
+ define (def);
+ }
+
+ //
+ // FIXME: This could be `Location.Push' but we have to
+ // find out why the MS compiler allows this
+ //
+ Monotalk.CSharp.Location.Push (fname);
+ }
+
+ bool is_identifier_start_character (char c)
+ {