-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsounds.coffee
44 lines (39 loc) · 1.08 KB
/
sounds.coffee
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
{Jison} = require('jison')
grammar =
comment: "Zompist Sound Generator"
author: "Scott Stephens"
lex:
rules: [
["[^\\n\\S]+", "/* skip whitespace */"]
#["[^=\/|\s]+", "return 'SYM';"]
["[^=\\s]+", "return 'SYM';"]
["=", "return '=';"]
#["/", "return '/';"]
#["|", "return '|';"]
#["\\n", "return 'EOL';"]
#["<<EOF>>", "return 'EOF';"]
]
tokens: "= SYM"
startSymbol: 'sound'
bnf:
sound: [["cat", "{$$=$1;}"]]
cat: [["SYM = SYM", "{$$ = {name:$1,symbols:$3}}"]]
#rule: [["SYM '/' SYM '/' SYM EOL", "{$$ = new Rule($1,$3,$5)}"]]
#rewrite: [["SYM '|' SYM EOL", "{$$ = new Rewrite($1,$3);}"]]
gen = new Jison.Generator grammar,
type: 'slr'
moduleType: 'js'
moduleName: 'sounds'
parser = gen.createParser()
console.log parser
source = """
V=aeiou
C=ptcqbdgmnlrhs
F=ie
B=ou
S=ptc
Z=bdg
"""
lines = source.split('\n')
for line in lines
console.log parser.parse(line)