-
Notifications
You must be signed in to change notification settings - Fork 449
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exception thrown trying to use parser generated by 0.4.14 #246
Comments
Same problem here. Because I am using jison via gulp-jison, created a temp fork of gulp-jison with an updated jison dependency: https://github.com/davidagraf/gulp-jison |
+1 |
2 similar comments
+1 |
+1 |
excact same problem here, but using grunt, not gulp. |
+1 |
Same problem on 0.4.15 as well. Using module-deps and browser-pack (components of browserify) to do custom bundling, but not entirely sure that's the cause |
Ran into this myself today. I can try to find a fix. Unless someone else has already fixed it, and it's just hanging out in a fork somewhere? |
OK, I found a fix ^ |
Fix this.lexer undefined, fixes zaach#246
I still have the same problem. |
me as well, 0.4.15 |
@mezzario I've discovered the problem was, at least for me, that no lexer is included by default. I've personally written a simple one myself, as described in the documentation, but I guess you can also simply add the following code at the beginning of your grammar file:
|
Aha, a trivial lexer didn't work for the more complex examples, needed to create an actual lexer. |
Pretty much all the documentation here implied that we should use (snipped from docs): var parser = require("./calculator").parser;
console.log(parser.parse("4 * 5")); // => TypeError where var parse = require("./calculator").parse;
console.log(parse("4 * 5")); // => 20 I don't know why this works (didn't spend too much time looking into it), but it probably has something to do with the definition exports.parse = function () { return parser.parse.apply(parser, arguments); }; at the bottom of the generated file, and the difference from |
The problem seems to be that when the parser is generated using code, the lexer does not get generated. Not sure if this is by design. To elaborate:
Doesn't appear to generate the lexer at all, even though the rules are there in the grammar file.
simply don't exist in the generated parser. Using the command line, it seems to work fine. i.e.,
Does generate the lexer. Both methods of accessing the parser. ie
and
works for me when using the parser generated from the command line. |
You're right, both seem to work now. Not sure what silly thing I was doing then. |
Any idea what I'm doing wrong that's causing the lexer to not be generated? Do I need to pass some additional options? I am calling it like this:
|
@gentwo I'm generating with the following code: var
fs = require('fs'),
bnf = require('jison/node_modules/ebnf-parser'),
lex = require('jison/node_modules/lex-parser'),
grammar = bnf.parse(fs.readFileSync('./src/bnf/cor.y', 'utf8')),
lexer = lex.parse(fs.readFileSync('./src/bnf/cor.l', 'utf8'));
grammar.lex = lexer;
gen = new jison.Generator(grammar, opts);
parserSrc = gen.generate(opts);
fs.writeFileSync('./src/parser.js', parserSrc); you can find the complete source code in https://github.com/yosbelms/cor/blob/master/make starting from line 102 |
@yosbelms Awesome! Thanks! That's exactly what I was looking for. This means I need to separate my grammar and lexing rules :-( Also, is this the expected use or is this a bug? |
@Blackhol3 Yeah I realized the err of my ways shortly after writing the comment, and therefore deleted it. Do you happen to know of an existing ansi c lexer written for jison? I'm going through an existing lex spec for it, but I'm sure I'll screw it up the first time here :) |
@mbroadst No, I don't know any, sorry. But lexers can generally be relatively easily written by yourself, if necessary :-). |
@pietersv just when I finished my own :) thanks for the resource! This seems to be taken mostly from the ANSI C lex grammar provided here, and I think is incompatible with jison. I'm unclear how to implement some of those functions, but I've converted the majority to reflect the examples provided in the repo here. I'll commit it back if it ends up working. |
Still happening on 0.4.14 and above also some versions below. Why someone closed the issue since I can't see any working solution from the above proposed solutions |
How are you generating the parser and what is the error message? |
@cosmicexplorer I generated the parser using this:
And I got lexer undefined error message. I tried using the JavaScriptCore grammar from the examples |
@irwansyahwii The root of problem is stated clearly in numerous messages of this thread: you should define a lexer, either inside your |
I'm using Jison 0.4.14 to try to generate a parser for this grammar, which is created using this script. The parser is generated, but warns of two conflicts (which I don't think should affect this, but I may be wrong).
Then trying to use it in a Node (v0.10.25) REPL, I'm getting:
The line it's referencing (parser.js:312) is
and
this.lexer
is undefined. I can't see any other reference tothis.lexer
anywhere in the file.Here's the generated parser: https://gist.github.com/markwatkinson/c211a15e08d43c71e447
0.4.15 hits the same problem.
0.4.13 seems to work ok
The text was updated successfully, but these errors were encountered: