示例#1
0
int globalDecl() { //za decl nebrat token
		if ((error = testToken(T_ID)) != E_OK) return error; //ID
		if(BSTSearch(TempTree, T.s) != NULL){
			return E_SEMA;
		}
		strInit(&IDstr);
		strCopystring(&IDstr, &T.s);
		gettoken();
		if ((error = testToken(T_COLON)) != E_OK) return error;
		    gettoken();
		if ((error = testToken(T_DATATYPE)) != E_OK) return error;

/******************************************INSERT***************************************************************/

		if(!(strCmpConstStr(&(T.s), "boolean"))) TempVar->type = O_BOOL;
		if(!(strCmpConstStr(&(T.s), "integer"))) TempVar->type = O_INT;		
		if(!(strCmpConstStr(&(T.s), "real")))    TempVar->type = O_REAL;
		if(!(strCmpConstStr(&(T.s), "string"))){
			TempVar->type = O_STRING;
			strInit(&TempVar->value.sval);
		}
		BSTInsert (&TempTree, IDstr, TempVar); 
		
/******************************************INSERT***************************************************************/

		gettoken();
		if ((error = testToken(T_SEMICOLON)) != E_OK) return error; // ";"
		gettoken();
		//strFree(&IDstr);
		if (testToken(T_ID) == E_OK)
		    if ((error = globalDecl()) != E_OK) return error;	//dalsia promena?
		return E_OK;
}
示例#2
0
int params() {
	int enumerator;
	if ((error = testToken(T_ID)) != E_OK) return error; // "ID_parametru" - mozna specifikovat
	strInit(&IDstr);
    strCopystring(&IDstr, &T.s);
	gettoken();
	if ((error = testToken(T_COLON)) != E_OK) return error; // ":"
	gettoken();
	if ((error = testToken(T_DATATYPE)) != E_OK) return error; 
	if(!(strCmpConstStr(&(T.s), "boolean")))	    enumerator = O_BOOL;		
	else if(!(strCmpConstStr(&(T.s), "integer")))	enumerator = O_INT;	
	else if(!(strCmpConstStr(&(T.s), "real")))      enumerator = O_REAL;
	else if(!(strCmpConstStr(&(T.s), "string")))    enumerator = O_STRING;
	else return E_SEMA;		
	gettoken();
	pc++;
	if(strCmpstring(&IDstr, &ActFun) == 0) return E_SEMA;          //ADDED
	if (searchParam(paramlist, &IDstr) != NULL) return E_SEMA;    
	if ((error = insertParam(paramlist,&IDstr, enumerator)) != E_OK) return error;;
	//strFree(&IDstr);
	if (testToken(T_SEMICOLON) == E_OK) {  
	  gettoken();
	  if((error = params()) != E_OK) return error; //vice parametru - rekurze
	}
	return E_OK;
}
示例#3
0
int main(int argc, char** argv)
{
  testBitRange();
  testSignExtend();
  testToken();
  testInstructionPrint();
  return 0;
}
示例#4
0
int localDecl() { //za decl nebrat token
		if ((error = testToken(T_ID)) != E_OK) return error; //ID
		if (searchParam(paramlist, &(T.s)) != NULL){ //zde budu muset nejspis dat jen jmenu aktualni fkce
			return E_SEMA;
		}
		if(strCmpstring(&(T.s), &ActFun) == 0){     //ADDED
			return E_SEMA;
		}
		if(BSTSearch (TempTreeL, T.s) != NULL){
			return E_SEMA;
		}
		strInit(&IDstr);
		strCopystring(&IDstr, &T.s);
		gettoken();
		if ((error = testToken(T_COLON)) != E_OK) return error;
		    gettoken();
		if ((error = testToken(T_DATATYPE)) != E_OK) return error; // typ
		
/******************************************INSERT***************************************************************/

		if(!(strCmpConstStr(&(T.s), "boolean"))) TempVar->type = O_BOOL;		
		if(!(strCmpConstStr(&(T.s), "integer"))) TempVar->type = O_INT;		
		if(!(strCmpConstStr(&(T.s), "real")))    TempVar->type = O_REAL;
		if(!(strCmpConstStr(&(T.s), "string"))){
			TempVar->type = O_STRING;
			strInit(&TempVar->value.sval);
		}
		BSTInsert (&TempTreeL, IDstr, TempVar); 

/******************************************INSERT***************************************************************/
		gettoken();
		if ((error = testToken(T_SEMICOLON)) != E_OK) return error; // ";"
		gettoken();
		//strFree(&IDstr);
		if (testToken(T_ID) == E_OK)
		    if ((error = localDecl()) != E_OK) return error;	//dalsia promena?
		return E_OK;
}
示例#5
0
int writefun() {
	if((error = testToken(T_ID)) == E_OK){
	  if(afun == 1){
	    if(strCmpstring(&(T.s), &ActFun) != 0){                             //added: Jmeno fkce, params, global, local
		  if (searchParam(paramlist, &(T.s)) == NULL){
		    if((TempVar = BSTSearch (TempTreeL, T.s)) == NULL){
			  if((TempVar = BSTSearch(TempTree, T.s)) == NULL) return E_SEMA;
		    }
		  }
	    }
	  }
	  else{
        if((TempVar = BSTSearch(TempTree, T.s)) == NULL) return E_SEMA;
	  }
		gettoken();
      if((error = testToken(T_RB)) == E_OK){
		  return E_OK;
	  }
	  else if((error = testToken(T_COMMA)) == E_OK){
		  gettoken();
		  if((error = writefun()) != E_OK) return error;
	  }
	  else
		  return error;
	}
	else if((error = testToken(T_STRING)) == E_OK){
		gettoken();
      if((error = testToken(T_RB)) == E_OK){
		  return E_OK;
	  }
	  else if((error = testToken(T_COMMA)) == E_OK){
		  gettoken();
		  if((error = testToken(T_STRING)) == E_OK) return error;
		  if((error = writefun()) != E_OK) return error;
	  }
	  else
		  return error;
	}
	else
		return error;

	return E_OK;
}
示例#6
0
void MToken::upd() { if(!testToken()) getToken();}
TEST(MediaQueryTokenizerCodepointsTest, Basic)
{
    for (UChar c = 0; c <= 1000; ++c) {
        if (isASCIIDigit(c))
            testToken(c, NumberToken);
        else if (isASCIIAlpha(c))
            testToken(c, IdentToken);
        else if (c == '_')
            testToken(c, IdentToken);
        else if (c == '\r' || c == ' ' || c == '\n' || c == '\t' || c == '\f')
            testToken(c, WhitespaceToken);
        else if (c == '(')
            testToken(c, LeftParenthesisToken);
        else if (c == ')')
            testToken(c, RightParenthesisToken);
        else if (c == '[')
            testToken(c, LeftBracketToken);
        else if (c == ']')
            testToken(c, RightBracketToken);
        else if (c == '{')
            testToken(c, LeftBraceToken);
        else if (c == '}')
            testToken(c, RightBraceToken);
        else if (c == '.' || c == '+' || c == '-' || c == '/' || c == '\\')
            testToken(c, DelimiterToken);
        else if (c == '\'' || c == '"')
            testToken(c, StringToken);
        else if (c == ',')
            testToken(c, CommaToken);
        else if (c == ':')
            testToken(c, ColonToken);
        else if (c == ';')
            testToken(c, SemicolonToken);
        else if (!c)
            testToken(c, EOFToken);
        else if (c > SCHAR_MAX)
            testToken(c, IdentToken);
        else
            testToken(c, DelimiterToken);
    }
    testToken(USHRT_MAX, IdentToken);
}
示例#8
0
int unregisterFromGtm(char *line)
{
	char *token;
	int rc;

	for(;GetToken();)
	{
		if (testToken("-n"))
		{
			if (!GetToken())
				return(inputError("No -n option value was found."));
			Free(myname);
			myname = Strdup(token);
			continue;
		}
		else if (testToken("-Z"))
		{
			if (!GetToken())
				return(inputError("No -Z option value was found."));
			if (testToken("gtm"))
			{
				nodetype = GTM_NODE_GTM;
				continue;
			}
			else if (testToken("gtm_proxy"))
			{
				nodetype = GTM_NODE_GTM_PROXY;
				break;
			}
			else if (testToken("gtm_proxy_postmaster"))
			{
				nodetype = GTM_NODE_GTM_PROXY_POSTMASTER;
				break;
			}
			else if (testToken("coordinator"))
			{
				nodetype = GTM_NODE_COORDINATOR;
				break;
			}
			else if (testToken("datanode"))
			{
				nodetype = GTM_NODE_DATANODE;
				break;
			}
			else
			{
				elog(ERROR, "ERROR: Invalid -Z option value, %s\n", token);
				return(-1);
			}
			continue;
		}
		else
			break;
	}
	if (nodetype == 0)
	{
		elog(ERROR, "ERROR: no node type was specified.\n");
		return(-1);
	}

	if (myname == NULL)
		myname = Strdup(DefaultName);
	
	if (!token)
	{
		fprintf(stderr,"%s: No command specified.\n", progname);
		exit(2);
	}
	if (!GetToken())
	{
		elog(ERROR, "ERROR: unregister: no node name was found to unregister.\n");
		return(-1);
	}
	nodename = Strdup(token);
	rc = process_unregister_command(nodetype, nodename);
	Free(nodename);
	return(rc);
}
示例#9
0
int program() {
	gettoken();
	switch(T.type){
      case T_KEYWORD:{
		if (var == 0){
		  if (!(strCmpConstStr (&(T.s), "var"))){ //var
			var = 1;
			gettoken();
			TempVar = allocate(sizeof(tVariable));
	      if ((error = globalDecl()) != E_OK) return error; // deklarace promennych
		    //free(TempVar);
		  }
		}
	    if (!strCmpConstStr (&(T.s), "begin")) {// BEGIN
		//if(searchFunListFW() != NULL) return E_SEMA;
		if((error = searchFunListCH()) != E_OK) return E_SEMA;
		    gettoken();
			//printf("main \n");
			if (!strCmpConstStr (&(T.s), "end")){           //BEGIN END. - prazdne
			    gettoken();
               	if ((error = testToken(T_DOT)) != E_OK) return error;
		          gettoken();
		        if ((error = testToken(T_EOF)) != E_OK) return error;
					error = InsertEmptyItemTape();        //vkladam novy prazdny prvek na pasku
					if (error == E_INTERN)
						return error;
					Tape->last->instruction = NOP;
				return E_OK;
			}
	        if ((error  = blockList()) != E_OK) return error;
		}
	    else if (!strCmpConstStr (&(T.s), "function")) { // funkce
		
		      BSTInit(&TempTreeL);
		      TempVar = allocate(sizeof(tVariable));
			  afun = 1; // ADDED
	       if ((error  = function()) != E_OK){
			   return error;
		   }
		   //printf("za funkcwma \n");
		   afun = 0;    //ADDED
		   //strFree(&ActFun); //ADDED
		   if ((error = program()) != E_OK) return error;
		   return E_OK;
		}
		else   {
			return E_SYN;}
		break;
		}
	  default:
	  {
		  return E_SYN;
		  }
    }
		gettoken();
		if ((error = testToken(T_DOT)) != E_OK) return error;
		gettoken();
		if ((error = testToken(T_EOF)) != E_OK) return error;

	 return E_OK;
}
示例#10
0
int commands() 
{
	tVariable *glob = NULL;
	tVariable *loc = NULL;
	tParamList *par = NULL;
	string *name = allocate(sizeof(string));
    tTapeItem *previous = Tape->last;
    tVariable *op1 = allocate(sizeof(tVariable));
    tVariable *op2 = allocate(sizeof(tVariable));
    tVariable *result = allocate(sizeof(tVariable));
    if((name == NULL) || (op1 == NULL) || (op2 == NULL) || (result == NULL)) return E_INTERN;
	switch(T.type){
		case T_ID:
	/*		if(afun == 1){                                 //ADDED pokud neni ve funkci kontroluje jen global
			  if ((par = searchParam(paramlist, &(T.s))) == NULL){            //added
			    if(strCmpstring(&(T.s), &ActFun) != 0){ //zde budu muset nejspis dat jen jmenu aktualni fkce
			      if((loc = BSTSearch (TempTreeL, T.s)) == NULL){
			        if((glob = BSTSearch (TempTree, T.s)) == NULL){
						return E_SEMA;
					}*/
//					else{
//                      Tape->last->op1 = glob;
//					}    
//			      }
//				  else{
//                    Tape->last->op1 = loc;
//				  }
//			    }
//				else{
//                  Tape->last->op1 = item;
//				}
//}
//			  else{
//                Tape->last->op1 = par;
//			  }
//			}
/*			else {*/
				if((glob = BSTSearch (TempTree, T.s)) == NULL){
					return E_SEMA;
				}
			/*else{
				  Tape->last->op1 = glob;				}*/
			//}


			gettoken();
			if ((error = testToken(T_ASSIGN)) != E_OK) return error;
			if ((error = ExpParser()) != E_OK) return error;
			//if(InsertEmptyItemTape() != E_OK) return E_INTERN;
			Tape->last->instruction = ASSIGN;
	       
			if (loc != NULL){
				Tape->last->op1 = loc;
			}
			else if (glob != NULL){
				Tape->last->op1 = glob;
			}
			 if (res != Tape->last->op1->type ) return E_SEMB;
			Tape->last->op2 = Tape->last->previous->result;
			Tape->last->result = Tape->last->op1;
			printf("parser adresa resultu v parseri %d \n",Tape->last->op2);
			if ((strCmpConstStr (&(T.s), "end"))) {
				if ((error = testToken(T_SEMICOLON)) != E_OK) return error;
				semi = 1;
			}
			break;

		case T_KEYWORD:
			if(!strCmpConstStr (&(T.s), "begin")){
				gettoken();
				if((error = blockList()) != E_OK) return error;
                gettoken();
			    if ((strCmpConstStr (&(T.s), "end"))) {
				    if ((error = testToken(T_SEMICOLON)) != E_OK) return error;
				    semi = 1;
			    }
				break;
			}
			if(!strCmpConstStr (&(T.s), "if")){ //if
				tTapeItem *label;
                tTapeItem *endelse;
                tVariable *op11 = allocate(sizeof(tVariable));
                tVariable *op22 = allocate(sizeof(tVariable));
                if((op11 == NULL) || (op22 == NULL)) return E_INTERN;
				
				if((error = ExpParser()) != E_OK) return error; //vyraz
				if (res != 3 ) return E_SEMB;
				//ZAKONECNTOVANO if(InsertEmptyItemTape() != E_OK) return E_INTERN; 
				Tape->last->instruction = JUMPN;
                Tape->last->op1 = Tape->last->previous->result;
                Tape->last->op2 = op2;
                Tape->last->op2->type = TAPE_POINTER;
                label = Tape->last;
				
				if((error = testToken(T_KEYWORD)) == E_OK){
					if(strCmpConstStr (&(T.s),"then")) return E_SYN; //then
				}
				else
					return error;
				gettoken();
				if((error = testToken(T_KEYWORD)) == E_OK){
					if(strCmpConstStr (&(T.s),"begin")) return E_SYN; //begin slozeneho prikazu
				}
				else
					return error;
				gettoken();
				if((error = blockList()) != E_OK) return error; //blocklist
				gettoken();
				
				Tape->last->instruction = JUMPN;
                Tape->last->op1 = op11;
                Tape->last->op1->type = O_BOOL;
                Tape->last->op1->value.bval = false;
                if(strInit(&(Tape->last->op1->name)) != STR_SUCCESS) return E_INTERN;
                Tape->last->op2 = op22;
                Tape->last->op2->type = TAPE_POINTER;
                endelse = Tape->last;
				
				if((error = testToken(T_KEYWORD)) != E_OK) return error;
				if(strCmpConstStr (&(T.s),"else")) return E_SYN;
				
				if(InsertEmptyItemTape() != E_OK) return E_INTERN;
                Tape->last->instruction = NOP;
                label->op2->value.tape_pointer = Tape->last;
				
				gettoken();
				if((error = testToken(T_KEYWORD)) != E_OK) return error;
				if(strCmpConstStr (&(T.s),"begin")) return E_SYN; //begin slozeneho prikazu
				gettoken();
				if((error = blockList()) != E_OK) return error; //blocklist
				gettoken();
			    if ((strCmpConstStr (&(T.s), "end"))) {
				    if (testToken(T_SEMICOLON) != E_OK) return E_SYN;
				    semi = 1;
			    }
				
				if(InsertEmptyItemTape() != E_OK) return E_INTERN;
                Tape->last->instruction = NOP;
                endelse->op2->value.tape_pointer = Tape->last;


				break;


			}
		    if(!strCmpConstStr (&(T.s), "while")){
				
				 if(InsertEmptyItemTape() != E_OK) return E_INTERN;
                Tape->last->instruction = NOP;
                tTapeItem *label1;
                tTapeItem *label2 = Tape->last;             // ukazatel na pasku kam se bude cyklus vracet
                tVariable *op11 = allocate(sizeof(tVariable));
                tVariable *op22 = allocate(sizeof(tVariable));
                if((op11 == NULL) || (op22 == NULL)) return E_INTERN;
				
                if((error = ExpParser()) != E_OK) return error; //vyraz
                if (res != 3 ) return E_SEMB;
				
				//ZAKONECNTOVANO  if(InsertEmptyItemTape() != E_OK) return E_INTERN;
                Tape->last->instruction = JUMPN;
                Tape->last->op1 = Tape->last->previous->result;
                Tape->last->op2 = op22;
                Tape->last->op2->type = TAPE_POINTER;
                label1 = Tape->last;  
				
				if((error = testToken(T_KEYWORD)) == E_OK){
					if(strCmpConstStr (&(T.s),"do")) return E_SYN; //begin slozeneho prikazu
				}
				else
					return error;
				gettoken();
				if((error = testToken(T_KEYWORD)) == E_OK){
					if(strCmpConstStr (&(T.s),"begin")) return E_SYN; //begin slozeneho prikazu
				}
				else{
					return error;
				}
				gettoken();
				if((error = blockList()) != E_OK) return error; //blocklist
				gettoken();
			    if ((strCmpConstStr (&(T.s), "end"))) {
				    if ((error = testToken(T_SEMICOLON)) != E_OK) return error;
				    semi = 1;
			    }
				
				if(InsertEmptyItemTape() != E_OK) return E_INTERN;
                Tape->last->instruction = JUMP;
                Tape->last->op1 = op1;
                Tape->last->op1->type = O_BOOL;
                Tape->last->op1->value.bval = false;
                if(strInit(&(Tape->last->op1->name)) != STR_SUCCESS) return E_INTERN;
                Tape->last->op2 = op2;
                Tape->last->op2->type = TAPE_POINTER;
                Tape->last->op2->value.tape_pointer = label2;     // nepodmineny skok zpet na zacatek vyhodnocovani podminky cyklu
                if(InsertEmptyItemTape() != E_OK) return E_INTERN;
                Tape->last->instruction = NOP;                    // instrukce, na kterou se skoci v pripade nesplneni podminky whilu
                label1->op2->value.tape_pointer = Tape->last;
				
				break;
			}
			if (!strCmpConstStr (&(T.s), "readln")) {
				
				gettoken();
				if((error = testToken(T_LB)) != E_OK) return error;
				gettoken();
				if((error = testToken(T_ID)) != E_OK) return error;
				if(afun == 1){
				  if(strCmpstring(&(T.s), &ActFun) != 0){                             //added: Jmeno fkce, params, global, local
				    if (searchParam(paramlist, &(T.s)) == NULL){
				      if((TempVar = BSTSearch (TempTreeL, T.s)) == NULL){
					    if((TempVar = BSTSearch(TempTree, T.s)) == NULL) return E_SEMA;
				      }
				    }
				  }
				}
				else{
					if((TempVar = BSTSearch(TempTree, T.s)) == NULL) return E_SEMA;
				}
				if (TempVar->type == O_BOOL){
			        TempVar = NULL;
					return E_SEMB;
				}
				gettoken();
                if((error = testToken(T_RB)) != E_OK){
					TempVar = NULL;
					return error;
				}
				gettoken();
			    if ((strCmpConstStr (&(T.s), "end"))) {
				    if ((error = testToken(T_SEMICOLON)) != E_OK){
						TempVar = NULL;
						return error;
					}
				    semi = 1;
			    }
				TempVar = NULL;
				break;
			}
	        if (!strCmpConstStr (&(T.s), "write")) { //write(ID) !!! integer or real !!!
				gettoken();
				if(InsertEmptyItemTape() != E_OK) return E_INTERN;
                Tape->last->instruction = JUMP;
                Tape->last->op1 = op1;
                Tape->last->op1->type = O_BOOL;
                Tape->last->op1->value.bval = false;
				
				if((error = testToken(T_LB)) != E_OK) return error;
				gettoken();
				if((error = writefun()) != E_OK) return error;
				gettoken();
			    if ((strCmpConstStr (&(T.s), "end"))) {
				    if ((error = testToken(T_SEMICOLON)) != E_OK) return error;
				    semi = 1;
			    }
				break;
			}
		default:
			return E_SYN;
	}
	return E_OK;

}
示例#11
0
int function() {
	int enumerator;
	int fw =0;
	pc =0;
	gettoken();
	if ((error = testToken(T_ID)) != E_OK) return error; // ID_funkce - mozna upresnit
	string name;                                          // tu je vkladanie funkcii do seznamu 98-103
	if(strInit(&name) != STR_SUCCESS) return E_INTERN;
	if(strInit(&ActFun) != STR_SUCCESS) return E_INTERN;     //added
    //if(searchFunList(&(T.s)) != NULL) return E_SEMA;
    strCopystring(&name, &(T.s));
	strCopystring(&ActFun, &(T.s));                          //added
	gettoken();
	
	if ((error = testToken(T_LB)) != E_OK) return error; // leva zavorka
	gettoken();
	if ((testToken(T_RB) != E_OK) && (testToken(T_ID) != E_OK)) return E_SYN; // prava zavorka(muze byt prazdne) nebo parametr
	if (testToken(T_ID) == E_OK){
		initParamlist(paramlist);
		if((error = params()) != E_OK) return error; //parametry
	}
	if ((error = testToken(T_RB)) != E_OK) return error;
	gettoken();
	if ((error = testToken(T_COLON)) != E_OK) return error; // ":"
	gettoken();
	if ((error = testToken(T_DATATYPE)) != E_OK) return error; // "typ" - mozna funkci pro typy - semantika? !!!!! TYPE
	if(!(strCmpConstStr(&(T.s), "boolean")))	    enumerator = O_BOOL;		
	else if(!(strCmpConstStr(&(T.s), "integer")))	enumerator = O_INT;	
	else if(!(strCmpConstStr(&(T.s), "real")))      enumerator = O_REAL;
	else if(!(strCmpConstStr(&(T.s), "string")))    enumerator = O_STRING;
	else return E_SEMA;	
	//if((searchFunList(&name)!= NULL)) return E_SYN;  
	gettoken();
	if ((error = testToken(T_SEMICOLON)) != E_OK) return error; //  ";"
	gettoken();
    
	switch(T.type){

	case T_KEYWORD:
		if (!strCmpConstStr (&(T.s), "forward")) {
			gettoken();
			fw = 1;
	
			if((searchFunListFW(&name)!= NULL)) return E_SEMA;
			if(insertFunListItem(&name,enumerator,paramlist,fw,pc) != E_OK) return E_INTERN;
			if ((error = testToken(T_SEMICOLON)) != E_OK) return error;  // FORWARD a ";"
		    return E_OK;
		}

		item = searchFunListN(&name);
		if((item != NULL)) {

		if (item->forward != 2)
		return E_SEMA;
		}
		else {
		fw = 2;
		if(insertFunListItem(&name,enumerator,paramlist,fw,pc) != E_OK) return E_INTERN;}
		if(InsertEmptyItemTape() != E_OK) return E_INTERN;
		item = searchFunListN(&name);
		Tape->last->instruction = FUNC;
		//item->tape_ptr = Tape->last;

		if (!strCmpConstStr (&(T.s), "var")) {
			gettoken();
			if ((error = localDecl()) != E_OK) return error; // deklarace lokalnich promennych
		}
	//	printf("za local decl \n");
		if (!strCmpConstStr (&(T.s), "begin")) {
			gettoken();
		//	printf("za bein \n");
			if ((error = blockList()) != E_OK) return error;
			gettoken();
		//	printf("semicollon \n");
			if ((error = testToken(T_SEMICOLON)) != E_OK) return error;
			return E_OK;
		}
		else
			return E_SYN;
		break;
	default:
		 return E_SYN;
	}
}