Skip to content
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

EBNF unable to get at sub-expression #254

Open
rogierschouten opened this issue Oct 13, 2014 · 5 comments
Open

EBNF unable to get at sub-expression #254

rogierschouten opened this issue Oct 13, 2014 · 5 comments

Comments

@rogierschouten
Copy link

Consider this grammar part:

function_call
    : IDENTIFIER "(" (expression ("," expression)* )? ")"
        {
            console.log($1);
            console.log($3);
            try {
                if ($5) {
                    console.log($5);
                }
            } catch (e) {
                console.log("exception");
            }
        }

This code executes the "exception" log statement. In this case, $5 can be undefined due to the asterisk-operator. However, I cannot test for this, because the $5 is translated by JISON into an array subscript. Am I doing something wrong or does JISON maybe need a way to discover whether $x is present?

@brianZeng
Copy link

I also have this issue.
for now,I just change the grammar like this

function_call:
    IDENTIFIER '(' ')'
   |IDENTIFIER '(' param ')'
   ;
param:
     expression
    |param ',' expression
    ;

Is there any other solution?

@agershun
Copy link

Exactly the same problem with %ebnf:

     CreateVertex
    : CREATE VERTEX Literal? (SET SetColumnsList | CONTENT ExprList | Select)?
        { 
            $$ = new yy.CreateVertex({class:$3, action:$4});
            $$.expr = $5; // this should be or SetColumnList or ExprList or undefined
        }
    ;

translates to:

    this.$ = new yy.CreateVertex({class:$$[$0-1], action:$$[$0]});
    this.$.expr = $$[$01]; // wrong parameter, because parser has only 3 values in stack

@agershun
Copy link

@brianZeng Thank you for the idea of solution. I used the same approach:

CreateVertex
    : CREATE VERTEX Literal? CreateVertexSet 
        { $$ = new yy.CreateVertex({class:$3}); yy.extend($$,$4); }
    ;
CreateVertexSet
    : SET SetColumnsList    { $$ = {sets:$2}; }
    | CONTENT ExprList  { $$ = {content:$2}; }
    | Select    { $$ = {select:$1}; }
    ;

GerHobbelt added a commit to GerHobbelt/jison that referenced this issue Oct 25, 2015
…write process so there'll always a risk of edge cases which won't fly exactly as intended, not due to the rewrite process, which in itself is fine, but because of ACTION mapping from EBNF rule with action block to rewritten ruleset: we do not/cannot validate the action code *perfectly* so userland action code *can* screw up when it tries hard enough.

TODO: at least *some* validation of the action code to ensure that subnames, subrefs, etc. are not used in the action block as those will be *nuked* by the rewrite process!
GerHobbelt added a commit to GerHobbelt/jison that referenced this issue Oct 25, 2015
…ms); all test pass again after rebuilding the compiler. TODO: cleanup the bnf.y file and remove the debug print code.

- tests have been inspected and corrected where necessary now that we propagate the *quoted* literals rather than the *unquoted* literals (which made `' '` literal whitespace tokens *disappear* when used in a grammar that way
- This work is related to zaach#254
GerHobbelt added a commit to GerHobbelt/jison that referenced this issue Oct 26, 2015
…istakes in relation to EBNF usage (related to zaach#254, completing the work done on that one)

- tightened and unified the regexes for named aliases in ACTION blocks: now only classic C variable names are accepted, i.e. `/[a-zA-Z_][a-zA-Z0-9_]*/`
GerHobbelt added a commit to GerHobbelt/jison that referenced this issue Oct 26, 2015
…ork on zaach#254. Now this stuff should be documented... Not at 3AM though.
@GerHobbelt
Copy link
Contributor

After some work on the EBNF stuff lately, I added a bit of docu in the wiki that might be useful, if only sideways today (as EBNF in latest jison is a tad skewered, while I must say that my own fork isn't super-duper either.

Here's the docs: https://github.com/zaach/jison/wiki/Deviations-From-Flex-Bison#extended-bnf

The TL;DR take-away is that you MUST NOT EVER attempt to reference any term inside the outermost wildcarded EBNF group/operator. The difference between vanilla and GerHobbelt today is that vanilla discards the terms beyond $1 in there, while GerHobbelt produces a nested set of arrays carrying the terms' values.

@agershun
Copy link

👍 Thanl you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants