Beispiel #1
0
        public virtual void Parse()
        {
            StreamReader reader;

            if (File.Exists(pathOrString))
            {
                reader = new StreamReader(pathOrString);
            }
            else
            {
                reader = new StreamReader(new MemoryStream(Encoding.ASCII.GetBytes(pathOrString)));
            }

            varsToWires = new Dictionary <string, BigWire>();
            string line       = null;
            int    lineNumber = 0;

            while (!reader.EndOfStream)
            {
                line = reader.ReadLine();
                if (line == null)
                {
                    break;
                }

                int commentIndex = line.IndexOf("//");
                if (commentIndex != -1)
                {
                    line = line.Substring(0, commentIndex);
                }

                try
                {
                    ReadLine(line.Trim().Replace("\t", ""));                            // remove white spaces
                    lineNumber++;
                }
                catch (Exception e)
                {
                    throw new Exception("Error in line " + lineNumber + "\n" + e.Message);
                }
            }
            outputWire          = GetWireFromString(outputVar);
            outputWire.IsOutput = true;
            circuit             = CreateCircuit(prime, inputs);
            if (circuit == null)
            {
                throw new Exception("Error in parsing the circuit!");
            }
        }
Beispiel #2
0
        public virtual void Parse()
        {
            StreamReader reader;
            if (File.Exists(pathOrString))
                reader = new StreamReader(pathOrString);
            else
                reader = new StreamReader(new MemoryStream(Encoding.ASCII.GetBytes(pathOrString)));

            varsToWires = new Dictionary<string, BigWire>();
            string line = null;
            int lineNumber = 0;
            while (!reader.EndOfStream)
            {
                line = reader.ReadLine();
                if (line == null)
                    break;

                int commentIndex = line.IndexOf("//");
                if (commentIndex != -1)
                    line = line.Substring(0, commentIndex);

                try
                {
                    ReadLine(line.Trim().Replace("\t", ""));	// remove white spaces
                    lineNumber++;
                }
                catch (Exception e)
                {
                    throw new Exception("Error in line " + lineNumber + "\n" + e.Message);
                }
            }
            outputWire = GetWireFromString(outputVar);
            outputWire.IsOutput = true;
            circuit = CreateCircuit(prime, inputs);
            if (circuit == null)
                throw new Exception("Error in parsing the circuit!");
        }