npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ellyzeul_/ll1-parser

v1.2.3

Published

A LL(1) Grammar parser

Downloads

4

Readme

LL1-parser

To install this package, just run

npm i @ellyzeul_/ll1-parser

A non-recursive predicative parser for LL(1) Grammars.

The grammar should already be properly in LL(1) format for the parser to work as expected, there isn't any kind of automatic treatment.

So, having the following grammar:

rexpr     -> rexpr + rterm | rterm
rterm     -> rterm rfactor | rfactor
rfactor   -> rfactor * | rprimary
rprimary  -> a | b

It has to be transformed, beforehand, into:

rexpr     -> rterm rexpr'
rexpr'    -> + rterm rexpr' | ε
rterm     -> rfactor rterm'
rterm'    -> rfactor rterm' | ε
rfactor   -> rprimary rfactor'
rfactor'  -> * rfactor' | ε
rprimary  -> a | b

It might be implemented in the future, but no guarantee.

Generating a parser

To generate a parser, the generateParser function should be used.

const parser = generateParser({
  headRule: '<rexpr>',
  '<rexpr>':                  '<rterm> <rexpr*>',
  '<rexpr*>':                 '+ <rterm> <rexpr*> | v',
  '<rterm>':                  '<rfactor> <rterm*>',
  '<rterm*>':                 '<rfactor> <rterm*> | v',
  '<rfactor>':                '<rprimary> <rfactor*>',
  '<rfactor*>':               '* <rfactor*> | v',
  '<rprimary>':               'a | b'
})

Any symbol wrapped around <> will be interpreted as a non-terminal.

The parser has some reserved symbols for internal processes. The symbols are the following:

| Symbol | What it means | User allowed to use | |--------|----------------------------------------------|---------------------| | v | Empty input character | Yes | | $ | End of string character | Yes | | @ | Synchronizing token. For panic recovery mode | No |

Parsing tokens

As for now, the parser only parses token by token, so an input should have been previously broke into tokens by a lexical analyzer.

To parse tokens, the parseToken function should be used on a procedural approach, or call the parser.parseToken method on an object-oriented approach.

const result = parseToken(parser, '$')

Or

const result = parser.parseToken('$')

The result object will have the following object:

{
  parsing_ended: boolean,
  errors: {
    expected: string[], 
    got: string
  }[],
  has_errors: boolean
}

The parsing_ended property says if the latest parsed token reached the end of the parsing table. The end may be reached by an errorless parsing, or by a error panic recovery.

The errors property bears all errors found on the parsing.

The has_errors property says if the errors array is empty or not. Just for coding convinience.

Contributing

As this project is for the an university project, for the Compilers subject, I'll likely not keep updating it after but, anyone who finds it useful and wants to contribute or fork, is welcome to do so.