metagrammar 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # This program is free software; you can redistribute it and/or modify
  2. # it under the terms of the GNU General Public License as published by
  3. # the Free Software Foundation; either version 2 of the License, or
  4. # (at your option) any later version.
  5. #
  6. # This program is distributed in the hope that it will be useful,
  7. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. # GNU General Public License for more details.
  10. #
  11. # You should have received a copy of the GNU General Public License
  12. # along with this program; if not, write to the Free Software
  13. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. # This is the grammar for all other grammar files that will work with the
  15. # Lime LALR(1) Context-Free Grammar Parser Generator.
  16. # You can read this to get an idea how things work, but this file is not
  17. # actually used in the system. Rather, it's an implementation guide for the
  18. # file "lime.bootstrap".
  19. %class lime_metaparser
  20. %start grammar
  21. grammar
  22. = {$$ = new lime();}
  23. | grammar/$ pragma/p toklist/t stop {$$->pragma($p, $t);}
  24. | grammar/$ rewrite/r stop {$r->update($$);}
  25. .
  26. rewrite
  27. = sym/s '=' rhs/r {$$ = new lime_rewrite($s); $$->add_rhs($r);}
  28. | rewrite/$ '|' rhs/r {$$->add_rhs($r);}
  29. .
  30. slot
  31. = action/a {$$ = new lime_action($a, NULL);}
  32. | action/a lambda/l {$$ = new lime_action($a, $l);}
  33. | sym/s {$$ = new lime_glyph($s, NULL);}
  34. | sym/s lambda/l {$$ = new lime_glyph($s, $l);}
  35. | lit/l {$$ = new lime_glyph($l, NULL);}
  36. .
  37. rhs
  38. = {$$ = new lime_rhs();}
  39. | rhs/$ slot/s {$$->add($s);}
  40. .
  41. action = '{' code/$ '}' .
  42. toklist = {$$=array();}
  43. | toklist/$ sym/s {$$[] = $s;}
  44. | toklist/$ lit/l {$$[] = $l;}
  45. .
  46. code = {}
  47. | code/$ php/p {$$.=$p;}
  48. | code/$ '{' code/c '}' {$$.='{'.$c.'}';}
  49. .