Register | Login
Forum Index > Plugins > PlugIn Example in C
Author Message
Pages: 1 2 3 4 5 6 7 8 9 10 11
Emil_halim
Ziron Beta Tester

avatar

(send private message)

Posts: 639
Topics: 104

Location:
Alex, Egypt
[803] - posted: 2011-11-22 23:11:51

okay , so i will waiting for the new handlers.

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

avatar

(send private message)

Posts: 933
Topics: 55

Location:
OverHertz Studio
[804] - posted: 2011-11-22 23:13:39
i will try to make the time to get them done over next couple days...

Download Ziron
Get free hosting for Ziron related fan-sites and Ziron projects, contact me in private message.
Emil_halim
Ziron Beta Tester

avatar

(send private message)

Posts: 639
Topics: 104

Location:
Alex, Egypt
[840] - posted: 2011-11-25 21:14:16

Hi all

while waiting for the new handlers, i have developed Masm plugin a Little.

now it supports multi line declaration , like this
Code:
program WIN32CUI 'Masm Syntax test';

#include 'console.zir';

.DATA 
{

var      DB 0x0f  ; Declare a byte, referred to as location var, containing the value 0x0f.
vv       Db 1      
ar1      DB ?  
ar2      DB 0 

ml       db 0 , 0 , 0 , 1
         db 5 , 6          // multi lines declration
         db ?              // an other line
         db 0xfc           //one more line

bytes    DB 10 DUP(0)   ; Declare 10 bytes starting at location bytes.

str1     DB 'hello',0

Wvar     dw 10

Dvar     dd 20

//Qvar     dq 30  // will be allowed later

varname   dword  1342 , 10 
          dword  13 , 100   // multi lines declration
          
vwrd      word   7
vbyte     byte   0x40

vchar     char   'welcome',10,13,0

CrLf      db   10,13

//svar      single 1.5 , 5.0 

//dblvar   double 10.0

//exvar   extended 100.0    

}

wait_key(nil);
ExitProcess(0);


http://www.freewebs.com/ogremagic/index.htm
Emil_halim
Ziron Beta Tester

avatar

(send private message)

Posts: 639
Topics: 104

Location:
Alex, Egypt
[903] - posted: 2011-11-29 19:48:04
HI Colin.

i am trying to make Masm plugin understand this
Code:
eax=10;
.WHILE( eax > 5)
{ 
  eax--;
}

.WHILE( eax == 5 and ebx != 7)
{
  
}

.WHILE  eax == 5
{
  
}

.WHILE  eax == 5 and ebx != 7
{
  
}


and here is the code snippet
Code:
//////////////////////////////
function event_While() {
  uses edi esi ecx ebx;
  boolean Flg = true;  
  char condBuf[1024];
  char label[1024];
  char tmp[1024];
  global Dword incr; 
  pointer pt; 
  
  if(Flg) {
        
        //get the condition from while
        condBuf=0;
        eax = Ziron_GetNextToken();
        if (eax == zirParenOpen)
         {
            eax = Ziron_GetNextToken();
            while( eax != zirParenClose)
             {
               pt = Ziron_GetStringValue();
               H_strjoin(@condBuf , ' ' ,pt);
               eax = Ziron_GetNextToken(); 
             }      
         } 
        else
         {
             eax = Ziron_IsNextLineBreak();
             while(!eax)
              {
                pt = Ziron_GetStringValue();
                H_strjoin(@condBuf , ' ' ,pt);
                Ziron_GetNextToken(); 
                eax = Ziron_IsNextLineBreak();
              }
             pt = Ziron_GetStringValue();
             H_strjoin(@condBuf , ' ' ,pt); 
         } 
             
       incr++; 
       // always start with  '{' 
       eax = Ziron_ExpectNextToken(zirBraceOpen);    
       if (eax == -1) {
            Ziron_FatalError('Expected { symbol');
            return true;
        }
       // put the label here
       label=0;
       IntToStr(incr, @tmp);
       H_strjoin(@label , '@__While__' , @tmp, ':'); 
       Ziron_Exec(@label);  
       Ziron_ShowMessage(@label);
       label=0;
       H_strjoin(@label , '@__While__' , @tmp );        
       
       tmp=0;
       H_strjoin(@tmp , 'if(' , @condBuf , '){ \r\n');
       Ziron_Exec(@tmp); 
       Ziron_ShowMessage(@tmp); 
             
       repeat {
          // found '}' so let's finished
          eax = Ziron_PeekNextToken(); 
          if (eax == zirBraceClose) {
              Ziron_GetNextToken(); 
              tmp=0;
              H_strjoin(@tmp , '\r\n goto ' , @label, '; }');
              Ziron_Exec(@tmp); 
              Ziron_ShowMessage(@tmp); 
              break;
           }
          // get the entire line and execute it 
          tmp=0; 
          eax = Ziron_IsNextLineBreak();
          while(!eax)
           {
              pt = Ziron_GetStringValue();
              H_strjoin(@tmp , ' ' ,pt);
              Ziron_GetNextToken(); 
              eax = Ziron_IsNextLineBreak();
           }
          pt = Ziron_GetStringValue();
          H_strjoin(@tmp , ' ' ,pt);  
          Ziron_Exec(@tmp);  
       };       
         
        
        return true;   // let Ziron handle the next line   
  } else {   
        return false;  // let Ziron handle the line  
  }  
}


