Example #1
0
        /// <summary>
        /// Gets friendly output text for "opening" or "closing", depending on the type of the bracket.
        /// </summary>
        /// <param name="bracket">The bracket.</param>
        /// <returns>Returns the opening or closing text.</returns>
        private static string GetOpeningOrClosingBracketText(BracketToken bracket)
        {
            Param.AssertNotNull(bracket, "bracket");

            switch (bracket.TokenType)
            {
            case TokenType.OpenAttributeBracket:
            case TokenType.OpenCurlyBracket:
            case TokenType.OpenGenericBracket:
            case TokenType.OpenParenthesis:
            case TokenType.OpenSquareBracket:
                return(Strings.Opening);

            case TokenType.CloseAttributeBracket:
            case TokenType.CloseCurlyBracket:
            case TokenType.CloseGenericBracket:
            case TokenType.CloseParenthesis:
            case TokenType.CloseSquareBracket:
                return(Strings.Closing);

            default:
                Debug.Fail("Invalid bracket type.");
                return(string.Empty);
            }
        }
Example #2
0
 /// <summary>
 /// Read
 /// This class will export
 /// </summary>
 /// <param name="name">Name</param>
 /// <param name="parameters">Parameters</param>
 /// <param name="netlist">Netlist</param>
 /// <returns></returns>
 public override bool Read(string type, Statement st, Netlist netlist)
 {
     for (int i = 0; i < st.Parameters.Count; i++)
     {
         if (st.Parameters[i].kind == BRACKET)
         {
             BracketToken bt = st.Parameters[i] as BracketToken;
             Statement    s  = new Statement(StatementType.Export, bt.Name, bt.Parameters);
             Generated = netlist.Readers.Read(s, netlist);
         }
     }
     return(true);
 }
Example #3
0
        /// <summary>
        /// Generate a current source
        /// </summary>
        /// <param name="name">Name</param>
        /// <param name="parameters">Parameters</param>
        /// <param name="netlist">Netlist</param>
        /// <returns></returns>
        protected ICircuitObject GenerateISRC(CircuitIdentifier name, List <Token> parameters, Netlist netlist)
        {
            Currentsource isrc = new Currentsource(name);

            isrc.ReadNodes(netlist.Path, parameters);

            // We can have a value or just DC
            for (int i = 2; i < parameters.Count; i++)
            {
                // DC specification
                if (i == 2 && parameters[i].image.ToLower() == "dc")
                {
                    i++;
                    isrc.ISRCdcValue.Set(netlist.ParseDouble(parameters[i]));
                }
                else if (i == 2 && ReaderExtension.IsValue(parameters[i]))
                {
                    isrc.ISRCdcValue.Set(netlist.ParseDouble(parameters[i]));
                }

                // AC specification
                else if (parameters[i].image.ToLower() == "ac")
                {
                    i++;
                    isrc.ISRCacMag.Set(netlist.ParseDouble(parameters[i]));

                    // Look forward for one more value
                    if (i + 1 < parameters.Count && ReaderExtension.IsValue(parameters[i + 1]))
                    {
                        i++;
                        isrc.ISRCacPhase.Set(netlist.ParseDouble(parameters[i]));
                    }
                }

                // Waveforms
                else if (parameters[i].kind == BRACKET)
                {
                    // Find the reader
                    BracketToken bt = parameters[i] as BracketToken;
                    Statement    st = new Statement(StatementType.Waveform, bt.Name, bt.Parameters);
                    isrc.ISRCwaveform = (IWaveform)netlist.Readers.Read(st, netlist);
                }
                else
                {
                    throw new ParseException(parameters[i], "Unrecognized parameter");
                }
            }

            return(isrc);
        }
        /// <summary>
        /// Read a statement
        /// </summary>
        /// <param name="st">Statement</param>
        /// <param name="netlist">Netlist</param>
        /// <returns></returns>
        public override object Read(Statement st, Netlist netlist)
        {
            // The name is not the name now, it is the type
            List <Token> parameters = new List <Token>();

            string type = null;

            if (st.Parameters.Count < 1)
            {
                throw new ParseException(st.Name, "Invalid model definition");
            }

            switch (st.Parameters[0].kind)
            {
            case TokenConstants.BRACKET:
                BracketToken bt = st.Parameters[0] as BracketToken;
                type = bt.Name.image.ToLower();
                foreach (var p in bt.Parameters)
                {
                    parameters.Add(p);
                }
                break;

            case SpiceSharpParserConstants.WORD:
                type = st.Parameters[0].image.ToLower();
                for (int i = 1; i < st.Parameters.Count; i++)
                {
                    parameters.Add(st.Parameters[i]);
                }
                break;

            default:
                throw new ParseException(st.Name, "Invalid model definition");
            }

            Statement mst = new Statement(StatementType.Model, st.Name, parameters);

            // The name should be the identifier
            if (!models.ContainsKey(type))
            {
                throw new ParseException(st.Name, $"Cannot read model \"{st.Name.image}\" of type \"{type}\"");
            }
            if (models[type].Read(type, mst, netlist))
            {
                return(models[type].Generated);
            }
            throw new ParseException(st.Name, $"Could not create model \"{st.Name.image}\"");
        }
Example #5
0
        /// <summary>
        /// Read
        /// </summary>
        /// <param name="name">Name</param>
        /// <param name="parameters">Parameters</param>
        /// <param name="netlist">Netlist</param>
        /// <returns></returns>
        public override bool Read(string type, Statement st, Netlist netlist)
        {
            // Only assignments are possible
            for (int i = 0; i < st.Parameters.Count; i++)
            {
                switch (st.Parameters[i].kind)
                {
                case ASSIGNMENT:
                    AssignmentToken at = st.Parameters[i] as AssignmentToken;
                    switch (at.Name.kind)
                    {
                    case BRACKET:
                        BracketToken bt = at.Name as BracketToken;
                        if (bt.Name.image.ToLower() == "v" && bt.Parameters.Length == 1 && ReaderExtension.IsNode(bt.Parameters[0]))
                        {
                            netlist.Circuit.Nodes.Nodeset.Add(new CircuitIdentifier(bt.Parameters[0].image), netlist.ParseDouble(at.Value));
                        }
                        else
                        {
                            throw new ParseException(st.Parameters[i], "Invalid format, v(<node>)=<ic> expected");
                        }
                        break;

                    default:
                        if (ReaderExtension.IsNode(at.Name))
                        {
                            netlist.Circuit.Nodes.Nodeset.Add(new CircuitIdentifier(at.Name.image), netlist.ParseDouble(at.Value));
                        }
                        else
                        {
                            throw new ParseException(st.Parameters[i], "Invalid format, <node>=<ic> expected");
                        }
                        break;
                    }
                    break;
                }
            }
            return(true);
        }