Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
18d4cf2
commit 21600eb
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,3 +37,5 @@ jspm_packages | |
.node_repl_history | ||
|
||
build/ | ||
|
||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Simple Arithmetics Grammar | ||
* ========================== | ||
* | ||
* Accepts expressions like "2 * (3 + 4)" and computes their value. | ||
*/ | ||
|
||
Expression | ||
= Whitespace ExpList Whitespace | ||
|
||
Integer "integer" | ||
= [0-9]+ { return parseInt(text(), 10); } | ||
|
||
ForwardArrow "forward arrow" | ||
= "->" | ||
|
||
TwoWayArrow "two way arrow" | ||
= "<->" | ||
|
||
Arrow | ||
= ForwardArrow / TwoWayArrow | ||
|
||
Label "label" | ||
= [0-9a-zA-Z]+ | ||
|
||
Subexp | ||
= Whitespace arrow:Arrow Whitespace label:Label Whitespace tail:Subexp* { return {kind: arrow, to: label, se:(tail === [])? undefined : tail}; } | ||
|
||
Exp | ||
= label:Label se:Subexp Whitespace ';' Whitespace { | ||
const unroll = function(dive) { return true; } | ||
return {from: label, se:(se === [])? undefined : se}; | ||
} | ||
|
||
SubexpItem | ||
= Subexp | ||
|
||
ExpList | ||
= exp:Exp* | ||
|
||
Whitespace "whitespace" | ||
= [ \t\n\r\v]* |