-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathexample.html
48 lines (36 loc) · 1.23 KB
/
example.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<meta charset="utf-8">
<script src="js/jquery.js"></script>
<script src="js/jqconsole.js"></script>
<script src="js/sugar.js"></script>
<script src="js/peg.js"></script>
<script src="js/plt.js"></script>
<script type="text/javascript">
// uncomment next line to enable refresh
// PLT.refresh = true
// write helper functions and semantics here
</script>
<title>Numbers</title>
<!--
PEG syntax quick reference
'x' : match the literal character 'x'
x+ : match x 1 or more times
x* : match x 0 or more times
x? : match x 0 or 1 times
!x : match anything but the match x
x/y : match x or y, trying in that order
[xyz] : match one of the literal character 'x', 'y', or 'z'
v:x : assign the result of the match x to the variable v
Full documentation: http://pegjs.majda.cz/documentation#grammar-syntax-and-semantics-parsing-expression-types
-->
<grammar>
start = '(' '+' space a:(start / number) ' ' b:(start / number) space ')' { return a + b }
number = d:digit+ { return parseInt( d.join('') ) }
digit = [0123456789]
space = ' '*
</grammar>
<h3>Addition</h3>
<code expect="15">(+ 5 10)</code>
<code expect="20">(+7 13)</code>
<code>(+ 7 13)</code>
<code>(+ 7 13 )</code>
<code>(+ 7 15 )</code>