DEV Community

Cover image for 🧬 PegLang — A Language Built on Parsing Expression Grammars as Executable Logic
Pʀᴀɴᴀᴠ
Pʀᴀɴᴀᴠ

Posted on

🧬 PegLang — A Language Built on Parsing Expression Grammars as Executable Logic

What is PegLang?

PegLang is an experimental language where Parsing Expression Grammars (PEGs) are not just used to parse input—they are the language. Instead of writing instructions in a traditional syntax, the program is expressed as grammar rules, and execution occurs as the parser processes text, symbols, or patterns.

PegLang blurs the line between interpreter, parser, and program, making code look more like formal grammar definitions than typical logic flow.


Specs

Language Type: Grammar-driven / PEG-based esolang

Era: ~2015–2022 language research phase

Execution Model: Matching and transforming input streams

Paradigm: Declarative, pattern-driven programming

Typing: Implicit — structure determined by grammar rules


Example Code (Hello World)

A minimal example may look like:

Start <- "Hello, PegLang!"
Enter fullscreen mode Exit fullscreen mode

Execution prints or outputs the matched literal when the program is run with no input stream.

A more dynamic sample:

Digit <- [0-9]
Number <- Digit+
Print <- Number { print }
Enter fullscreen mode Exit fullscreen mode

Depending on interpreter support, this prints any numeric input fed into the engine.


How It Works

PegLang programs consist of production rules similar to:

Top comments (0)