parser.yy 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. %skeleton "lalr1.cc" /* -*- C++ -*- */
  2. %require "3.0.2"
  3. %defines
  4. %define parser_class_name {EvalParser}
  5. %define api.token.constructor
  6. %define api.value.type variant
  7. %define api.namespace {isc::eval}
  8. %define parse.assert
  9. %code requires
  10. {
  11. #include <string>
  12. #include <eval/token.h>
  13. class EvalContext;
  14. }
  15. // The parsing context.
  16. %param { EvalContext& ctx }
  17. %locations
  18. %initial-action
  19. {
  20. // Initialize the initial location.
  21. @$.begin.filename = @$.end.filename = &ctx.file;
  22. };
  23. %define parse.trace
  24. %define parse.error verbose
  25. %code
  26. {
  27. # include "eval_context.h"
  28. }
  29. %define api.token.prefix {TOKEN_}
  30. %token
  31. END 0 "end of file"
  32. EQUAL "=="
  33. SUBSTRING "substring"
  34. COMA ","
  35. LPAREN "("
  36. RPAREN ")"
  37. ;
  38. %token <std::string> STRING "constant string"
  39. %token <int> OPTION "option code"
  40. %printer { yyoutput << $$; } <*>;
  41. %%
  42. // The whole grammar starts with an expression.
  43. %start expression;
  44. // Expression can either be a single token or a (something == something) expression
  45. expression:
  46. token EQUAL token
  47. | token;
  48. token:
  49. STRING { /* push back TokenString */ }
  50. | OPTION { /* push back TokenOption */ }
  51. | SUBSTRING "(" token "," token "," token ")" {
  52. /* push back TokenSubstring */
  53. }
  54. %%
  55. void
  56. isc::eval::EvalParser::error(const location_type& l,
  57. const std::string& m)
  58. {
  59. ctx.error(l, m);
  60. }