This repo contains code to mirror other repos. It also contains the code that is getting mirrored.
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 

43 líneas
778 B

  1. #
  2. # This example shows how to use get explicit ambiguity from Lark's Earley parser.
  3. #
  4. from lark import Lark
  5. grammar = """
  6. sentence: noun verb noun -> simple
  7. | noun verb "like" noun -> comparative
  8. noun: adj? NOUN
  9. verb: VERB
  10. adj: ADJ
  11. NOUN: "flies" | "bananas" | "fruit"
  12. VERB: "like" | "flies"
  13. ADJ: "fruit"
  14. %import common.WS
  15. %ignore WS
  16. """
  17. parser = Lark(grammar, start='sentence', ambiguity='explicit')
  18. if __name__ == '__main__':
  19. print(parser.parse('fruit flies like bananas').pretty())
  20. # Output:
  21. #
  22. # _ambig
  23. # comparative
  24. # noun fruit
  25. # verb flies
  26. # noun bananas
  27. # simple
  28. # noun
  29. # fruit
  30. # flies
  31. # verb like
  32. # noun bananas
  33. #
  34. # (or view a nicer version at "./fruitflies.png")