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

lex-bnf

v1.1.5

Published

General-purpose recursive descent parser and evaluator

Downloads

73

Readme

Lex-BNF

Build Status Coverage Status version license

This is a general-purpose recursive descent parser and evaluator.

Using this module, You can:

  1. Defines a syntax rule such as programming languages, expressions, or structured statements.
  2. Parses the code written based on the rules.
  3. Evaluates the result of the parsing.

NOTE: The class BNF exported in v0.3.3 is deprecated and it can be used as Language.BNF.

Create A Language Definition

The parser is defined as an instance of Language class by using objects of BNF-like notation and its evaluator functions. Those can run in dynamically and immediately.

The Language constructor takes one array of syntax rule. To create the syntax rule, use Language.syntax() function.

Paramters of Language.syntax():

  1. A name of the syntax rule.
  2. An array of a rule which is an array of terms.
    • A character '*' at the end of a rule name as an element of the terms is Repetition Specifier that means the rule is repeatable.
    • See the rule declaration part of additive-expression in sample/calc.js to use the feature.
  3. An evaluator function (optional). It can be omitted when the second parameter contains only one rule which containing only one other name of syntax rule.

Demo: Evaluating arithmetic expression

With following files, those shows how define a syntax of language.

run on bash

$ node sample/eval-expr.js '(1 + 2) * ((3 + 4) / 2)'
10.5
$

Documents

  • GitHub Pages
  • API Reference
    • v1.1.1
      • Fix the issue #16
    • v1.1.0
      • Repetition specifier * is available for the rule name. It is important for getting correct answer of multi term arithmetic expressions such as 1 - 2 - 3 = ?.
    • v1.0.1
    • v1.0.0

LICENSE

This software is released under the MIT License, see LICENSE