jison

Jison: Reduce Conflict where actually no conflict is

我的梦境 提交于 2019-12-24 00:57:02
问题 I'm trying to generate a small JavaScript parser which also includes typed variables for a small project. Luckily, jison already provides a jscore.js which I just adjusted to fit my needs. After adding types I ran into a reduce conflict. I minimized to problem to this minimum JISON: Jison: %start SourceElements %% // This is up to become more complex soon Type : VAR | IDENT ; // Can be a list of statements SourceElements : Statement | SourceElements Statement ; // Either be a declaration or

Issue with a Jison Grammar, Strange error from generate dparser

左心房为你撑大大i 提交于 2019-12-13 02:56:48
问题 I am writing a simple Jison grammar in order to get some experience before starting a more complex project. I tried a simple grammar which is a comma separated list of numeric ranges, with ranges where the beginning and ending values were the same to use a single number shorthand. However, when running the generated parser on some test input I get an error which doe snot make alot of sense to me. Here is the grammar i came up with: /* description: Parses end executes mathematical expressions.

Combine similar constructs in recursive rules

爷,独闯天下 提交于 2019-12-12 04:13:46
问题 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, right: $3 } | expr "-" expr -> { type: "-", left: $1, right: $3 } | expr "*" expr -> { type: "*", left: $1, right: $3 } | expr "/" expr -> { type: "/", left: $1, right: $3 } ; I the same grammar I also have a rule for a "filter expression" that also supports

How to handle multiple rules for one token with PLY

不打扰是莪最后的温柔 提交于 2019-12-11 16:47:49
问题 I'm working with a jison file and converting it to a parser generator using the lex module from python PLY. I've noticed that in this jison file, certain tokens have multiple rules associated with them. For example, for the token CONTENT , the file specifies the following three rules: [^\x00]*?/("{{") { if(yytext.slice(-2) === "\\\\") { strip(0,1); this.begin("mu"); } else if(yytext.slice(-1) === "\\") { strip(0,1); this.begin("emu"); } else { this.begin("mu"); } if(yytext) return 'CONTENT';

JISON errors occuring with nonterminals

被刻印的时光 ゝ 提交于 2019-12-11 15:38:02
问题 I am writing a JISON file for a class and trying to use nonterminals in place of declaring associativity for operators but am utterly lost on what the errors really mean, as this is a one time assignment for a class and I haven't found amazing examples of using nonterminals for this use case. My JISON code: /* lexical grammar */ %lex %% \s+ /* skip whitespace */ [0-9]+("."[0-9]+)?\b return 'NUMBER' "*" return '*' "/" return '/' "-" return '-' "+" return '+' "^" return '^' "!" return '!' "%"

Adding functions to bison/jison calculator language

喜欢而已 提交于 2019-12-10 21:18:24
问题 I'm trying to expand the Jison calculator example with some simple functions. I'm rather new to parsing and bison/jison, but this is a bit of what I have so far: /* lexical grammar */ %lex %{ var funcs = { pow: function(a, b) { return Math.pow(a, b); }, test: function(a) { return a*2; } } %} %% \s+ /* skip whitespace */ [0-9]+("."[0-9]+)?\b return 'NUMBER' [a-zA-Z]+ return 'NAME' "," return ',' "*" return '*' "(" return '(' ")" return ')' <<EOF>> return 'EOF' . return 'INVALID' /lex %start

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

我们两清 提交于 2019-11-30 10:48:48
问题 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 'HEX';"] ] }, "bnf": { "hex_strings" :[ "hex_strings HEX", "HEX" ] } }; // `grammar` can also be a string that uses jison's grammar format var parser = new Parser(grammar); // generate source, ready to be written to disk var parserSource = parser.generate(); // you can also use the

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

不羁岁月 提交于 2019-11-29 22:33:12
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 'HEX';"] ] }, "bnf": { "hex_strings" :[ "hex_strings HEX", "HEX" ] } }; // `grammar` can also be a string that uses jison's grammar format var parser = new Parser(grammar); // generate source, ready to be written to disk var parserSource = parser.generate(); // you can also use the parser directly from memory // returns true parser.parse("adfe34bc e82a"); // throws lexical error parser