Questions tagged [jison]

A parser generator for JavaScript.

Jison produces a parser from a context-free grammar.

Highlights:

  • Close compatibility with bison, lex and yacc grammars for lexer and parser definitions.
  • As the parsers it generates are plain JavaScript, they can be embedded in a web page executing inside the browser (similarly to OmetaJS, in that regard).

Resources:

Note:
There is the original Jison (AKA Vanilla Jison) that has not been updated lately and the GitHub GerHobbelt fork that is actively maintained.

139 questions
15
votes
2 answers

How to get Abstract Syntax Tree (AST) out of JISON parser?

So I have generated a parser via JISON: // mygenerator.js var Parser = require("jison").Parser; // a grammar in JSON var grammar = { "lex": { "rules": [ ["\\s+", "/* skip whitespace */"], ["[a-f0-9]+", "return…
Tower
  • 98,741
  • 129
  • 357
  • 507
10
votes
2 answers

Jison global variables

In previous versions of Jison, it was possible to have a Flex-like feature that allowed defining variables accessible in both the lexer and parser contexts, such as: %{ var chars = 0; var words = 0; var lines = 0; %} %lex %options flex %% \s [^…
Marcelo Camargo
  • 2,240
  • 2
  • 22
  • 51
6
votes
1 answer

jison start conditions with json format

Despite long search in documentation and forums, I still fail to get the right syntax for Jison start condition using JSON format in node.js > ** Documentation at http://zaach.github.io/jison/docs/ says: > // Using the JSON format, start conditions…
Fulup
  • 545
  • 3
  • 14
6
votes
1 answer

What are the %lex and /lex lines in jison?

The below code snippet can be found on: http://zaach.github.io/jison/demos/calc/, and also the jison documentation page. After reading the jison, lex, and flex documentation - I still don't fully understand the %lex and /lex syntax. Is it specific…
aaaaaa
  • 1,233
  • 13
  • 24
6
votes
1 answer

Looking for examples of Jison grammars that use indentation for block-structure

Has anyone got a simple example of how to define a grammar that parses python-like indentation for blocks using Jison?
interstar
  • 26,048
  • 36
  • 112
  • 180
6
votes
1 answer

Grammar spec resolving Shift/Reduce conflicts

I'm using Jison (Bison) to create a simple markup language. I'm clearly new to this, but slight variations are working very well. I just don't understand the source of the S/R conflict. It doesn't seem matter that 'Text' is returned by two lexer…
Jason Kleban
  • 20,024
  • 18
  • 75
  • 125
5
votes
2 answers

Adding declarations to JISON

I have here an only slightly modified version of the JISON calculator example: /* description: Parses end executes mathematical expressions. */ /* lexical grammar */ %lex %% \s+ /* skip whitespace */ [0-9]+("."[0-9]+)?\b return…
user1916428
4
votes
1 answer

recursive boolean and/or to array jison parser

I'm exceptionally new to jison and have managed to piece together a helpful query parser. I'm now trying to create a parser that can parse a string like "a == 1 and b == 1 and c == 1" into an object like {and: [ {a: {eq: 1}}, {b: {eq: 1}}, {c:…
jonotron
  • 83
  • 7
4
votes
0 answers

How to use EBNF groups properly in Jison

I am trying to figure out how to deal with a situation I am having while using the EBNF extension in Jison (Jison by default supports only BNF -- you can activate that option on a need basis). I am trying to write a simple XML parser. In XML, there…
Harald
  • 41
  • 1
4
votes
1 answer

Debugging in Jison

I'm using Jison to write a parser. This is my grammar: { "program": [ ["statements EOF", "return $1;"] ], "statements": [ ["statement", "$$ = $1;"], ["statements statement", "$$ = $1 + '\\n' + $2;"] …
Aadit M Shah
  • 72,912
  • 30
  • 168
  • 299
4
votes
1 answer

How do you match zero or more tokens in Jison?

I'm writing a simple expression parser in Jison allowing an arbitrary number of newlines to follow a binary operator in an expression. This is my grammar so far: { "operators": [ ["left", "+", "-"], ["left", "*", "/", "%"] …
Aadit M Shah
  • 72,912
  • 30
  • 168
  • 299
4
votes
1 answer

How is this grammar ambiguous?

I'm writing a simple expression parser in Jison. Here's my grammar: { "operators": [ ["left", "+", "-"], ["left", "*", "/", "%"] ], "bnf": { "program": [ ["statement EOF", "return $1;"] ], …
Aadit M Shah
  • 72,912
  • 30
  • 168
  • 299
4
votes
1 answer

How to get line number from an AST node (Jison)

I'm using Jison to build a simple calculator language, which includes variables. I want these variables to work similar to JavaScript, that is you have to initialise it with the var keyword the first time. In my language, I want to show an error if…
Cobby
  • 5,273
  • 4
  • 28
  • 41
3
votes
1 answer

bison precedence (actually using jison but it should be the same)

I'm using jison (a javascript equivalent of Bison) and I'm having the following precedence problem. I'll illustrate it using the calculator demo http://zaach.github.com/jison/try/ It works fine as is. The precedence is %left '+' '-' %left '*'…
user1213898
  • 173
  • 7
3
votes
1 answer

Parsing an SQL-like micro-language which is a superset of Javascript

I am currently developing an application in Javascript in which I will allow the users to add "rules" to the application by the use of a small self-declared programming language. In order to achieve this functionality, I need to be able to parse…
Astarno
  • 405
  • 3
  • 10
1
2 3
9 10