Commit c200bcf7 authored by Victor Yacovlev's avatar Victor Yacovlev

Added braces/brackets checking for variables declaration

parent 619dcbb7
......@@ -1880,6 +1880,69 @@ bool hasArrayElement(const AST::Expression * expr, QList<Lexem*> & lexems)
QList<AST::Variable*> SyntaxAnalizerPrivate::parseVariables(int statementIndex, VariablesGroup &group, AST::Module *mod, AST::Algorhitm *alg, bool algHeader)
{
// First -- check brackets
QStack<Lexem *> openBrackets;
QStack<Lexem *> openSqBrackets;
QStack<Lexem *> openBraces;
const QList<Lexem*> lexems = group.lexems;
for (int i=0; i<lexems.size(); i++) {
Lexem * lx = lexems.at(i);
if (lx->type==LxOperLeftBr) {
openBrackets.push_back(lx);
}
else if (lx->type==LxOperLeftSqBr) {
openSqBrackets.push_back(lx);
}
else if (lx->type==LxOperLeftBrace) {
openBraces.push_back(lx);
}
else if (lx->type==LxOperRightBr) {
if (openBrackets.size()==0) {
lx->error = _("Unpaired )");
return QList<AST::Variable*>();
}
else {
openBrackets.pop_back();
}
}
else if (lx->type==LxOperRightSqBr) {
if (openSqBrackets.size()==0) {
lx->error = _("Unpaired ]");
return QList<AST::Variable*>();
}
else {
openSqBrackets.pop_back();
}
}
else if (lx->type==LxOperRightBrace) {
if (openBraces.size()==0) {
lx->error = _("Unpaired }");
return QList<AST::Variable*>();
}
else {
openBraces.pop_back();
}
}
}
foreach (Lexem * lx, openBrackets) {
lx->error = _("Unpaired (");
}
foreach (Lexem * lx, openSqBrackets) {
lx->error = _("Unpaired [");
}
foreach (Lexem * lx, openBraces) {
lx->error = _("Unpaired {");
}
if (openBrackets.size()+openSqBrackets.size()+openBraces.size() > 0) {
return QList<AST::Variable*>();
}
// Pежим работы автомата-парсера.
// type -- разбор типа
// name -- разбор имени переменной
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment