Skip to content

Instantly share code, notes, and snippets.

@geoffrasb
Created February 10, 2012 18:37
Show Gist options
  • Select an option

  • Save geoffrasb/1791529 to your computer and use it in GitHub Desktop.

Select an option

Save geoffrasb/1791529 to your computer and use it in GitHub Desktop.
A graph expression grammar spec

A graph expression grammar spec

Tokens:

\s+			#ignore whitespace
{		"{"
}		"}"
[		"["
]		"]"
,		","
[a-zA-Z0-9_]+	"LABEL"
[><\-]		"CONJ"	#left assoc
:		":"

Grammar:

graph
	: { relations }
	| { subgraphs }

subgraphs
	: graph , subgraphs
	| graph

relations
	: chain , relations
	| chain

chain
	: LABEL CONJ chain
	| LABEL

Example

    1     a->b
   / \       |
  6   5      c
 / \ / \
7   8   9

{ {5-1-6-8-5-9, 6-7} , {a>b-c} }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment