Skip to content

Missing reduce for epsilon LR0 items #6

@rick-masters

Description

@rick-masters

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 |
--------------------------------

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions