Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. #!/usr/bin/env perl6
  2. no precompilation;
  3. use Grammar::Tracer;
  4.  
  5. grammar G {
  6.  
  7. token TOP { <s> }
  8.  
  9. proto token s { * }
  10.  
  11. token s:sym<a> { <one> }
  12. token s:sym<b> { <one> <two> }
  13. token s:sym<c> { <one> <two> <three> }
  14. token s:sym<d> { <one> <two> <three> <four> }
  15.  
  16. token one { '1' }
  17. token two { '2' }
  18. token three { '3' }
  19. token four { '4' }
  20. }
  21.  
  22. my $g = G.new;
  23.  
  24. say $g.parse: '1234';
  25.  
  26. # Output: Match
  27. # token three { '3' }
  28.  
  29. TOP
  30. | s
  31. | | s:sym<d>
  32. | | | one
  33.  
  34. # Output No Match
  35. # token three { <digit> }
  36.  
  37. TOP
  38. | s
  39. | | s:sym<b>
  40. | | | one
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement