Created
March 20, 2010 17:33
-
-
Save colomon/338783 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/Perl6/Grammar.pm b/src/Perl6/Grammar.pm | |
index 00c3f07..234677f 100644 | |
--- a/src/Perl6/Grammar.pm | |
+++ b/src/Perl6/Grammar.pm | |
@@ -938,7 +938,7 @@ token numish { | |
[ | |
| <dec_number> | |
| <integer> | |
-# | <rad_number> | |
+ | <rad_number> | |
| 'NaN' >> | |
| 'Inf' >> | |
| '+Inf' >> | |
@@ -952,6 +952,34 @@ token dec_number { | |
| $<coeff> = [ <int=.decint> ] <escale> | |
} | |
+token rad_number { | |
+ ':' $<radix> = [\d+] <.unsp>? | |
+ {} # don't recurse in lexer | |
+ # :dba('number in radix notation') | |
+ [ | |
+ || '<' | |
+ $<intpart> = [ <[ 0..9 a..z A..Z ]>+ [ _ <[ 0..9 a..z A..Z ]>+ ]* ] | |
+ $<fracpart> = [ '.' <[ 0..9 a..z A..Z ]>+ [ _ <[ 0..9 a..z A..Z ]>+ ]* ]? | |
+ [ '*' <base=.radint> '**' <exp=.radint> ]? | |
+ '>' | |
+# { make radcalc($<radix>, $<intpart>, $<fracpart>, $<base>, $<exp>) } | |
+ || <?before '['> <circumfix> | |
+ || <?before '('> <circumfix> | |
+ || <.panic: "Malformed radix number"> | |
+ ] | |
+} | |
+ | |
+token radint { | |
+ [ | |
+ | <integer> | |
+ # | <?before ':'\d> <rad_number> <?{ | |
+ # defined $<rad_number><intpart> | |
+ # and | |
+ # not defined $<rad_number><fracpart> | |
+ # }> | |
+ ] | |
+} | |
+ | |
token escale { <[Ee]> $<sign>=[<[+\-]>?] <decint> } | |
token typename { | |
==================================================== | |
.namespace [] | |
.sub 'radcalc' | |
.param int radix | |
.param string intpart | |
.param string fracpart :optional | |
.param int has_fracpart :opt_flag | |
.param num base :optional | |
.param int has_base :opt_flag | |
.param num exp :optional | |
.param int has_exp :opt_flag | |
.local num result, fracdivisor, magnitude | |
.local pmc it |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment