jainpranav1 / Nand2Tetris-HDL-Visualizer

Repository for Nand2Tetris HDL Visualizer extension
2 stars 0 forks source link

Expected [a-z,A-Z], comment, or whitespace but "}" found. #6

Closed docentYT closed 1 year ago

docentYT commented 1 year ago

I'm getting an error:

Command 'Visualize HDL File' resulted in an error
Expected [a-z,A-Z], comment, or whitespace but "}" found.

when I am trying to visualize the following code:

// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/01/Xor.hdl

/**
 * Exclusive-or gate:
 * out = not (a == b)
 */

CHIP Xor {
    IN a, b;
    OUT out;

    PARTS:
    Not(in=a, out=nota);
    Not(in=b, out=notb);
    And(a=a, b=notb, out=aAndNotB);
    And(a=nota, b=b, out=bAndNotA);
    Or(a=aAndNotB, b=bAndNotA, out=out);
}
jainpranav1 commented 1 year ago

Thanks for trying out the extension! I'll take a look and see what the issue is.

jainpranav1 commented 1 year ago

It seems to work fine for me.

image
jainpranav1 commented 1 year ago

The error you are receiving looks like a parsing error. The parser I use is from here: https://www.npmjs.com/package/hdl-parser.

docentYT commented 1 year ago

I found what the error is in. I did not have parts defined for the components I was using. If I remember correctly, it was mentioned in the nand2tetris course that the simulation program has predefined components so that you don't have to manually create all of them. And I rather don't see the point of using them for visualization when a single .hdl file could suffice.

jainpranav1 commented 1 year ago

Awesome that you figured out the error! The reason the the extension needs to examine the components is to determine what pins are inputs and what pins are outputs to show the visualization correctly.

docentYT commented 1 year ago

needs to examine the components is to determine what pins are inputs and what pins are outputs

It is not necessary to know all the PARTS for this. IN and OUT will be enough.

jainpranav1 commented 1 year ago

The way the extension works is the following. If the extension observes a component with the same name of a builtin nand2tetris chip, it will first check the directory to see if the user has defined the component. If no file is found, the extension assumes the component is a builtin nand2tetris chip and uses information from here to determine the inputs. This mechanism is useful for example if I want to define a custom chip that shares the name of a builtin chip, but has different pins. For example, a custom ALU.

jainpranav1 commented 1 year ago

In short, if you don't want to define builtin nand2tetris chip yourself, don't include their files in your directory.