https://github.com/paladitya/jparser
A Java library to give YACC like facility
https://github.com/paladitya/jparser
functional-programming java java8 lambdas library maven parser utility-application yacc
Last synced: 5 months ago
JSON representation
A Java library to give YACC like facility
- Host: GitHub
- URL: https://github.com/paladitya/jparser
- Owner: PalAditya
- Created: 2019-09-09T11:18:47.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-10-13T17:51:11.000Z (about 5 years ago)
- Last Synced: 2025-02-28T21:21:56.729Z (9 months ago)
- Topics: functional-programming, java, java8, lambdas, library, maven, parser, utility-application, yacc
- Language: Java
- Size: 30.3 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# JParser: An easy-to-use library to quickly debug your work.
Currently supported parsers: *LR0*, *SLR*, *LR1* and *LALR* parsers.
A basic usage of the library is as easy as follows:
```java
LR1Parser obj=new LR1Parser();//Create an instance of the desired parser-In this case LR1 type parser
obj.read_grammar("Path_to_grammar");//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
```
An example grammar files is included in the files directory.
- The map of the states

- The parse table

- The actions taken by stack to parse the table

Functions
*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 and computes it's closure
getGoto|HashSetComputes 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.
If you choose option 1, you can use **mvn clean install** on the files in src and pom.xml directly (don't use the files directory) to build the jar, javadoc and run tests.
The files in the **files** directory gives you all the source files, if you want to run them individually, with more verbose debugging options.
For option 2 and **release** build:
```java
io.github.PalAditya
parser-library
0.1.1
```
For **snapshot** build:
```java
io.github.PalAditya
parser-library
0.1-SNAPSHOT
```
In case you want the pre-release (latest) versions, you can download it manually from [here](https://oss.sonatype.org/content/repositories/central_bundles-18962/io/github/PalAditya/parser-library/0.1.1/)
More documentation coming soon!