Now parsing structs and unions
This commit is contained in:
parent
deea46241f
commit
6c4c881adf
104
src/parser.c
104
src/parser.c
@ -41,6 +41,11 @@ static int _declaration_specifiers(C99 * c99);
|
|||||||
static int _storage_class_specifier(C99 * c99);
|
static int _storage_class_specifier(C99 * c99);
|
||||||
static int _type_specifier(C99 * c99);
|
static int _type_specifier(C99 * c99);
|
||||||
static int _struct_or_union_specifier(C99 * c99);
|
static int _struct_or_union_specifier(C99 * c99);
|
||||||
|
static int _struct_or_union(C99 * c99);
|
||||||
|
static int _struct_declaration_list(C99 * c99);
|
||||||
|
static int _struct_declaration(C99 * c99);
|
||||||
|
static int _struct_declarator_list(C99 * c99);
|
||||||
|
static int _struct_declarator(C99 * c99);
|
||||||
static int _enum_specifier(C99 * c99);
|
static int _enum_specifier(C99 * c99);
|
||||||
static int _enumerator_list(C99 * c99);
|
static int _enumerator_list(C99 * c99);
|
||||||
static int _enumerator(C99 * c99);
|
static int _enumerator(C99 * c99);
|
||||||
@ -285,14 +290,107 @@ static int _type_specifier(C99 * c99)
|
|||||||
|
|
||||||
/* struct-or-union-specifier */
|
/* struct-or-union-specifier */
|
||||||
static int _struct_or_union_specifier(C99 * c99)
|
static int _struct_or_union_specifier(C99 * c99)
|
||||||
|
/* struct-or-union [ identifier ] "{" struct-declaration-list "}"
|
||||||
|
* | struct-or-union identifier */
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
fprintf(stderr, "DEBUG: %s() \"%s\"\n", __func__);
|
||||||
|
#endif
|
||||||
|
ret = _struct_or_union(c99);
|
||||||
|
if(token_get_code(c99->token) == C99_CODE_IDENTIFIER)
|
||||||
|
{
|
||||||
|
ret |= _identifier(c99);
|
||||||
|
if(token_get_code(c99->token) != C99_CODE_OPERATOR_LBRACE)
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
ret |= _parse_check(c99, C99_CODE_OPERATOR_LBRACE);
|
||||||
|
ret |= _struct_declaration_list(c99);
|
||||||
|
if(token_get_code(c99->token) == C99_CODE_COMMA)
|
||||||
|
ret |= c99_scan(c99);
|
||||||
|
ret |= _parse_check(c99, C99_CODE_OPERATOR_RBRACE);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* struct-or-union */
|
||||||
|
static int _struct_or_union(C99 * c99)
|
||||||
|
/* "struct" | "union" */
|
||||||
{
|
{
|
||||||
/* FIXME implement */
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
fprintf(stderr, "DEBUG: %s() \"%s\"\n", __func__,
|
fprintf(stderr, "DEBUG: %s() \"%s\"\n", __func__,
|
||||||
token_get_string(c99->token));
|
token_get_string(c99->token));
|
||||||
#endif
|
#endif
|
||||||
c99_scan(c99);
|
return c99_scan(c99);
|
||||||
return 0;
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* struct-declaration-list */
|
||||||
|
static int _struct_declaration_list(C99 * c99)
|
||||||
|
/* struct-declaration { struct-declaration } */
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
fprintf(stderr, "DEBUG: %s() \"%s\"\n", __func__);
|
||||||
|
#endif
|
||||||
|
ret = _struct_declaration(c99);
|
||||||
|
while(token_in_set(c99->token, c99set_struct_declaration))
|
||||||
|
ret |= _struct_declaration(c99);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* struct-declaration */
|
||||||
|
static int _struct_declaration(C99 * c99)
|
||||||
|
/* specifier-qualifier-list struct-declarator-list ";" */
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
fprintf(stderr, "DEBUG: %s() \"%s\"\n", __func__);
|
||||||
|
#endif
|
||||||
|
ret = _specifier_qualifier_list(c99);
|
||||||
|
ret |= _struct_declarator_list(c99);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* struct-declarator-list */
|
||||||
|
static int _struct_declarator_list(C99 * c99)
|
||||||
|
/* struct-declarator { "," struct-declarator } */
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
fprintf(stderr, "DEBUG: %s() \"%s\"\n", __func__);
|
||||||
|
#endif
|
||||||
|
ret = _struct_declarator(c99);
|
||||||
|
while(token_get_code(c99->token) == C99_CODE_COMMA)
|
||||||
|
ret |= _struct_declarator(c99);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* struct-declarator */
|
||||||
|
static int _struct_declarator(C99 * c99)
|
||||||
|
/* declarator
|
||||||
|
* [ declarator ] : constant-expr */
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
fprintf(stderr, "DEBUG: %s() \"%s\"\n", __func__);
|
||||||
|
#endif
|
||||||
|
if(token_get_code(c99->token) == C99_CODE_OPERATOR_COLON)
|
||||||
|
{
|
||||||
|
ret |= c99_scan(c99);
|
||||||
|
ret |= _constant_expr(c99);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
ret = _declarator(c99);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
2
src/sets/specifier_qualifier_list.set
Normal file
2
src/sets/specifier_qualifier_list.set
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
#include "type_specifier.set"
|
||||||
|
#include "type_qualifier.set"
|
1
src/sets/struct_declaration.set
Normal file
1
src/sets/struct_declaration.set
Normal file
@ -0,0 +1 @@
|
|||||||
|
#include "specifier_qualifier_list.set"
|
@ -322,6 +322,16 @@ static TokenCode _c99set_storage_class_specifier[] =
|
|||||||
TokenSet c99set_storage_class_specifier = _c99set_storage_class_specifier;
|
TokenSet c99set_storage_class_specifier = _c99set_storage_class_specifier;
|
||||||
|
|
||||||
|
|
||||||
|
/* struct-declaration */
|
||||||
|
static TokenCode _c99set_struct_declaration[] =
|
||||||
|
{
|
||||||
|
#include "sets/struct_declaration.set"
|
||||||
|
C99_CODE_NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
TokenSet c99set_struct_declaration = _c99set_struct_declaration;
|
||||||
|
|
||||||
|
|
||||||
/* struct-or-union-specifier */
|
/* struct-or-union-specifier */
|
||||||
static TokenCode _c99set_struct_or_union_specifier[] =
|
static TokenCode _c99set_struct_or_union_specifier[] =
|
||||||
{
|
{
|
||||||
|
@ -53,6 +53,7 @@ extern TokenSet c99set_punctuator;
|
|||||||
extern TokenSet c99set_selection_statement;
|
extern TokenSet c99set_selection_statement;
|
||||||
extern TokenSet c99set_statement;
|
extern TokenSet c99set_statement;
|
||||||
extern TokenSet c99set_storage_class_specifier;
|
extern TokenSet c99set_storage_class_specifier;
|
||||||
|
extern TokenSet c99set_struct_declaration;
|
||||||
extern TokenSet c99set_struct_or_union_specifier;
|
extern TokenSet c99set_struct_or_union_specifier;
|
||||||
extern TokenSet c99set_type_qualifier;
|
extern TokenSet c99set_type_qualifier;
|
||||||
extern TokenSet c99set_type_qualifier_list;
|
extern TokenSet c99set_type_qualifier_list;
|
||||||
|
Loading…
Reference in New Issue
Block a user