void SymbolTreeBuilder::visit(VariableAccessNode& node) { node.setScope(currentScope()); const char* symbol_name = node.variableName(); auto sym = _curScope->resolveSymbol(symbol_name); if (!sym) { std::stringstream stream; stream << "Symbol '" << symbol_name << "' is undefined" << std::endl; throw SemanticException(stream.str(), node); } if (!sym->isVariable()) { std::stringstream stream; stream << "Symbol '" << symbol_name << "' is not a variable" << std::endl; throw SemanticException(stream.str(), node); } _expResult = ExpressionResult(sym->symbolType(), sym); node.setNodeType(_expResult.type); node.setExpressionResult(_expResult); sym->touchRead(); }
SglExprLex::ScanResult SglExprLex::searchResult2scanResult(Tables::SearchResult sr) { ScanResult tokens[maxOverloadSymbols]; ScanResult tmp; SymType stype; tokens[0].type = UNKNOWNTOKEN; tokens[0].symbol = 0; if (sr.count > maxOverloadSymbols) sr.count = 0; for (int i = -1; ++i < sr.count; ++sr.pt) { tmp.symbol = sr.pt.value(); stype = tmp.symbol? tmp.symbol->type() : unassigned; switch(stype) { case tagSym: tmp.type = baseTag(tmp.symbol); break; case operatorSym: tmp.type = opToken(tmp.symbol); break; default: tmp.type = symbolType(stype); } // sort overloaded symbols (insertion sort) int j = i; for (; --j >= 0 && tokenOrder(tokens[j].type) < tokenOrder(tmp.type);) tokens[j+1] = tokens[j]; tokens[j+1] = tmp; } for (int i = sr.count; --i > 0;) pending.enqueue(tokens[i]); if (sr.count == 1) { switch (stype) { case operatorSym: if (!tmp.symbol->asOp()->isUnary()) { // append a NOPREFIX token for not overloaded binary operators tmp.type = NOPREFIX; tmp.symbol = 0; pending.enqueue(tmp); } break; case tagSym: if (tmp.symbol->asTag()->complement()) { // split a complement tag into a base token and a complement token pending.enqueue(tmp); tokens[0].type = CMPLTAG; } break; default: ; } } return tokens[0]; }
bool IqAmeSymbol::loadFromString(const QString &string) { QRegExp textRx("^\\s*(SYMP|S)\\s*:\\s*(\\*([^\\*]*)\\*){0,1}"); textRx.setCaseSensitivity(Qt::CaseInsensitive); if (textRx.indexIn(string) == -1) return false; setName(textRx.cap(3)); //Получим оставшуюся строку QString clearString = string.mid(textRx.matchedLength()); //Выделим комментарий QRegExp commentRx("\\*([^\\*]*)\\*\\W*$"); if (commentRx.indexIn(clearString) != -1) setComment(commentRx.cap(1)); //Удалим все комментарии из строки QRegExp extraCommentsRx("\\*[^\\*]*\\*"); clearString.remove(extraCommentsRx); //Выделим тип символа QRegExp symbolType("^\"(\\d+)\"(.*)"); if (symbolType.indexIn(clearString.trimmed()) == -1) return false; switch (symbolType.cap(1).toInt()) { case 1: setType(PointRequedReport); break; case 2: setType(PointRequestReport); break; case 3: setType(Ndb); break; case 4: setType(ArtificalObstaclesWithouLight); break; case 6: setType(VorDme); break; case 7: setType(CivilAirport); break; case 8: setType(MixedAirport); break; case 9: setType(MilitaryAirport); break; default: qWarning() << tr("Symbol type \"%0\" not know. Symbol element skipped...") .arg(symbolType.cap(1)); return false; } clearString = symbolType.cap(2).trimmed(); QString symbolString = clearString.trimmed(); //Выделим атрибуты QRegExp attributeRx("(<\\s*[^>]*\\s*>)(.*)"); attributeRx.setCaseSensitivity(Qt::CaseInsensitive); if (attributeRx.indexIn(clearString) != -1) { //Нашли атрибуты, создадим их if (!attributes()) { setAttributes(new IqAmeShapesAttributes(this)); } attributes()->loadFromString(attributeRx.cap(1)); symbolString = attributeRx.cap(2).trimmed(); } QString pName = symbolString; if (!pName.isEmpty()) { IqAmeGeoPoint *p = IqAmeApplication::aeroMapModel()->pointsModel()->point(pName.trimmed(), Qt::CaseInsensitive); if (!p) { //Если не нашли точку, то попробуем ее создать IqAmeGeoPoint newPoint; if (newPoint.fromCoordinate(pName)) { int newPointRow = IqAmeApplication::aeroMapModel()->pointsModel()->rowCount(); IqAmeApplication::aeroMapModel()->pointsModel()->insertRow(newPointRow); p = IqAmeApplication::aeroMapModel()->pointsModel()->at(newPointRow); p->setName(newPoint.name()); p->setLatitude(newPoint.latitude()); p->setLongitude(newPoint.longitude()); } else { qWarning() << tr("Point \"%0\" not found and can not create. Symbol element skipped...").arg(pName); return false; } } setPoint(p); return true; } return false; }
int statement(int value) { int error = value; //Changes the values of ints (Works) if (tokenValues[i] == identsym) { int j = find(tokenTable[i], level); if (j == -1) { addError(11); error = 1; } if (symbolType(j) != 2) { addError(12); error = 1; } i++; if (tokenValues[i] != becomessym) { addError(13); error = 1; } i++; error = expression(error); emit(sto, level-symbolLevel(j), symbolAddress(j)); } else if (tokenValues[i] == callsym) //Callsym, currently does nothing { i++; if (tokenValues[i] != identsym) { addError(14); error = 1; } else { int j = find(tokenTable[i], level); if (j == -1) { addError(11); error = 1; } if (symbolType(j) != 3) { addError(12); error = 1; } emit(cal, level-symbolLevel(j), symbolAddress(j)); } i++; } else if (tokenValues[i] == beginsym) { i++; error = statement(error); while (tokenValues[i] == semicolonsym) { i++; error = statement(error); } if (tokenValues[i] != endsym) { addError(19); error = 1; } i++; } else if (tokenValues[i] == ifsym) //If then statements, does not work!!!******************* { i++; error = condition(error); if (tokenValues[i] != thensym) addError(16); i++; int ctemp = cx; emit(jpc, 0, 0); error = statement(error); int ctemp2 = cx; emit(jmp,0,0); code[ctemp].m = cx; if(tokenValues[i] == elsesym){ i++; error = statement(error); } code[ctemp2].m = cx; return error; } else if (tokenValues[i] == whilesym) //While, DOES NOT WORK**************** { int cx1 = cx; i++; error = condition(error); int cx2 = cx; emit(jpc, 0, 0); if (tokenValues[i] != dosym) { addError(18); error = 1; } else i++; error = statement(error); emit(jmp, 0, cx1); code[cx2].m = cx; } else if(tokenValues[i] == writesym){ i++; error = expression(error); emit(sio,0,1); } else if(tokenValues[i] == readsym){ i++; if(tokenValues[i] == identsym) { int j = find(tokenTable[i], level); if(symbol_table[j].kind != 2) addError(11); else { emit(sio2,0,2); emit(sto,symbol_table[j].level,symbol_table[j].addr); } } i++; } return error; }
CELL * p_deleteSymbol(CELL * params) { SYMBOL * sPtr = NULL; CELL * cell; CELL * ctx; int checkReferences = TRUE; cell = evaluateExpression(params); if(cell->type != CELL_SYMBOL) return(errorProcExt(ERR_SYMBOL_EXPECTED, params)); sPtr = (SYMBOL*)cell->contents; if(sPtr == mainContext) return(nilCell); if(symbolType(sPtr) == CELL_CONTEXT) { ctx = (CELL*)sPtr->contents; if(ctx->contents == (UINT)sPtr) { sPtr->flags &= ~SYMBOL_PROTECTED; cell = ctx; } } if(sPtr->flags & (SYMBOL_PROTECTED | SYMBOL_BUILTIN) ) return(nilCell); /* nil as extra parameter deletes without reference checking. true as extra parameter deletes only if no references are found, No extra parameter assumes reference checking is on and if a reference is found it is replaced with nil. */ params = params->next; /* extra parameter is specified as nil */ if(params != nilCell && !getFlag(params)) checkReferences = FALSE; /* extra parameter is specified as true */ else if(getFlag(params)) { if(cell->type == CELL_CONTEXT) { if(externalReferences(sPtr, FALSE) > 0) { sPtr->flags |= SYMBOL_PROTECTED; return(nilCell); } checkReferences = FALSE; } else { if(references(sPtr, FALSE) > 1) return(nilCell); checkReferences = FALSE; } } if(cell->type == CELL_CONTEXT) { deleteContextSymbols(cell, checkReferences); cell->type = CELL_SYMBOL; /* demote */ deleteList((CELL *)sPtr->contents); sPtr->contents = (UINT)copyCell(nilCell); } else deleteFreeSymbol(sPtr, checkReferences); return(trueCell); }
SYMBOL * translateCreateSymbol (char * token, int type, SYMBOL * context, int forceFlag) { SYMBOL * sPtr; CELL * cell = NULL; size_t len; cell = (CELL *)context->contents; root = (SYMBOL *)cell->aux; if(forceFlag) sPtr = findInsertSymbol(token, FORCE_CREATION); else /* try to inherit from MAIN, if not here create in current context */ { sPtr = findInsertSymbol(token, LOOKUP_ONLY); if(sPtr == NULL) { if(context != mainContext) { root = (SYMBOL *)((CELL *)mainContext->contents)->aux; sPtr = findInsertSymbol(token, LOOKUP_ONLY); /* since 7.2.7 only inherit primitives and other globals */ if(sPtr != NULL && !(sPtr->flags & SYMBOL_GLOBAL)) { if(symbolType(sPtr) != CELL_CONTEXT || (SYMBOL *)((CELL*)sPtr->contents)->contents != sPtr) sPtr = NULL; } root = (SYMBOL *)cell->aux; } if(sPtr == NULL) sPtr = findInsertSymbol(token, FORCE_CREATION); } } /* the symbol existed already, return */ if(sPtr->contents != 0) return(sPtr); /* root might have changed, after symbol insertion */ cell->aux = (UINT)root; /* a new symbol has been allocated by findInsertSymbol() */ if(type != CELL_PRIMITIVE) { len = strlen(token); sPtr->name = (char *)allocMemory(len + 1); memcpy(sPtr->name, token, len + 1); cell = copyCell(nilCell); sPtr->contents = (UINT)cell; /* make a new context symbol */ if(type == CELL_CONTEXT && context == mainContext) { cell->type = CELL_CONTEXT; cell->contents = (UINT)sPtr; cell->aux = 0; sPtr->flags |= (SYMBOL_PROTECTED | SYMBOL_GLOBAL); } } else { sPtr->name = token; sPtr->contents = (UINT)nilCell; } sPtr->context = context; return(sPtr); }