Exemplo n.º 1
0
 foreach(QString word,newword)
 {
     addKeyWord(word);
 }
Exemplo n.º 2
0
int lineToTokens(const char *line,const char *symtab,const char *outfile,NFA *N,int nfaCount){
	int lbegin=0;
	int bestmatch;
	int match1,match2;
	int Code[MAXNFACOUNT];
	int End[MAXNFACOUNT];
	attrType Attrib[MAXNFACOUNT];
	for(int i=0;i<MAXNFACOUNT;i++){
		Attrib[i].string=(char *)malloc(sizeof(char)*100);
	}
	while(1){
		for(int i=0;i<nfaCount;i++){
			simulate_NFA(&N[i],line,lbegin,&End[i],&Attrib[i]);
		}
		getBestMatch(End,nfaCount,&match1,&match2);
		printf("\nMatch1 = %d\tMatch2 = %d",match1,match2);
		if(match2==-1){
			bestmatch=match1;
		}else if(match1==match2){
			if(getNFAID(&N[match1])==IDNTIFIER){
				bestmatch=match2;
			}else{
				bestmatch=match1;
			}
		}else{
			printf("\nFatal error in matching !!\n");
			exit(-1);
		}
		lbegin=End[bestmatch];
		switch(Code[bestmatch]){
			case IDNTIFIER:{
				addIdentifier(&Attrib[bestmatch],symtab,outfile);
				break;
			}
			case INT_CONST:{
				add_Numerical(&Attrib[bestmatch],symtab,outfile,INT_CONST);
				break;	
			}
			case FLO_CONST:{
				add_Numerical(&Attrib[bestmatch],symtab,outfile,FLO_CONST);
				break;
			}
			case NOTOK:{
				printf("\nLexeme not detected in any of the NFA !!!\n");
				exit(-1);
				// break;
			}
			default:{
				if((Code[bestmatch]>=422)&&(Code[bestmatch]<=445)){
					// treat lexeme as keyword
					addKeyWord(&Attrib[bestmatch],symtab,outfile,code[bestmatch]);
				}else{
					// treat lexeme as symbol
					add_Symbol(&Attrib[bestmatch],symtab,outfile,code[bestmatch]);
				}
			}
		}
		lbegin=End[bestmatch];
		if(line[lbegin]=='\0'){
			// we have reached the End of the current line
			break;
		}
		if(line[lbegin]==' '){
			lbegin++;
			continue;
		}
	}

	for(int i=0;i<MAXNFACOUNT;i++){
		free(Attrib[i].string);
		Attrib[i].string=NULL;
	}
}