Slash Boxes
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)

  (email not shown publicly)

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:


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.
More | Login | Reply
Loading... please wait.