Skip to content

Parser for nand2tetris HDL (Hardware Description Language), written in JavaScript

License

Notifications You must be signed in to change notification settings

wokwi/hdl-parser

Repository files navigation

hdl-parser

Parser for nand2tetris HDL (Hardware Description Language), built on top of Peggy.

Build Status NPM Version License: MIT Types: TypeScript

Usage example

const { parse } = require('hdl-parser');

console.log(parse(`
  CHIP Not {
    IN in;
    OUT out;

    PARTS:
    Nand(a=in, b=true, out=out);
  }
`));

And the result:

({
  name: 'Not',
  definitions: [
    { type: 'IN', pins: [{ name: 'in', bits: 1 }] },
    { type: 'OUT', pins: [{ name: 'out', bits: 1 }] },
  ],
  parts: [
    {
      name: 'Nand',
      connections: [
        { from: { pin: 'a', bits: null }, to: { pin: 'in', bits: null } },
        { from: { pin: 'b', bits: null }, to: { const: 'true' } },
        { from: { pin: 'out', bits: null }, to: { pin: 'out', bits: null } },
      ],
    },
  ],
})

For more examples, see the tests file.

License

Released under the terms of the MIT licence. Copyright (c) 2021, Uri Shaked.

About

Parser for nand2tetris HDL (Hardware Description Language), written in JavaScript

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published