zaach / jison

Bison in JavaScript.
http://jison.org
4.36k stars 450 forks source link

this.lexer is undefined #353

Open mochicode opened 7 years ago

mochicode commented 7 years ago

When I build and run the ansic example from the repository I get the following error:

var lexer = Object.create(this.lexer);
                       ^

TypeError: Object prototype may only be an Object or null: undefined
    at Function.create (<anonymous>)
    at Parser.parse (C:\workspace\src\github.com\zaach\jison\ansic.js:106:24)
    at Object.commonjsMain [as main] (C:\workspace\src\github.com\zaach\jison\ansic.js:259:27)
    at Object.<anonymous> (C:\workspace\src\github.com\zaach\jison\ansic.js:262:11)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.runMain (module.js:605:10)

I used yarn run jison examples/ansic.jison to build the parser and tried to use the cli as well as to embed the parser in a program and I'm getting the same error.

The calculator example, however, works fine.

GerHobbelt commented 7 years ago

The calculator example comes with both lexer (inside a %lex.../lex section) and a grammar (parser), while the ansic example does not include a lexer spec, hence jison does not produce a lexer to go with the parser. Hence this.lexer is not defined.

mochicode commented 7 years ago

Hey, sorry that I didn't had time to responde. I thought that the examples would work, thous I was a little confused.