Add gcc-style attributes to parser
This commit is contained in:
parent
625410faa0
commit
aa6ef6b8d6
@ -121,6 +121,7 @@ continue return CONTINUE;
|
|||||||
|
|
||||||
sizeof return SIZEOF;
|
sizeof return SIZEOF;
|
||||||
|
|
||||||
|
__attribute__ return ATTRIBUTE;
|
||||||
|
|
||||||
L?'[^\\]' return CHAR_CONST;
|
L?'[^\\]' return CHAR_CONST;
|
||||||
L?'\\.' return CHAR_CONST;
|
L?'\\.' return CHAR_CONST;
|
||||||
|
@ -112,6 +112,7 @@ int yylex(YYSTYPE *, YYLTYPE *);
|
|||||||
%token IDENTIFIER;
|
%token IDENTIFIER;
|
||||||
|
|
||||||
%token TYPE_NAME;
|
%token TYPE_NAME;
|
||||||
|
%token ATTRIBUTE;
|
||||||
|
|
||||||
%start translation_unit
|
%start translation_unit
|
||||||
|
|
||||||
@ -303,6 +304,14 @@ declaration_specifiers
|
|||||||
$$ = $2;
|
$$ = $2;
|
||||||
$$->list->push_back($1);
|
$$->list->push_back($1);
|
||||||
}
|
}
|
||||||
|
| attribute_spec {
|
||||||
|
$$ = new Node(NODE_TYPE_LIST);
|
||||||
|
$$->list->push_back($1);
|
||||||
|
}
|
||||||
|
| attribute_spec declaration_specifiers {
|
||||||
|
$$ = $2;
|
||||||
|
$$->list->push_back($1);
|
||||||
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
init_declarator_list
|
init_declarator_list
|
||||||
@ -404,8 +413,8 @@ type_qualifier
|
|||||||
;
|
;
|
||||||
|
|
||||||
declarator
|
declarator
|
||||||
: pointer direct_declarator { $$ = $2; }
|
: pointer direct_declarator opt_attribute_spec { $$ = $2; }
|
||||||
| direct_declarator
|
| direct_declarator opt_attribute_spec
|
||||||
;
|
;
|
||||||
|
|
||||||
direct_declarator
|
direct_declarator
|
||||||
@ -558,10 +567,46 @@ external_declaration
|
|||||||
;
|
;
|
||||||
|
|
||||||
function_definition
|
function_definition
|
||||||
: declaration_specifiers declarator declaration_list compound_statement
|
: declaration_specifiers declarator declaration_list opt_attribute_spec compound_statement
|
||||||
| declaration_specifiers declarator compound_statement
|
| declaration_specifiers declarator opt_attribute_spec compound_statement
|
||||||
| declarator declaration_list compound_statement
|
| declarator declaration_list opt_attribute_spec compound_statement
|
||||||
| declarator compound_statement
|
| declarator opt_attribute_spec compound_statement
|
||||||
|
;
|
||||||
|
|
||||||
|
opt_attribute_spec
|
||||||
|
: { $$ = nullptr; }
|
||||||
|
| attribute_spec
|
||||||
|
;
|
||||||
|
|
||||||
|
attribute_spec
|
||||||
|
: ATTRIBUTE LPAREN LPAREN attribute_list RPAREN RPAREN
|
||||||
|
;
|
||||||
|
|
||||||
|
attribute_list
|
||||||
|
: attribute {
|
||||||
|
$$ = new Node(NODE_TYPE_LIST);
|
||||||
|
$$->list->push_back($1);
|
||||||
|
}
|
||||||
|
| attribute_list COMMA attribute {
|
||||||
|
$$ = $1;
|
||||||
|
$$->list->push_back($3);
|
||||||
|
}
|
||||||
|
;
|
||||||
|
|
||||||
|
attribute
|
||||||
|
: IDENTIFIER
|
||||||
|
| IDENTIFIER LPAREN primary_expression_list RPAREN
|
||||||
|
;
|
||||||
|
|
||||||
|
primary_expression_list
|
||||||
|
: primary_expression {
|
||||||
|
$$ = new Node(NODE_TYPE_LIST);
|
||||||
|
$$->list->push_back($1);
|
||||||
|
}
|
||||||
|
| primary_expression_list COMMA primary_expression {
|
||||||
|
$$ = $1;
|
||||||
|
$$->list->push_back($3);
|
||||||
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
%%
|
%%
|
||||||
|
Loading…
x
Reference in New Issue
Block a user