// This file was generated by qlalr - DO NOT EDIT! #line 106 "exp.g" /************************************************************************************* * Copyright (C) 2008 by Aleix Pol * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License * * as published by the Free Software Foundation; either version 2 * * of the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * *************************************************************************************/ #include #include "expressionparser.h" #include "abstractlexer.h" #include "operator.h" #include ExpressionParser::ExpressionParser() {} ExpressionParser::~ExpressionParser() {} QString funcToTag(const QString& name) { if(Analitza::Operator::toOperatorType(name)!=Analitza::Operator::none) return QString("<%1 />").arg(name); else return ""+name+""; } void ExpressionParser::reallocateStack() { int size = m_stateStack.size(); if (size == 0) size = 128; else size <<= 1; m_symStack.resize(size); m_stateStack.resize(size); } bool ExpressionParser::parse(AbstractLexer *lexer) { const int INITIAL_STATE = 0; int yytoken = -1; reallocateStack(); m_tos = 0; m_stateStack[++m_tos] = INITIAL_STATE; for(;;) { const int state = m_stateStack.at(m_tos); if (yytoken == -1 && - TERMINAL_COUNT != action_index [state]) { yytoken = lexer->lex(); if(!lexer->error().isEmpty()) { m_err += lexer->error(); return false; } } int act = t_action (state, yytoken); if (act == ACCEPT_STATE) return true; else if (act > 0) { if (++m_tos == m_stateStack.size()) reallocateStack(); m_stateStack[m_tos] = act; yytoken = -1; } else if (act < 0) { int r = - act - 1; m_tos -= rhs [r]; act = m_stateStack.at(m_tos++); switch (r) { #line 195 "exp.g" case 0: m_exp = ""+sym(1)+""; break; #line 202 "exp.g" case 1: #line 204 "exp.g" case 2: sym(1) = lexer->current.val; break; #line 212 "exp.g" case 4: sym(1) = ""+sym(1)+""; break; #line 220 "exp.g" case 6: sym(1) = sym(2); break; #line 230 "exp.g" case 9: sym(1)=sym(2); break; #line 231 "exp.g" case 10: sym(1)=funcToTag(sym(1)); break; #line 233 "exp.g" case 11: sym(1) = ""+sym(1)+sym(2)+""; break; #line 234 "exp.g" case 12: sym(1) = ""+sym(1)+sym(3)+""; break; #line 235 "exp.g" case 13: sym(1) = ""+sym(1)+ ""; break; #line 241 "exp.g" case 15: sym(1).prepend(sym(3)); break; #line 248 "exp.g" case 16: sym(1)=sym(3)+sym(5)+sym(1); break; #line 255 "exp.g" case 17: sym(1)=sym(3)+""+sym(5)+""+sym(1); break; #line 263 "exp.g" case 18: sym(1) = '<'+sym(1)+" />"; break; #line 270 "exp.g" case 19: sym(1) = '<'+sym(1)+'>'+sym(3)+"'; break; #line 278 "exp.g" case 20: sym(1) = ""+sym(1)+sym(3)+""; break; #line 286 "exp.g" case 21: sym(1) = ""+sym(2)+""; break; #line 293 "exp.g" case 22: sym(1) = ""+sym(2)+""; break; #line 300 "exp.g" case 23: sym(1) = "" +sym(1)+sym(3)+""; break; #line 301 "exp.g" case 24: sym(1) = "" +sym(1)+sym(3)+""; break; #line 302 "exp.g" case 25: sym(1) = "" +sym(1)+sym(3)+""; break; #line 303 "exp.g" case 26: sym(1) = "" +sym(1)+sym(2)+""; break; #line 304 "exp.g" case 27: sym(1) = ""+sym(1)+sym(3)+""; break; #line 305 "exp.g" case 28: sym(1) = "" +sym(1)+sym(3)+""; break; #line 306 "exp.g" case 29: sym(1) = "" +sym(1)+sym(3)+""; break; #line 307 "exp.g" case 30: sym(1) = "" +sym(1)+sym(3)+""; break; #line 308 "exp.g" case 31: sym(1) = "" +sym(1)+sym(3)+""; break; #line 309 "exp.g" case 32: sym(1) = "" +sym(1)+sym(3)+""; break; #line 310 "exp.g" case 33: sym(1) = "" +sym(1)+sym(3)+""; break; #line 311 "exp.g" case 34: sym(1) = "" +sym(1)+sym(3)+""; break; #line 313 "exp.g" case 35: sym(1) = ""+sym(3)+sym(1)+""; break; #line 314 "exp.g" case 36: sym(1) = ""+sym(1)+""+sym(3)+""; break; #line 319 "exp.g" case 38: sym(1) += sym(3); break; #line 328 "exp.g" case 40: sym(1) = sym(2); break; #line 335 "exp.g" case 41: sym(1) = ""+sym(1)+""; break; #line 342 "exp.g" case 42: sym(1) += sym(3); break; #line 349 "exp.g" case 43: sym(1) += sym(3); break; #line 356 "exp.g" case 44: sym(1) = ""+sym(3)+""+sym(1)+""; break; #line 362 "exp.g" } // switch m_stateStack[m_tos] = nt_action(act, lhs[r] - TERMINAL_COUNT); } else { int ers = state; int shifts = 0; int reduces = 0; int expected_tokens[3]; for (int tk = 0; tk < TERMINAL_COUNT; ++tk) { int k = t_action(ers, tk); if (! k) continue; else if (k < 0) ++reduces; else if (spell[tk]) { if (shifts < 3) expected_tokens[shifts] = tk; ++shifts; } } m_errorLineNumber = lexer->lineNumber(); int tokFoundType=lexer->current.type; QString error; if (shifts && shifts<3) { QString tokFound(spell[tokFoundType]); QStringList expectedTokens; for (int s = 0; s < shifts; ++s) { expectedTokens += '\''+QLatin1String(spell[expected_tokens[s]])+'\''; } error=i18nc("error message", "Expected %1 instead of '%2'", expectedTokens.join(i18n(", ")), tokFound); } else if(tokFoundType==tLpr) { error=i18n("Missing right parenthesis"); } else if(tokFoundType==tRpr || tokFoundType==tRcb) { error=i18n("Unbalanced right parenthesis"); } else error=i18n("Unexpected token %1", spell[tokFoundType]); m_err.append(error); return false; } } return false; }