Beispiel #1
0
static void declarePredefines(void)
{
    TreeNode *input;
    TreeNode *output;
    TreeNode *temp;

    /* define "int input(void)" */
    input = newDecNode(FuncDecK);
    input->name = copyString("input");
    input->functionReturnType = Integer;
    input->expressionType = Function;
    
    /* define "void output(int)" */
    temp = newDecNode(ScalarDecK); 
    temp->name = copyString("arg"); 
    temp->variableDataType = Integer;
    temp->expressionType = Integer; 
    
    output = newDecNode(FuncDecK); 
    output->name = copyString("output"); 
    output->functionReturnType = Void; 
    output->expressionType = Function; 
    output->child[0] = temp;

    /* get input() and output() added to global scope */
    insertSymbol("input", input, 0);
    insertSymbol("output", output, 0);
}
Beispiel #2
0
Datei: c8c.c Projekt: c8c/c8c
/*Maintain Symbol Table*/
bool insertSymbolDriver(SymbolType type, nodeType* p){
    int i;
    int *size;
    if(!p) return false;
    switch(p->type){
                    case typeId://A variable
                    size = (int *)malloc(sizeof(int));
                    *size = 1;
                        return insertSymbol(p->id.i,type,1,size);//name type dimesion size
                        break;
                    case typeArr://An array
                    size = (int *)malloc(sizeof(int) * p->arr.dimension);
                    int tempsize;
                    for(i = 0;i < p->arr.dimension; i++){
                        tempsize = inter(p->arr.index[i]);
                        if(tempsize > 0)
                            size[i] = tempsize;
                        else{
                            strcat(err,"Error: size of array is zero or negative"); errtext = p->arr.id;
                            return false;
                        }                        
                    }
                        return insertSymbol(p->arr.id, type, p->arr.dimension, size);//last parameter: size
                        break;
                    }
                }
/****************************************************************
 * mdsdcl_insert_symbols:
 ****************************************************************/
