Created
December 20, 2012 11:13
-
-
Save chomwitt/4344731 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<!DOCTYPE HTML> | |
<html> | |
<head> | |
<title>WebTurtle/Parser tests</title> | |
<meta charset="utf-8"> | |
<script language="javascript" SRC="./js/peg-0.7.0.js"></script> | |
<script language="peg" id="grammar"> | |
start | |
= additive | |
additive | |
= left:multiplicative "+" right:additive { return left + right; } | |
/ multiplicative | |
multiplicative | |
= left:primary "*" right:multiplicative { return left * right; } | |
/ primary | |
primary | |
= integer | |
/ "(" additive:additive ")" { return additive; } | |
integer "integer" | |
= digits:[0-9]+ { return parseInt(digits.join(""), 10); } | |
</script> | |
</head> | |
<body> | |
<script> | |
var parser = PEG.buildParser(document.getElementById("grammar").innerText); | |
result = parser.parse("5 + 6"); | |
document.write("<h1>Out with the old - in with the new!</h1>" ); | |
document.write(result); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment