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

Missing reduce for epsilon LR0 items #6

Open
rick-masters opened this issue Feb 24, 2020 · 0 comments
Open

Missing reduce for epsilon LR0 items #6

rick-masters opened this issue Feb 24, 2020 · 0 comments

Comments

@rick-masters
Copy link
Contributor

The following test problem shows a missing reduce on $ (EOF) for state 0.
Grammar:
S -> a
S -> epsilon
I'll create a pull request with fix.

import util.*;
import lr0.*;
import lr1.*;
public class TestLR
{
    public static void main(String[] args) {
        String g = "S -> a\n" +
                   "S -> epsilon\n";

        LR0Parser lr0Parser = new LR0Parser(new Grammar(g));
        if (lr0Parser.parserSLR1()) {
            System.out.println(lr0Parser.actionTableStr());
            System.out.println(lr0Parser.goToTableStr());
        }
        else {
            System.out.println("parse not ok");
        }
    }
}
$ java TestLR
Rules: 
0 : S' -> S 
1 : S -> a 
2 : S -> epsilon 
Action Table : 

                a         $         
--------------------------------
|0         |  SHIFT 2|         |
--------------------------------
|1         |         | REDUCE 2|
--------------------------------
|2         |         | REDUCE 1|
--------------------------------
|3         |         |  ACCEPT |
--------------------------------
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

1 participant