Skip to content
Low-level programming · Higher-level thinking
Login Register
Forum / Requests and Feedback

ZirToken

A community discussion post from the original code:zIRON forum.

Replies

Colin admin
Posts
928
Threads
49
Location
Bulgaria

ps

c = ord('A');

i will explain a little about '' and ""

anything inside ' is classed as a literal string and will be passed regardless as size as a pointer to a string, however inside " will be converted do the ordinal, it will accept strings sized 1-4

c = "A";

another good example is

eax = "BIG";

char myBuf[4];
myBuf = eax;

print('myBuf = ', @myBuf, '\r\n');

the final byte since there is only 3 will be a 0x00 :)

Emil_halim member
Posts
639
Threads
104
Location
Alex, Egypt

ok , now i found an other problem.

i was trying to support array with dim keyword , something like that

DIM A3 [1024] AS char

and this is the paresing code

       /*********   dim k  [1024] as char;    **************/   
      state zirBracketOpen:              
        eax = Ziron_ExpectNextToken(zirNumber);
        if (eax == -1) {
          Ziron_FatalError('Expected max index number of array');
          return true;
        }
        H_strcpy(@tmp,Ziron_GetStringValue());                   
        eax = Ziron_ExpectNextToken(zirBracketClose);
        if (eax == -1) {
          Ziron_FatalError('Expected ]');
          return true;
        }     
        eax = Ziron_ExpectNextToken(zirAs);
        if (eax == -1) {
          Ziron_FatalError('Expected As');
          return true;
        }           
        eax = Ziron_ExpectNextToken(zirDATA_TYPE);
        if (eax == -1) {
          Ziron_FatalError('Expected data type');
          return true;
        }       
        eax =  Ziron_GetStringValue();
        H_strcat(@buf,eax); 
        H_strcat(@buf,' ');  
        H_strcat(@buf,@var);
        H_strcat(@buf,'[');
        H_strcat(@buf,@tmp);
        H_strcat(@buf,']'); 
        H_strcat(@buf,';');  
Ziron_ShowMessage(@buf);
        Len = H_strlen(@buf);          
/*   
        eax = Ziron_Execute(@buf,Len);
        if (eax == false) {
          Ziron_FatalError('Dim plugin is not compatible with this version of Ziron');
          return true;
        }  
*/           
        break;

the problem is the paresing code execute 2 times so it print this

char A3[1024];
char A3[1024];

and this gave error when compiling.

any help please.

http://www.freewebs.com/ogremagic/index.htm

Colin admin
Posts
928
Threads
49
Location
Bulgaria

i've just added it to the function i have from your main plugin post

