本文整理汇总了C++中SyntaxException类的典型用法代码示例。如果您正苦于以下问题:C++ SyntaxException类的具体用法?C++ SyntaxException怎么用?C++ SyntaxException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SyntaxException类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Parse
// Parse
void VariableNode::Parse(Parser &parser, Parser::size_type start, Parser::size_type end,
Parser::size_type v1)
{
// Check some basic syntax
if(start != end)
{
SyntaxException e;
e.SetStart(parser[start].GetStart());
e.SetEnd(parser[end].GetEnd());
throw(e);
}
// Get value list
ValueList *vlist = m_expr->GetValueList();
if(vlist == 0)
{
NoValueListException e;
e.SetStart(parser[start].GetStart());
e.SetEnd(parser[start].GetEnd());
throw(e);
}
// Get name
string ident = parser[start].GetIdentifier();
// Get address
double *vaddr = vlist->GetAddress(ident);
if(vaddr == 0)
{
// If it does not already exist, try to create it
vlist->Add(ident);
vaddr = vlist->GetAddress(ident);
}
if(vaddr == 0)
{
NotFoundException e(ident);
e.SetStart(parser[start].GetStart());
e.SetEnd(parser[start].GetEnd());
throw(e);
}
// Set information
m_var = vaddr;
}
示例2: throw
// Parse expression
void FunctionNode::Parse(Parser &parser, Parser::size_type start, Parser::size_type end,
Parser::size_type v1)
{
Parser::size_type pos, last;
int plevel = 0;
// Sanity check (start/end are function parenthesis)
if(start >= end)
throw(SyntaxException());
// Look
last = start + 1;
for(pos = start + 1; pos <= end && start + 1 != end; pos++)
{
switch(parser[pos].GetType())
{
case Token::TypeOpenParenthesis:
{
plevel++;
break;
};
case Token::TypeComma:
case Token::TypeCloseParenthesis:
{
// Handle Close parenthesis for all but the last one at the end
if(parser[pos].GetType() == Token::TypeCloseParenthesis && pos != end)
{
plevel--;
if(plevel < 0)
{
UnmatchedParenthesisException e;
e.SetStart(parser[pos].GetStart());
e.SetEnd(parser[pos].GetEnd());
throw(e);
}
break;
}
// Handle comma, or if it was the ending parenthesis treat it like comma
if(plevel == 0)
{
if(pos > last)
{
// reference parameter?
if(parser[last].GetType() == Token::TypeAmpersand)
{
// Reference parameter, check position and type of next parameter
if(last == pos - 2 && parser[last + 1].GetType() == Token::TypeIdentifier)
{
// Get value list
ValueList *vlist = m_expr->GetValueList();
if(vlist == 0)
{
NoValueListException e;
e.SetStart(parser[last + 1].GetStart());
e.SetEnd(parser[last + 1].GetEnd());
throw(e);
}
// Get name
string ident = parser[last + 1].GetIdentifier();
// Make sure it is not a constant
if(vlist->IsConstant(ident))
{
ConstantReferenceException e(ident);
e.SetStart(parser[last + 1].GetStart());
e.SetEnd(parser[last + 1].GetEnd());
throw(e);
}
// Get address
double *vaddr = vlist->GetAddress(ident);
if(vaddr == 0)
{
// Try to add it and get again
vlist->Add(ident);
vaddr = vlist->GetAddress(ident);
}
if(vaddr == 0)
{
NotFoundException e(ident);
e.SetStart(parser[last + 1].GetStart());
e.SetEnd(parser[last + 1].GetEnd());
throw(e);
}
// Add it
m_refs.push_back(vaddr);
//.........这里部分代码省略.........
示例3: throw
// Parse a region of tokens
Node *Parser::ParseRegion(Parser::size_type start, Parser::size_type end)
{
size_type pos;
size_type fgopen = (size_type)-1;
size_type fgclose = (size_type)-1;
size_type assignindex = (size_type)-1;
size_type addsubindex = (size_type)-1;
size_type muldivindex = (size_type)-1;
size_type posnegindex = (size_type)-1;
size_type expindex = (size_type)-1;
bool multiexpr = false;
int plevel = 0;
// Check simple syntax
if(start > end)
throw(SyntaxException());
// Scan through tokens
for(pos = start; pos <= end; pos++)
{
switch(m_tokens[pos].GetType())
{
case Token::TypeOpenParenthesis:
{
plevel++;
// Opening of first group?
if(plevel == 1 && fgopen == (size_type)-1)
fgopen = pos;
break;
};
case Token::TypeCloseParenthesis:
{
plevel--;
// First group closed?
if(plevel == 0 && fgclose == (size_type)-1)
fgclose = pos;
if(plevel < 0)
{
UnmatchedParenthesisException e;
e.SetStart(m_tokens[pos].GetStart());
e.SetEnd(m_tokens[pos].GetEnd());
throw(e);
}
break;
}
case Token::TypeEqual:
{
if(plevel == 0)
{
if(assignindex == (size_type)-1)
assignindex = pos;
}
break;
}
case Token::TypeAsterisk:
case Token::TypeForwardSlash:
{
if(plevel == 0)
{
muldivindex = pos;
}
break;
}
case Token::TypeHat:
{
if(plevel == 0)
{
expindex = pos;
}
break;
}
case Token::TypePlus:
case Token::TypeHyphen:
{
if(plevel == 0)
{
if(pos == start)
{
// Positive or negative sign
if(posnegindex == (size_type)-1)
posnegindex = pos;
}
else
{
// What is before us
//.........这里部分代码省略.........