aboutsummaryrefslogtreecommitdiffstats
path: root/cparser/Lexer.mll
diff options
context:
space:
mode:
authorXavier Leroy <xavier.leroy@inria.fr>2015-04-06 11:38:35 +0200
committerXavier Leroy <xavier.leroy@inria.fr>2015-04-06 11:38:35 +0200
commitaca71566249cd13f506b70f88457eaa8efc5b795 (patch)
treea41152b81b0466b9263942f99e695318163999a1 /cparser/Lexer.mll
parent5dadfeabe2eece08c798f29f0329970b693415cc (diff)
downloadcompcert-kvx-aca71566249cd13f506b70f88457eaa8efc5b795.tar.gz
compcert-kvx-aca71566249cd13f506b70f88457eaa8efc5b795.zip
Detect (and reject with an error) preprocessing numbers that are not valid integer or floating constants.
Diffstat (limited to 'cparser/Lexer.mll')
-rw-r--r--cparser/Lexer.mll7
1 files changed, 7 insertions, 0 deletions
diff --git a/cparser/Lexer.mll b/cparser/Lexer.mll
index 13c1248b..82e6589c 100644
--- a/cparser/Lexer.mll
+++ b/cparser/Lexer.mll
@@ -233,6 +233,11 @@ let hexadecimal_floating_constant =
| hexadecimal_prefix (hexadecimal_digit_sequence as intpart)
binary_exponent_part floating_suffix?
+(* Preprocessing numbers *)
+let preprocessing_number =
+ '.'? ['0'-'9']
+ (['0'-'9' 'A'-'Z' 'a'-'z' '_' '.'] | ['e' 'E' 'p' 'P']['+' '-'])*
+
(* Character and string constants *)
let simple_escape_sequence =
'\\' ( ['\'' '\"' '?' '\\' 'a' 'b' 'e' 'f' 'n' 'r' 't' 'v'] as c)
@@ -273,6 +278,8 @@ rule initial = parse
| None -> None
| Some c -> Some (String.make 1 c) },
currentLoc lexbuf)}
+ | preprocessing_number as s { error lexbuf "invalid numerical constant '%s'@ These characters form a preprocessor number, but not a constant" s;
+ CONSTANT (Cabs.CONST_INT "0", currentLoc lexbuf) }
| "'" { let l = char_literal [] lexbuf in
CONSTANT (Cabs.CONST_CHAR(false, l),
currentLoc lexbuf) }