Simplified Circuit Diagram

From Esolang
Jump to navigation Jump to search

Simplified Circuit Diagram is a language created by user:ps4star and is a 1-dimensional simplified version of the Circuit Diagram language.

Syntax and Commands

Syntax

Simplified Circuit Diagram uses an Assembly-like syntax where the command name and parameters are separated by spaces. A typical program should look like this:

XOR 1 2
AND 1 3

Commands

Name Effect
EXEC Executes a file as code, then jumps back to the file it was called from. See *NOTE 1 below.
WIRES Defines the number of wires the circuit uses.
OUTPUT-MODE Defines how detailed the output of the program is. See *NOTE 2 below.
SPLIT Splits a wire into two wires with the same value as the original wire. See *NOTE 3 below.
AND Sends two wires through an AND gate.
OR Sends two wires through an OR gate.
XOR Sends two wires through an XOR gate.
NOR Sends two wires through a NOR gate.
NAND Sends two wires through a NAND gate.
XNOR Sends two wires through an XNOR gate.
NOT Sends a wire through a NOT gate.
  • NOTE 1: The interpreter will always start reading from the file "MAIN.cdl". The EXEC function can be called in the MAIN.cdl file to change the file it runs from the main to something else.
  • NOTE 2: If the mode is 1 (which is the default value if no value is set), the program only outputs the values of the wires. If the mode is 2, the program also outputs the wire dictionary after every instruction. If the mode is 3, the program outputs each command and the change in the wires after the command is run, as well as the values of the wires.
  • NOTE 3: The new wire created from the SPLIT will be named the highest wire ever assigned plus one. So if you call WIRES 3 then SPLIT a wire, you now have 4 wires: 1, 2, 3, 4. So the name of the wire that is created from the first SPLIT instruction will be Input_Wires + 1. Then the second SPLIT instruction you call will be have the name of Input_Wires + 2, and so on.

Examples

Full Adder Circuit

WIRES 3
OUTPUT-MODE 3
SPLIT 1
SPLIT 2
SPLIT 3
XOR 1 2
SPLIT 1
XOR 1 3
AND 6 7
AND 4 5
OR 4 6

Adds the 3 input wires together.

Full Subtractor Circuit

WIRES 3
OUTPUT-MODE 3
SPLIT 1
SPLIT 2
SPLIT 3
XOR 2 3
SPLIT 2
NOT 7
AND 4 7
NOT 5
AND 5 6
XOR 1 2
OR 4 5

Subtracts the first wire by the second wire; the third wire is the carry value.

Interpreters/Compilers

Python Interpreter by ps4star.