-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdeeg.coffee
executable file
·28 lines (24 loc) · 938 Bytes
/
deeg.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
#!/usr/bin/env coffee
argv = require 'yargs'
.usage '$0 [-t] [-a] [-o] [-i] [--target js] filename'
.boolean ['t','a','o','i']
.describe 't', 'show tokens after scanning then stop'
.describe 'a', 'show abstract syntax tree after parsing then stop'
.describe 'o', 'do optimizations'
.describe 'i', 'generate and show the intermediate code then stop'
.describe 'target', 'generate code for JavaScript (more to come later)'
.default {target:'js'}
.demand(1)
.argv
scan = require "#{__dirname}/scanner/scanner.coffee"
parse = require "#{__dirname}/parser/parser.coffee"
scan argv._[0], (errors, tokens) ->
return (console.log err for err in errors) if errors.length > 0
if argv.t
console.log t for t in tokens
return
parse tokens, (errors, program) ->
return (console.log err for err in errors) if errors.length > 0
if argv.a
console.log program.toString()
return