Permalink
Browse files

Add workflow for generating parsers

- use example parser as a starting point
  • Loading branch information...
1 parent 8c3e5e1 commit 96812415bca5ba9e149b77a2212c4239e9582140 Antti Rasinen committed Feb 24, 2012
Showing with 661 additions and 1 deletion.
  1. +32 −0 clical.pegjs
  2. +6 −0 compile_parsers.sh
  3. +2 −0 index.html
  4. +619 −0 js/parser.js
  5. +2 −1 package.json
View
@@ -0,0 +1,32 @@
+/*
+ * Classic example grammar, which recognizes simple arithmetic expressions like
+ * "2*(3+4)". The parser generated from this grammar then computes their value.
+ *
+ * Unceremoniously lifted from PEG.js examples.
+ */
+
+start
+ = _ additive:additive _ { return 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); }
+
+/* ===== Whitespace ===== */
+
+_ "whitespace"
+ = whitespace*
+
+whitespace
+ = [ \t\n\r]
View
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+export PATH=$PATH:$(npm bin)
+
+pegjs clical.pegjs js/dev-parser.js
+pegjs -e clicalparser clical.pegjs js/parser.js
View
@@ -4,6 +4,8 @@
<link rel="stylesheet" href="css/main.css"></style>
<script src="js/jquery-1.7.1.min.js"></script>
<script src="js/ui.js"></script>
+ <script src="js/parser.js"></script>
+
</head>
<body>
<ul id="results">
Oops, something went wrong.

0 comments on commit 9681241

Please sign in to comment.