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
1
vote
1 answer

JISON: How do I avoid "dog" being parsed as "do"?

I have the following JISON file (lite version of my actual file, but reproduces my problem): %lex %% "do" return 'DO'; [a-zA-Z_][a-zA-Z0-9_]* return 'ID'; "::" return 'DOUBLECOLON' <> …
palantus
  • 155
  • 2
  • 12
1
vote
1 answer

Parse individual productions in JISON

In JISON, is there a way to parse a string for an individual production? For instance, this primitive parser defines a master expressions in terms of several productions such as ary. Right now this returns a function that can parse expressions: var…
prototype
  • 7,249
  • 15
  • 60
  • 94
1
vote
1 answer

Using Jison to convert a list of commands into an array of objects

I am trying to use Jison, which is a JS port of Bison, the parser generator. My goal is to convert this input: foo(10) bar() foo(28) baz(28) into this: [ { func: 'foo', arg: 10 }, { func: 'bar' }, { func: 'foo', arg: 28 }, { func: 'baz',…
AndyPerlitch
  • 4,539
  • 5
  • 28
  • 43
1
vote
0 answers

Proper bison definition file for a multi-statement language with Jison

I am trying to get a handle on jison, which is a javascript implementation of Bison. My specific language I am trying to parse looks like this: foo(10) bar() foo(20) baz() I want to parse this into something like: return [ { func: 'foo', arg: 10…
AndyPerlitch
  • 4,539
  • 5
  • 28
  • 43
1
vote
0 answers

Convert input string with jison

I have a function inside a string: def sum(num): end And I want to convert it to: function sum(num) { } using jison. I am using the grammar defined in a javascript object: const grammar = { "lex": { "macros": { "function": "def…
anlijudavid
  • 509
  • 6
  • 12
1
vote
1 answer

Combine similar constructs in recursive rules

This is for a parser in Jison but I guess the same applies for Bison. I have a rule that has a definition for an expression. expr : NUMBER -> { type: "number", value: $1 } | "(" expr ")" -> $2 | expr "+" expr -> { type: "+", left: $1,…
rveerd
  • 3,620
  • 1
  • 14
  • 30
1
vote
1 answer

How to return multiple tokens with Jison lexer

I'm new to lexing and parsing so sorry if the title isn't clear enough. Basically, I'm using Jison to parse some text and I am trying to get the lexer to comprehend indentation. Here's the bit in question: (\r\n|\r|\n)+\s* %{ …
rescuecreative
  • 3,607
  • 3
  • 18
  • 28
1
vote
0 answers

Parse character representation in Jison/Javascript

I'm coding a C++ grammar in Jison and I've managed to correctly detect character literals with this regex: \'([^\\\']|\\.)\' return 'CHAR_LIT' and then add it to the AST like this: | CHAR_LIT {$$ = new yy.Ast('CHAR_LIT', [$1])} However, with…
albertsgrc
  • 13
  • 4
1
vote
1 answer

Conflict in grammar: multiple actions possible

I've tried to write simple parser with jison (http://zaa.ch/jison/docs/) at stuck in describing text. %lex %% [\s\n\t]+ return 'TK_SPACE'; [0-9]+("."[0-9]+)?\b return 'TK_NUMBER'; [a-zA-Z]+([a-zA-Z0-9]+)?\b return…
1
vote
1 answer

Handling clike comments in Jison

I'm writing a compiler of clike language in JS using Jison as an lexer/parser generator with angular frontend. I nearly got the result I expected, but there is one thing that is puzzling me - how to make Jison ignore comments (both /* block */ and…
Vees
  • 703
  • 4
  • 9
1
vote
1 answer

Change lexical state from within Jison

Is it possible to change lexical state (aka "start condition") from within the grammar rules of Jison? Am parsing a computer language where lexical state clearly changes (at least to my human mindset) when certain grammar rules are satisfied,…
prototype
  • 7,249
  • 15
  • 60
  • 94
1
vote
1 answer

Jison Lex without white spaces

I have this Jison lexer and parser: %lex %% \s+ /* skip whitespace */ 'D01' return 'D01' [xX][+-]?[0-9]+ return 'COORD' <> return 'EOF' . return 'INVALID' /lex %start source %% source :…
jpcgt
  • 2,138
  • 2
  • 19
  • 34
1
vote
0 answers

Jison parser: Retrieve n number of text after a specific token

I am using jison parser to parse my commands. I want to parse the command: grp -i ...... and want to retrieve the data as: { group: , id: [id1, id2, id3...] } But to parse using jison parser, I could try…
Amala James
  • 1,336
  • 3
  • 16
  • 32
1
vote
2 answers

Jison Lexer - Detect Certain Keyword as an Identifier at Certain Times

"end" { return 'END'; } ... 0[xX][0-9a-fA-F]+ { return 'NUMBER'; } [A-Za-z_$][A-Za-z0-9_$]* { return 'IDENT'; } ... Call : IDENT ArgumentList {{ $$ = ['CallExpr', $1, $2]; }} | IDENT {{ $$ = ['CallExprNoArgs', $1]; }} ; CallArray :…
1
vote
0 answers

Contextual conditions when building AST for C program

I'm writing an interpreter for C (subset) in Javascript (I want to provide program's execution visualisation in browser). As the first step I want to create an AST tree for the user program. I'm using Jison for this, which is similar to flex/bizon…
kitek
  • 117
  • 1
  • 13