hdl-parser
v1.0.2
Published
Parser for nand2tetris HDL language
Downloads
8
Readme
hdl-parser
Parser for nand2tetris HDL (Hardware Description Language), built on top of Peggy.
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.