You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
3.1 KiB

  1. //
  2. // Hoa
  3. //
  4. //
  5. // @license
  6. //
  7. // New BSD License
  8. //
  9. // Copyright © 2007-2015, Ivan Enderlin. All rights reserved.
  10. //
  11. // Redistribution and use in source and binary forms, with or without
  12. // modification, are permitted provided that the following conditions are met:
  13. // * Redistributions of source code must retain the above copyright
  14. // notice, this list of conditions and the following disclaimer.
  15. // * Redistributions in binary form must reproduce the above copyright
  16. // notice, this list of conditions and the following disclaimer in the
  17. // documentation and/or other materials provided with the distribution.
  18. // * Neither the name of the Hoa nor the names of its contributors may be
  19. // used to endorse or promote products derived from this software without
  20. // specific prior written permission.
  21. //
  22. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE
  26. // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  27. // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  28. // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  29. // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  30. // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  31. // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  32. // POSSIBILITY OF SUCH DAMAGE.
  33. //
  34. // Grammar \Hoa\Compiler\Llk.
  35. //
  36. // Provide grammar for the LL(k) parser.
  37. //
  38. // @author Ivan Enderlin <ivan.enderlin@hoa-project.net>
  39. // @copyright Copyright © 2007-2015 Ivan Enderlin.
  40. // @license New BSD License
  41. //
  42. %skip space \s
  43. %token or \|
  44. %token zero_or_one \?
  45. %token one_or_more \+
  46. %token zero_or_more \*
  47. %token n_to_m \{[0-9]+,[0-9]+\}
  48. %token zero_to_m \{,[0-9]+\}
  49. %token n_or_more \{[0-9]+,\}
  50. %token exactly_n \{[0-9]+\}
  51. %token token [a-zA-Z_][a-zA-Z0-9_]*
  52. %token skipped ::
  53. %token kept_ <
  54. %token _kept >
  55. %token named \(\)
  56. %token node #[a-zA-Z][a-zA-Z0-9]+
  57. %token capturing_ \(
  58. %token _capturing \)
  59. %token unification_ \[
  60. %token unification [0-9]+
  61. %token _unification \]
  62. #rule:
  63. choice()
  64. choice:
  65. concatenation() ( ::or:: concatenation() #choice )*
  66. concatenation:
  67. repetition() ( repetition() #concatenation )*
  68. repetition:
  69. simple() ( quantifier() #repetition )? <node>?
  70. simple:
  71. ::capturing_:: choice() ::_capturing::
  72. | ::skipped:: <token> ( ::unification_:: <unification> ::_unification:: )?
  73. ::skipped:: #skipped
  74. | ::kept_:: <token> ( ::unification_:: <unification> ::_unification:: )?
  75. ::_kept:: #kept
  76. | <token> ::named::
  77. ( ::unification_:: <unification> ::_unification:: )? #named
  78. quantifier:
  79. <zero_or_one>
  80. | <one_or_more>
  81. | <zero_or_more>
  82. | <n_to_m>
  83. | <n_or_more>
  84. | <exactly_n>