STYPE *addConstant(char *name, uint8_t type, int32_t *value, STYPE *parent) { STYPE *constPtr; TRACE(lstFile,"[addConstant]"); /* Get a slot in the symbol table */ constPtr = addSymbol(name, type); if (constPtr) { /* Add the value of the constant to the symbol table */ if (type == tREAL_CONST) constPtr->sParm.c.val.f = *((double*) value); else constPtr->sParm.c.val.i = *value; constPtr->sParm.c.parent = parent; } /* end if */ /* Return a pointer to the new constant symbol */ return constPtr; } /* end addConstant */
STYPE *addTypeDefine(char *name, uint8_t type, uint16_t size, STYPE *parent) { STYPE *typePtr; TRACE(lstFile,"[addTypeDefine]"); /* Get a slot in the symbol table */ typePtr = addSymbol(name, sTYPE); if (typePtr) { /* Add the type definition to the symbol table * NOTES: * 1. The minValue and maxValue fields (for scalar and subrange) * types must be set external to this function * 2. For most variables, allocated size/type (rsize/rtype) and * the clone size/type are the same. If this is not the case, * external logic will need to clarify this as well. * 3. We assume that there are no special flags associated with * the type. */ typePtr->sParm.t.type = type; typePtr->sParm.t.rtype = type; typePtr->sParm.t.flags = 0; typePtr->sParm.t.asize = size; typePtr->sParm.t.rsize = size; typePtr->sParm.t.parent = parent; } /* end if */ /* Return a pointer to the new constant symbol */ return typePtr; } /* end addTypeDefine */
TypePtr VariableTable::checkVariable(const string &name, TypePtr type, bool coerce, AnalysisResultConstPtr ar, ConstructPtr construct) { return checkVariable(addSymbol(name), type, coerce, ar, construct); }
PdBase& PdBase::operator<<(const char* var) { addSymbol((string) var); return *this; }
LatvianAlphabet::LatvianAlphabet() { addSymbol(AA_macron); addSymbol(a_macron); addSymbol(CC_inv_roof); addSymbol(c_inv_roof); addSymbol(EE_macron); addSymbol(e_macron); addSymbol(GG_bottom_accent); addSymbol(LATVIAN_g); addSymbol(II_macron); addSymbol(i_macron); addSymbol(KK_bottom_accent); addSymbol(k_bottom_accent); addSymbol(LL_bottom_accent); addSymbol(l_bottom_accent); addSymbol(NN_bottom_accent); addSymbol(n_bottom_accent); addSymbol(SS_inv_roof_baltic); addSymbol(s_inv_roof_baltic); addSymbol(UU_macron); addSymbol(u_macron); addSymbol(ZZ_inv_roof_baltic); addSymbol(z_inv_roof_baltic); removeSymbol('Q'); removeSymbol('q'); removeSymbol('W'); removeSymbol('w'); removeSymbol('X'); removeSymbol('x'); removeSymbol('Y'); removeSymbol('y'); }
// allocate a path with one symbol. MLPath::MLPath(const MLSymbol sym) : mStart(0), mEnd(0), mCopy(0) { memset(mpData, '\0', kMLPathMaxSymbols*sizeof(MLSymbol)); addSymbol(sym); }
List& List::operator<<(const char var) { std::string s; s = var; addSymbol(s); return *this; }
int ex(nodeType *p) { if (!p) return 0; pushSymbolTable(); switch(p->type) { case typeIntCon: //printf("Int constant\n"); return p->conInt.value; case typeDoubleCon: //printf("Double constant %f\n", p->conDbl.value); return p->conDbl.value; case typeIntId: { struct symbol_entry *entry = getSymbolEntry(p->idInt.i); if(!entry) { printf("Undefined variable.\n"); return 0; } return entry->iVal; } case typeDblId: //printf("Double variable\n"); return sym[p->idDbl.i]; case typeOpr: switch(p->opr.oper) { case DECLAREINT: { const char *name = p->opr.op[0]->idInt.i; int value = ex(p->opr.op[1]); struct symbol_entry *entry = getSymbolEntry(name); if(!entry) //make sure this variable name doesn't already exists { //entry = calloc(1, sizeof(struct symbol_entry)+300); entry = malloc(sizeof(struct symbol_entry)); entry->name = name; entry->iVal = value; addSymbol(entry, yylineno); free(entry); } else { printf("This int variable has already been declared.\n"); } break; } case DO: do { ex(p->opr.op[0]); } while(ex(p->opr.op[1])); break; case WHILE: while(ex(p->opr.op[0])) { ex(p->opr.op[1]); } break; case REPEAT: do { ex(p->opr.op[0]); } while(!ex(p->opr.op[1])); break; case IF: if (ex(p->opr.op[0])) ex(p->opr.op[1]); else if (p->opr.nops > 2) ex(p->opr.op[2]); return 0; case PRINT: { printf("%d\n", ex(p->opr.op[0])); return 0; } case ';': ex(p->opr.op[0]); return ex(p->opr.op[1]); case '=': { const char *name = p->opr.op[0]->idInt.i; int value = ex(p->opr.op[1]); struct symbol_entry *entry = getSymbolEntry(name); if(!entry) { printf("No variable by that name found\n"); } else { entry->iVal = value; } return value;//sym[p->opr.op[0]->idInt.i] = ex(p->opr.op[1]); } case UMINUS: return -ex(p->opr.op[0]); case '+': return ex(p->opr.op[0]) + ex(p->opr.op[1]); case '-': return ex(p->opr.op[0]) - ex(p->opr.op[1]); case '*': return ex(p->opr.op[0]) * ex(p->opr.op[1]); case '/': return ex(p->opr.op[0]) / ex(p->opr.op[1]); case '<': return ex(p->opr.op[0]) < ex(p->opr.op[1]); case '>': return ex(p->opr.op[0]) > ex(p->opr.op[1]); case GE: return ex(p->opr.op[0]) >= ex(p->opr.op[1]); case LE: return ex(p->opr.op[0]) <= ex(p->opr.op[1]); case NE: return ex(p->opr.op[0]) != ex(p->opr.op[1]); case EQ: return ex(p->opr.op[0]) == ex(p->opr.op[1]); } break; //case typeOpr } return 0; }
Compiler::llvmObject Compiler::compile(parsing::AST ast) { TRACE_INDATA(ast.display()); for (unsigned int i = 0; i < ast.size(); i++) { if (ast[i].size() == 0 && symbols.find(ast[i].getContent().get()) != symbols.end()) { TRACE_COUT("found symbol - " << ast[i].getContent().get() << "\n"); if (ast[i+1].size() == 0 && ast[i+1].getContent().get().compare("(") == 0) { TRACE_COUT(" with arguments...\n"); vector<parsing::AST> args = tokenizeAST(ast[i+2], ","); for (vector<parsing::AST>::iterator j = args.begin(); j != args.end(); j++) { if (j->size() == 0) { errors.push_back(parsing::ASTError(ast[i+1].getContent(), "empty argument")); return llvmObjectNull(); } else { llvmObject tmp = compile(*j); } } if (ast[i+3].size() != 0 || ast[i+3].getContent().get().compare(")") != 0) { errors.push_back(parsing::ASTError(ast[i+3].getContent(), "expected a right parenthesis")); } if (ast[i+4].size() != 0 || ast[i+4].getContent().get().compare(";") != 0) { errors.push_back(parsing::ASTError(ast[i+4].getContent(), "expected a semicolon")); } } else if (ast[i+1].size() == 0 && ast[i+1].getContent().get().compare(";") == 0) { TRACE_COUT(" line ends...\n"); } else if (ast[i+1].size() == 0 && ast[i+1].getContent().get().compare("=") == 0) { TRACE_COUT("found assignment of expression - " << ast[i+1].getContent().get() << "\n"); } else { errors.push_back(parsing::ASTError(ast[i+1].getContent(), "unexpected token")); return llvmObjectNull(); } } else if (ast[i].size() == 0 && types.find(ast[i].getContent().get()) != types.end()) { TRACE_COUT("found type - " << ast[i].getContent().get() << "\n"); for (i++; i < ast.size(); i++) { if (ast[i].size() == 0 && types.find(ast[i].getContent().get()) != types.end()) { TRACE_COUT("found type - " << ast[i].getContent().get() << "\n"); } else if (ast[i].size() == 0 && ast[i].getContent().get().compare("(") == 0) { if (ast[i+1].size() == 0) { errors.push_back(parsing::ASTError(ast[i].getContent(), "expected scope, but got a leaf")); return llvmObjectNull(); } else { llvmObject tmp = compile(ast[i+1]); } if (ast[i+2].size() != 0 || ast[i+2].getContent().get().compare(")") != 0) { errors.push_back(parsing::ASTError(ast[i+2].getContent(), "expected a left parenthesis")); return llvmObjectNull(); } } else if (ast[i].size() == 0 && isSymbolToken(ast[i].getContent())) { TRACE_COUT("found symbol after types - " << ast[i].getContent().get() << "\n"); addSymbol(ast[i].getContent().get()); break; } else { errors.push_back(parsing::ASTError(ast[i].getContent(), "expected either type, type expression, or an expression symbol")); return llvmObjectNull(); } } } else if (ast[i].size() == 0 && isValueToken(ast[i].getContent())) { TRACE_COUT("found value - " << ast[i].getContent().get() << "\n"); } else if (ast[i].size() == 0 && isOperatorToken(ast[i].getContent())) { TRACE_COUT("found operator - " << ast[i].getContent().get() << "\n"); if (ast[i].getContent().get().compare("!") == 0 || ast[i].getContent().get().compare("~") == 0) { TRACE_COUT(" unary right operation\n"); } else if (ast[i].getContent().get().compare("++") == 0 || ast[i].getContent().get().compare("--") == 0) { TRACE_COUT(" unary left operation\n"); } else { TRACE_COUT(" binary operation\n"); } } } return llvmObjectNull(); }
void VelocityVector::initialize( InstanceIDPool &symbolIdPool ) { waterlineReference = new SymbolLine(); waterlineReference->setID( symbolIdPool.getAvailableID() ); // fixme - error checking addSymbol( waterlineReference.get() ); waterlineReference->addImplementation( new SerializableSymbolLine( waterlineReference.get(), outgoingMessage ) ); waterlineReference->setState( Symbol::Visible ); waterlineReference->setSurfaceID( SURFACE_ID ); waterlineReference->setColor( Vect4( 0.0, 1.0, 0.0, 1.0 ) ); waterlineReference->setFlashDutyCyclePercentage( 100 ); waterlineReference->setPosition( 0.0, waterlinePosition ); waterlineReference->setRotation( 0.0 ); // waterlineReference has no geometry pip = new SymbolCircle(); pip->setID( symbolIdPool.getAvailableID() ); // fixme - error checking pip->setParent( true, waterlineReference->getID(), waterlineReference.get() ); waterlineReference->addSymbol( pip.get() ); pip->addImplementation( new SerializableSymbolCircle( pip.get(), outgoingMessage ) ); pip->setState( Symbol::Visible ); pip->setSurfaceID( SURFACE_ID ); pip->setColor( Vect4( 0.0, 1.0, 0.0, 1.0 ) ); pip->setFlashDutyCyclePercentage( 100 ); pip->setPosition( 0.0, 0.0 ); pip->setRotation( 0.0 ); pip->setDrawingStyle( SymbolCircle::Line ); SymbolCircle::Circle circle; circle.centerPosition.Set( 0., 0. ); circle.radius = pipRadius; circle.innerRadius = 0.; // unused circle.startAngle = 0.; circle.endAngle = 0.; pip->addCircle( circle ); SymbolLine *line = new SymbolLine(); line->setID( symbolIdPool.getAvailableID() ); // fixme - error checking line->setParent( true, pip->getID(), pip.get() ); pip->addSymbol( line ); line->addImplementation( new SerializableSymbolLine( line, outgoingMessage ) ); line->setState( Symbol::Visible ); line->setSurfaceID( SURFACE_ID ); line->setColor( Vect4( 0.0, 1.0, 0.0, 1.0 ) ); line->setFlashDutyCyclePercentage( 100 ); line->setPosition( 0., 0. ); line->setRotation( 0.0 ); line->setPrimitiveType( SymbolLine::Lines ); line->addVertex( 0.0, pipRadius ); line->addVertex( 0.0, pipRadius + 0.6 ); line->addVertex( -pipRadius, 0. ); line->addVertex( -pipRadius - 0.7, 0. ); line->addVertex( pipRadius, 0. ); line->addVertex( pipRadius + 0.7, 0. ); velocityVectorPositionChanged( hudState.get() ); }
void VariableTable::addSuperGlobal(const string &name) { addSymbol(name)->setSuperGlobal(); }
TypePtr VariableTable::setType(AnalysisResultConstPtr ar, const std::string &name, TypePtr type, bool coerce) { return setType(ar, addSymbol(name), type, coerce); }
void VariableTable::addNeeded(const string &name) { addSymbol(name)->setNeeded(); }
void VariableTable::addLvalParam(const string &name) { addSymbol(name)->setLvalParam(); }
void VariableTable::addNestedStatic(const string &name) { addSymbol(name)->setNestedStatic(); }
void VariableTable::addLocalGlobal(const string &name) { addSymbol(name)->setLocalGlobal(); }
Compiler::Compiler() { addSymbol("import"); addType("int"); }
void SuffixTree::buildSuffixTree() { for (int i = 0; i < line.size(); ++i) { addSymbol(i); } }
void Library::scanObjModule(ObjModule *om) { int easyomf; unsigned u; unsigned char result = 0; char name[LIBIDMAX + 1]; Array names; names.push(NULL); // don't use index 0 assert(om); easyomf = 0; // assume not EASY-OMF unsigned char *pend = om->base + om->length; unsigned char *pnext; for (unsigned char *p = om->base; 1; p = pnext) { assert(p < pend); unsigned char recTyp = *p++; unsigned short recLen = *(unsigned short *)p; p += 2; pnext = p + recLen; recLen--; // forget the checksum switch (recTyp) { case LNAMES: case LLNAMES: while (p + 1 < pnext) { parseName(&p, name); names.push(strdup(name)); } break; case PUBDEF: if (easyomf) recTyp = PUB386; // convert to MS format case PUB386: if (!(parseIdx(&p) | parseIdx(&p))) p += 2; // skip seg, grp, frame while (p + 1 < pnext) { parseName(&p, name); p += (recTyp == PUBDEF) ? 2 : 4; // skip offset parseIdx(&p); // skip type index addSymbol(om, name); } break; case COMDAT: if (easyomf) recTyp = COMDAT+1; // convert to MS format case COMDAT+1: int pickAny = 0; if (*p++ & 5) // if continuation or local comdat break; unsigned char attr = *p++; if (attr & 0xF0) // attr: if multiple instances allowed pickAny = 1; p++; // align p += 2; // enum data offset if (recTyp == COMDAT+1) p += 2; // enum data offset parseIdx(&p); // type index if ((attr & 0x0F) == 0) // if explicit allocation { parseIdx(&p); // base group parseIdx(&p); // base segment } unsigned idx = parseIdx(&p); // public name index if( idx == 0 || idx >= names.dim) { //debug(printf("[s] name idx=%d, uCntNames=%d\n", idx, uCntNames)); error("corrupt COMDAT"); return; } //printf("[s] name='%s'\n",name); addSymbol(om, (char *)names.data[idx],pickAny); break; case ALIAS: while (p + 1 < pnext) { parseName(&p, name); addSymbol(om, name); parseName(&p, name); } break; case MODEND: case M386END: result = 1; goto Ret; case COMENT: // Recognize Phar Lap EASY-OMF format { static unsigned char omfstr[7] = {0x80,0xAA,'8','0','3','8','6'}; if (recLen == sizeof(omfstr)) { for (unsigned i = 0; i < sizeof(omfstr); i++) if (*p++ != omfstr[i]) goto L1; easyomf = 1; break; L1: ; } } // Recognize .IMPDEF Import Definition Records { static unsigned char omfstr[] = {0,0xA0,1}; if (recLen >= 7) { p++; for (unsigned i = 1; i < sizeof(omfstr); i++) if (*p++ != omfstr[i]) goto L2; p++; // skip OrdFlag field parseName(&p, name); addSymbol(om, name); break; L2: ; } } break; default: // ignore ; } } Ret: for (u = 1; u < names.dim; u++) free(names.data[u]); }
int Grammar::addTerminal(const String &name, SymbolType type, int precedence, const SourcePosition &pos) { m_terminalCount++; return addSymbol(GrammarSymbol(getSymbolCount(), name, type, precedence, pos, 1)); }
void Parser::addSymbol(const ParserTreeItem::Ptr &item, const CPlusPlus::Symbol *symbol) { if (item.isNull() || !symbol) return; // easy solution - lets add any scoped symbol and // any symbol which does not contain :: in the name // if (symbol->isDeclaration()) // return; //! \todo collect statistics and reorder to optimize if (symbol->isForwardClassDeclaration() || symbol->isExtern() || symbol->isFriend() || symbol->isGenerated() || symbol->isUsingNamespaceDirective() || symbol->isUsingDeclaration() ) return; // skip static local functions // if ((!symbol->scope() || symbol->scope()->isClass()) // && symbol->isStatic() && symbol->isFunction()) // return; const CPlusPlus::Name *symbolName = symbol->name(); if (symbolName && symbolName->isQualifiedNameId()) return; QString name = d->overview.prettyName(symbol->name()).trimmed(); QString type = d->overview.prettyType(symbol->type()).trimmed(); int iconType = CPlusPlus::Icons::iconTypeForSymbol(symbol); SymbolInformation information(name, type, iconType); ParserTreeItem::Ptr itemAdd; // If next line will be removed, 5% speed up for the initial parsing. // But there might be a problem for some files ??? // Better to improve qHash timing itemAdd = item->child(information); if (itemAdd.isNull()) itemAdd = ParserTreeItem::Ptr(new ParserTreeItem()); // locations are 1-based in Symbol, start with 0 for the editor SymbolLocation location(QString::fromUtf8(symbol->fileName() , symbol->fileNameLength()), symbol->line(), symbol->column() - 1); itemAdd->addSymbolLocation(location); // prevent showing a content of the functions if (!symbol->isFunction()) { const CPlusPlus::Scope *scope = symbol->asScope(); if (scope) { CPlusPlus::Scope::iterator cur = scope->firstMember(); while (cur != scope->lastMember()) { const CPlusPlus::Symbol *curSymbol = *cur; ++cur; if (!curSymbol) continue; // if (!symbol->isClass() && curSymbol->isStatic() && curSymbol->isFunction()) // return; addSymbol(itemAdd, curSymbol); } } } bool appendChild = true; // if item is empty and has not to be added if (symbol->isNamespace() && itemAdd->childCount() == 0) appendChild = false; if (appendChild) item->appendChild(itemAdd, information); }
int Grammar::addNonTerminal(const String &name, const SourcePosition &pos) { return addSymbol(GrammarSymbol(getSymbolCount(), name, NONTERMINAL, 0, pos, getTerminalCount())); }
List& List::operator<<(const std::string& var) { addSymbol((std::string) var); return *this; }
void defineRSLSymbols(Object * root) { Object *objBaseType, *temp2, *temp3, *temp4, *temp5, *rslFunc; // ============== Built-in Types =============== objBaseType = CreateObject("BaseType", "BaseType", 0, Type, "BaseType"); setFlags(objBaseType, FLAG_EXTERNAL); addSymbol(root, objBaseType); temp2 = CreateObject("Generic_$$", "Generic_$$" COMPILER_SEP "BaseType", objBaseType, Type, "Generic_$$"); setFlags(temp2, FLAG_EXTERNAL); addSymbol(root, temp2); temp2 = CreateObject("Generic_YTYPE$$", "Generic_YTYPE$$" COMPILER_SEP "BaseType", objBaseType, Type, "Generic_YTYPE$$"); setFlags(temp2, FLAG_EXTERNAL); addSymbol(root, temp2); temp2 = CreateObject("Generic_ZTYPE$$", "Generic_ZTYPE$$" COMPILER_SEP "BaseType", objBaseType, Type, "Generic_ZTYPE$$"); setFlags(temp2, FLAG_EXTERNAL); addSymbol(root, temp2); temp2 = CreateObject("bool", "bool" COMPILER_SEP "BaseType", objBaseType, Type, "bool"); setFlags(temp2, FLAG_EXTERNAL); setFlags(temp2, FLAG_PRIMITIVE); addSymbol(root, temp2); temp2 = CreateObject("tern", "tern" COMPILER_SEP "BaseType", objBaseType, Type, "tern"); setFlags(temp2, FLAG_EXTERNAL); setFlags(temp2, FLAG_PRIMITIVE); addSymbol(root, temp2); temp2 = CreateObject("Number", "Number" COMPILER_SEP "BaseType", objBaseType, Type, "Number"); setFlags(temp2, FLAG_EXTERNAL); addSymbol(root, temp2); temp3 = CreateObject("int", "int" COMPILER_SEP "Number", temp2, Type, "int"); setFlags(temp3, FLAG_EXTERNAL); setFlags(temp3, FLAG_PRIMITIVE); addSymbol(root, temp3); temp3 = CreateObject("float", "float" COMPILER_SEP "Number", temp2, Type, "float"); setFlags(temp3, FLAG_EXTERNAL); setFlags(temp3, FLAG_PRIMITIVE); addSymbol(root, temp3); temp3 = CreateObject("char", "char" COMPILER_SEP "Number", temp2, Type, "char"); setFlags(temp3, FLAG_EXTERNAL); setFlags(temp3, FLAG_PRIMITIVE); addSymbol(root, temp3); temp4 = CreateObject("System", "System" COMPILER_SEP "BaseType", objBaseType, Type, "System"); setFlags(temp4, FLAG_EXTERNAL); addSymbol(root, temp4); temp4 = CreateObject(IDENT_MPTR, IDENT_MPTR COMPILER_SEP "BaseType", objBaseType, Type, IDENT_MPTR); setFlags(temp4, FLAG_EXTERNAL); addSymbol(root, temp4); temp4 = CreateObject(IDENT_HEAP_MPTR, IDENT_HEAP_MPTR COMPILER_SEP "BaseType", objBaseType, Type, IDENT_HEAP_MPTR); setFlags(temp4, FLAG_EXTERNAL); addSymbol(root, temp4); // ============== Basetype constructor =============== rslFunc = CreateObject("BaseType", "BaseType" COMPILER_SEP "BaseType" COMPILER_SEP, 0, Constructor, IDENT_MPTR); setFlags(rslFunc, FLAG_EXTERNAL); addParam(rslFunc, "BaseType"); addSymbol(root, rslFunc); // ============== Exponent functions =============== rslFunc = CreateObject("exponent", "float" COMPILER_SEP "exponent" COMPILER_SEP "int", 0, Function, "float"); setFlags(rslFunc, FLAG_EXTERNAL); addParam(rslFunc, "float"); addParam(rslFunc, "int"); addSymbol(root, rslFunc); rslFunc = CreateObject("exponent", "int" COMPILER_SEP "exponent" COMPILER_SEP "float", 0, Function, "float"); setFlags(rslFunc, FLAG_EXTERNAL); addParam(rslFunc, "int"); addParam(rslFunc, "float"); addSymbol(root, rslFunc); rslFunc = CreateObject("exponent", "float" COMPILER_SEP "exponent" COMPILER_SEP "float", 0, Function, "float"); setFlags(rslFunc, FLAG_EXTERNAL); addParam(rslFunc, "float"); addParam(rslFunc, "float"); addSymbol(root, rslFunc); rslFunc = CreateObject("exponent", "int" COMPILER_SEP "exponent" COMPILER_SEP "int", 0, Function, "int"); setFlags(rslFunc, FLAG_EXTERNAL); addParam(rslFunc, "int"); addParam(rslFunc, "int"); addSymbol(root, rslFunc); // ============== Sqrt functions ============== // ============== TODO sqrt(int) should be a float? ============== rslFunc = CreateObject("sqrt", "int" COMPILER_SEP "sqrt" COMPILER_SEP, 0, Function, "int"); setFlags(rslFunc, FLAG_EXTERNAL); addParam(rslFunc, "int"); addSymbol(root, rslFunc); // ============== String Functions =============== // rslFunc = // CreateObject("String", "String" COMPILER_SEP "String" COMPILER_SEP, 0, // Constructor, IDENT_MPTR); // setFlags(rslFunc, FLAG_EXTERNAL); // addParam(rslFunc, "String"); // addSymbol(root, rslFunc); rslFunc = CreateObject("assign", "String" COMPILER_SEP "String" COMPILER_SEP, 0, Function, "String"); setFlags(rslFunc, FLAG_EXTERNAL); addParam(rslFunc, "String"); addParam(rslFunc, "String"); addSymbol(root, rslFunc); rslFunc = CreateObject("assign", "String" COMPILER_SEP "assign" COMPILER_SEP "String", 0, Function, "String"); setFlags(rslFunc, FLAG_EXTERNAL); addParam(rslFunc, "String"); addParam(rslFunc, "String"); addSymbol(root, rslFunc); rslFunc = CreateObject("plus", "String" COMPILER_SEP "plus" COMPILER_SEP "String", 0, Function, "String"); setFlags(rslFunc, FLAG_EXTERNAL); addParam(rslFunc, "String"); addParam(rslFunc, "String"); addSymbol(root, rslFunc); rslFunc = CreateObject("plus", "int" COMPILER_SEP "plus" COMPILER_SEP "String", 0, Function, "String"); setFlags(rslFunc, FLAG_EXTERNAL); addParam(rslFunc, "int"); addParam(rslFunc, "String"); addSymbol(root, rslFunc); rslFunc = CreateObject("plus", "String" COMPILER_SEP "plus" COMPILER_SEP "int", 0, Function, "String"); setFlags(rslFunc, FLAG_EXTERNAL); addParam(rslFunc, "String"); addParam(rslFunc, "int"); addSymbol(root, rslFunc); rslFunc = CreateObject("plus", "float" COMPILER_SEP "plus" COMPILER_SEP "String", 0, Function, "String"); setFlags(rslFunc, FLAG_EXTERNAL); addParam(rslFunc, "float"); addParam(rslFunc, "String"); addSymbol(root, rslFunc); rslFunc = CreateObject("plus", "String" COMPILER_SEP "plus" COMPILER_SEP "float", 0, Function, "String"); setFlags(rslFunc, FLAG_EXTERNAL); addParam(rslFunc, "String"); addParam(rslFunc, "float"); addSymbol(root, rslFunc); rslFunc = CreateObject("getObjectAtIndex", "String" COMPILER_SEP "getObjectAtIndex" COMPILER_SEP "int", 0, Function, "Char"); setFlags(rslFunc, FLAG_EXTERNAL); addParam(rslFunc, "String"); addParam(rslFunc, "int"); addSymbol(root, rslFunc); // ============== Conditional Functions =============== rslFunc = CreateObject("if", "bool" COMPILER_SEP "if", 0, Function, "bool"); setFlags(rslFunc, FLAG_EXTERNAL); setFlags(rslFunc, FLAG_SAVERESULT); addParam(rslFunc, "bool"); addSymbol(root, rslFunc); rslFunc = CreateObject("elif", "bool" COMPILER_SEP "elif" COMPILER_SEP "bool", 0, Function, "bool"); setFlags(rslFunc, FLAG_EXTERNAL); setFlags(rslFunc, FLAG_SAVERESULT); addParam(rslFunc, "bool"); addParam(rslFunc, "bool"); addSymbol(root, rslFunc); rslFunc = CreateObject("else", "bool" COMPILER_SEP "else", 0, Function, "bool"); setFlags(rslFunc, FLAG_EXTERNAL); setFlags(rslFunc, FLAG_SAVERESULT); addParam(rslFunc, "bool"); addSymbol(root, rslFunc); rslFunc = CreateObject("tf", "bool" COMPILER_SEP "tf" COMPILER_SEP GENERIC_PARAM COMPILER_SEP GENERIC_PARAM, 0, Function, "Generic_$$"); setFlags(rslFunc, FLAG_EXTERNAL); addParam(rslFunc, "bool"); addParam(rslFunc, "Generic_$$"); addParam(rslFunc, "Generic_$$"); addGenericType(rslFunc, 0, 1); addSymbol(root, rslFunc); //============= Python style conditional Functions ============= rslFunc = CreateObject("if", "if" COMPILER_SEP "bool", 0, Function, "bool"); setFlags(rslFunc, FLAG_EXTERNAL); //setFlags(rslFunc, FLAG_SAVERESULT); addParam(rslFunc, "bool"); addSymbol(root, rslFunc); rslFunc = CreateObject("elif", "elif" COMPILER_SEP "bool", 0, Function, "bool"); setFlags(rslFunc, FLAG_EXTERNAL); //setFlags(rslFunc, FLAG_SAVERESULT); addParam(rslFunc, "bool"); addSymbol(root, rslFunc); rslFunc = CreateObject("else", "else" COMPILER_SEP, 0, Function, "bool"); setFlags(rslFunc, FLAG_EXTERNAL); //setFlags(rslFunc, FLAG_SAVERESULT); addSymbol(root, rslFunc); //============= Ternary Functions ============= rslFunc = CreateObject("compare", "int" COMPILER_SEP "compare" COMPILER_SEP "int", 0, Function, "Ternary"); setFlags(rslFunc, FLAG_EXTERNAL); addParam(rslFunc, "int"); addParam(rslFunc, "int"); addSymbol(root, rslFunc); rslFunc = CreateObject("gel", "Ternary" COMPILER_SEP "gel" COMPILER_SEP GENERIC_PARAM "0" COMPILER_SEP GENERIC_PARAM "1" COMPILER_SEP GENERIC_PARAM "2", 0, Function, "Generic_$$"); setFlags(rslFunc, FLAG_EXTERNAL); addParam(rslFunc, "Ternary"); addParam(rslFunc, "Generic_$$"); addParam(rslFunc, "Generic_$$"); addParam(rslFunc, "Generic_$$"); addGenericType(rslFunc, 0, 1); addSymbol(root, rslFunc); rslFunc = CreateObject("leg", "Ternary" COMPILER_SEP "leg" COMPILER_SEP GENERIC_PARAM "0" COMPILER_SEP GENERIC_PARAM "1" COMPILER_SEP GENERIC_PARAM "2", 0, Function, "Generic_$$"); setFlags(rslFunc, FLAG_EXTERNAL); addParam(rslFunc, "Ternary"); addParam(rslFunc, "Generic_$$"); addParam(rslFunc, "Generic_$$"); addParam(rslFunc, "Generic_$$"); addGenericType(rslFunc, 0, 1); addSymbol(root, rslFunc); // ============== bool true, false as Dummies =============== // TODO: Introduce constants rslFunc = CreateObject("false", "false", 0, Variable, "bool"); setFlags(rslFunc, FLAG_EXTERNAL); setFlags(rslFunc, FLAG_GLOBAL); setFlags(rslFunc, FLAG_NO_CODEGEN); addSymbol(root, rslFunc); rslFunc = CreateObject("true", "true", 0, Variable, "bool"); setFlags(rslFunc, FLAG_EXTERNAL); setFlags(rslFunc, FLAG_GLOBAL); setFlags(rslFunc, FLAG_NO_CODEGEN); addSymbol(root, rslFunc); // ============== Looping Functions =============== rslFunc = CreateObject("while", "bool" COMPILER_SEP "while" COMPILER_SEP, 0, Function, "void"); setFlags(rslFunc, FLAG_EXTERNAL); addParam(rslFunc, "bool"); addSymbol(root, rslFunc); rslFunc = CreateObject("while", "while" COMPILER_SEP "bool", 0, Function, "void"); setFlags(rslFunc, FLAG_EXTERNAL); addParam(rslFunc, "bool"); addSymbol(root, rslFunc); rslFunc = CreateObject("for", "for" COMPILER_SEP "int" COMPILER_SEP "int", 0, Function, "int"); setFlags(rslFunc, FLAG_EXTERNAL); setFlags(rslFunc, FLAG_ASSIGNMENT); addParam(rslFunc, "int"); addParam(rslFunc, "int"); addSymbol(root, rslFunc); rslFunc = CreateObject("for", "for" COMPILER_SEP "int" COMPILER_SEP "int" COMPILER_SEP "int", 0, Function, "int"); setFlags(rslFunc, FLAG_EXTERNAL); setFlags(rslFunc, FLAG_ASSIGNMENT); addParam(rslFunc, "int"); addParam(rslFunc, "int"); addParam(rslFunc, "int"); addSymbol(root, rslFunc); // ============== Print Functions =============== rslFunc = CreateObject("print", "print" COMPILER_SEP "Char", 0, Function, "int"); setFlags(rslFunc, FLAG_EXTERNAL); addParam(rslFunc, "int"); addSymbol(root, rslFunc); rslFunc = CreateObject("print", "print" COMPILER_SEP "int", 0, Function, "int"); setFlags(rslFunc, FLAG_EXTERNAL); addParam(rslFunc, "int"); addSymbol(root, rslFunc); rslFunc = CreateObject("print", "print" COMPILER_SEP "float", 0, Function, "int"); setFlags(rslFunc, FLAG_EXTERNAL); addParam(rslFunc, "float"); addSymbol(root, rslFunc); rslFunc = CreateObject("print", "print" COMPILER_SEP "String", 0, Function, "int"); setFlags(rslFunc, FLAG_EXTERNAL); addParam(rslFunc, "String"); addSymbol(root, rslFunc); rslFunc = CreateObject("echo", "echo" COMPILER_SEP "Char", 0, Function, "int"); setFlags(rslFunc, FLAG_EXTERNAL); addParam(rslFunc, "int"); addSymbol(root, rslFunc); rslFunc = CreateObject("echo", "echo" COMPILER_SEP "int", 0, Function, "int"); setFlags(rslFunc, FLAG_EXTERNAL); addParam(rslFunc, "int"); addSymbol(root, rslFunc); rslFunc = CreateObject("echo", "echo" COMPILER_SEP "float", 0, Function, "int"); setFlags(rslFunc, FLAG_EXTERNAL); addParam(rslFunc, "float"); addSymbol(root, rslFunc); rslFunc = CreateObject("echo", "echo" COMPILER_SEP "String", 0, Function, "int"); setFlags(rslFunc, FLAG_EXTERNAL); addParam(rslFunc, "String"); addSymbol(root, rslFunc); // ============== System Functions =============== rslFunc = CreateObject("args", "args" COMPILER_SEP "int", 0, Function, "String"); setFlags(rslFunc, FLAG_EXTERNAL); addParam(rslFunc, "int"); addSymbol(root, rslFunc); rslFunc = CreateObject("args", "args" COMPILER_SEP, 0, Function, "int"); setFlags(rslFunc, FLAG_EXTERNAL); addSymbol(root, rslFunc); // ============== int Functions =============== rslFunc = CreateObject("int", "int" COMPILER_SEP "int" COMPILER_SEP "String", 0, Function, "int"); setFlags(rslFunc, FLAG_EXTERNAL); addParam(rslFunc, "String"); addSymbol(root, rslFunc); // ============== Condreturn Functions =============== rslFunc = CreateObject("condreturn", "bool" COMPILER_SEP "condreturn" COMPILER_SEP GENERIC_PARAM "0", 0, Function, "void"); setFlags(rslFunc, FLAG_EXTERNAL); addParam(rslFunc, "bool"); addSymbol(root, rslFunc); }
HungarAlphabet::HungarAlphabet() { addSymbol(AA_right_accent); addSymbol(a_right_accent); addSymbol(EE_right_accent); addSymbol(e_right_accent); addSymbol(II_right_accent); addSymbol(i_right_accent); addSymbol(OO_right_accent); addSymbol(o_right_accent); addSymbol(OO_2dot_accent); addSymbol(o_2dot_accent); addSymbol(OO_double_right); addSymbol(o_double_right); }
Lexer::Lexer(){ mTypeToString; mStringToType; mOperatorMap; mOperatorTypes; mKeywordMap; mKeywordTypes; mTokens; mLine; mNextLine; stack; addSymbol("(",SymbolType::SYMBOL_LPARENTHESIS); addSymbol(")",SymbolType::SYMBOL_RPARENTHESIS); addSymbol("[",SymbolType::SYMBOL_LBRACKET); addSymbol("]",SymbolType::SYMBOL_RBRACKET); addSymbol("{",SymbolType::SYMBOL_LBRACE); addSymbol("}",SymbolType::SYMBOL_RBRACE); addSymbol(";",SymbolType::SYMBOL_SEMICOLON); addSymbol(".",SymbolType::SYMBOL_DOT); addSymbol(",",SymbolType::SYMBOL_COMMA); addSymbol(":",SymbolType::SYMBOL_COLON); addSymbol("+",SymbolType::SYMBOL_PLUS); addSymbol("-",SymbolType::SYMBOL_MINUS); addSymbol("/",SymbolType::SYMBOL_DIVIDE); addSymbol("*",SymbolType::SYMBOL_MULTIPLY); addSymbol("%",SymbolType::SYMBOL_MOD); addSymbol("^",SymbolType::SYMBOL_POWER); addSymbol("=",SymbolType::SYMBOL_EQUALS); addSymbol("+=",SymbolType::SYMBOL_PLUSEQUALS); addSymbol("-=",SymbolType::SYMBOL_MINUSEQUALS); addSymbol("/=",SymbolType::SYMBOL_DIVIDEEQUALS); addSymbol("*=",SymbolType::SYMBOL_MULTIPLYEQUALS); addSymbol("%=",SymbolType::SYMBOL_MODEQUALS); addSymbol("^=",SymbolType::SYMBOL_POWEREQUALS); addSymbol("++",SymbolType::SYMBOL_INCREMENT); addSymbol("--",SymbolType::SYMBOL_DECREMENT); addSymbol("//",SymbolType::SYMBOL_COMMENTSINGLE); addSymbol("/*",SymbolType::SYMBOL_COMMENTMULTISTART); addSymbol("*/",SymbolType::SYMBOL_COMMENTMULTIEND); addSymbol("#",SymbolType::SYMBOL_PREPROCESSOR); addSymbol("\"",SymbolType::SYMBOL_STRINGDELIM); setOperator(SymbolType::SYMBOL_COLON); setOperator(SymbolType::SYMBOL_COMMA); setOperator(SymbolType::SYMBOL_DIVIDE); setOperator(SymbolType::SYMBOL_DIVIDEEQUALS); setOperator(SymbolType::SYMBOL_DECREMENT); setOperator(SymbolType::SYMBOL_DOT); setOperator(SymbolType::SYMBOL_INCREMENT); setOperator(SymbolType::SYMBOL_LBRACE); setOperator(SymbolType::SYMBOL_LBRACKET); setOperator(SymbolType::SYMBOL_LPARENTHESIS); setOperator(SymbolType::SYMBOL_MINUS); setOperator(SymbolType::SYMBOL_MINUSEQUALS); setOperator(SymbolType::SYMBOL_MOD); setOperator(SymbolType::SYMBOL_MODEQUALS); setOperator(SymbolType::SYMBOL_MULTIPLY); setOperator(SymbolType::SYMBOL_MULTIPLYEQUALS); setOperator(SymbolType::SYMBOL_PLUS); setOperator(SymbolType::SYMBOL_PLUSEQUALS); setOperator(SymbolType::SYMBOL_POWER); setOperator(SymbolType::SYMBOL_POWEREQUALS); setOperator(SymbolType::SYMBOL_RBRACE); setOperator(SymbolType::SYMBOL_RBRACKET); setOperator(SymbolType::SYMBOL_RPARENTHESIS); setOperator(SymbolType::SYMBOL_SEMICOLON); addKeyword("require",KEYWORD_REQUIRE); addKeyword("imply", KEYWORD_IMPLY); addKeyword("peek", KEYWORD_PEEK); addKeyword("define", KEYWORD_DEFINE); addKeyword("global", KEYWORD_GLOBAL); addKeyword("local", KEYWORD_LOCAL); addKeyword("return", KEYWORD_RETURN); };
//---------------------------------------------------------- PdBase& PdBase::operator<<(const char var) { string s; s = var; addSymbol(s); return *this; }
static int parseit (void) { int r; char *dot = NULL; if (!exports_seen) { if ((r = lexit2 ()) == -1) return 0; if (r == TK_EXPORTS) { r = expect_newline ("EXPORTS"); return (r != -1 ? 1 : 0); } if (r == TK_LIBRARY) { r = lexit2 (); if (r != TK_STRING && r != TK_NAME) { fprintf (stderr, "Expect name/string after LIBRARY keyword.\n"); return (r != -1 ? 1 : 0); } cur_libname = unifyStr (t_buf); if ((dot = strchr (t_buf, '.')) != NULL) { *dot = '\0'; cur_libbasename = unifyStr (t_buf); } fprintf (stderr, "Current library-name set to %s'\n", cur_libname); cur_outlibbasename = unifyCat (cur_libbasename, SUFFIX); r = expect_newline ("LIBRARY"); return (r != -1 ? 1 : 0); } } else { if ((r = lexit2 ()) == -1) return 0; if (r != TK_NAME) { fprintf (stderr, "Unexpected token ,%s'. Would have expected a string/name.\n", t_buf); return (expect_newline ("UNKNOWN") == -1 ? 0 : 1); } cur_symbol = unifyStr (t_buf); cur_alias = ""; cur_libsymbol = ""; cur_srcfile = ""; cur_data = 0; while ((r = lexit2 ()) != -1 && r != TK_NL) { if (r == TK_DATA) cur_data = 1; else if (r == TK_EQUAL) { r = lexit2 (); if (r != TK_NAME) { fprintf (stderr, "Expected name after = expression.\n"); if (r != -1 && r != TK_NL) r = expect_newline ("SYMBOL"); return (r == -1 ? 0 : 1); } cur_libsymbol = unifyStr (t_buf); } else if (r == TK_EQUALEQUAL) { r = lexit2 (); if (r != TK_NAME) { fprintf (stderr, "Expected name after == expression.\n"); if (r != -1 && r != TK_NL) r = expect_newline ("SYMBOL"); return (r == -1 ? 0 : 1); } cur_alias = unifyStr (t_buf); } else if (r == TK_SOURCEFILENAME) { cur_srcfile = unifyStr (t_buf); } else { fprintf (stderr, "Unknown token ,%s'.\n", t_buf); } } addSymbol (cur_symbol, cur_libsymbol, cur_alias, cur_srcfile, cur_data); } return (r != -1 ? 1 : 0); }
PdBase& PdBase::operator<<(const std::string& var) { addSymbol(var); return *this; }
bool VariableTable::setClassInitVal(string varName, ConstructPtr value) { Symbol *sym = addSymbol(varName); bool exists = (sym->getClassInitVal() != nullptr); sym->setClassInitVal(value); return exists; }