add class declaration to the parser

This commit is contained in:
Josh Holtrop 2018-06-12 23:57:08 -04:00
parent 153d129111
commit 21e8c6c4ca
4 changed files with 35 additions and 0 deletions

View File

@ -131,6 +131,8 @@ asm return ASM;
__asm__ return ASM;
__extension__ return EXTENSION;
class return CLASS;
L?'[^\\]' return CHAR_CONST;
L?'\\.' return CHAR_CONST;
L?'\\x[0-9A-Fa-f]{2}' return CHAR_CONST;

View File

@ -117,6 +117,8 @@ int yylex(YYSTYPE *, YYLTYPE *);
%token ASM;
%token EXTENSION;
%token CLASS;
%start translation_unit
%%
@ -591,6 +593,7 @@ type_specifier
| UNSIGNED { $$ = $1; }
| struct_or_union_specifier { $$ = $1; }
| enum_specifier { $$ = $1; }
| class_specifier { $$ = $1; }
| TYPE_NAME { $$ = $1; }
;
@ -743,6 +746,26 @@ enumerator
}
;
class_specifier
: CLASS IDENTIFIER LCURLY RCURLY {
$$ = new Node(NODE_TYPE_LIST);
}
| CLASS IDENTIFIER LCURLY external_declaration_list RCURLY {
$$ = new Node(NODE_TYPE_LIST);
}
;
external_declaration_list
: external_declaration {
$$ = new Node(NODE_TYPE_LIST);
$$->list->push_back($1);
}
| external_declaration_list external_declaration {
$$ = $1;
$$->list->push_back($2);
}
;
type_qualifier
: CONST { $$ = $1; }
| VOLATILE { $$ = $1; }

10
tests/t006.cxl Normal file
View File

@ -0,0 +1,10 @@
#include <stdio.h>
class Foo
{
};
int main(int argc, char * argv[])
{
return 0;
}

0
tests/t006.x Normal file
View File