Skip to content

Commit

Permalink
Backtracking PEG parsers
Browse files Browse the repository at this point in the history
  • Loading branch information
horo-fox committed Mar 7, 2024
1 parent 659eb1a commit d626e75
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/content/journal/backtracking-and-array-asts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
title: "How to do backtracking and array-backed ASTs?"
published: 3-6-2024
summary: "An observation that seems to make array-backed ASTs viable for backtracking grammars"
---

I've wanted to make a parser for Python that spits outs an AST backed by an array like Zig's AST. The main trouble is that Python's grammar requires backtracking. I think the solution is to split the parsing into two phases: pre-commit (which is cached) and committing (which isn't). This should also make packrat parsing more memory efficient cause I'm storing just a bit per token, though that will likely end up a bool per token rather than a bitvec. (Actually, it might be 2 bits per token? I need to think about this more.)

0 comments on commit d626e75

Please sign in to comment.