GerHobbelt / jison

bison / YACC / LEX in JavaScript (LALR(1), SLR(1), etc. lexer/parser generator)
https://gerhobbelt.github.io/jison/
MIT License
118 stars 20 forks source link

examples/test-ll2-grammar-1.jison appears to have syntax errors #8

Closed nwhetsell closed 6 years ago

nwhetsell commented 7 years ago

Attempting to create a JavaScript file from examples/test-ll2-grammar-1.jison using Jison 0.4.18-180 results in:

/…/jison-gho/lib/jison.js:192
            throw err;
            ^

JisonParserError: Parse error on line 55: 
S → G;
--^
Expecting ":", got unexpected "ARROW_ACTION"
    at Parser.parseError (/…/jison-gho/lib/util/parser.js:2464:15)
    at Parser.parse (/…/jison-gho/lib/util/parser.js:2800:34)
    at Object.parse (/…/jison-gho/lib/util/ebnf-parser.js:6:16)
    at autodetectAndConvertToJSONformat (/…/jison-gho/lib/jison.js:182:32)
    at new Jison_Generator (/…/jison-gho/lib/jison.js:6605:15)
    at Object.generateParserString (/…/jison-gho/lib/cli.js:325:21)
    at processInputFile (/…/jison-gho/lib/cli.js:262:26)
    at Object.cliMain [as main] (/…/jison-gho/lib/cli.js:314:9)
    at Object.<anonymous> (/…/jison-gho/lib/cli.js:340:9)
    at Module._compile (module.js:571:32)

(I made the file paths shorter for clarity’s sake.)

GerHobbelt commented 6 years ago

This particular grammar was copied from a paper/book to test against Jison and doesn't necessarily compile/work-as-expected.

This type of activity will happen more often, so Jison has been augmented to provide a slightly better error report:

$ node dist/cli-cjs.js  --main  examples/test-ll2-arrows-fail.jison
W:\Users\Ger\Projects\sites\library.visyond.gov\80\lib\tooling\jison\dist\cli-cjs.js:26664
            throw err;
            ^

JisonParserError:
rule id should be followed by a colon instead of an arrow:
please adjust your grammar to use this format:

    rule_id : terms  { optional action code }
            | terms  { optional action code }
            ...
            ;

  Erroneous area:
38: S → G;
^^....^
39:
40: G → P

    at Object.parseError (...\jison\dist\cli-cjs.js:21184:15)
    at Object.yyError (...\jison\dist\cli-cjs.js:21343:25)
    at Object.parser__PerformAction (...\jison\dist\cli-cjs.js:19293:14)
    at Object.parse (...\jison\dist\cli-cjs.js:22544:40)
    at Object.parse (...\jison\dist\cli-cjs.js:25426:23)
    at autodetectAndConvertToJSONformat (...\jison\dist\cli-cjs.js:26617:32)
    at new Jison_Generator (...\jison\dist\cli-cjs.js:34893:15)
    at Object.generateParserString (...\tooling\jison\dist\cli-cjs.js:35435:25)
    at processInputFile (...\tooling\jison\dist\cli-cjs.js:35350:30)
    at Object.cliMain [as main] (...\tooling\jison\dist\cli-cjs.js:35428:13)