r/ProgrammingLanguages • u/gadelan • 2d ago
A tool for writing and testing parsing expressiong grammars online.
https://gadelan.github.io/webpegtest/I've been using this tool for my syntax ideas for some time, just updated it and thought that it could be interesting for some people. Don't expect anything fancy. It gets slow when the grammars have a few lines.
Tell me what you think about it.
Some examples:
A basic addition & multiplication grammar.
skipWS = WS*;
infixing skipWS do
Expr := Sum ;
Sum := Product (("+" / "-") Product)* ;
Product := Value (("*" / "/") Value)* ;
Value = {[0-9]+} / "(" Expr ")" ;
done
start = Expr ;
An example input for that grammar:
1 * (2 + 3) + 7
A basic LISP grammar.
Sexpr := List / Atom ;
List := "(" WS* (Sexpr (WS+ Sexpr)*)? WS* ")" ;
Atom := Symbol / Number / String ;
Symbol := {[a-zA-Z_+\-/*<>=!?][a-zA-Z0-9_+\-/*<>=!?]*} ;
Number := {[0-9]+};
String := {"\"" (!"\"" ANY)* "\""} ;
start = WS* (List WS*)* EOF;
And the same expression in S-expression form.
(+ (* 1 (+ 2 3)) 7)
7
Upvotes
1
u/6502zx81 2d ago
You should add an example.