Пример #1
0
nl_double netlist_parser::eval_param(const token_t tok)
{
	static const char *macs[6] = {"", "RES_K", "RES_M", "CAP_U", "CAP_N", "CAP_P"};
	static nl_double facs[6] = {1, 1e3, 1e6, 1e-6, 1e-9, 1e-12};
	int i;
	int f=0;
	bool e;
	nl_double ret;
	pstring val;

	//printf("param %s\n", tok.m_token.cstr());
	for (i=1; i<6;i++)
		if (tok.str().equals(macs[i]))
			f = i;
	if (f>0)
	{
		require_token(m_tok_param_left);
		val = get_identifier();
	}
	else
		val = tok.str();

	ret = val.as_double(&e);

	if (e)
		error("Error with parameter ...\n");
	if (f>0)
		require_token(m_tok_param_right);
	return ret * facs[f];
}
Пример #2
0
nl_double parser_t::eval_param(const token_t tok)
{
	static pstring macs[6] = {"", "RES_K", "RES_M", "CAP_U", "CAP_N", "CAP_P"};
	static nl_double facs[6] = {1, 1e3, 1e6, 1e-6, 1e-9, 1e-12};
	int i;
	int f=0;
	nl_double ret;

	for (i=1; i<6;i++)
		if (tok.str() == macs[i])
			f = i;
	if (f>0)
	{
		require_token(m_tok_param_left);
		ret = get_number_double();
		require_token(m_tok_param_right);
	}
	else
	{
		bool err;
		ret = plib::pstonum_ne<nl_double>(tok.str(), err);
		if (err)
			error(plib::pfmt("Parameter value <{1}> not double \n")(tok.str()));
	}
	return ret * facs[f];

}
Пример #3
0
void ptokenizer::require_token(const token_t tok, const token_id_t &token_num)
{
	if (!tok.is(token_num))
	{
		error("Error: expected token <%s> got <%s>\n", m_tokens[token_num.id()].cstr(), tok.str().cstr());
	}
}
Пример #4
0
nl_double parser_t::eval_param(const token_t tok)
{
    static const char *macs[6] = {"", "RES_K", "RES_M", "CAP_U", "CAP_N", "CAP_P"};
    static nl_double facs[6] = {1, 1e3, 1e6, 1e-6, 1e-9, 1e-12};
    int i;
    int f=0;
    bool e;
    nl_double ret;
    pstring val;

    for (i=1; i<6; i++)
        if (tok.str().equals(macs[i]))
            f = i;
#if 1
    if (f>0)
    {
        require_token(m_tok_param_left);
        ret = get_number_double();
        require_token(m_tok_param_right);
    }
    else
    {
        val = tok.str();
        ret = val.as_double(&e);
        if (e)
            error("Error with parameter ...\n");
    }
    return ret * facs[f];

#else
    if (f>0)
    {
        require_token(m_tok_param_left);
        val = get_identifier();
    }
    else
        val = tok.str();

    ret = val.as_double(&e);

    if (e)
        fatal("Error with parameter ...\n");
    if (f>0)
        require_token(m_tok_param_right);
    return ret * facs[f];
#endif
}
Пример #5
0
void ptokenizer::require_token(const token_t tok, const token_id_t &token_num)
{
	if (!tok.is(token_num))
	{
		pstring val("");
		for (auto &i : m_tokens)
			if (i.second.id() == token_num.id())
				val = i.first;
		error(pfmt("Expected token <{1}> got <{2}>")(val)(tok.str()) );
	}
}