number_constant.guppy 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. guppy is a pattern-matching language by Joey Adams that's not implemented or formalized yet.
  3. See http://www.funsitelots.com/pub/guppy.g for a near self-definition
  4. This is a guppy representation of integer and floating point formatting in C.
  5. 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
  6. */
  7. number_constant: [
  8. integer_constant()
  9. floating_constant()
  10. ]
  11. integer_constant: [
  12. ([1-9] [0-9]*) //decimal
  13. (0 [0-7]*) //octal
  14. (0 [X x] [0-9 A-F a-f]*) //hexadecimal
  15. ]
  16. integer_suffix: [
  17. ([U u] [L l]*0..2)
  18. ([L l]*1..2 [U u]*0..1)
  19. ]
  20. floating_constant: [
  21. decimal_floating_constant()
  22. hexadecimal_floating_constant()
  23. ]
  24. decimal_floating_constant: [
  25. ([0-9]* '.' [0-9]+ exponent_part()*0..1 floating_suffix())
  26. ([0-9]+ '.' exponent_part()*0..1 floating_suffix())
  27. ([0-9]+ exponent_part() floating_suffix())
  28. ]
  29. exponent_part:
  30. ([E e] ['+' '-']*0..1 [0-9]+)
  31. hexadecimal_floating_constant:
  32. (0 [X x] [
  33. [0-9 A-F a-f]* '.' [0-9 A-F a-f]+
  34. [0-9 A-F a-f]+ '.'
  35. [0-9 A-F a-f]+
  36. ] [P p] ['+' '-']*0..1 [0-9]+ floating_suffix())
  37. floating_suffix: [F L f l]*0..1
  38. scan_number:
  39. (
  40. [
  41. (0 [X x] [0-9 A-F a-f '.']*)
  42. (0 [B b] [0-1] [0-9 '.']*)
  43. ([0-9 '.']*)
  44. ]
  45. ( [E P e p] ['+' '-']*0..1 [0-9]* )*0..1
  46. [0-9 A-Z a-z '.' '_' '$']*
  47. )
  48. /*
  49. Notes:
  50. A numeric constant can begin with any of:
  51. 0-9 '.'
  52. and can contain any of:
  53. 0-9 a-f e f l p u x '.' '+' '-'
  54. along with capital equivalents.
  55. If scanning finds something starting with a '.' but no decimal digit after it, it is the '.' operator and not a number.
  56. */