This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
"""Demonstrates parsing of bracket expressions via recursive descent. | |
The formal grammar is as follows (notice the lack of left recursion): | |
S := '(' S ')' S | '[' S ']' S | '{' S '}' S | '<' S '>' S | '' | |
Observe how `parse_expression` follows this definition. | |
""" | |
import enum | |
from typing import Iterable, Tuple |