function event_Dim() {
	uses edi;  
	Dword Len;
	char var[255];  
	char buf[1024]; 
	char tmp[16];
    	
	repeat {         
		buf = 0; //make sure buf is initialized otherwise it may be filled with junk
		tmp = 0;
		
		eax = Ziron_ExpectNextToken(zirIdent);
		if (eax == -1) {
			Ziron_FatalError('Expected Variable Name');
			return true;
		}
		
		H_strcpy(@var,Ziron_GetStringValue());   
		Ziron_ShowMessage(@var);
  
		eax = Ziron_GetNextToken();
		//push eax; Ziron_ShowMessage(@var); pop eax;   
  
		case (eax) {
		
			/*********   Dim Var as int32;    **************/         
			state zirAs:
				eax = Ziron_ExpectNextToken(zirDATA_TYPE);
				if (eax == -1) {
					Ziron_FatalError('Expected data type');
					return true;
				}
				eax =  Ziron_GetStringValue();
				H_strcat(@buf,eax); 
				H_strcat(@buf,' ');  
				H_strcat(@buf,@var);
				H_strcat(@buf,';');  

				Len = H_strlen(@buf);          
				eax = Ziron_Execute(@buf,Len);
				if (eax == false) {
					Ziron_FatalError('Dim plugin is not compatible with this version of Ziron');
					return true;
				}  
				break;
				
			/*********   dim k%;    **************/        
			state zirModSym:
				H_strcat(@buf,'int32 '); 
				H_strcat(@buf,@var);
				H_strcat(@buf,';');   

				Len = H_strlen(@buf);          
				eax = Ziron_Execute(@buf,Len);
				if (eax == false) {
					Ziron_FatalError('Dim plugin is not compatible with this version of Ziron');
					return true;
				}
				break;
				
			/*********   dim k$;    **************/              
			state zirDollarSym:
				H_strcat(@buf,'char '); 
				H_strcat(@buf,@var);
				H_strcat(@buf,'[1024];');  

				Len = H_strlen(@buf);          
				eax = Ziron_Execute(@buf,Len);
				if (eax == false) {
					Ziron_FatalError('Dim plugin is not compatible with this version of Ziron');
					return true;
				}
				break;
				
			/*********   dim k!;    **************/          
			state zirExclamation:
				H_strcat(@buf,'single '); 
				H_strcat(@buf,@var);
				H_strcat(@buf,';');  

				Len = H_strlen(@buf);          
				eax = Ziron_Execute(@buf,Len);
				if (eax == false) {
					Ziron_FatalError('Dim plugin is not compatible with this version of Ziron');
					return true;
				}        
				break; 
				
			/*********   dim k#;    **************/          
			state zirHash:
				H_strcat(@buf,'double '); 
				H_strcat(@buf,@var);
				H_strcat(@buf,';');

				Len = H_strlen(@buf);          
				eax = Ziron_Execute(@buf,Len);
				if (eax == false) {
					Ziron_FatalError('Dim plugin is not compatible with this version of Ziron');
					return true;
				}                
				break;  
				
				
			/*********   dim k  [1024] as char;    **************/   
			state zirBracketOpen:              
				eax = Ziron_ExpectNextToken(zirNumber);
				if (eax == -1) {
					Ziron_FatalError('Expected max index number of array');
					return true;
				}
				H_strcpy(@tmp,Ziron_GetStringValue());                   
				eax = Ziron_ExpectNextToken(zirBracketClose);
				if (eax == -1) {
					Ziron_FatalError('Expected ]');
					return true;
				}     
				eax = Ziron_ExpectNextToken(zirAs);
				if (eax == -1) {
					Ziron_FatalError('Expected As');
					return true;
				}           
				eax = Ziron_ExpectNextToken(zirDATA_TYPE);
				if (eax == -1) {
					Ziron_FatalError('Expected data type');
					return true;
				}       
				eax =  Ziron_GetStringValue();
				H_strcat(@buf,eax); 
				H_strcat(@buf,' ');  
				H_strcat(@buf,@var);
				H_strcat(@buf,'[');
				H_strcat(@buf,@tmp);
				H_strcat(@buf,']'); 
				H_strcat(@buf,';');  
				
				Ziron_ShowMessage(@buf);
				
				Len = H_strlen(@buf);          
   
				eax = Ziron_Execute(@buf,Len);
				if (eax == false) {
					Ziron_FatalError('Dim plugin is not compatible with this version of Ziron');
					return true;
				}  
           
				break;				
				
			/*********       **************          
			//state zirIdent:
				//eax = Ziron_GetStringValue();  
				//break;
				
			/*********       **************/            
			default:
				Ziron_FatalError('Expected as Keyword');
				return true;
		}

		eax = Ziron_IsNextLineBreak(); 
		if (eax) {
			break;      // check end of line so we end without semicolon
		} 

		eax = Ziron_PeekNextToken();    
		if (eax == zirCOMMA) {
			Ziron_GetNextToken();
		} else {
			break;
		}
	};
	return true;
}

and it works like a charm, i do not seem any problem, i just tested with

dim myarr[1024] as char

if you still have a problem, can you paste your whole event code?

Emil_halim member
Posts
639
Threads
104
Location
Alex, Egypt

ok here is the entire function, note i add code to pares \\\'=\\\' and \\\'*\\\'

