diff options
author | xleroy <xleroy@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e> | 2012-11-03 10:36:15 +0000 |
---|---|---|
committer | xleroy <xleroy@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e> | 2012-11-03 10:36:15 +0000 |
commit | dcb9f48f51cec5e864565862a700c27df2a1a7e6 (patch) | |
tree | b453b51b7406d3b1cf7191729637446a23ffc92c /cparser/Lexer.mll | |
parent | bd93aa7ef9c19a4def8aa64c32faeb04ab2607e9 (diff) | |
download | compcert-dcb9f48f51cec5e864565862a700c27df2a1a7e6.tar.gz compcert-dcb9f48f51cec5e864565862a700c27df2a1a7e6.zip |
Flocq-based parsing of floating-point literals (Jacques-Henri Jourdan)
git-svn-id: https://yquem.inria.fr/compcert/svn/compcert/trunk@2065 fca1b0fc-160b-0410-b1d3-a4f43f01ea2e
Diffstat (limited to 'cparser/Lexer.mll')
-rw-r--r-- | cparser/Lexer.mll | 46 |
1 files changed, 28 insertions, 18 deletions
diff --git a/cparser/Lexer.mll b/cparser/Lexer.mll index 424252e7..0820e4e7 100644 --- a/cparser/Lexer.mll +++ b/cparser/Lexer.mll @@ -365,9 +365,8 @@ let letter = ['a'- 'z' 'A'-'Z'] let usuffix = ['u' 'U'] let lsuffix = "l"|"L"|"ll"|"LL" -let intsuffix = lsuffix | usuffix | usuffix lsuffix | lsuffix usuffix +let intsuffix = lsuffix | usuffix | usuffix lsuffix | lsuffix usuffix | usuffix ? "i64" - let hexprefix = '0' ['x' 'X'] @@ -375,21 +374,19 @@ let intnum = decdigit+ intsuffix? let octnum = '0' octdigit+ intsuffix? let hexnum = hexprefix hexdigit+ intsuffix? -let exponent = ['e' 'E']['+' '-']? decdigit+ -let fraction = '.' decdigit+ -let decfloat = (intnum? fraction) - |(intnum exponent) - |(intnum? fraction exponent) - | (intnum '.') - | (intnum '.' exponent) - -let hexfraction = hexdigit* '.' hexdigit+ | hexdigit+ -let binexponent = ['p' 'P'] ['+' '-']? decdigit+ -let hexfloat = hexprefix hexfraction binexponent - | hexprefix hexdigit+ binexponent - -let floatsuffix = ['f' 'F' 'l' 'L'] -let floatnum = (decfloat | hexfloat) floatsuffix? +let floating_suffix = ['f' 'F' 'l' 'L'] as suffix +let exponent_part = ['e' 'E']((['+' '-']? decdigit+) as expo) +let fractional_constant = ((decdigit+ as intpart)? '.' (decdigit+ as frac)) + |((decdigit+ as intpart) '.') +let decimal_floating_constant = + (fractional_constant exponent_part? floating_suffix?) + |((decdigit+ as intpart) exponent_part floating_suffix?) +let binary_exponent_part = ['p' 'P']((['+' '-']? decdigit+) as expo) +let hexadecimal_fractional_constant = ((hexdigit+ as intpart)? '.' (hexdigit+ as frac)) + |((hexdigit+ as intpart) '.') +let hexadecimal_floating_constant = + (hexprefix hexadecimal_fractional_constant binary_exponent_part floating_suffix?) + |(hexprefix (hexdigit+ as intpart) binary_exponent_part floating_suffix?) let ident = (letter|'_'|'$')(letter|decdigit|'_'|'$')* let blank = [' ' '\t' '\012' '\r']+ @@ -425,7 +422,20 @@ rule initial = CST_STRING (str lexbuf, currentLoc lexbuf) } | "L\"" { (* weimer: wchar_t string literal *) CST_WSTRING(str lexbuf, currentLoc lexbuf) } -| floatnum {CST_FLOAT (Lexing.lexeme lexbuf, currentLoc lexbuf)} +| decimal_floating_constant + {CST_FLOAT ({Cabs.isHex_FI = false; + Cabs.integer_FI = intpart; + Cabs.fraction_FI = frac; + Cabs.exponent_FI = expo; + Cabs.suffix_FI = suffix}, + currentLoc lexbuf)} +| hexadecimal_floating_constant + {CST_FLOAT ({Cabs.isHex_FI = true; + Cabs.integer_FI = intpart; + Cabs.fraction_FI = frac; + Cabs.exponent_FI = Some expo; + Cabs.suffix_FI = suffix}, + currentLoc lexbuf)} | hexnum {CST_INT (Lexing.lexeme lexbuf, currentLoc lexbuf)} | octnum {CST_INT (Lexing.lexeme lexbuf, currentLoc lexbuf)} | intnum {CST_INT (Lexing.lexeme lexbuf, currentLoc lexbuf)} |