Currently supported parsers: LR0, SLR, LR1 and LALR parsers.
A basic usage of the library is as easy as follows:
LR1Parser obj=new LR1Parser();//Create an instance of the desired parser-In this case LR1 type parser
obj.read_grammar("D://Documents/Lab4/LR0.txt");//Read the grammar file
obj.buildDFA();//Build a dfa from the file
System.out.println(obj.states);//Prints the transitions in all states
obj.print_transitions();//Print all the transitions
obj.getParsingTable(true);//Use false to avoid printing the table after creation
obj.parse("a c e",true);//Parse the string; use false to prevent the stack actions from displaying on screen
- The map of the states
- The parse table
- The actions taken by stack to parse the table
Parser.java is the base class which all the other classes inherit from. It exposes the following methods:
Function | Return Type | Action |
---|---|---|
read_grammar | void | Reads the grammar, augments it and fills in the list of terminals and non-terminals |
join | String | Utility method to join convert ArrayList to String |
getClosure | void | Accepts a HashSet of type <Parser.Pair> and computes it's closure |
getGoto | HashSet<Parser.Pair>Computes Goto | |
augment, unaugment | void,void | Augments and unaugments the grammar |
parse | void | Parses the string using the generated table |
getIndex | int | Returns the index of the state, or -1 if a new state |
pretty_it | void | Formatting |
print_transitions | void | Prints all transitions |
You can either clone the repository here for a minimal usage, or download it from maven, with full documentation and junit tests.
For release build:
<dependency>
<groupId>io.github.PalAditya</groupId>
<artifactId>parser-library</artifactId>
<version>0.1.1</version>
</dependency>
For snapshot build:
<dependency>
<groupId>io.github.PalAditya</groupId>
<artifactId>parser-library</artifactId>
<version>0.1-SNAPSHOT</version>
</dependency>
In case you want the pre-release (latest) versions, you can download it manually from here
Note: This is not being maintained anymore. Please see here to get the latest version of the code.