function event_Dim() {
    uses edi;  
    Dword Len;
    char var[255];  
    char buf[1024]; 
    char tmp[255];  
  repeat {         
    buf = 0; 
    
    // get the variable name and hold it in Var 
    eax = Ziron_ExpectNextToken(zirIdent);
    if (eax == -1) {
      Ziron_FatalError('Expected Variable Name');
      return true;
    }
    H_strcpy(@var,Ziron_GetStringValue());   
  
    // get whatever after variable name
    eax = Ziron_GetNextToken();
       
    // let's pares it
    // it can be one of those  
    // As % $ ! # [] 
    case (eax) {
      /*********   Dim Var as int32;    **************/         
      state zirAs:
        eax = Ziron_ExpectNextToken(zirDATA_TYPE);
        if (eax == -1) {
          Ziron_FatalError('Expected data type');
          return true;
        }
        eax =  Ziron_GetStringValue();
        H_strcat(@buf,eax); 
        H_strcat(@buf,' ');  
        H_strcat(@buf,@var);
        H_strcat(@buf,';');  
        Len = H_strlen(@buf);          
        eax = Ziron_Execute(@buf,Len);
        if (eax == false) {
          Ziron_FatalError('Dim plugin is not compatible with this version of Ziron');
          return true;
        }  
        break;       
      /*********   dim k%;    **************/        
      state zirModSym:
        H_strcat(@buf,'int32 '); 
        H_strcat(@buf,@var);
        H_strcat(@buf,';');   
        Len = H_strlen(@buf);          
        eax = Ziron_Execute(@buf,Len);
        if (eax == false) {
          Ziron_FatalError('Dim plugin is not compatible with this version of Ziron');
          return true;
        }
        break;    
      /*********   dim k$;    **************/              
      state zirDollarSym:
        buf = 0;
        H_strcat(@buf,'char '); 
        H_strcat(@buf,@var);
        eax = Ziron_PeekNextToken();    
        if (eax == zirMulSym)
         {
             Ziron_GetNextToken(); // remove '*'
             eax = Ziron_ExpectNextToken(zirNumber);
             if (eax == -1) {
                 Ziron_FatalError('Expected number');
                 return true;
              }
             H_strcat(@buf,'[');
             H_strcat(@buf,Ziron_GetStringValue());  
             H_strcat(@buf,'];');     
         }
        else
         {         
           H_strcat(@buf,'[1024];');  
         }      
        Len = H_strlen(@buf);          
        eax = Ziron_Execute(@buf,Len);
        if (eax == false) {
          Ziron_FatalError('Dim plugin is not compatible with this version of Ziron');
          return true;
        }
        break;

http://www.freewebs.com/ogremagic/index.htm

Emil_halim member
Posts
639
Threads
104
Location
Alex, Egypt

sorry , forum refuse to post it in one post

so here is the rest part of function

      /*********   dim k!;    **************/          
      state zirExclamation:
        H_strcat(@buf,'single '); 
        H_strcat(@buf,@var);
        H_strcat(@buf,';');  
        Len = H_strlen(@buf);          
        eax = Ziron_Execute(@buf,Len);
        if (eax == false) {
          Ziron_FatalError('Dim plugin is not compatible with this version of Ziron');
          return true;
        }        
        break; 
      /*********   dim k#;    **************/          
      state zirHash:
        H_strcat(@buf,'double '); 
        H_strcat(@buf,@var);
        H_strcat(@buf,';');

        Len = H_strlen(@buf);          
        eax = Ziron_Execute(@buf,Len);
        if (eax == false) {
          Ziron_FatalError('Dim plugin is not compatible with this version of Ziron');
          return true;
        }              
        break;  
       /*********   dim k  [1024] as char;    **************/   
      state zirBracketOpen:         
        eax = Ziron_ExpectNextToken(zirNumber);
        if (eax == -1) {
          Ziron_FatalError('Expected max index number of array');
          return true;
        }
        H_strcpy(@tmp,Ziron_GetStringValue());                  
        eax = Ziron_ExpectNextToken(zirBracketClose);
        if (eax == -1) {
          Ziron_FatalError('Expected ]');
          return true;
        }   
        eax = Ziron_ExpectNextToken(zirAs);
        if (eax == -1) {
          Ziron_FatalError('Expected As');
          return true;
        }       
        eax = Ziron_ExpectNextToken(zirDATA_TYPE);
        if (eax == -1) {
          Ziron_FatalError('Expected data type');
          return true;
        }
        eax =  Ziron_GetStringValue();
        H_strcat(@buf,eax); 
        H_strcat(@buf,' ');  
        H_strcat(@buf,@var);
        H_strcat(@buf,'[');
        H_strcat(@buf,@tmp);
        H_strcat(@buf,']'); 
        H_strcat(@buf,';'); 
        Len = H_strlen(@buf);    
        eax = Ziron_Execute(@buf,Len);
        if (eax == false) {
          Ziron_FatalError('Dim plugin is not compatible with this version of Ziron');
          return true;
        }
        
        break;      
      /*********       **************          
      //state zirIdent:
        //eax = Ziron_GetStringValue();  
        //break;
        
      /*********       **************/            
      default:
        Ziron_FatalError('Expected as Keyword');
        return true;
    }
    eax = Ziron_IsNextLineBreak(); 
    if (eax) {
      break;      // check end of line so we end without semicolon
    }   
    eax = Ziron_PeekNextToken();    
    /*********  pares  Assignment '=' **************/ 
    if (eax == zirAssignment)
     {
        Ziron_GetNextToken();
        eax = Ziron_ExpectNextToken(zirNumber);
        if (eax == -1) {
          Ziron_FatalError('Expected max index number of array');
          return true;
        }
        H_strcpy(@tmp,Ziron_GetStringValue());   
        H_strcpy(@buf,@var);  
        H_strcat(@buf,' = '); 
        H_strcat(@buf,@tmp);
        H_strcat(@buf,';'); 
        Len = H_strlen(@buf);    
        eax = Ziron_Execute(@buf,Len);
        if (eax == false) {
          Ziron_FatalError('Dim plugin is not compatible with this version of Ziron');
          return true;
        }       
     }
    if (eax == zirCOMMA) {
      Ziron_GetNextToken();
    } else {
      break;
    }
  };
  return true;
}

http://www.freewebs.com/ogremagic/index.htm

Colin admin
Posts
928
Threads
49
Location
Bulgaria

I have just compiled that function you posted and it had no compile errors. Can you explain the problem you have when compiling, and can you quote the exact error message you receive?

Thanks.

Colin admin
Posts
928
Threads
49
Location
Bulgaria

hmm, that zip file is corrupt :)