Skip to content

Instantly share code, notes, and snippets.

@getify
Last active December 15, 2022 05:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save getify/61088517c65c44d29dc65c3eed595565 to your computer and use it in GitHub Desktop.
Save getify/61088517c65c44d29dc65c3eed595565 to your computer and use it in GitHub Desktop.
exploring grammars
(* as checked here: https://mdkrajnak.github.io/ebnftest/ *)
(* ebnf syntax rules defined here: https://github.com/Engelberg/instaparse *)
Program := WhSp* (StmtSemi WhSp*)* StmtSemiOpt? WhSp*;
Stmt := AStmt | BStmt | CStmt | DStmt;
StmtSemi := Stmt? (WhSp* ";")+;
StmtSemiOpt := Stmt? (WhSp* ";")*;
WhSp := "_";
AStmt := "a";
BStmt := "b";
CStmt := "c";
DStmt := "d";
(* as checked here: https://mdkrajnak.github.io/ebnftest/ *)
(* ebnf syntax rules defined here: https://github.com/Engelberg/instaparse *)
(* backport from the normalized bnf in '2b.bnf' *)
Leading := WhSp Leading Program | Semi Leading Program | Program;
Program := Stmt | Stmt WhSp | Stmt WhSpOptSemi Program | Stmt WhSpOptSemi WhSp Program | Epsilon;
Stmt := AStmt | BStmt | CStmt | DStmt;
WhSpOptSemi := Semi | WhSp Semi | Semi WhSpOptSemi | WhSp Semi WhSpOptSemi;
WhSp := "_" | "_" WhSp;
Semi := ";";
AStmt := "a";
BStmt := "b";
CStmt := "c";
DStmt := "d";
/* as checked here: https://smlweb.cpsc.ucalgary.ca/start.html */
/* analysis here: shorturl.at/bjBO7 */
/* bnf syntax rules defined here: https://smlweb.cpsc.ucalgary.ca/readme.html */
Program -> StmtSemi FinalStmtSemiOpt .
StmtSemi -> WhSp StmtSemiOpt | StmtSemiOpt .
FinalStmtSemiOpt -> StmtOpt SemiOpt WhSpOpt | WhSpOpt .
Stmt -> AStmt | BStmt | CStmt | DStmt .
StmtOpt -> Stmt | .
StmtSemiOpt -> StmtOpt Semi | StmtOpt Semi WhSpOpt StmtSemiOpt | .
Semi -> WhSpOpt ; | WhSpOpt ; Semi .
SemiOpt -> Semi | .
WhSp -> _ | _ WhSp .
WhSpOpt -> WhSp | .
AStmt -> a .
BStmt -> b .
CStmt -> c .
DStmt -> d .
/* as checked here: https://smlweb.cpsc.ucalgary.ca/start.html */
/* analysis here: shorturl.at/huCOP */
/* bnf syntax rules defined here: https://smlweb.cpsc.ucalgary.ca/readme.html */
Leading -> WhSp Leading Program | Semi Leading Program | Program .
Program -> Stmt | Stmt WhSp | Stmt WhSpOptSemi Program | Stmt WhSpOptSemi WhSp Program | .
Stmt -> AStmt | BStmt | CStmt | DStmt .
WhSpOptSemi -> Semi | WhSp Semi | Semi WhSpOptSemi | WhSp Semi WhSpOptSemi .
WhSp -> _ | _ WhSp .
Semi -> ; .
AStmt -> a .
BStmt -> b .
CStmt -> c .
DStmt -> d .
_____
;;;;;
_;_;_
a
__a__
a;
a;b;
a;_b;
_a;_b;_
_a_;_b_;_
__a__;;
_;_a;_b;c;;;__;;__d;___a___
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment