Giter Club home page Giter Club logo

lr's Introduction

LR

explore different techniques to generate LR(k) parsing code

m41.ml -- hand-rolled parsers for ASU grammar 4.1 and 4.55. These parsers serve as references for how generated code should look like.

lr_parser.ml -- a type-safe LR(1) automata building engine. The idea is to build automata and interpret it to generate code (or we can generate on-the-fly).

genf1.ml -- some crazy code by Drup. It can be useful.

Methods

  • Normal approach

    • very naive LR(1) parsing algorithm. use hardcoded lr(1) parsing code to interpret array-based table
  • Automata simulated by GADT

    • Hardcoded GADT

    • Hardcoded optimized GADT

    • token information --> optional intermediate data structure like a GADT? --> use typed refunctionalization to generate mutually recursive functionals (optimized)

    • Generate optimized GADT using MetaOCaml (techinically impossible now)

  • Stackless LR(1) parser

    • An improvement to Derivation of a Typed Functional LR Parser
      Stack is implicitly represented as continuation function (CPS). Since no explicit stack data structure is present, it is possible to use MetaOCaml to generate parser.

      Jeremy, Runhang (01/18/16):
      maybe can use direct style, which is much easier for us to generate code. But if one state has two different reduce production rules, we can't turn CPS to direct style. Frederic showed one state can have to different reduction rules, so we can't have direct style :(

How-to

Take a canonical example, Grammar 4.1 in Aho.

  1. manually go over all algorithms on paper, get very familar with LR(1) parsing process. How optimization works?

  2. write naive LR(1) parser on computer

  3. try different black technologies

lr's People

Contributors

objmagic avatar yallop avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

Forkers

yallop

lr's Issues

Existential unpacking

When reducing, we need to apply semantic function. However, the type of (any) semantic function cannot be recovered due to existential unpacking.

Generation of stackless LR(1) parser

Good news:
I finally decide to spend some time and dive into LR parsing again. The result is we have a stackless LR(1) parser for grammar 4.55 in ASU86. The idea of course comes from Ralf Hinze's paper. This is particular cool because no explicit stack data structure is present now. The procedure of how to write such stackless parser is also clear to me.

Bad news:

  1. MetaOCaml still cannot generate pattern matching.
  2. Even if 1 is resolved, the program to generate such parser could be horribly complex. I expect there will tons of GADT, memorization tricks, code generation hacks, etc... Anyway, it will definitely be a triumph if I can finish it
  3. Consider 2 is done. Menhir, as a very mature and advanced parser generator, has many advantages over our technique. Although the aim of this project is different, I still expect our parser can be usable in real world, which means extra tons of effort to bring it to usable condition. I still remember to original goal of this project, which is to design a more PEG-like parser generator.

any opinion? @yallop

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.