[cig-commits] r6507 - cs/babel/trunk/spike/Spike/Compiler

leif at geodynamics.org leif at geodynamics.org
Wed Apr 4 01:04:30 PDT 2007


Author: leif
Date: 2007-04-04 01:04:29 -0700 (Wed, 04 Apr 2007)
New Revision: 6507

Modified:
   cs/babel/trunk/spike/Spike/Compiler/gram.y
   cs/babel/trunk/spike/Spike/Compiler/scan.l
Log:
Added grammar rules for classes.  These are pulled from the C++ ARM
[1] with the following simplifications:

* The list of base classes follows Python syntax
  ("class Foo(Bar) { ... };")

* No anonymous classes

* No access specifiers (public, protected, private)

* No 'inline' or 'virtual' keywords; no pure virtual functions

* No operator functions

* No bit fields allowed in classes

In short, there is just enough C++-esque syntax to describe a
Python/Pyrex class.  (I'm not necessarily opposed to adding any of the
above features over time.)

--

[1] Margaret A. Ellis and Bjarne Stroustrup, _The Annotated C++
Reference Manual_ (Addison-Wesley, 1990) Section 17.5 ("Class
Declarations")


Modified: cs/babel/trunk/spike/Spike/Compiler/gram.y
===================================================================
--- cs/babel/trunk/spike/Spike/Compiler/gram.y	2007-04-04 04:58:23 UTC (rev 6506)
+++ cs/babel/trunk/spike/Spike/Compiler/gram.y	2007-04-04 08:04:29 UTC (rev 6507)
@@ -23,7 +23,8 @@
 
 %token TYPEDEF EXTERN STATIC AUTO REGISTER
 %token CHAR SHORT INT LONG SIGNED UNSIGNED FLOAT DOUBLE CONST VOLATILE VOID
-%token STRUCT UNION ENUM ELIPSIS RANGE
+%token STRUCT UNION ENUM CLASS
+%token ELIPSIS RANGE
 %token OBJ
 
 %token CASE DEFAULT IF ELSE SWITCH WHILE DO FOR GOTO CONTINUE BREAK RETURN
@@ -215,6 +216,7 @@
 	| OBJ
 	| struct_or_union_specifier
 	| enum_specifier
+	| class_specifier
 	| TYPE_NAME
 	;
 
@@ -351,6 +353,48 @@
 	| initializer_list ',' initializer
 	;
 
+class_specifier
+	: class_head '{' '}'
+	| class_head '{' member_list '}'
+	;
+
+class_head
+	: CLASS identifier
+	| CLASS identifier base_spec
+	| CLASS TYPE_NAME
+	| CLASS TYPE_NAME base_spec
+	;
+
+member_list
+	: member_declaration
+	| member_list member_declaration
+	;
+
+member_declaration
+	: declaration_specifiers ';'
+	| declaration_specifiers member_declarator_list ';'
+	| function_definition
+	| function_definition ';'
+	;
+
+member_declarator_list
+	: member_declarator
+	| member_declarator_list ',' member_declarator
+	;
+
+member_declarator
+	: declarator
+	;
+
+base_spec
+	: '(' base_list ')'
+	;
+
+base_list
+	: TYPE_NAME
+	| base_list ',' TYPE_NAME
+	;
+
 statement
 	: labeled_statement
 	| compound_statement

Modified: cs/babel/trunk/spike/Spike/Compiler/scan.l
===================================================================
--- cs/babel/trunk/spike/Spike/Compiler/scan.l	2007-04-04 04:58:23 UTC (rev 6506)
+++ cs/babel/trunk/spike/Spike/Compiler/scan.l	2007-04-04 08:04:29 UTC (rev 6507)
@@ -33,6 +33,7 @@
 "break"			{ TOKEN(BREAK); }
 "case"			{ TOKEN(CASE); }
 "char"			{ TOKEN(CHAR); }
+"class"			{ TOKEN(CLASS); }
 "const"			{ TOKEN(CONST); }
 "continue"		{ TOKEN(CONTINUE); }
 "default"		{ TOKEN(DEFAULT); }



More information about the cig-commits mailing list