Exemplo n.º 1
0
        private static CircuitGate ParseGate(string gateString, WireTable wires)
        {
            var gate = new CircuitGate();

            if (gateString.Contains("NOT"))
            {
                gate.Operator = CircuitGateType.NOT;

                gate.Wire1 = ParseOperand(gateString.Substring(3).Trim(), wires);
            }
            else
            {
                //Two operands separated by an operator
                var parsed = Regex.Match(gateString, "(?<in1>\\w+)\\s+(?<op>\\w+)\\s+(?<in2>\\w+)");

                if (parsed.Groups.Count <= 3)
                {
                    Console.WriteLine(string.Format("Problem parsing gate: '{0}'.", gateString));
                }

                //Match the operator
                foreach (var oper in Enum.GetNames(typeof(CircuitGateType)))
                {
                    if (oper.ToUpper() == parsed.Groups["op"].Value.Trim())
                    {
                        gate.Operator = (CircuitGateType)Enum.Parse(typeof(CircuitGateType), oper);
                        break;
                    }
                }

                //Parse the operands
                gate.Wire1 = ParseOperand(parsed.Groups["in1"].Value, wires);
                gate.Wire2 = ParseOperand(parsed.Groups["in2"].Value, wires);
            }

            return gate;
        }
Exemplo n.º 2
0
        internal void SetWireSignal(string wire, CircuitGate gate)
        {
            var wireObj = GetWire(wire);

            wireObj.Gate = gate;
        }
Exemplo n.º 3
0
        internal void SetWireSignal(string wire, CircuitGate gate)
        {
            var wireObj = GetWire(wire);

            wireObj.Gate = gate;
        }