WIP - very basic grammar

This commit is contained in:
Raghu Rajagopalan 2016-03-26 19:37:21 +05:30
parent d585121bdb
commit 8084d80d64

View File

@ -0,0 +1,55 @@
/*
* Parse following
* gitGraph:
* commit
* commit
* branch
*/
%lex
%options case-insensitive
%%
[\n]+ return 'NL';
\s+ /* skip all whitespace */
\#[^\n]* /* skip comments */
\%%[^\n]* /* skip comments */
"gitGraph" return 'GG';
"commit" return 'COMMIT';
"branch" return 'BRANCH';
"merge" return 'MERGE';
"reset" return 'RESET';
":" return ':';
[a-zA-Z][a-zA-Z0-9_]+ return 'ID';
<<EOF>> return 'EOF';
/lex
%left '^'
%start start
%% /* language grammar */
start
: GG ':' document EOF{ return $3; }
;
document
: /* empty */ {$$ =[]}
| document line {$1.push($2); $$ = $1}
;
line
: statement {$$ =$1}
| NL
;
statement
: COMMIT
| BRANCH ID
| MERGE ID
;