A demo project from the http://greatcodeclub.com/ to play with parsing and Jison.
You need:
- A recent version of node.
make
. You probably have it already.
To install Node modules and start the test:
$ npm install
$ make watch
Then modify any file, the parser will be recompiled and the file test.js
will be executed.
Here are the files you should take a look at, in logical order:
tokens.jisonlex
defines the tokens produced by the lexer.grammar.jison
is the grammar defining the syntax. It is compiled toparser.js
.test.js
uses the parser to parse and output the results to the console. Modify this file.
Here's an idea to modify the parser on your own. Try adding support for parsing false
or floating point numbers.
You first need to define a new token in tokens.jisonlex
:
[regexp/string to match that token] return 'A_UNIQUE_AND_AWESOME_NAME'
Then, add that tokens to grammar.jison
.
expression:
...
| A_UNIQUE_AND_AWESOME_NAME
;
You can test your parser using test.js
.
Copyright 2014 Coded Inc.
marc@codedinc.com
You are free to modify and distribute this however you want. Except for teaching purposes.