Formal language specification #6
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
I am interested in specifying a formal language, grammar, and parser for Sprite's syntax, mostly for the sake of learning about parsing. I'm hoping the language is currently context-free and can be described using a context-free grammar (e.g. in EBNF), which could be used to generate a parser as well as railroad diagrams for documentation (e.g. using
gll
for parsing andrailroad
for diagrams).Due to features like macros and typedefs, many commonly used programming languages are not fully context-free, limiting the use of context-free parsing to the initial stage or eliminating it entirely. That said, there are common parsing techniques capable of dealing with context sensitivity, such as parsing expression grammars.
References
rust-analyzer
gll
, the Rust grammar working group's implementation of GLL parsinggll-pg
, an unrelated GLL parser generator in Rust that uses Logos as a lexerrailroad
, a package library for making railroad diagrams (a visual representation of context-free grammars)I'm currently re-implementing Sprite parsing using Pest, which consumes a parsing expression grammar (PEG) file and autogenerates parsing code.
Here's what the grammar looks like so far:
b47137d27d/src/sprite.pest
No, PEGs are generally not context-free, and I'm not educated enough on CFGs to determine if Spritelang as it currently exists could be represented in a CFG, but right now this is working well as a parsing framework for the current examples.