本文整理汇总了C++中ParserError函数的典型用法代码示例。如果您正苦于以下问题:C++ ParserError函数的具体用法?C++ ParserError怎么用?C++ ParserError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ParserError函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ParserError
//------------------------------------------------------------------------------
void FunMax::Eval(ptr_val_type &ret, const ptr_val_type *a_pArg, int a_iArgc)
{
if (a_iArgc < 1)
throw ParserError(ErrorContext(ecTOO_FEW_PARAMS, GetExprPos(), GetIdent()));
float_type smax(-1e30), sval(0);
for (int i=0; i<a_iArgc; ++i)
{
switch(a_pArg[i]->GetType())
{
case 'f': sval = a_pArg[i]->GetFloat(); break;
case 'i': sval = a_pArg[i]->GetFloat(); break;
case 'n': break; // ignore not in list entries (missing parameter)
case 'c':
default:
{
ErrorContext err;
err.Errc = ecTYPE_CONFLICT_FUN;
err.Arg = i+1;
err.Type1 = a_pArg[i]->GetType();
err.Type2 = 'f';
throw ParserError(err);
}
}
smax = max(smax, sval);
}
*ret = smax;
}
示例2: GetType
//---------------------------------------------------------------------------
bool IValue::operator<=(const IValue &a_Val) const
{
char_type type1 = GetType(),
type2 = a_Val.GetType();
if (type1 == type2 || (IsScalar() && a_Val.IsScalar()))
{
switch (GetType())
{
case 's': return GetString() <= a_Val.GetString();
case 'i':
case 'f':
case 'c': return GetFloat() <= a_Val.GetFloat();
case 'b': return GetBool() <= a_Val.GetBool();
default:
ErrorContext err;
err.Errc = ecINTERNAL_ERROR;
err.Pos = -1;
err.Type1 = GetType();
err.Type2 = a_Val.GetType();
throw ParserError(err);
} // switch this type
}
else
{
ErrorContext err;
err.Errc = ecTYPE_CONFLICT_FUN;
err.Arg = (type1 != 'f' && type1 != 'i') ? 1 : 2;
err.Type1 = type2;
err.Type2 = type1;
throw ParserError(err);
}
}
示例3: Backwards_Fixed_Array_Format
/* this parsing rule allows compatibility with RTC fixed array formats
like [17:char]. note it doesn't handle more general formats like
[3,4:char]. use of these formats is deprecated: use, for example,
[char:17] instead */
static FORMAT_PTR Backwards_Fixed_Array_Format(Format_Parse_Ptr parser,
BOOLEAN *error)
{
FORMAT_PTR Form, next_format;
TokenPtr tmp, arraySizeToken;
arraySizeToken = NextToken(parser);
if (INT_TOK != arraySizeToken->Type) {
ParserError(arraySizeToken, parser, "an integer value");
return NULL;
}
tmp = NextToken(parser);
if (COLON_TOK != tmp->Type) {
ParserError(tmp, parser, "':'");
return NULL;
}
next_format = Parse(parser, FALSE, error); /* Formatter */
tmp = NextToken(parser);
if (RBRACK_TOK != tmp->Type) {
ParserError(tmp, parser, "']'");
return NULL;
}
Form = new_a_formatter(FixedArrayFMT, 3);
Form->formatter.a[1].f = next_format;
Form->formatter.a[2].i = arraySizeToken->value.num;
return Form;
}
示例4: assert
//-----------------------------------------------------------------------------------------------
void OprtSubCmplx::Eval(ptr_val_type &ret, const ptr_val_type *a_pArg, int num)
{
assert(num==2);
const IValue *arg1 = a_pArg[0].Get();
const IValue *arg2 = a_pArg[1].Get();
if ( a_pArg[0]->IsNonComplexScalar() && a_pArg[1]->IsNonComplexScalar())
{
*ret = arg1->GetFloat() - arg2->GetFloat();
}
else if (a_pArg[0]->GetType()=='m' && a_pArg[1]->GetType()=='m')
{
// Matrix + Matrix
*ret = arg1->GetArray() - arg2->GetArray();
}
else
{
if (!a_pArg[0]->IsScalar())
throw ParserError( ErrorContext(ecTYPE_CONFLICT_FUN, GetExprPos(), GetIdent(), a_pArg[0]->GetType(), 'c', 1));
if (!a_pArg[1]->IsScalar())
throw ParserError( ErrorContext(ecTYPE_CONFLICT_FUN, GetExprPos(), GetIdent(), a_pArg[1]->GetType(), 'c', 2));
*ret = cmplx_type(a_pArg[0]->GetFloat() - a_pArg[1]->GetFloat(),
a_pArg[0]->GetImag() - a_pArg[1]->GetImag());
}
}
示例5: indices
/** \brief Index operator implementation
\param ret A reference to the return value
\param a_pArg Pointer to an array with the indices as ptr_val_type
\param a_iArgc Number of indices (=dimension) actully used in the expression found. This must
be 1 or 2 since three dimensional data structures are not supported by muParserX.
*/
void OprtIndex::At(ptr_val_type &ret, const ptr_val_type *a_pArg, int a_iArgc)
{
try
{
// The index is -1, thats the actual variable reference
if (a_iArgc!=a_pArg[-1]->GetDim())
{
throw ParserError(ErrorContext(ecINDEX_DIMENSION, -1, GetIdent()));
}
switch(a_iArgc)
{
case 1:
ret.Reset(new Variable( &(ret->At(*a_pArg[0], Value(0))) ) );
break;
case 2:
ret.Reset(new Variable( &(ret->At(*a_pArg[0], *a_pArg[1])) ) );
break;
default:
throw ParserError(ErrorContext(ecINDEX_DIMENSION, -1, GetIdent()));
}
}
catch(ParserError &exc)
{
exc.GetContext().Pos = GetExprPos();
throw exc;
}
}
示例6: Enum_Format
static FORMAT_PTR Enum_Format(Format_Parse_Ptr parser, BOOLEAN *error)
{
TokenPtr Token;
FORMAT_PTR Form, subform;
LIST_PTR format_list;
int num_formats, i, maxVal;
num_formats = 0;
Token = NextToken(parser);
if (Token->Type == COLON_TOK) {
Token = NextToken(parser);
if (Token->Type != INT_TOK) {
*error = TRUE;
ParserError(Token, parser, "an integer");
return NULL;
} else {
maxVal = Token->value.num;
}
} else {
format_list = x_ipc_listCreate();
do {
if (num_formats > 0) Token = NextToken(parser);
if (Token->Type != STR_TOK) {
*error = TRUE;
ParserError(Token, parser, "a string");
return NULL;
} else {
Form = new_n_formatter(Token->value.str);
/* More efficient for Lisp if all enum format names are upper case */
LOCK_M_MUTEX;
if (IS_LISP_MODULE()) {
upcase(Form->formatter.name);
}
UNLOCK_M_MUTEX;
x_ipc_listInsertItem((char *)Form, format_list);
num_formats++;
}
Token = NextToken(parser);
} while (Token->Type == COMMA_TOK);
UngetToken(parser, Token);
maxVal = num_formats - 1;
}
Form = new_a_formatter(EnumFMT, num_formats+2);
Form->formatter.a[1].i = maxVal;
if (num_formats > 0) {
/* Index from high to low since "format_list"
has formatters in reverse order */
subform = (FORMAT_PTR)x_ipc_listFirst(format_list);
for(i=num_formats;i>0;i--) {
Form->formatter.a[i+1].f = subform;
subform = (FORMAT_PTR)x_ipc_listNext(format_list);
}
x_ipc_listFree(&format_list);
}
return Form;
}
示例7: Fixed_Array_Format
static FORMAT_PTR Fixed_Array_Format(Format_Parse_Ptr parser, BOOLEAN *error)
{
FORMAT_PTR Form, next_format;
TokenPtr Token, tmp;
int NumberOfIndexes, Continue, array_index;
tmp = parser->TokenList;
if (INT_TOK == tmp->Type) {
return Backwards_Fixed_Array_Format(parser, error);
}
next_format = Parse(parser, FALSE, error); /* Formatter */
Token = NextToken(parser);
if (Token->Type != COLON_TOK) {
ParserError(Token, parser, "':'");
return NULL;
}
tmp = parser->TokenList;
NumberOfIndexes = 0;
Continue = TRUE;
do {
if (tmp->Type != INT_TOK) {
ParserError(tmp, parser, "an integer value");
return NULL;
}
else {
NumberOfIndexes++;
tmp = tmp->next;
if (tmp->Type == COMMA_TOK) {
tmp = tmp->next;
Continue = TRUE;
} else if (tmp->Type == RBRACK_TOK) {
Continue = FALSE;
} else {
ParserError(tmp, parser, "a ',' or ']'");
return NULL;
}
}
} while (Continue);
Form = new_a_formatter(FixedArrayFMT, NumberOfIndexes+2);
Form->formatter.a[1].f = next_format;
/* this time munch tokens */
NumberOfIndexes += 2;
for (array_index=2; array_index < NumberOfIndexes; array_index++) {
Token = NextToken(parser); /* This is an INT_TOK */
Form->formatter.a[array_index].i = Token->value.num;
Token = NextToken(parser); /* This is a COMMA_TOK or a RBRACK_TOK */
}
return Form;
}
示例8: assert
/** \brief Implements the Division operator.
\throw ParserError in case one of the arguments if
nonnumeric or an array.
*/
void OprtDiv::Eval(ptr_val_type &ret, const ptr_val_type *a_pArg, int num)
{
assert(num==2);
if (!a_pArg[0]->IsNonComplexScalar())
throw ParserError( ErrorContext(ecTYPE_CONFLICT_FUN, -1, GetIdent(), a_pArg[0]->GetType(), 'f', 1));
if (!a_pArg[1]->IsNonComplexScalar())
throw ParserError( ErrorContext(ecTYPE_CONFLICT_FUN, -1, GetIdent(), a_pArg[1]->GetType(), 'f', 2));
*ret = a_pArg[0]->GetFloat() / a_pArg[1]->GetFloat();
}
示例9: ExtractToken
/** \brief Check wheter a token at a given position is an undefined variable.
\param a_Tok [out] If a variable tom_pParser->m_vStringBufken has been found it will be placed here.
\return true if a variable token has been found.
\throw nothrow
*/
bool TokenReader::IsUndefVarTok(ptr_tok_type &a_Tok)
{
string_type sTok;
int iEnd = ExtractToken(m_pParser->ValidNameChars(), sTok, m_nPos);
if (iEnd == m_nPos || (sTok.size() > 0 && sTok[0] >= _T('0') && sTok[0] <= _T('9')))
return false;
if (m_nSynFlags & noVAR)
{
ErrorContext err;
err.Errc = ecUNEXPECTED_VAR;
err.Ident = sTok;
err.Expr = m_sExpr;
err.Pos = m_nPos;
throw ParserError(err);
}
// Create a variable token
if (m_pParser->m_bAutoCreateVar)
{
ptr_val_type val(new Value); // Create new value token
m_pDynVarShadowValues->push_back(val); // push to the vector of shadow values
a_Tok = ptr_tok_type(new Variable(val.Get())); // bind variable to the new value item
(*m_pVarDef)[sTok] = a_Tok; // add new variable to the variable list
}
else
a_Tok = ptr_tok_type(new Variable(nullptr)); // bind variable to empty variable
a_Tok->SetIdent(sTok);
m_UsedVar[sTok] = a_Tok; // add new variable to used-var-list
m_nPos = iEnd;
m_nSynFlags = noVAL | noVAR | noFUN | noBO | noIFX;
return true;
}
示例10: MUP_ASSERT
//------------------------------------------------------------------------------
void OprtSign::Eval(ptr_val_type &ret, const ptr_val_type *a_pArg, int a_iArgc)
{
MUP_ASSERT(a_iArgc==1);
if (a_pArg[0]->IsScalar())
{
*ret = -a_pArg[0]->GetFloat();
}
else if (a_pArg[0]->GetType()=='m')
{
Value v(a_pArg[0]->GetRows(), 0);
for (int i=0; i<a_pArg[0]->GetRows(); ++i)
{
v.At(i) = -a_pArg[0]->At(i).GetFloat();
}
*ret = v;
}
else
{
ErrorContext err;
err.Errc = ecINVALID_TYPE;
err.Type1 = a_pArg[0]->GetType();
err.Type2 = 's';
throw ParserError(err);
}
}
示例11: min
/** \brief Returns the minimum value of all values.
\param a_pArg Pointer to an array of Values
\param a_iArgc Number of values stored in a_pArg
*/
void FunMin::Eval(ptr_val_type &ret, const ptr_val_type *a_pArg, int a_iArgc)
{
float_type min(1e30), val(min);
for (int i=0; i<a_iArgc; ++i)
{
switch(a_pArg[i]->GetType())
{
case 'f':
case 'i': val = a_pArg[i]->GetFloat(); break;
default:
{
ErrorContext err;
err.Errc = ecTYPE_CONFLICT_FUN;
err.Arg = i+1;
err.Type1 = a_pArg[i]->GetType();
err.Type2 = 'f';
throw ParserError(err);
}
}
min = std::min(min, val);
}
*ret = min;
}
示例12: throw
void TypeParser::TypeDefineStatement(TokenStream *lexerStream, TypeSystem *__typeSystem) throw(ParserError)
{
// current is `LET
// read next
lexerStream->next();
// 这里指向下一个token
TypeSpecifier(lexerStream, __typeSystem);
lexerStream->next();
if(lexerStream->current().value() == "as") {
lexerStream->next();
if(__typeSystem->isRegisterType(lexerStream->current().value())) {
__typeSystem->registerType(lexerStream->current().value(),
__typeSystem->getHelper()->takeCurrentArgumentTypeMetaData());
__typeSystem->mapTypeName(lexerStream->current().value(),
__typeSystem->getHelper()->takeFullTypeName());
} else {
throw ParserError(-1, "Type "+lexerStream->current().value()+" Already exist.");
}
TypeName(lexerStream, __typeSystem);
lexerStream->next();
}
}
示例13: ParserError
//---------------------------------------------------------------------------
const SToken* ParserByteCode::GetBase() const
{
if (m_vRPN.size()==0)
throw ParserError(ecINTERNAL_ERROR);
else
return &m_vRPN[0];
}
示例14: GetIdent
/** \brief Return the value as an integer.
This function should only be called if you really need an integer value and
want to make sure your either get one or throw an exception if the value
can not be implicitely converted into an integer.
*/
int_type Value::GetInteger() const
{
float_type v = m_val.real();
if (m_cType!='i') //!IsScalar() || (int_type)v-v!=0)
{
ErrorContext err;
err.Errc = ecTYPE_CONFLICT;
err.Type1 = m_cType;
err.Type2 = 'i';
if (GetIdent().length())
{
err.Ident = GetIdent();
}
else
{
stringstream_type ss;
ss << *this;
err.Ident = ss.str();
}
throw ParserError(err);
}
return (int_type)v;
}
示例15: ParserError
//---------------------------------------------------------------------------
IValue& Value::At(int nRow, int nCol)
{
if (IsMatrix())
{
if (nRow>=m_pvVal->GetRows() || nCol>=m_pvVal->GetCols() || nRow<0 || nCol<0)
throw ParserError( ErrorContext(ecINDEX_OUT_OF_BOUNDS, -1, GetIdent()) );
return m_pvVal->At(nRow, nCol);
}
else if (nRow==0 && nCol==0)
{
return *this;
}
else
throw ParserError( ErrorContext(ecINDEX_OUT_OF_BOUNDS) );
}