Ejemplo n.º 1
0
        /// <summary>
        /// Read named parameters for a Parameterized object
        /// </summary>
        /// <param name="obj">The parameterized object</param>
        /// <param name="parameters">The parameters</param>
        /// <param name="start">The starting index</param>
        public static void ReadParameters(this Netlist netlist, IParameterized obj, List <Token> parameters, int start = 0)
        {
            for (int i = start; i < parameters.Count; i++)
            {
                if (parameters[i].kind == TokenConstants.ASSIGNMENT)
                {
                    AssignmentToken at = parameters[i] as AssignmentToken;
                    string          pname;
                    if (at.Name.kind == WORD)
                    {
                        pname = at.Name.image.ToLower();
                    }
                    else
                    {
                        throw new ParseException(parameters[i], "Invalid assignment");
                    }
                    switch (at.Value.kind)
                    {
                    case VALUE:
                        obj.Set(pname, netlist.Readers.ParseDouble(at.Value.image.ToLower()));
                        break;

                    case EXPRESSION:
                        obj.Set(pname, netlist.Readers.ParseDouble(at.Value.image.Substring(1, at.Value.image.Length - 2).ToLower()));
                        break;

                    case WORD:
                    case STRING:
                        obj.Set(pname, netlist.ParseString(at.Value));
                        break;

                    default:
                        throw new ParseException(parameters[i], "Invalid assignment");
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Read
        /// </summary>
        /// <param name="name">The type of the waveform</param>
        /// <param name="parameters">Parameters</param>
        /// <param name="netlist">The netlist</param>
        /// <returns></returns>
        public override bool Read(string type, Statement st, Netlist netlist)
        {
            IParameterized w = Generate(type);

            if (st.Parameters.Count > keys.Length)
            {
                throw new ParseException(st.Name, $"Too many arguments for waveform \"{st.Name.image}\"");
            }
            for (int i = 0; i < st.Parameters.Count; i++)
            {
                w.Set(keys[i], netlist.ParseDouble(st.Parameters[i]));
            }

            Generated = w;
            return(true);
        }