void  mdsdcl_insert_symbols(		/* Returns: void		*/
    struct descriptor  *dsc_cmdline	/* <m> command line		*/
    ,struct descriptor  *dsc_prmList	/* <r> parameter list		*/
)
{
    int   doubleQuotes;
    int   offsetStart;
    char  *p;

    p = dsc_cmdline->dscA_pointer;
    if (!p)  return;

    doubleQuotes = 0;
    for ( ; *p ; p++)
    {
        if (*p == '"')
        {   /*========= Double-quote char =========*/
            if (!doubleQuotes)
                doubleQuotes = 1;
            else if (*(p+1) == '"')
                p++;
            else
                doubleQuotes = 0;
        }
        else if (*p == '\'')
        {   /*========= Single-quote char =========*/
            if (!doubleQuotes)
            {   /* normal unquoted string ...		*/
                if (*(p+1) == '\'')
                    strcpy(p,p+1);	/* replace by single quote	*/
                else
                {   /*...else, replace symbol	*/
                    offsetStart = p - dsc_cmdline->dscA_pointer;
                    p = insertSymbol(dsc_cmdline,offsetStart,offsetStart+1,
                                     dsc_prmList);
                }
            }
            else
            {   /* inside quoted string ...		*/
                if (*(p+1) == '\'')
                {   /* 2 single quotes denote symbol */
                    offsetStart = p - dsc_cmdline->dscA_pointer;
                    p = insertSymbol(dsc_cmdline,offsetStart,offsetStart+2,
                                     dsc_prmList);
                }
            }
        }
    }
    return;
}
Beispiel #4
0
Stack::Stack(QWidget* parent) :
	QWidget(parent),
	m_symbols_dialog(0),
	m_printer(0),
	m_current_document(0),
	m_footer_margin(0),
	m_header_margin(0),
	m_footer_visible(0),
	m_header_visible(0)
{
	setMouseTracking(true);

	m_contents = new QStackedWidget(this);

	m_alerts = new AlertLayer(this);

	m_scenes = new SceneList(this);
	setScenesVisible(false);

	m_menu = new QMenu(this);
	m_menu_group = new QActionGroup(this);
	m_menu_group->setExclusive(true);
	connect(m_menu_group, SIGNAL(triggered(QAction*)), this, SLOT(actionTriggered(QAction*)));

	m_find_dialog = new FindDialog(this);
	connect(m_find_dialog, SIGNAL(findNextAvailable(bool)), this, SIGNAL(findNextAvailable(bool)));

	connect(ActionManager::instance(), SIGNAL(insertText(QString)), this, SLOT(insertSymbol(QString)));

	m_layout = new QGridLayout(this);
	m_layout->setMargin(0);
	m_layout->setSpacing(0);
	m_layout->setRowMinimumHeight(1, 6);
	m_layout->setRowMinimumHeight(4, 6);
	m_layout->setRowStretch(2, 1);
	m_layout->setColumnMinimumWidth(1, 6);
	m_layout->setColumnMinimumWidth(4, 6);
	m_layout->setColumnStretch(1, 1);
	m_layout->setColumnStretch(2, 1);
	m_layout->setColumnStretch(3, 1);
	m_layout->addWidget(m_contents, 1, 0, 4, 6);
	m_layout->addWidget(m_scenes, 1, 0, 4, 3);
	m_layout->addWidget(m_alerts, 3, 3);

	m_resize_timer = new QTimer(this);
	m_resize_timer->setInterval(50);
	m_resize_timer->setSingleShot(true);
	connect(m_resize_timer, SIGNAL(timeout()), this, SLOT(updateBackground()));

	m_theme_renderer = new ThemeRenderer(this);
	connect(m_theme_renderer, SIGNAL(rendered(QImage,QRect,Theme)), this, SLOT(updateBackground(QImage,QRect)));

	setHeaderVisible(Preferences::instance().alwaysShowHeader());
	setFooterVisible(Preferences::instance().alwaysShowFooter());

	// Always draw background
	setAttribute(Qt::WA_OpaquePaintEvent);
	setAutoFillBackground(false);
	updateBackground();
}
void SymbolTable::insertSymbols(const SymbolList& symbols) {
    for (SymbolList::const_iterator it = symbols.begin();
            it != symbols.end();
            ++it) {
        insertSymbol(*it);
    }
}
void SymbolTable::registrarImprima() {
  Symbol f(SymbolTable::GlobalScope, "imprima", 0, true, TIPO_NULO, false);
  f.cd = currentCod++;
  f.param.setVariable(true);
  f.isBuiltin = true;
  insertSymbol(f, SymbolTable::GlobalScope);  
}
Beispiel #7
0
void OSSymbolPool::reconstructSymbols(bool grow)
{
    unsigned int new_nBuckets = nBuckets;
    OSSymbol *insert;
    OSSymbolPoolState state;

    if (grow) {
        new_nBuckets += new_nBuckets + 1;
    } else {
       /* Don't shrink the pool below the default initial size.
        */
        if (nBuckets <= INITIAL_POOL_SIZE) {
            return;
        }
        new_nBuckets = (new_nBuckets - 1) / 2;
    }

   /* Create old pool to iterate after doing above check, cause it
    * gets finalized at return.
    */
    OSSymbolPool old(this);

    count = 0;
    nBuckets = new_nBuckets;
    buckets = (Bucket *) kalloc(nBuckets * sizeof(Bucket));
    ACCUMSIZE(nBuckets * sizeof(Bucket));
    /* @@@ gvdl: Zero test and panic if can't set up pool */
    bzero(buckets, nBuckets * sizeof(Bucket));

    state = old.initHashState();
    while ( (insert = old.nextHashState(&state)) )
        insertSymbol(insert);
}
Beispiel #8
0
void
addQueryToCache(Client c)
{
	MalBlkPtr mb;
	backend *be;
	str msg = 0, pipe;

	be = (backend *) c->sqlcontext;
	assert(be && be->mvc);	/* SQL clients should always have their state set */
	pipe = getSQLoptimizer(be->mvc);

	insertSymbol(c->nspace, c->curprg);
	trimMalBlk(c->curprg->def);
	c->blkmode = 0;
	mb = c->curprg->def;
	chkProgram(c->fdout, c->nspace, mb);
#ifdef _SQL_OPTIMIZER_DEBUG
	mnstr_printf(GDKout, "ADD QUERY TO CACHE\n");
	printFunction(GDKout, mb, 0, LIST_MAL_ALL);
#endif
	/*
	 * An error in the compilation should be reported to the user.
	 * And if the debugging option is set, the debugger is called
	 * to allow inspection.
	 */
	if (mb->errors) {
		showErrors(c);

		if (c->listing)
			printFunction(c->fdout, mb, 0, c->listing);
		if (be->mvc->debug) {
			msg = runMALDebugger(c, c->curprg);
			if (msg != MAL_SUCCEED)
				GDKfree(msg); /* ignore error */
		}
		return;
	}
	addOptimizers(c, mb, pipe);
	msg = optimizeMALBlock(c, mb);
	if (msg != MAL_SUCCEED) {
		showScriptException(c->fdout, mb, 0, MAL, "%s", msg);
		GDKfree(msg);
		return;
	}

	/* time to execute the optimizers */
	if (c->debug)
		optimizerCheck(c, mb, "sql.baseline", -1, 0);
#ifdef _SQL_OPTIMIZER_DEBUG
	mnstr_printf(GDKout, "ADD optimized QUERY TO CACHE\n");
	printFunction(GDKout, mb, 0, LIST_MAL_ALL);
#endif
}
Beispiel #9
0
void
addQueryToCache(Client c)
{
	str msg = NULL;

	insertSymbol(c->nspace, c->curprg);
	msg = optimizeQuery(c);
	if (msg != MAL_SUCCEED) {
		showScriptException(c->fdout, c->curprg->def, 0, MAL, "%s", msg);
		GDKfree(msg);
	}
}
int main (){

	node *list;

		list = createList(list);

		node *SymbolTeste;
		insertSymbol(list, "TESTE");

		SymbolTeste = findSymbol(list, "TESTE");

		destroyList(list);

}
Beispiel #11
0
Stack::Stack(QWidget* parent) :
	QWidget(parent),
	m_symbols_dialog(0),
	m_current_document(0),
	m_background_position(0),
	m_margin(0),
	m_footer_margin(0),
	m_header_margin(0),
	m_footer_visible(0),
	m_header_visible(0)
{
	setMouseTracking(true);

	m_contents = new QStackedWidget(this);

	m_alerts = new AlertLayer(this);

	m_scenes = new SceneList(this);
	setScenesVisible(false);

	m_load_screen = new LoadScreen(this);

	m_find_dialog = new FindDialog(this);
	connect(m_find_dialog, SIGNAL(findNextAvailable(bool)), this, SIGNAL(findNextAvailable(bool)));

	connect(ActionManager::instance(), SIGNAL(insertText(QString)), this, SLOT(insertSymbol(QString)));

	m_layout = new QGridLayout(this);
	m_layout->setMargin(0);
	m_layout->setSpacing(0);
	m_layout->setRowMinimumHeight(1, 6);
	m_layout->setRowMinimumHeight(4, 6);
	m_layout->setRowStretch(2, 1);
	m_layout->setColumnMinimumWidth(1, 6);
	m_layout->setColumnMinimumWidth(4, 6);
	m_layout->setColumnStretch(1, 1);
	m_layout->setColumnStretch(2, 1);
	m_layout->setColumnStretch(3, 1);
	m_layout->addWidget(m_contents, 1, 0, 4, 6);
	m_layout->addWidget(m_scenes, 1, 0, 4, 3);
	m_layout->addWidget(m_alerts, 3, 3);
	m_layout->addWidget(m_load_screen, 0, 0, 6, 6);

	m_resize_timer = new QTimer(this);
	m_resize_timer->setInterval(50);
	m_resize_timer->setSingleShot(true);
	connect(m_resize_timer, SIGNAL(timeout()), this, SLOT(updateBackground()));
	connect(&background_loader, SIGNAL(finished()), this, SLOT(updateBackground()));
}
Beispiel #12
0
bool saveSymbol (tNodePtr * currTS, char * key, char * name, int type, int argCount, bool errOnRedef)
{
    /* Otestujem či už náhodou neexistuje daný symbol */

    if (searchSymbol (currTS, key) == 0)
    {

    /* Alokujem si miesto pre data pre nový symbol v tabulke */

    tData newsymbol = malloc (sizeof (struct tData));
    
    /* Ak alokácia zlyhala alebo predaný name či key je NULL volám chybu 99 */
    /* Ak alokácia prebehla bez problémov a názvy sú neprázdne, pokračujem  */

    if (newsymbol != NULL || key != NULL || name != NULL)
    {
        /*Do dátovej štruktúry uložím dáta predané funkcii*/

        newsymbol -> name     = name;
        newsymbol -> type     = type;
        newsymbol -> nextArg  = NULL;
        newsymbol -> argCount = argCount;
        newsymbol -> localTSadr = NULL;
        newsymbol -> localILadr = NULL;
        //newsymbol -> content.integer = rand() % 100;

        /*Uložím do aktuálnej tabulky nový symbol ktorý som si práve pripravil*/
        /*Ak vloženie zlyhá, vraciam internú chybu errInt(99)                 */

        if (insertSymbol (currTS, key, newsymbol) == 0)
        {
            printf ("jkebol saveSymbol\n");
            errorHandler (errInt);
        }

        return true; 
    }
        else
        {    
            printf ("jebol saveSymbol 2\n");
            errorHandler (errInt);
        }
    }
    else
        if (errOnRedef == true)
            errorHandler (errSemDef);
        return false;
}
Beispiel #13
0
void Stack::showSymbols()
{
	// Load symbols dialog on demand
	if (!m_symbols_dialog) {
		window()->setCursor(Qt::WaitCursor);
		m_symbols_dialog = new SymbolsDialog(this);
		m_symbols_dialog->setInsertEnabled(!m_current_document->isReadOnly());
		m_symbols_dialog->setPreviewFont(m_current_document->text()->font());
		connect(m_symbols_dialog, SIGNAL(insertText(QString)), this, SLOT(insertSymbol(QString)));
		window()->unsetCursor();
	}

	// Show dialog
	m_symbols_dialog->show();
	m_symbols_dialog->raise();
	m_symbols_dialog->activateWindow();
}
Beispiel #14
0
bool LineOfSymbols::replaceVar(const QString &pattern, modbusVar *var, unsigned int pos)
{
    variable curVar;
    QVector<quint16> curSymbols;

    for(int i=0;i<vars.count();i++)
    {
        unsigned char startPos = vars[i].view.getPosition();
        unsigned char endPos = startPos + vars[i].view.getLength()-1;
        if((pos>=startPos)&&(pos<=endPos))
        {
            curVar = vars[i];
            for(int j=startPos;j<=endPos;j++) curSymbols+=symbols.at(j);
            break;
        }
    }

    for(int i=0;i<vars.count();i++)
    {
        unsigned char startPos = vars[i].view.getPosition();
        unsigned char endPos = startPos + vars[i].view.getLength()-1;
        if((pos>=startPos)&&(pos<=endPos))
        {
            vars.remove(i);
            for(int j=startPos;j<=endPos;j++)
            {
                if(j<symbols.count()) deleteSymbol(startPos);
            }
            bool res = insertVar(pattern,var,startPos);
            if(res==false)
            {
                for(int j=startPos;j<=endPos;j++)
                {
                    insertSymbol(curSymbols[j-startPos],j);
                }
                vars+=curVar;
            }
            return res;
        }
    }
    return false;
}
Beispiel #15
0
void
MSinitClientPrg(Client cntxt, str mod, str nme)
{
	InstrPtr p;
	MalBlkPtr mb;

	if (cntxt->curprg && idcmp(nme, cntxt->curprg->name) == 0) {
		MSresetClientPrg(cntxt);
		return;
	}
	cntxt->curprg = newFunction(putName("user", 4), putName(nme, strlen(nme)), FUNCTIONsymbol);
	mb = cntxt->curprg->def;
	p = getSignature(cntxt->curprg);
	if (mod)
		setModuleId(p, mod);
	else
		setModuleScope(p, cntxt->nspace);
	setVarType(mb, findVariable(mb, nme), TYPE_void);
	insertSymbol(cntxt->nspace, cntxt->curprg);
	cntxt->glb = 0;
	assert(cntxt->curprg->def != NULL);
}
Beispiel #16
0
void Font::loadSymbols(std::string name){
	std::string path = "../res/fonts/";
	std::ifstream file;
	file.open(path + name + ".fnt", std::ios::in);
	std::string infoFaceLine, commonLine, countLine, buff;
	getline(file, infoFaceLine);
	getline(file, commonLine);
	getline(file, buff); // non used
	getline(file, countLine);
	//
	float sizeU = (float)rgxIntSearch(commonLine, R"(scaleW=([\-]?[0-9]+))");
	float sizeV = (float)rgxIntSearch(commonLine, R"(scaleH=([\-]?[0-9]+))");
	int charCount = rgxIntSearch(countLine, R"(count=([\-]?[0-9]+))");
	std::vector<std::string> lines;
	lines.resize(charCount);
	this->height = rgxIntSearch(commonLine, R"(lineHeight=([\-]?[0-9]+))");;

	for (int i = 0; i < charCount; i++)
		getline(file, lines[i]);
	for(auto &it : lines)
		insertSymbol(it, sizeU, sizeV);
}
Beispiel #17
0
void constructParsingTable()
{
	/*read the set of Productions and constructs Parsing Table*/
	FILE *fp;
	int i,j,num,prod_count;
	char name[50];
	Symbol symbol,nonterminal;
	List prod_right, first_set;
	Production production;

	fp = fopen("productions","r");
	while(!feof(fp))
	{
		fscanf(fp,"%d %s",&num,name);
		//abstract out the non terminal whose production it is
		nonterminal = findSymbol(name);
		//construct list of symbols on the right hand side of production
		prod_right = (List)malloc(sizeof(struct list)*(num-1));
		for(i=0;i<(num-1);i++)
		{
			fscanf(fp,"%s",name);
			symbol = findSymbol(name);
			if(symbol==NULL)
				symbol = insertSymbol(name,TERMINAL);
			prod_right[i].symbol=symbol;
		}
		//now we need to fill the parsing table corresponding to nonterminal and the production
		if(nonterminal->prodtable==NULL)
		{
			nonterminal->prodtable = (ProductionTable)malloc(sizeof(struct prodtable));
			nonterminal->prodtable->productions = (Production)malloc((PROD_TABLE_SIZE)*sizeof(struct production));
		}
		//enter production X->beta in row X, column T for each T in FIRST[beta]
		for(i=0;i<(num-1);i++)
		{
			first_set=prod_right[i].symbol->first;
			for(j=0;j<prod_right[i].symbol->num_first;j++)
			{
				production = insertProduction(nonterminal->prodtable, first_set[j].symbol);	
				production->prod_right=prod_right;
				production->num_symbols=(num-1);
			}
			if(prod_right[i].symbol->nullable==YES)
				continue;
			else
				break;
		}
		//enter production X->beta in row X, column T for each T in FOLLOW[X], if nullable(beta)
		if(i==(num-1))
		{
			//nullable(beta)==YES
			for(j=0;j<nonterminal->num_follow;j++)
			{
				production = insertProduction(nonterminal->prodtable, nonterminal->follow[j].symbol);	
				production->prod_right=prod_right;
				production->num_symbols=(num-1);
			}
		}
		//calculate number of production criteria entered for the current symbol
		prod_count=0;
		for(i=0;i<PROD_TABLE_SIZE;i++)
		{
			if(nonterminal->prodtable->productions[i].terminal!=NULL)
				prod_count++;
		}
		nonterminal->prodtable->num_productions=prod_count;
	}
	fclose(fp);
}
Beispiel #18
0
void loadParsingTables(FILE *fp)
{
	/*loads the saved data structures from the file*/
	int i,j,k,num;
	Nullable nullable;
	Type type;
	char sname[20];
	symbols = (STable)malloc(sizeof(struct stable));
	symbols->symbol = (Symbol *)malloc(sizeof(struct symbol)*S_TABLE_SIZE);
	symbols->size = S_TABLE_SIZE;
	Symbol s,term;
	Production production;
	
	while(!feof(fp))
	{
		//read symbol name, nullable & type
		fscanf(fp,"%s %d %d",sname,(int*)&nullable,(int*)&type);
		s=insertSymbol(sname,type);
		s->nullable=nullable;
		//read in FIRST set
		fscanf(fp,"%d",&num);
		s->num_first = num;
		s->first=(List)malloc(sizeof(struct list)*num);
		for(i=0;i<num;i++)
		{
			fscanf(fp,"%s",sname);
			term = findSymbol(sname);
			if(term==NULL)
				term = insertSymbol(sname,TERMINAL);
			s->first[i].symbol=term;
		}
		if(type==NONTERMINAL)
		{
			//read in FOLLOW set
			fscanf(fp,"%d",&num);
			s->num_follow=num;
			s->follow=(List)malloc(sizeof(struct list)*num);
			for(i=0;i<num;i++)
			{
				fscanf(fp,"%s",sname);
				term = findSymbol(sname);
				if(term==NULL)
					term = insertSymbol(sname,TERMINAL);
				s->follow[i].symbol=term;
			}
			//read in ProductionTable
			if(s->prodtable==NULL)
			{
				s->prodtable = (ProductionTable)malloc(sizeof(struct prodtable));
				s->prodtable->productions = (Production)malloc((PROD_TABLE_SIZE)*sizeof(struct production));
			}
			fscanf(fp,"%d",&num);
			s->prodtable->num_productions=num;
			for(i=0;i<num;i++)
			{
				fscanf(fp,"%s",sname);
				term = findSymbol(sname);
				if(term==NULL)
					term = insertSymbol(sname,TERMINAL);
				production = insertProduction(s->prodtable,term);
				fscanf(fp,"%d",&k);
				production->num_symbols = k;
				production->prod_right = (List)malloc(sizeof(struct list)*k);
				for(j=0;j<k;j++)
				{
					fscanf(fp,"%s %d",sname,(int*)&type);
					term = findSymbol(sname);
					if(term==NULL)
						term = insertSymbol(sname,type);
					production->prod_right[j].symbol=term;
				}
			}

		}
	}
}
Beispiel #19
0
static void buildSymbolTable2(TreeNode *syntaxTree)
{
    int         i;         /* iterate over node children */
    HashNodePtr luSymbol;  /* symbol being looked up */
    char        errorMessage[80];  

    /* used to decorate RETURN nodes with enclosing procedure */
    static TreeNode *enclosingFunction = NULL;
    
    while (syntaxTree != NULL)
    {
	/*
	 * Examine current symbol: if it's a declaration, insert into
	 *  symbol table.
	 */
	if (syntaxTree->nodekind == DecK)
	    insertSymbol(syntaxTree->name, syntaxTree, syntaxTree->lineno);
	
	/* If entering a new function, tell the symbol table */
	if ((syntaxTree->nodekind == DecK)
	    && (syntaxTree->kind.dec == FuncDecK))
	{
	    /* record the enclosing procedure declaration */
	    enclosingFunction = syntaxTree;
	    
	    if (TraceAnalyse)
		/*
		 *  For functions at least, it's nice to tell the user
		 *   whereabouts in the program the variable comes into
		 *   scope.  We don't bother printing out compound-stmt
		 *   scopes
		*/
		drawRuler(listing, syntaxTree->name);
	    
	    newScope();
	    ++scopeDepth;
	}

	/* If entering a compound-statement, create a new scope as well */
	if ((syntaxTree->nodekind == StmtK)
	    && (syntaxTree->kind.stmt == CompoundK))
	{
	    newScope();
	    ++scopeDepth;
	}

	/*
	 *  If the current node is an identifier, it needs to be checked
	 *   against the symbol table, and annotated with a pointer back to
	 *   it's declaration.
	 */

	if (((syntaxTree->nodekind == ExpK)  /* identifier reference... */
	     && (syntaxTree->kind.exp == IdK))
	    || ((syntaxTree->nodekind == StmtK)  /* function call... */
		&& (syntaxTree->kind.stmt == CallK)))
	{
	    DEBUG_ONLY(
		fprintf(listing,
			"*** Annotating identifier \"%s\" on line %d\n",
			syntaxTree->name, syntaxTree->lineno); );

	    luSymbol = lookupSymbol(syntaxTree->name);
	    if (luSymbol == NULL)
	    {
		/* operation failed; say so to user */
		sprintf(errorMessage,
			"identifier \"%s\" unknown or out of scope\n",
			syntaxTree->name);
		flagSemanticError(errorMessage);
	    }
	    else
	    {
		/*
		 *  Annotate identifier tree-node with a pointer to it's
		 *   declaration.
		 */
		syntaxTree->declaration = luSymbol->declaration;
	    }		 
	}
Beispiel #20
0
void constructSTable()
{
	/*Reads in FIRST-FOLLOW Sets and puts all grammar symbols into Hash Table*/
	FILE *fp;
	char symbol[20];
	int i,num;
	symbols = (STable)malloc(sizeof(struct stable));
	symbols->symbol = (Symbol *)malloc(sizeof(struct symbol)*S_TABLE_SIZE);
	symbols->size = S_TABLE_SIZE;
	for(i=0;i<S_TABLE_SIZE;i++)
	{
		symbols->symbol[i]=NULL;
	}
	Symbol nonterm,term;

	fp=fopen("ffsets","r");
	while(!feof(fp))
	{
		//read symbol name and if nullable
		fscanf(fp,"%s",symbol);
		nonterm = insertSymbol(symbol,NONTERMINAL);
		fscanf(fp,"%s",symbol);
		if(strcmp(symbol,"NO")==0)
			nonterm->nullable = NO;
		else
			nonterm->nullable = YES;
		//read FIRST set
		fscanf(fp,"%d",&num);
		nonterm->num_first=num;
		nonterm->first=(List)malloc(sizeof(struct list)*num);
		for(i=0;i<num;i++)
		{
			fscanf(fp,"%s",symbol);
			term = findSymbol(symbol);
			if(term==NULL)
				term = insertSymbol(symbol,TERMINAL);
			nonterm->first[i].symbol=term;
		}
		//read FOLLOW set
		fscanf(fp,"%d",&num);
		nonterm->num_follow=num;
		nonterm->follow=(List)malloc(sizeof(struct list)*num);
		for(i=0;i<num;i++)
		{
			fscanf(fp,"%s",symbol);
			term = findSymbol(symbol);
			if(term==NULL)
				term = insertSymbol(symbol,TERMINAL);
			nonterm->follow[i].symbol=term;
		}
	}
	fclose(fp);
	//manually add terminal entry for ε (null production)
	term = insertSymbol("ε",TERMINAL); 
	term->nullable = YES;
	term->num_first = 0;
	term->num_follow = 0;
	term->first=NULL;
	term->follow=NULL;
	term->prodtable=NULL;
}
void SymbolTable::registrarLeia() {
  Symbol f(SymbolTable::GlobalScope, "leia", 0, true, TIPO_ALL, false);
  f.cd = currentCod++;
  f.isBuiltin = true;
  insertSymbol(f, SymbolTable::GlobalScope);
}
Beispiel #22
0
void block(){

  int jmpLoc = reserveCode();

  int thisScope;
  int numVars = 0;
  char tempSymbol[MAX_IDENT_LENGTH + 1];
 
  if(currentToken == constsym){
    /***************************************************************/
    /* const-declaration ::= [ "const" ident "=" number            */
    /*                               {"," ident "=" number} ";"]   */
    /***************************************************************/
    do{
      readToken();
      
      if(currentToken != identsym){
        throwError(ID_FOLLOW_CONST_VAR_PROC);
      }else{
        strcpy(tempSymbol, tokenVal.string);
      }
 
      readToken();
      
      if(currentToken != eqsym){
        if(currentToken == becomessym)
          throwError(EQ_NOT_BECOMES);
        else
          throwError(EQ_FOLLOW_ID);
      }
      
      readToken();
    
      if(currentToken != numbersym){
        throwError(NUM_FOLLOW_EQ);
      }else{
        insertSymbol(symTable, newSymbol(CONST, tempSymbol, scope, 0,
                                         tokenVal.numeric));
      }
    
      readToken();
    }while(currentToken == commasym);
    
    if(currentToken != semicolonsym)
      throwError(SEMICOL_COMMA_MISS);
 
    readToken();
  }
  
  if(currentToken == intsym){
    /*******************************************************/
    /* var-declaration ::= ["int" ident {"," ident} ";"] */
    /*******************************************************/
    do{
      readToken();
      
      if(currentToken != identsym){
        throwError(ID_FOLLOW_CONST_VAR_PROC);
      }else{
        insertSymbol(symTable, newSymbol(VAR, tokenVal.string,
                                         scope, BASE_OFFSET + numVars++, 0));
      }
        
      readToken();
    }while(currentToken == commasym);
    
    if(currentToken != semicolonsym)
      throwError(SEMICOL_COMMA_MISS);
      
    readToken();
  }
  
  //Saving the scope before moving into procedure declarations
  thisScope = scope;

  while(currentToken == procsym){
    /**********************************************************************/
    /* proc-declaration ::= {"procedure" ident ";" block ";"} statement   */
    /**********************************************************************/

    readToken();
    
    if(currentToken != identsym)
      throwError(ID_FOLLOW_CONST_VAR_PROC);

    //Storing the function name in the symbol table
    insertSymbol(symTable, newSymbol(FUNC, tokenVal.string, thisScope, 
                                     genLabel(), 0));

    
    readToken();
    
    if(currentToken != semicolonsym)
      throwError(SEMICOL_COMMA_MISS);
      
    readToken();

    //Incrementing the scope for our new function and saving its parent
    //in the disjoint set
    scope++;
    scopeParent[scope] = thisScope;

    block();
    
    if(currentToken != semicolonsym)
      throwError(WRONG_SYM_AFTER_PROC);
    
    readToken();
  }

  //Restoring the scope
  scope = thisScope;

  backPatch(jmpLoc, JMP, 0, genLabel());
  genCode(INC, 0, BASE_OFFSET + numVars);
 
  statement();
  
  genCode(OPR, 0, RET);
 
  return;
}
AnnotationTerminals::AnnotationTerminals() {
    insertSymbol("[", ID_LBRACKET);
    insertSymbol("]", ID_RBRACKET);
    insertSymbol("@", ID_AT);
    insertSymbol("=", ID_EQUAL);
    insertSymbol(",", ID_COMMA);
    insertSymbol("\"", ID_QUOTE);
    insertSymbol("'", ID_APOSTROPHE);

    insertSymbol("true", ID_TRUE, true);
    insertSymbol("false", ID_FALSE, true);

    insertSymbol("IDENTIFIER", ID_IDENTIFIER);
    insertSymbol("INTCONST", ID_INTCONST);
    insertSymbol("FLOATCONST", ID_FLOATCONST);
    insertSymbol("STRING", ID_STRING);
    insertSymbol("CHARACTER", ID_CHARACTER);
}
PlotFunctionTerminals::PlotFunctionTerminals() {
    insertSymbol("(", ID_LPAREN);
    insertSymbol(")", ID_RPAREN);
    insertSymbol("[", ID_LBRACKET);
    insertSymbol("]", ID_RBRACKET);
    insertSymbol(".", ID_DOT);
    insertSymbol(",", ID_COMMA);
    insertSymbol(":", ID_COLON);
    insertSymbol(";", ID_SEMICOLON);
    insertSymbol("-", ID_DASH);
    insertSymbol("+", ID_PLUS);
    insertSymbol("*", ID_STAR);
    insertSymbol("/", ID_SLASH);
    insertSymbol("^", ID_CARET);
    insertSymbol("|", ID_VERTICAL_BAR);

    insertSymbol("RANGE_TERM", ID_RANGE_TERM);
    insertSymbol("FUNCTION-TERM",ID_FUNCTION_TERM);
    insertSymbol("FUNCTION", ID_FUNCTION);
    insertSymbol("INTCONST", ID_INTCONST);
    insertSymbol("FLOATCONST", ID_FLOATCONST);
    insertSymbol("VARIABLE", ID_VARIABLE);
    insertSymbol("EMPTY",ID_EMPTY);
}
void hoistSymbols(uint32_t slot, Node *table, symtab_t *symbols, symtab_t *block) {

  while (slot)
	switch (table[slot].type) {
	case node_endlist:
	case node_list: {
		listNode *ln;

		do {
			ln = (listNode *)(table + slot);
			hoistSymbols(ln->elem, table, symbols, block);
			slot -= sizeof(listNode) / sizeof(Node);
		} while ( ln->hdr->type == node_list );

		return;
	}
	case node_elem: {
		binaryNode *bn = (binaryNode *)(table + slot);
		slot = bn->right;
		continue;
	}
	case node_obj: {
		objNode *on = (objNode *)(table + slot);
		slot = on->elemlist;
		continue;
	}
	case node_pipe:
	case node_fcncall: {
		fcnCallNode *fc = (fcnCallNode *)(table + slot);
		hoistSymbols(fc->name, table, symbols, block);
		
		slot = fc->args;
		continue;
	}
	case node_ifthen: {
		ifThenNode *iftn = (ifThenNode *)(table + slot);
		hoistSymbols(iftn->thenstmt, table, symbols, block);
		slot = iftn->elsestmt;
		continue;
	}
	case node_while:
	case node_dowhile: {
		whileNode *wn = (whileNode *)(table + slot);
		slot = wn->stmt;
		continue;
	}
	case node_forin: {
		forInNode *forn = (forInNode*)(table + slot);

		// make a new scope frame

		forn->symbols.depth = symbols->depth;
		forn->symbols.parent = block;
		block = &forn->symbols;

		hoistSymbols(forn->var, table, symbols, block);

		if (forn->symbols.parent) {
		  if (forn->symbols.parent->scopeCnt < block->frameIdx)
		    forn->symbols.parent->scopeCnt = block->frameIdx;
		} else {
		  if (symbols->scopeCnt < block->frameIdx)
			symbols->scopeCnt = block->frameIdx;
		}

		slot = forn->stmt;
		continue;
	}
	case node_for: {
		forNode *forn = (forNode*)(table + slot);

		// make a new scope frame

		forn->symbols.depth = symbols->depth;
		forn->symbols.parent = block;
		block = &forn->symbols;

		hoistSymbols(forn->init, table, symbols, block);

		if (forn->symbols.parent) {
		  if (forn->symbols.parent->scopeCnt < block->frameIdx)
		    forn->symbols.parent->scopeCnt = block->frameIdx;
		} else {
		  if (symbols->scopeCnt < block->frameIdx)
			symbols->scopeCnt = block->frameIdx;
		}

		slot = forn->stmt;
		continue;
	}
	case node_opassign:
	case node_assign: {
		binaryNode *bn = (binaryNode *)(table + slot);
		hoistSymbols(bn->left, table, symbols, block);
		slot = bn->right;
		continue;
	}
	case node_var: {
		symNode *sym = (symNode *)(table + slot);
		stringNode *sn = (stringNode *)(table + sym->name);

		if (sym->hdr->flag & flag_decl) {
		  if (sym->hdr->flag & flag_scope && block)
			insertSymbol(&sn->str, block, true);
		  else
			insertSymbol(&sn->str, symbols, false);
		}

		return;
	}
	case node_block: {
		blkEntryNode *be = (blkEntryNode *)(table + slot);

		//	make new scope

		be->symbols.depth = symbols->depth;
		be->symbols.parent = block;
		block = &be->symbols;

		hoistSymbols(be->body, table, symbols, block);

		if (be->symbols.parent) {
		  if (be->symbols.parent->scopeCnt < block->frameIdx)
		    be->symbols.parent->scopeCnt = block->frameIdx;
		} else {
		  if (symbols->scopeCnt < block->frameIdx)
			symbols->scopeCnt = block->frameIdx;
		}

		return;
	}
	case node_fcndef: {
		fcnDeclNode *fd = (fcnDeclNode *)(table + slot);

		// install the function name in symbol table

		symNode *sym = (symNode *)(table + fd->name);
		stringNode *sn = (stringNode *)(table + sym->name);
		sym->frameIdx = insertSymbol(&sn->str, symbols, false);
		sym->level = 0;

		if (hoistDebug)
			printf("node %d hoist fcndecl: %s\n", slot, sn->str.val);

		// add to list of child fcns

		fd->next = symbols->childFcns;
		symbols->childFcns = slot;
	}
	case node_fcnexpr: {
		fcnDeclNode *fd = (fcnDeclNode *)(table + slot);
		fd->symbols.depth = symbols->depth + 1;
		fd->symbols.parent = symbols;

		hoistSymbols(fd->params, table, &fd->symbols, block);
		fd->nparams = fd->symbols.frameIdx;

		// install fcn name from fcn expression

		if (fd->hdr->type == node_fcnexpr)
		  if (fd->name && table[fd->name].type == node_var) {
 	 		symNode *sym = (symNode *)(table + fd->name);
			stringNode *sn = (stringNode *)(table + sym->name);

			// install the function name in the table

			sym->frameIdx = insertSymbol(&sn->str, &fd->symbols, false);
			sym->level = 0;

			if (hoistDebug)
				printf("node %d hoist fcnexpr: %s\n", slot, sn->str.val);
		  }

		// hoist function body declarations

		hoistSymbols(fd->body, table, &fd->symbols, block);
		return;
	}
	case node_return: {
		exprNode *en = (exprNode *)(table + slot);
		slot = en->expr;
		continue;
	}
	default:
		if (hoistDebug)
			printf("node %d unprocessed: %d\n", slot, (int)table[slot].type);

		return;
	}
}
Beispiel #26
0
GLSLTerminals::GLSLTerminals() {
    insertSymbol("<<", ID_LSHIFT_OP);
    insertSymbol(">>", ID_RSHIFT_OP);
    insertSymbol("++", ID_INC_OP);
    insertSymbol("--", ID_DEC_OP);
    insertSymbol("<=", ID_LE_OP);
    insertSymbol(">=", ID_GE_OP);
    insertSymbol("==", ID_EQ_OP);
    insertSymbol("!=", ID_NE_OP);
    insertSymbol("&&", ID_AND_OP);
    insertSymbol("||", ID_OR_OP);
    insertSymbol("^^", ID_XOR_OP);

    insertSymbol("<<=", ID_LSHIFT_ASSIGN);
    insertSymbol(">>=", ID_RSHIFT_ASSIGN);
    insertSymbol("+=", ID_ADD_ASSIGN);
    insertSymbol("/=", ID_DIV_ASSIGN);
    insertSymbol("*=", ID_MUL_ASSIGN);
    insertSymbol("-=", ID_SUB_ASSIGN);
    insertSymbol("%=", ID_MOD_ASSIGN);
    insertSymbol("&=", ID_AND_ASSIGN);
    insertSymbol("|=", ID_OR_ASSIGN);
    insertSymbol("^=", ID_XOR_ASSIGN);

    insertSymbol("(", ID_LPAREN);
    insertSymbol(")", ID_RPAREN);
    insertSymbol("[", ID_LBRACKET);
    insertSymbol("]", ID_RBRACKET);
    insertSymbol("{", ID_LBRACE);
    insertSymbol("}", ID_RBRACE);
    insertSymbol("<", ID_LANGLE);
    insertSymbol(">", ID_RANGLE);
    insertSymbol(".", ID_DOT);
    insertSymbol(",", ID_COMMA);
    insertSymbol(":", ID_COLON);
    insertSymbol(";", ID_SEMICOLON);
    insertSymbol("=", ID_EQUAL);
    insertSymbol("!", ID_BANG);
    insertSymbol("-", ID_DASH);
    insertSymbol("~", ID_TILDE);
    insertSymbol("+", ID_PLUS);
    insertSymbol("*", ID_STAR);
    insertSymbol("/", ID_SLASH);
    insertSymbol("%", ID_PERCENT);
    insertSymbol("|", ID_VERTICAL_BAR);
    insertSymbol("^", ID_CARET);
    insertSymbol("&", ID_AMPERSAND);
    insertSymbol("?", ID_QUESTION);

    insertSymbol("attribute", ID_ATTRIBUTE, true);
    insertSymbol("const", ID_CONST, true);
    insertSymbol("in", ID_IN, true);
    insertSymbol("inout", ID_INOUT, true);
    insertSymbol("out", ID_OUT, true);
    insertSymbol("uniform", ID_UNIFORM, true);
    insertSymbol("varying", ID_VARYING, true);
    insertSymbol("centroid", ID_CENTROID, true);
    insertSymbol("invariant", ID_INVARIANT, true);

    insertSymbol("flat", ID_FLAT, true);
    insertSymbol("layout", ID_LAYOUT, true);
    insertSymbol("noperspective", ID_NONPERSPECTIVE, true);
    insertSymbol("smooth", ID_SMOOTH, true);

    // precision qualifiers
    //
    insertSymbol("highp", ID_HIGHP, true);
    insertSymbol("lowp", ID_LOWP, true);
    insertSymbol("mediump", ID_MEDIUMP, true);
    insertSymbol("precision", ID_PRECISION, true);

    // program control / statements
    //
    insertSymbol("case", ID_CASE, true);
    insertSymbol("default", ID_DEFAULT, true);
    insertSymbol("do", ID_DO, true);
    insertSymbol("else", ID_ELSE, true);
    insertSymbol("for", ID_FOR, true);
    insertSymbol("if", ID_IF, true);
    insertSymbol("switch", ID_SWITCH, true);
    insertSymbol("while", ID_WHILE, true);

    insertSymbol("break", ID_BREAK, true);
    insertSymbol("continue", ID_CONTINUE, true);
    insertSymbol("discard", ID_DISCARD, true);
    insertSymbol("return", ID_RETURN, true);
    insertSymbol("false", ID_FALSE, true);
    insertSymbol("true", ID_TRUE, true);
    insertSymbol("struct", ID_STRUCT, true);

    // "primitive" types
    //
    insertSymbol("bool", ID_BOOL, true);
    insertSymbol("float", ID_FLOAT, true);
    insertSymbol("int", ID_INT, true);
    insertSymbol("uint", ID_UINT, true);
    insertSymbol("void", ID_VOID, true);

    // "complexe" types
    //
    insertSymbol("bvec2", ID_BVEC2, true);
    insertSymbol("bvec3", ID_BVEC3, true);
    insertSymbol("bvec4", ID_BVEC4, true);

    insertSymbol("ivec2", ID_IVEC2, true);
    insertSymbol("ivec3", ID_IVEC3, true);
    insertSymbol("ivec4", ID_IVEC4, true);

    insertSymbol("uvec2", ID_UVEC2, true);
    insertSymbol("uvec3", ID_UVEC3, true);
    insertSymbol("uvec4", ID_UVEC4, true);

    insertSymbol("vec2", ID_VEC2, true);
    insertSymbol("vec3", ID_VEC3, true);
    insertSymbol("vec4", ID_VEC4, true);

    insertSymbol("mat2", ID_MAT2, true);
    insertSymbol("mat3", ID_MAT3, true);
    insertSymbol("mat4", ID_MAT4, true);

    insertSymbol("mat2x2", ID_MAT2X2, true);
    insertSymbol("mat2x3", ID_MAT2X3, true);
    insertSymbol("mat2x4", ID_MAT2X4, true);

    insertSymbol("mat3x2", ID_MAT3X2, true);
    insertSymbol("mat3x3", ID_MAT3X3, true);
    insertSymbol("mat3x4", ID_MAT3X4, true);

    insertSymbol("mat4x2", ID_MAT4X2, true);
    insertSymbol("mat4x3", ID_MAT4X3, true);
    insertSymbol("mat4x4", ID_MAT4X4, true);

    insertSymbol("sampler1D", ID_SAMPLER1D, true);
    insertSymbol("sampler2D", ID_SAMPLER2D, true);
    insertSymbol("sampler3D", ID_SAMPLER3D, true);
    insertSymbol("samplerCube", ID_SAMPLERCUBE, true);
    insertSymbol("sampler1DShadow", ID_SAMPLER1DSHADOW, true);
    insertSymbol("sampler2DShadow", ID_SAMPLER2DSHADOW, true);

    insertSymbol("sampler1DArray", ID_SAMPLER1DARRAY, true);
    insertSymbol("sampler2DArray", ID_SAMPLER2DARRAY, true);
    insertSymbol("sampler1DArrayShadow", ID_SAMPLER1DARRAYSHADOW, true);
    insertSymbol("sampler2DArrayShadow", ID_SAMPLER2DARRAYSHADOW, true);
    insertSymbol("isampler1D", ID_ISAMPLER1D, true);
    insertSymbol("isampler2D", ID_ISAMPLER2D, true);
    insertSymbol("isampler3D", ID_ISAMPLER3D, true);
    insertSymbol("isamplerCube", ID_ISAMPLERCUBE, true);
    insertSymbol("isampler1DArray", ID_ISAMPLER1DARRAY, true);
    insertSymbol("isampler2DArray", ID_ISAMPLER2DARRAY, true);
    insertSymbol("usampler1D", ID_USAMPLER1D, true);
    insertSymbol("usampler2D", ID_USAMPLER2D, true);
    insertSymbol("usampler3D", ID_USAMPLER3D, true);
    insertSymbol("usamplerCube", ID_USAMPLERCUBE, true);
    insertSymbol("usampler1DArray", ID_USAMPLER1DARRAY, true);
    insertSymbol("usampler2DArray", ID_USAMPLER2DARRAY, true);
    insertSymbol("sampler2DRect", ID_SAMPLER2DRECT, true);
    insertSymbol("sampler2DRectShadow", ID_SAMPLER2DRECTSHADOW, true);
    insertSymbol("isampler2DRect", ID_ISAMPLER2DRECT, true);
    insertSymbol("usampler2DRect", ID_USAMPLER2DRECT, true);
    insertSymbol("samplerBuffer", ID_SAMPLERBUFFER, true);
    insertSymbol("isamplerBuffer", ID_ISAMPLERBUFFER, true);
    insertSymbol("usamplerBuffer", ID_USAMPLEBUFFER, true);
    insertSymbol("sampler2DMS", ID_SAMPLER2DMS, true);
    insertSymbol("isampler2DMS", ID_ISAMPLER2DMS, true);
    insertSymbol("usampler2DMS", ID_USAMPLER2DMS, true);
    insertSymbol("sampler2DMSArray", ID_SAMPLER2DMSARRY, true);
    insertSymbol("isampler2DMSArray", ID_ISAMPLER2DMSARRAY, true);
    insertSymbol("usampler2DMSArray", ID_USAMPLER2DMSARRAY, true);

    insertSymbol("IDENTIFIER", ID_IDENTIFIER);
    insertSymbol("INTCONSTANT", ID_INTCONST);
    insertSymbol("UINTCONSTANT", ID_UINTCONST);
    insertSymbol("FLOATCONSTANT", ID_FLOATCONST);
    insertSymbol("TYPE-NAME", ID_TYPE_NAME);
    insertSymbol("FIELD-SELECTION", ID_FIELDSELECTION);
    insertSymbol("NATIVE-TYPE", ID_NATIVE_TYPE);
    insertSymbol("LEADING-ANNOTATION", ID_LEADING_ANNOTATION);
    insertSymbol("TRAILING-ANNOTATION", ID_TRAILING_ANNOTATION);

    // other keywords reserved by GLSL specification 1.50
    //
    const size_t NUM_OTHERS = 70;
    std::string others[NUM_OTHERS] = {
        "common", "partition", "active", "asm", "class",
        "union", "enum", "typedef", "template", "this",
        "packed", "goto", "inline", "noinline", "volatile",
        "public", "static", "extern", "external", "interface",
        "long", "short", "double", "half", "fixed",
        "unsigned", "superp", "input", "output", "hvec2",
        "hvec3", "hvec4", "dvec2", "dvec3", "dvec4",
        "fvec2", "fvec3", "fvec4", "sampler3DRect", "filter",
        "image1D", "image2D", "image3D", "imageCube", "iimage1D",
        "iimage2D", "iimage3D", "iimageCube", "uimage1D", "uimage2D",
        "uimage3D", "uimageCube", "image1DArray", "image2DArray", "iimage1DArray",
        "iimage2DArray", "uimage1DArray", "uimage2DArray", "image1DShadow", "image2DShadow",
        "image1DArrayShadow", "image2DArrayShadow", "imageBuffer", "iimageBuffer", "uimageBuffer",
        "sizeof", "cast", "namespace", "using", "row_major"
    };

    for (size_t i = 0; i < NUM_OTHERS; ++i)
        insertSymbol(others[i], ID_RESERVED_KEYWORD, true);

}
Beispiel #27
0
/* queries are added to the MAL catalog  under the client session namespace */
void
SQLaddQueryToCache(Client c)
{
	insertSymbol(c->usermodule, c->curprg);
}