Skip to content

Commit 24ac406

Browse files
committed
Update README
1 parent 5f24e45 commit 24ac406

File tree

3 files changed

+23
-12
lines changed

3 files changed

+23
-12
lines changed

README.md

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Usage from the command line
2626
Now you're ready to generate some parsers:
2727

2828
cd jison
29-
narwhal bin/jison examples/calculator.jison examples/calculator.jisonlex
29+
narwhal bin/jison examples/calculator.jison
3030

3131
This will generate a `calculator.js` file in your current working directory. This file can be used to parse an input file, like so:
3232

@@ -144,11 +144,14 @@ A demo of the calculator script used in a web page is [here](http://zaach.github
144144

145145
Specifying a language
146146
---------------------
147-
The process of parsing a language involves two phases: **lexical analysis** (tokenizing) and **parsing**, which the Lex/Yacc and Flex/Bison combinations are famous for. Jison lets you specify a parser much like you would using Bison/Flex, with separate files for tokenization rules and for the language grammar.
147+
The process of parsing a language involves two phases: **lexical analysis** (tokenizing) and **parsing**, which the Lex/Yacc and Flex/Bison combinations are famous for. Jison lets you specify a parser much like you would using Bison/Flex, with separate files for tokenization rules and for the language grammar, or with the tokenization rules embedded in the main grammar.
148148

149-
For example, here is the calculator parser:
149+
For example, here is the grammar for the calculator parser:
150150

151-
calc.jisonlex, tokenization rules
151+
/* description: Parses end executes mathematical expressions. */
152+
153+
/* lexical grammar */
154+
%lex
152155

153156
%%
154157
\s+ {/* skip whitespace */}
@@ -164,18 +167,20 @@ calc.jisonlex, tokenization rules
164167
"E" {return 'E';}
165168
<<EOF>> {return 'EOF';}
166169

167-
and calc.jison, language grammar
170+
/lex
168171

169-
/* description: Grammar for a parser that parses and executes mathematical expressions. */
172+
/* operator associations and precedence */
170173

171174
%left '+' '-'
172175
%left '*' '/'
173176
%left '^'
174177
%left UMINUS
175178

176-
%%
179+
%start expressions
180+
181+
%% /* language grammar */
177182

178-
S
183+
expressions
179184
: e EOF
180185
{print($1); return $1;}
181186
;
@@ -203,7 +208,8 @@ and calc.jison, language grammar
203208
{$$ = Math.PI;}
204209
;
205210

206-
which compiles down to this JSON:
211+
212+
which compiles down to this JSON representation used directly by Jison:
207213

208214
{
209215
"lex": {
@@ -231,7 +237,7 @@ which compiles down to this JSON:
231237
],
232238

233239
"bnf": {
234-
"S" :[[ "e EOF", "print($1); return $1;" ]],
240+
"expressions" :[[ "e EOF", "print($1); return $1;" ]],
235241

236242
"e" :[[ "e + e", "$$ = $1+$3;" ],
237243
[ "e - e", "$$ = $1-$3;" ],
@@ -248,10 +254,13 @@ which compiles down to this JSON:
248254

249255
Jison accepts both the Bison/Flex style formats, or the raw JSON format, e.g:
250256

251-
narwhal bin/jison examples/calculator.jison examples/calculator.jisonlex
257+
narwhal bin/jison examples/calculator.jison
252258
or
253259
narwhal bin/jison examples/calculator.json
254260

261+
When the lexical grammar resides in its own (.jisonlex) file, use that as the second argument to Jison, e.g.:
262+
narwhal bin/jison examples/classy.jison examples/classy.jisonlex
263+
255264
More examples can be found in the `examples/` and `tests/parser/` directories.
256265

257266
Sharing scope

examples/README

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Use Jison to generate parsers from an example, e.g.:
2+
$ ../bin/jison basic_lex.jison

examples/calculator.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
],
2727

2828
"bnf": {
29-
"S" :[[ "e EOF", "print($1); return $1;" ]],
29+
"expressions" :[[ "e EOF", "print($1); return $1;" ]],
3030

3131
"e" :[[ "e + e", "$$ = $1+$3;" ],
3232
[ "e - e", "$$ = $1-$3;" ],

0 commit comments

Comments
 (0)