WHITE [ \t\n\f\v]
CLASS (class)|(struct)|(union)
ACCESS (public)|(protected)|(private)
-OP \+|\-|\/|\||\^|(==)|(!=)|(<<)|(>>)
+OP \+|\-|\/|\||\^|(==)|(!=)|(<<)|(>>)|(->)
%%
+ /* Commentary template arguments for the parser */
"//<" { return COMTEMP; }
+ /* End of declaration section */
+
+\n?"/*"[-* ]*[Ii]nline.* { return ENDOFDECL; }
+
+
\n?"/*" { yy_push_state(COMMENT); }
<COMMENT>.
<COMMENT>\n
/* Ignore friend declarations so far */
-friend[^;]+; {}
+friend[^;]+; { return FRIEND; }
/*** keywords ***/
virtual { return VIRTUAL; }
operator { return OPERATOR; }
unsigned { return UNSIGNED; }
+static { return STATIC; }
+mutable { return MUTABLE; }
template { return TEMPLATE; }
enum { return ENUM; }
friend { return FRIEND; }
+typedef { return TYPEDEF; }
+typename {}
{CLASS} { yylval = string(yytext); return CLASS; }
{ACCESS} { yylval = string(yytext); return ACCESS; }
%}
%token CLASS
+%token TYPEDEF
%token ACCESS
%token IDENTIFIER
%token FARG
%token CONST
+%token STATIC
+%token MUTABLE
%token VIRTUAL
%token ENUM
%token FRIEND
%token COMTEMP
%token DECLEXCEPTION
%token INLINE
+%token ENDOFDECL
%%
all: declaration_list
| declaration_list INLINE { return 0; }
+ | declaration_list ENDOFDECL { return 0; }
;
declaration_list: declaration
| declaration_list ';'
;
-declaration: class_declaration ';'
+declaration:
+ class_declaration ';'
| function_declaration ';'
| function_declaration '{' '}' ';'
| function_declaration '{' '}'
| variable_declaration ';'
| enum_declaration ';'
+ | typedef_declaration ';'
| template_declaration class_declaration ';'
{ cout << setw(OUTW) << "Template-Description:" << $1 << endl; }
| template_declaration function_declaration ';'
vartype identifier
{ cout << setw(OUTW) << "Variable-Declaration:" << $2 << endl
<< setw(OUTW) << "Type:" << $1 << endl
+ << setw(OUTW) << "In-Class:" << class_stack.top() << endl
<< setw(OUTW) << "Access:" << access_stack.top() << endl; }
| vartype identifier array_dimensions
{ cout << setw(OUTW) << "Variable-Declaration:" << $2 << endl
<< setw(OUTW) << "Type:" << $1 << endl
+ << setw(OUTW) << "In-Class:" << class_stack.top() << endl
<< setw(OUTW) << "Access:" << access_stack.top() << endl
<< setw(OUTW) << "Array-Dimension:" << $3 << endl; }
+ | variable_declaration '=' expression
+;
+
+typedef_declaration:
+ TYPEDEF vartype identifier
+ { cout << setw(OUTW) << "Typedef:" << $3 << endl
+ << setw(OUTW) << "Type:" << $2 << endl
+ << setw(OUTW) << "Access:" << access_stack.top() << endl; }
+ | TYPEDEF vartype identifier array_dimensions
+ { cout << setw(OUTW) << "Typedef:" << $3 << endl
+ << setw(OUTW) << "Type:" << $2 << endl
+ << setw(OUTW) << "Access:" << access_stack.top() << endl
+ << setw(OUTW) << "Array-Dimension:" << $4 << endl; }
;
array_dimensions:
identifier
| '~' identifier { $$ = string("~") + $2; }
| OPERATOR operator { $$ = string("operator") + $2; }
+ | OPERATOR vartype { $$ = string("operator") + $2; }
+
;
operator: OP
+ | operator '=' { $$ = $1 + string("="); }
| '='
| '&'
| '*'
| vartype identifier { $$ = $1 + SPC + $2; }
| vartype identifier '=' default_arg
{ $$ = $1 + SPC + $2 + string(" = ") + $4; }
+ | CLASS IDENTIFIER { $$ = $1 + SPC + $2; }
+ | vartype '(' identifier ')' argument_declaration
+ { $$ = $1 + $2 + $3 + $4 + string(" (") + $5 + string(")"); }
;
default_arg:
- literal
- | identifier
+ expression
;
enum_declaration:
;
enum_list: /* empty */
- | enum_list ',' enumerator
+ | enumerator
+ | enum_list ',' enumerator { $$ = $1 + string("@") + $3; }
;
enumerator: IDENTIFIER
cout << setw(OUTW) << "Virtual:" << "pure" << endl;
}
| ACCESS ':' { access_stack.top() = $1; }
+ | friend_declaration
+;
+
+friend_declaration:
+ FRIEND /* declaration { cout << setw(OUTW) << "Friend:" << endl; } */
+ | TEMPLATE '<' '>' FRIEND /*declaration { cout << setw(OUTW) << "Friend:" << endl; } */
;
vartype:
/* | vartype CONST { $$ = $1 + string(" const"); } */
| vartype '&' { $$ = $1 + string("&"); }
| vartype '*' { $$ = $1 + string("*"); }
+ | STATIC vartype { $$ = string("static ") + $2; }
+ | MUTABLE vartype { $$ = string("mutable ") + $2; }
;
virtualopt: VIRTUAL { $$ = string("virtual"); }
| OP expression { $$ = $1 + $2; }
| expression OP expression { $$ = $1 + $2 + $3; }
| expression INT { $$ = $1 + $2; }
+ | identifier argument_declaration { $$ = $1 + $2; }
;
literal:
template_arg:
vartype
| expression
+ | CLASS IDENTIFIER { $$ = $1 + SPC + $2; }
;
template_declaration:
;
deal_exception_output_declaration: OP
- | deal_exception_output_declaration IDENTIFIER
+ | deal_exception_output_declaration vartype
| deal_exception_output_declaration literal
| deal_exception_output_declaration OP
;