X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Fccan_tokenizer%2Fnumber_constant.guppy;fp=ccan%2Fccan_tokenizer%2Fnumber_constant.guppy;h=8adfa3c5caa193a6311794504a99a6b9bedd931f;hb=69cc1b45b4921c0be738902fe0d5225f135e2aae;hp=0000000000000000000000000000000000000000;hpb=46b1a03e21303e03b68de213b41c0840767fbc96;p=ccan diff --git a/ccan/ccan_tokenizer/number_constant.guppy b/ccan/ccan_tokenizer/number_constant.guppy new file mode 100644 index 00000000..8adfa3c5 --- /dev/null +++ b/ccan/ccan_tokenizer/number_constant.guppy @@ -0,0 +1,70 @@ +/* +guppy is a pattern-matching language by Joey Adams that's not implemented or formalized yet. +See http://www.funsitelots.com/pub/guppy.g for a near self-definition + +This is a guppy representation of integer and floating point formatting in C. +It is based on http://c0x.coding-guidelines.com/6.4.4.1.html and http://c0x.coding-guidelines.com/6.4.4.2.html +*/ + +number_constant: [ + integer_constant() + floating_constant() +] + +integer_constant: [ + ([1-9] [0-9]*) //decimal + (0 [0-7]*) //octal + (0 [X x] [0-9 A-F a-f]*) //hexadecimal +] + +integer_suffix: [ + ([U u] [L l]*0..2) + ([L l]*1..2 [U u]*0..1) +] + +floating_constant: [ + decimal_floating_constant() + hexadecimal_floating_constant() +] + +decimal_floating_constant: [ + ([0-9]* '.' [0-9]+ exponent_part()*0..1 floating_suffix()) + ([0-9]+ '.' exponent_part()*0..1 floating_suffix()) + ([0-9]+ exponent_part() floating_suffix()) +] + +exponent_part: + ([E e] ['+' '-']*0..1 [0-9]+) + +hexadecimal_floating_constant: + (0 [X x] [ + [0-9 A-F a-f]* '.' [0-9 A-F a-f]+ + [0-9 A-F a-f]+ '.' + [0-9 A-F a-f]+ + ] [P p] ['+' '-']*0..1 [0-9]+ floating_suffix()) + +floating_suffix: [F L f l]*0..1 + +scan_number: +( + [ + (0 [X x] [0-9 A-F a-f '.']*) + (0 [B b] [0-1] [0-9 '.']*) + ([0-9 '.']*) + ] + ( [E P e p] ['+' '-']*0..1 [0-9]* )*0..1 + [0-9 A-Z a-z '.' '_' '$']* +) + +/* +Notes: + +A numeric constant can begin with any of: + 0-9 '.' +and can contain any of: + 0-9 a-f e f l p u x '.' '+' '-' +along with capital equivalents. + +If scanning finds something starting with a '.' but no decimal digit after it, it is the '.' operator and not a number. + +*/