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 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) (limited to 'cparser/Lexer.mll') 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 -- cgit v1.2.3