Skip to content

Latest commit

 

History

History
26 lines (22 loc) · 675 Bytes

README.md

File metadata and controls

26 lines (22 loc) · 675 Bytes

predictive-parser

A simple (naive) LL(1) parser in Python.

  • You can send pull requests, I'd appreciate.

Basic usage

  1. The first parameter receives the start symbol, the second receives the grammar:
parser = PredictiveParser("S", {
  # Each nonterminal contains a list of productions:
  # S -> hello
  "S": [["hello"]]
})
  1. Empty productions are represented by [""]:
parser = PredictiveParser("S", {
  # S -> hello T
	"S": [["hello", "T"]],
	# T -> + | hello | ε
	"T": [["+"], ["hello"], [""]]
})
  1. A complete usage is found in examples.