question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Java implemention with bnf does not generate valid Java

See original GitHub issue

Trying out the new Java support. My uses will want to use yacc/bison flavor of grammar. Given:

./bin/syntax  -m LALR1 --grammar ../syntax_test/src/com/syntax/calc.bnf -o ../syntax_test/src/com/syntax/Parser.java -w

Here is the .bnf:

%left '+'
%left '*'

%%

exp
  : exp '+' exp
    /* Explicitly calculate location */
    { $$ = new BinaryExpression("+", $1, $3); }

  | exp '*' exp
    /* Use default result location: @$ */
    { $$ = new BinaryExpression("*", $1, $3) }

  | '(' exp ')'
    { $$ = $2 }

  | number
    /* Named args and position */
    { $$ = new NumericLiteral(Integer.parseInt((String) $number)) }
  ;

literal
  : number
  ;

number
  : number digit
    { $$ = (String) $number + (String) $digit; }

  | digit
  ;

digit : '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9';

Generating this will show two immediate issues:

_lexRule0 has no lhs for semanticValue = null;

  String _lexRule0() {
      .semanticValue = null;
  }

The classes generated need to be inner classes to be valid. Which led me to add the following to the top of the file:

%{
class Parser {

%}

Unfortunately, I could not figure out how to add the closing ‘}’. In yacc I would solve this with adding:


%%

}

underneath the grammar section but this grammar does not seem to like that.

If I manually add that final ‘}’ then it exposes a second tier issue that there are static method declarations in inner classes which are not marked static.

Not sure how much I should have broken this up for the report. I figure I would dump all I noticed here. Let me know if I can report stuff differently. I am sure once the basics are working I will be able to make more granular reports.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
enebocommented, Dec 6, 2018

Wacky. I don’t get it … it now works. All the inner class stuff does not seem to be issue. I am fairly confused now. My only thought was I used npm build from master vs actual release. I guess though I have no current issues after 89996de.

@DmitrySoshnikov as to your other suggestion I will try changing the source so I can plug in a lexer. It should be good enough for a test.

I might suggest that a character-based parser in Java should maybe work with a Reader instead of a String, but that may be a future enhancement issue I can open (unfortunately Ruby supports encodings that Java charsets do not support so we do everything with raw bytes (or InputStream)). Decoupling lexer as interface would definitely allow switching between different input types…but again a feature request.

Thanks for your work!

0reactions
enebocommented, Dec 6, 2018

@DmitrySoshnikov I will follow those step by step and let you know but I gave instructions and file with what I used above and they are not much different. I do not see a sizable difference between the two unless the -w did something odd? I will play a little bit…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Tutology( DNF) and Contradiction ( CNF ) methods
I need to make a method for CNF an DNF, though im having a difficult time understanding how to implement it in the...
Read more >
1200302 – dnf reinstall breaks alternatives - Red Hat Bugzilla
After this action I was not able to use java related applications (e.g. eclipse) It took me few hours to find a root...
Read more >
dnf module does not install two versions of a package #66854
SUMMARY When installing two versions of the same package using the dnf module, it says the second time "nothing to do".
Read more >
Generic implementation of ... - Jean-Charles Quinton research page
This Java framework serves two purposes : 1) Exploring and comparing the parameters or implementations of well studied dynamic neural fields (such DNF...
Read more >
Building a Native Executable - Quarkus
This means that it does not profit from a few small enhancements that Oracle have ... will contain the application code, required libraries,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found