Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

ChrisDolan (2855)

ChrisDolan
  (email not shown publicly)
http://www.chrisdolan.net/

Journal of ChrisDolan (2855)

Tuesday January 13, 2009
10:29 PM

Regex for floating hex

[ #38283 ]

A couple days ago I wrote about Java syntax for hexadecimal representation of floating point numbers like this:

0x1.fffffeP+127f

Here are the Perl 6 grammar snippets I put together to parse this. Easy!

token HexLiteral {
  '0' ['x'|'X'] [
     | '.' <HexDigit>+ <HexExponent>? <FloatTypeSuffix>?
     | <HexDigit>+ [
         | '.' <HexDigit>* <HexExponent>? <FloatTypeSuffix>?
         | <IntegerTypeSuffix>?
     ]
  ]
}
token HexDigit { [\d|<[a..f]>|<[A..F]>] }
token HexExponent { ['p'|'P'] ['+'|'-']? \d+ }
token FloatTypeSuffix { 'f'|'F'|'d'|'D' }

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.