Convert EBNF to BNF for LALR analyzer

I know that there are several posts with a similar headline. Most links to a dead site - and I have a more specific question.

I am trying to convert EBNF to XPath specification for direct BNF so that I can easily create a Bison compatible grammar file.

Some time has passed since I did this, and I don’t remember which side the recursion is coming from. I thought it was left, but my "direct" translation gives me syntax errors with XPath simple phrase expressions when they are run through a Bison-processed parser.

So, if someone can humor me and weigh me - therefore I do not pursue a ghost:

In the Expr rule below:

 Expr::= ExprSingle ("," ExprSingle)* 

Is this the correct translation? (putting recursion on the left):

 Expr::= Expr "," ExprSingle | ExprSingle 
+4
source share
1 answer

It's fine....

You can put the recursion on the right and it should work, but you get the parser to "do more work" because it needs to track the recursion spine, and for this it needs to use more stack places,

+4
source

Source: https://habr.com/ru/post/1393690/


All Articles