Register | Login
Forum Index > Source Help > detecting '\'
Author Message
Pages: 1 2 3 4 5
Emil_halim
Ziron Beta Tester

avatar

(send private message)

Posts: 639
Topics: 104

Location:
Alex, Egypt
[1128] detecting '\' - posted: 2012-05-17 19:48:36

is there a better way to detecting back slash more than this

BTW , i want to detect the last token of the line against '\'
Code:
          eax = Ziron_IsNextLineBreak();
          while(!eax)
           {
               Ziron_GetNextToken(); 
               eax = Ziron_GetStringValue();
               if(char[eax] == 92) // '\'
                 {
                  H_strcat(@val, '\r\n'); 
                  edi = Ziron_GetNextToken(); 
                }
               H_strcat(@val, Ziron_GetStringValue()); 
               eax = Ziron_IsNextLineBreak();    
           }


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

avatar

(send private message)

Posts: 933
Topics: 55

Location:
OverHertz Studio
[1132] - posted: 2012-05-17 22:18:52
not quite sure what you are trying to accomplish, but i've updated the beta, Ziron_RegisterKeyword can now accept single characters to be registered (note these are handled very differently to actual keywords - since they are intended for tokenization)

e.g.

Code:
Ziron_RegisterKeyword('\', @event_...


and i've also implemented pf function Ziron_MoveNextChar (see plugin_interface.rtf)

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
[1140] - posted: 2012-05-17 23:26:03

as you already know , i am extending #define c_like directive .

so with #define function_like macro can be in more than one line , something like this
Code:
#define getrandom(min, max) \
    ((rand()%(int)(((max) + 1)-(min)))+ (min))


so i want to detect the '\' at the end of line so here is my event handler
Code:
function event_Define() 
{
    uses edi esi ecx ebx;
    char  buf[2048];
    char  idnt[255];
    char  val[1024];
    char  par[1024];
       
//    eax = Ziron_ExtractLine(@buf,2047);
//    Ziron_ShowMessage(@buf); 
      
    eax = Ziron_ExpectNextToken(zirIdent); 
    if (eax == -1) {
        Ziron_FatalError('Expected identfire Name');
        return true;
    }
    H_strcpy(@idnt, Ziron_GetStringValue());
    
    eax = Ziron_GetNextToken();
    if(eax == zirParenOpen) // function like macro
     {
          H_strcpy(@par, '(');
          eax = Ziron_GetNextToken();
          while( eax != zirParenClose)
           {
              H_strcat(@par, Ziron_GetStringValue()); 
              eax = Ziron_GetNextToken();          
           }
          H_strcat(@par, ')');  
          //Ziron_ShowMessage(@par);
          
          val = 0;
          eax = Ziron_IsNextLineBreak();
          while(!eax)
           {
               Ziron_GetNextToken(); 
               eax = Ziron_GetStringValue();
               if(char[eax] == 92) // '\'
                 {
                  H_strcat(@val, '\r\n'); 
                  edi = Ziron_GetNextToken(); 
                }
               H_strcat(@val, Ziron_GetStringValue()); 
               eax = Ziron_IsNextLineBreak();    
           }
           
         // Ziron_ShowMessage(@val);  
          buf = 0;
          H_strjoin(@buf ,'inline procedure ', @idnt, @par, '{' , @val , '}');
          Ziron_ShowMessage(@buf); 
     }
    else  // it is simple #define
     { 
        if( eax == zirHexadecimal) 
         {  
            H_strcpy(@val, '0x');
            H_strcat(@val, Ziron_GetStringValue());
         }
        else
         {
            H_strcpy(@val, Ziron_GetStringValue());
            eax = Ziron_IsNextLineBreak();
            while(!eax)
             {
                  Ziron_GetNextToken(); 
                  H_strcat(@val, Ziron_GetStringValue()); 
                  eax = Ziron_IsNextLineBreak();    
             } 
         }    
        buf=0;    
        H_strjoin(@buf ,'const ', @idnt, ' = ', @val , ';');
        //    Ziron_ShowMessage(@buf);
        Ziron_Exec(@buf); 
     }
    
    return true; 
}


so how can i make use of you new feature char_token?

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

avatar

(send private message)

Posts: 933
Topics: 55

Location:
OverHertz Studio
[1142] - posted: 2012-05-18 12:31:50
This looks ok, does it work correctly?

2 things, first maybe you do not know the usage of "", i see you wrote a comment // \ you can make it easier for yourself to do:

Code:
  if(char[eax] == "\")


and second, you should also allow support for standard ziron defines

Code:
  }
  elseif (eax == zirSemiColon)
  {
    buf=0;    
    H_strjoin(@buf ,'#define ', @idnt, ';');
    Ziron_Exec(@buf); 
  }
  else
  {   // it is simple #define 


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
[1144] - posted: 2012-05-18 17:13:21

yes it works fine.

but when using "\" as you suggested i got this error
Code:
    if(char[eax] == "\") 


[97,1580]: Ordinal strings can only be between 0 and 4 characters. in [define.zir]
Code:
char[eax] = "_";


and when using that
Code:
    elseif(eax == zirSemiColon)
     {
          buf=0;    
          H_strjoin(@buf ,'#define ', @idnt, ';');
          Ziron_Exec(@buf); 
     }


i got that error

[112,32]: Expected register or data type or variable or local variable or local parameter or constant or number or constant string or - but found zirSemiColon in [define.zir]
Code:
elseif(eax == zirSemiColon)




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

avatar

(send private message)

Posts: 933
Topics: 55

Location:
OverHertz Studio
[1145] - posted: 2012-05-18 17:25:46
sorry my mistake, it is added as zirSemi_Colon, but i suggest to change this in framework.zir as i will change it in next release

Code:
zirSemi_Colon = 1,


to

Code:
zirSemiColon = 1,


as for the ordinal error that is odd, i do not see any problems to cause this, i will look into it further.

Download Ziron
Get free hosting for Ziron related fan-sites and Ziron projects, contact me in private message.
Admin
Site Admin

avatar

(send private message)

Posts: 933
Topics: 55

Location:
OverHertz Studio
[1146] - posted: 2012-05-18 17:27:04
aha, probably " is also processing backslash for special chars, try "\\" instead, since \ is an escape character.

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
[1147] - posted: 2012-05-18 17:33:02

ok thanks , it works well now.

i have an other problem , this line give this error
Code:
H_strjoin(@val, ' ' ,Ziron_GetStringValue()); 


[133,62]: Expected , or ) but found ( in [define.zir]
Code:
H_strjoin(@val, ' ' ,Ziron_GetStringValue());


any help please.

http://www.freewebs.com/ogremagic/index.htm
Pages: 1 2 3 4 5
create new reply


Quick reply:

Message:



Currently Active Users:
There are currently 2 user(s) online. 0 member(s) and 2 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