diff options
author | François Pottier <francois.pottier@inria.fr> | 2015-10-07 15:43:52 +0200 |
---|---|---|
committer | François Pottier <francois.pottier@inria.fr> | 2015-10-23 12:49:47 +0200 |
commit | b371ea255077d700f848165a5834f104601e8253 (patch) | |
tree | 417da20fd0dde17183a6a9cd0790de4a9c274885 /cparser | |
parent | e9ae100975a868a6e0e91a51ce54d243d52ab6c7 (diff) | |
download | compcert-b371ea255077d700f848165a5834f104601e8253.tar.gz compcert-b371ea255077d700f848165a5834f104601e8253.zip |
Added a phantom parameter to [declaration_specifiers].
This does not change the automaton at all.
It allows us to distinguish more easily between two contexts:
- the beginning of a declaration or function definition;
- the beginning of a parameter declaration.
This leads to better error messages.
Diffstat (limited to 'cparser')
-rw-r--r-- | cparser/pre_parser.mly | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/cparser/pre_parser.mly b/cparser/pre_parser.mly index 8002d5c4..0bbf10ca 100644 --- a/cparser/pre_parser.mly +++ b/cparser/pre_parser.mly @@ -319,8 +319,8 @@ constant_expression: typedef). *) declaration: -| declaration_specifiers init_declarator_list? SEMICOLON -| declaration_specifiers_typedef typedef_declarator_list? SEMICOLON +| declaration_specifiers(declaration) init_declarator_list? SEMICOLON +| declaration_specifiers_typedef typedef_declarator_list? SEMICOLON {} init_declarator_list: @@ -384,7 +384,11 @@ declaration_specifiers_no_typedef_name: The first field is a named t, while the second is unnamed of type t. *) -declaration_specifiers: +(* The phantom parameter is EITHER [declaration], which we take to mean that + this is the beginning of a declaration *or* a function definition (we + cannot distinguish the two!), OR [parameter_declaration], which means that + this is the beginning of a parameter declaration. *) +declaration_specifiers(phantom): | ioption(declaration_specifiers_no_type) TYPEDEF_NAME declaration_specifiers_no_type? | declaration_specifiers_no_type? type_specifier_no_typedef_name declaration_specifiers_no_typedef_name? {} @@ -565,9 +569,9 @@ parameter_list: { i::l } parameter_declaration: -| declaration_specifiers id=declare_varname(fst(declarator)) +| declaration_specifiers(parameter_declaration) id=declare_varname(fst(declarator)) { Some id } -| declaration_specifiers abstract_declarator(parameter_declaration)? +| declaration_specifiers(parameter_declaration) abstract_declarator(parameter_declaration)? { None } type_name: @@ -826,12 +830,12 @@ external_declaration: {} function_definition_begin: -| declaration_specifiers ioption(pointer) x=direct_declarator +| declaration_specifiers(declaration) ioption(pointer) x=direct_declarator { match x with | (_, None) -> $syntaxerror | (i, Some restore_fun) -> restore_fun () } -| declaration_specifiers ioption(pointer) x=direct_declarator +| declaration_specifiers(declaration) ioption(pointer) x=direct_declarator LPAREN params=identifier_list RPAREN open_context declaration_list { match x with | (_, Some _) -> $syntaxerror |