but ...... got that error

[1,6]: Expected ; or >> or << or += or -= or = or ( or as or ++ or -- but found in [plugin buffer]
any help pleas .



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

avatar

(send private message)

Posts: 933
Topics: 55

Location:
OverHertz Studio
[908] - posted: 2011-11-29 21:58:21
why not just use the init function to modify the file buffer?

when using strOffset('_While, .... etc

you can then move forward and add in the parenthesis if they do not exist and remove the _ from while... then ziron will be able to handle it..

e.g.

Code:
.while eax > 5
  eax = 10;
.wend


first removing . from while

Code:
 while eax > 5
  eax = 10;
.wend


now you can shift the whole left back 1 space to provide a space on the end before the newline

Code:
while eax > 5<space here> 
  eax = 10;
.wend


next you would move to the space after while and exchange it with a ( and then move to the end space and replace it with )

Code:
while(eax > 5)
  eax = 10;
.wend


now the problem is the "{" so first we will replace .wend with "} "

Code:
while(eax > 5)
  eax = 10;
}


ok onto the problem "{"

your syntax will need to check to make sure they have written at least 1 space between the while.. so

while eax>5 would not be valid, but while eax >5 would... this then gives you 1 space to play with, allowing you to shift everything after the space left 1 character, and then you can put the final { character on the end space you just created.

Code:
while(eax> 5){
  eax = 10;
}


Else you could also create a buffer and set the file buffer.

Download Ziron
Get free hosting for Ziron related fan-sites and Ziron projects, contact me in private message.
Emil_halim
Ziron Beta Tester

avatar

(send private message)

Posts: 639
Topics: 104

Location:
Alex, Egypt
[917] - posted: 2011-11-30 18:40:21

using and modify the file buffer is a good idea , i will think about it.

but what about my code i think it has an error , is that error is a logical or it is in Ziron itself ?

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

avatar

(send private message)

Posts: 933
Topics: 55

Location:
OverHertz Studio
[922] - posted: 2011-11-30 18:59:44
i replaced your H_strJoin with the default ziron strJoin (since i don't have your function) and i get no syntax errors with the code.

Code:
function event_While() {
  uses edi esi ecx ebx;
  boolean Flg = true;  
  char condBuf[1024];
  char label[1024];
  char tmp[1024];
  global Dword incr; 
  pointer pt; 
  
  if(Flg) {
        
        //get the condition from while
        condBuf=0;
        eax = Ziron_GetNextToken();
        if (eax == zirParenOpen)
         {
            eax = Ziron_GetNextToken();
            while( eax != zirParenClose)
             {
               pt = Ziron_GetStringValue();
               strjoin(@condBuf , ' ' ,pt, 1000);
               eax = Ziron_GetNextToken(); 
             }      
         } 
        else
         {
             eax = Ziron_IsNextLineBreak();
             while(!eax)
              {
                pt = Ziron_GetStringValue();
                strjoin(@condBuf , ' ' ,pt, 1000);
                Ziron_GetNextToken(); 
                eax = Ziron_IsNextLineBreak();
              }
             pt = Ziron_GetStringValue();
             strjoin(@condBuf , ' ' ,pt, 1000); 
         } 
             
       incr++; 
       // always start with  '{' 
       eax = Ziron_ExpectNextToken(zirBraceOpen);    
       if (eax == -1) {
            Ziron_FatalError('Expected { symbol');
            return true;
        }
       // put the label here
       label=0;
       IntToStr(incr, @tmp);
       strjoin(@label , '@__While__' , @tmp, ':', 1000); 
       Ziron_Exec(@label);  
       Ziron_ShowMessage(@label);
       label=0;
       strjoin(@label , '@__While__' , @tmp , 1000);        
       
       tmp=0;
       strjoin(@tmp , 'if(' , @condBuf , '){ \r\n', 1000);
       Ziron_Exec(@tmp); 
       Ziron_ShowMessage(@tmp); 
             
       repeat {
          // found '}' so let's finished
          eax = Ziron_PeekNextToken(); 
          if (eax == zirBraceClose) {
              Ziron_GetNextToken(); 
              tmp=0;
              strjoin(@tmp , '\r\n goto ' , @label, '; }', 1000);
              Ziron_Exec(@tmp); 
              Ziron_ShowMessage(@tmp); 
              break;
           }
          // get the entire line and execute it 
          tmp=0; 
          eax = Ziron_IsNextLineBreak();
          while(!eax)
           {
              pt = Ziron_GetStringValue();
              strjoin(@tmp , ' ' ,pt, 10000);
              Ziron_GetNextToken(); 
              eax = Ziron_IsNextLineBreak();
           }
          pt = Ziron_GetStringValue();
          strjoin(@tmp , ' ' ,pt, 10000);  
          Ziron_Exec(@tmp);  
       };       
         
        
        return true;   // let Ziron handle the next line   
  } else {   
        return false;  // let Ziron handle the line  
  }  
}


compiles with no problems.

Download Ziron
Get free hosting for Ziron related fan-sites and Ziron projects, contact me in private message.
Emil_halim
Ziron Beta Tester

avatar

(send private message)

Posts: 639
Topics: 104

Location:
Alex, Egypt
[923] - posted: 2011-11-30 19:12:57

ok i will replace it later , but i discovered new problem with latest beta.

when i fixed this term '[eax]=0' to 'char[eax]=0' i got this error

Ziron Compiler 1.1.29.3
Copyright (C) 2011. OverHertz Ltd. All rights reserved.
--------------------------------------------
11/30/2011 7:08:32 PM
--------------------------------------------

PlugSys: Basic plugin has loaded!
PlugSys: Emit plugin has loaded!
PlugSys: Masm plugin version 0.01 has loaded!
PlugSys: Sleep seconds plugin has loaded
[8,13]: PlugSys: Expected DB or DW or DD or DQ symple in [testprg.zir]
Code:
var DB 0x0f ; Declare a byte, referred to as location var, containing the value 0x0f.

--------------------------------------------



here is the plugin code
Code:
function event_Data() {
  uses edi esi ecx ebx;
  char buf[2048];
  char var[255];
  char right[5100];
  char tmp[255];
  char dtype[32];
  char extn[32];
  dword indx,ndx;
  const stp = 16;
  boolean Flg = true;  
  
  if(Flg) {
    // always start with  '{' 
    eax = Ziron_ExpectNextToken(zirBraceOpen);    
    if (eax == -1) {
      Ziron_FatalError('Expected { symbol');
      return true;
    }
          
    repeat {
      // found '}' so let's finished
      eax = Ziron_PeekNextToken(); 
      if (eax == zirBraceClose) {
        Ziron_GetNextToken(); 
        break;
      } 
              
      buf=0; 
      right=0;
      indx = 0;         
      // get the variable name and hold it in Var
     /*   
      DWord dt = Ziron_ExpectNextToken(zirIdent); 
      if (dt == -1) {
        Ziron_FatalError('Expected Variable Name');
        return true;
      }
     */
      DWord dt = Ziron_GetNextToken();  
      char tVar[512];
      char* strTemp;
      H_strcpy(@tvar, Ziron_GetStringValue());
      strLower(@tVar);
      H_Trim(@tVar,nil);
      eax = @tVar;
      if( word[eax] == "db" or word[eax] == "dw" or word[eax] == "dd" or word[eax] == "dq" or dt == zirData_Type) 
       {
          strTemp = eax;  
          ndx++;
         // Ziron_ShowMessage(@tVar);
          IntToStr(ndx, @tmp);
          var=0;    
          H_strjoin(@var ,@extn,  '_' , @tmp, '_temp');
          goto @forwerd;
       }
      else
       {
          ndx=0; 
          extn=0;   
          H_strcpy(@var, Ziron_GetStringValue()); 
          H_strcpy(@extn, Ziron_GetStringValue());     
       }       
      // get DB or DW or DD or DQ or (data type)
      dt = Ziron_GetNextToken(); 
      boolean  _db, _dw, _dd, _dq;        
      strTemp = strLower(Ziron_GetStringValue());
      @forwerd:
      _db = strCmp('db',strTemp);
      if (_db)
       {
            H_strcpy(@dtype,'byte ');     // found DB
       } 
      else
       {
           _dw = strCmp('dw',strTemp); //  
            if (_dw) 
             {
                  H_strcpy(@dtype,'word '); // found DW
             }
            else 
             {
                  _dd = strCmp('dd', strTemp);     
                  if (_dd) 
                   {
                        H_strcpy(@dtype,'DWord '); // found DD
                   } 
                  else 
                   {
                        _dq = strCmp('dq', strTemp);    
                        if (_dq) 
                         {
                              H_strcpy(@dtype,'qword '); // found DQ
                         }
                        else
                         {
                           if(dt == zirData_Type)  // found data type
                             {
                                H_strcpy(@dtype,Ziron_GetStringValue()); 
                                H_strcat(@dtype,' '); 
                             }
                            else
                             {          
                               // there is no DB or DW or DD or DQ or (data type) so fire error 
                               Ziron_FatalError('Expected DB or DW or DD or DQ symple');
                               return true;
                             }
                         }
                  }
            }
      }
              
      @digit:
        
      // get whatever after DB 
      eax = Ziron_GetNextToken();
      //  var  DB ?  
      if (eax == zirQuestionSym) {
        H_strjoin(@buf, @dtype , @var, ' = ' , '0;' ); 
        Ziron_Exec(@buf);
        continue;
      }
          
      case (eax) {
        // var DB 0x0f 
        state zirHEXADECIMAL:
          edx = indx; imul edx, stp; eax = @right; edx += eax;
          H_strcpy(edx,'0x');            
          H_strcat(edx,Ziron_GetStringValue());
          break; 
        // var Db 1  
        state zirNUMBER:
          edx = indx; imul edx, stp; eax = @right; edx += eax;            
          H_strcpy(edx,Ziron_GetStringValue());                 
          break;   
        // str  DB 'hello',0  
        state zirConstString:
              char str1[2048];
              H_strcpy(@str1,Ziron_GetStringValue());
              ecx = H_strlen(@str1);
              while(ecx > 0)
               {      
                 esi = @str1;
                 edx = indx; bl = [esi+edx]; imul edx, stp; eax = @right; edx += eax; 
                 char[edx] = ord('"');
                 char[edx+1] = bl;
                 char[edx+2] = ord('"');
                 char[edx+3] = 0;
                 indx++;
                 ecx--; 
               } 
               indx--;  
          break;
          state zirFLOAT:
              edx = indx; imul edx, stp; eax = @right; edx += eax;            
              H_strcpy(edx,Ziron_GetStringValue());         
              //Ziron_ShowMessage(Ziron_GetStringValue());
          break;     
        default:
          Ziron_FatalError('Expected number');
          return true;
      }
        
        
      eax = Ziron_PeekNextToken();
      // check for ','
      // var db 0 , 0 , 0 , 1
      if (eax == zirCOMMA) {
        Ziron_GetNextToken(); // remove ','
        indx++;        
        goto @digit;
      } 
      // check for ';'
      // var DB 0x0f  ; Declare a byte
      SkipSemiToLineEnd();
        
      // bytes DB 10 DUP(0)
      eax = strCmp('dup',strLower(Ziron_GetStringValue()));
      if (eax) 
       { 
         Ziron_GetNextToken(); // remove 'DUP'
         Ziron_GetNextToken(); // remove '('
         Ziron_GetNextToken(); // remove '0'
         char  v[10];
         H_strcpy(@v,Ziron_GetStringValue());
         Ziron_GetNextToken(); // remove ')'           
         ecx = strVal(@right);
         while(ecx > 0)
          {
             edx = indx; imul edx, stp; eax = @right; edx += eax; 
             H_strcpy(edx,@v);   
             indx++;
             ecx--; 
          } 
         indx--;   
         // check for ';'
         SkipSemiToLineEnd();
       }  
      
      
      
       
      // 
      buf = 0;
      if (indx == 0) { 
        H_strjoin(@buf, @dtype , @var, ' = ' , @right , ';' ); 
        Ziron_ShowMessage(@buf);
        Ziron_Exec(@buf); 
      }
      else
      {
          H_strcat(@buf, @dtype );            
          edi = xor;        
          while (edi <= indx)
           {       
              IntToStr(edi, @tmp);           
              edx = edi; imul edx, stp; eax = @right; edx += eax; 
              H_strjoin(@buf, @var,  '[' , @tmp ,']=' , edx , '; ' ); 
              edi++; 
           }   
          Ziron_ShowMessage(@buf);
          Ziron_Exec(@buf);  
      } 

      
    };            
    return true;
  } else {   
    return false;                           // let Ziron handle the line  
  }  
}


http://www.freewebs.com/ogremagic/index.htm
Pages: 1 2 3 4 5 6 7 8 9 10 11
create new reply


Quick reply:

Message:



Currently Active Users:
There are currently 11 user(s) online. 0 member(s) and 11 guest(s)
Most users ever online was 1046, January 28, 2022, 2:08 pm.


Statistics:
Threads: 225 | Posts: 1848 | Members: 51 | Active Members: 51
Welcome to our newest member, yecate
const Copyright = '2011-2024 © OverHertz Ltd. All rights reserved.';
Web development by OverHertz Ltd