From f3a4e6b8796f8358ff85a7a50d1a14fe0e5642b1 Mon Sep 17 00:00:00 2001 From: xleroy Date: Mon, 5 May 2014 08:15:46 +0000 Subject: Treat all identifiers as VAR_NAME by default (i.e. if not bound by a typedef). This produces better error messages for unbound variable names (proper error message in Elab rather than cryptic syntax error in pre_parser). git-svn-id: https://yquem.inria.fr/compcert/svn/compcert/trunk@2477 fca1b0fc-160b-0410-b1d3-a4f43f01ea2e --- cparser/Lexer.mll | 19 +++++++------------ cparser/pre_parser.mly | 4 +--- 2 files changed, 8 insertions(+), 15 deletions(-) (limited to 'cparser') diff --git a/cparser/Lexer.mll b/cparser/Lexer.mll index e0f36f4..059c568 100644 --- a/cparser/Lexer.mll +++ b/cparser/Lexer.mll @@ -87,10 +87,12 @@ let init filename channel : Lexing.lexbuf = end; declare_varname := begin fun id -> - Hashtbl.add lexicon id (fun loc -> VAR_NAME (id, ref VarId, loc)); - match !contexts with - | [] -> () - | t::q -> contexts := (id::t)::q + if Hashtbl.mem lexicon id then begin + Hashtbl.add lexicon id (fun loc -> VAR_NAME (id, ref VarId, loc)); + match !contexts with + | [] -> () + | t::q -> contexts := (id::t)::q + end end; declare_typename := begin fun id -> @@ -302,13 +304,7 @@ rule initial = parse | "." { DOT(currentLoc lexbuf) } | identifier as id { try Hashtbl.find lexicon id (currentLoc lexbuf) - with Not_found -> - let pref = "__builtin_" in - if String.length id > String.length pref && - String.sub id 0 (String.length pref) = pref then - VAR_NAME (id, ref VarId, currentLoc lexbuf) - else - UNKNOWN_NAME(id, ref OtherId, currentLoc lexbuf) } + with Not_found -> VAR_NAME (id, ref VarId, currentLoc lexbuf) } | eof { EOF } | _ as c { Cerrors.fatal_error "%s:%d Error:@ invalid symbol %C" @@ -478,7 +474,6 @@ and hash = parse | TILDE loc -> loop TILDE't loc | TYPEDEF loc -> loop TYPEDEF't loc | TYPEDEF_NAME (id, typ, loc) - | UNKNOWN_NAME (id, typ, loc) | VAR_NAME (id, typ, loc) -> let terminal = match !typ with | VarId -> VAR_NAME't diff --git a/cparser/pre_parser.mly b/cparser/pre_parser.mly index c7c807a..a33c592 100644 --- a/cparser/pre_parser.mly +++ b/cparser/pre_parser.mly @@ -38,7 +38,7 @@ %} %token - VAR_NAME TYPEDEF_NAME UNKNOWN_NAME + VAR_NAME TYPEDEF_NAME %token CONSTANT %token STRING_LITERAL PRAGMA @@ -81,7 +81,6 @@ when a is a TYPEDEF_NAME. It is specified by 6.7.5.3 11. general_identifier: | i = VAR_NAME | i = TYPEDEF_NAME -| i = UNKNOWN_NAME { i } string_literals_list: @@ -443,7 +442,6 @@ gcc_attribute: | gcc_attribute_word LPAREN argument_expression_list? RPAREN {} | gcc_attribute_word LPAREN i = TYPEDEF_NAME COMMA argument_expression_list RPAREN -| gcc_attribute_word LPAREN i = UNKNOWN_NAME COMMA argument_expression_list RPAREN (* This is to emulate GCC's attribute syntax : we make this identifier a var name identifier, so that the parser will see it as a variable reference *) -- cgit v1.2.3