Giter Club home page Giter Club logo

asparserations's Introduction

Asparserations

Asparserations is an LR(1) parser generator frontend written in C++. It outputs JSON representing the state machine table. A C++ backend, used to generate the grammar parser, is included in the bootstrap folder.

Features

  • Outputs JSON for consumption by backends, without needing to implement the [LA]LR(1) table construction algorithm
  • Productions are named instead of indexed and names are local to the nonterminal
  • Preserves shift/reduce and reduce/reduce conflicts in JSON
  • Used to generate the parser for grammar files
  • Can be integrated with lexers easily (the grammar file lexer is lazy/a generator/monadic!)

Options

  • --version, -v - Prints the software version
  • --help, -h - Prints the help
  • --out, -o - Specifies the output file (a.out.json by default)
  • --root, -r - Specifies the root node (Root by default)
  • --lalr, -l - Use LALR(1) (experimental)
  • --debug, -d - Output the item sets as well as the states

Building From Source

Prerequisites

This project requires G++, GNU Make, and Python 3 in order to build from source.

Installing

$ git clone https://github.com/TheAspiringHacker/Asparserations.git
$ cd Asparserations
$ make install

The binary file is saved to ~/local/bin and can be invoked by typing asparserations [flags...] grammar_file_name.

Installing with CMake

I've decided to learn CMake by using it for this project. Use it by running:

$ git clone https://github.com/TheAspiringHacker/Asparserations.git
$ cd Asparserations
$ mkdir build
$ cd build
$ cmake ../
$ make

The resulting binary is build/bin/asparserations.

You can then run CPack:

$ cpack --config CPackConfig.cmake

(You will have to move the binary to a location in your PATH yourself.)

Trying it out

Create a file called grammar in your favorite text editor:

tokens {
  number,
  plus,
  minus,
  asterisk,
  slash
}

Term : Term plus Factor # add
     | Term minus Factor # sub
     | Factor # base_case
     ;

Factor : Factor asterisk number # mult
       | Factor slash number # div
       | number # base_case
       ;

Run:

$ asparserations -r Term -o table.json grammar
$ cat table.json

asparserations's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

ginochenhj defmc

asparserations's Issues

Empty Rule Error

I am trying to use a grammar with a rule in the following format: NB : # empty ;. However, this is generating an invalid parse table. Is this use case supported by this implementation? It may look like a useless rule to have in the grammar, but it's a convenient way to add information when doing scope analysis later on.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.