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
#!/usr/bin/env perl6 | |
use Grammar::Tracer; | |
# use Grammar::Debugger; | |
grammar J-NUMERIC-LITERAL { | |
rule TOP { <numeric-atom>* %% \s+ } # vector of atoms | |
token numeric-atom { <decimal-number> ( b <[0..9]+[A..Z]>+ )? x? } # based constants, e.g. 16bFFFF | |
token decimal-number { <complex-number> (<[px]> <complex-number> )? } # π- and e-notation, e.g. 2p1, 1e0.5 | |
token complex-number { <rational> ( (j|ar|ad) <rational> )? } # e.g. 1j1, 2ar3, 4ad5 | |
token rational { <scientific> ( r <scientific> )? } # e.g. 1r2, 22r7 | |
token scientific { <floating-point> ( e _?<nn-integer> )? } # e.g. 1.234e_56 | |
token floating-point { _?(_|<nn-integer>( '.' <nn-integer> )?) | '_.' } # _1.234, Nan (_.), +Inf (_), -Inf (__) | |
token nn-integer { <[0..9]>+ } # non-negative ints | |
} | |
sub MAIN(Str $s) { | |
my Match $m = J-NUMERIC-LITERAL.parse($s); | |
say "Numbers: {$m.hash.join(',')}"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment