Skip to content
Low-level programming · Higher-level thinking
Login Register
Forum / Source Help

detecting '\'

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

Emil_halim member
Posts
639
Threads
104
Location
Alex, Egypt

detecting '\'

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

BTW , i want to detect the last token of the line against '\'

          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

Replies

Colin admin
Posts
928
Threads
49
Location
Bulgaria

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.

Ziron_RegisterKeyword('\', @event_...

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

Emil_halim member
Posts
639
Threads
104
Location
Alex, Egypt

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

#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

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

Colin admin
Posts
928
Threads
49
Location
Bulgaria

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:

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

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

	}
	elseif (eax == zirSemiColon)
	{
		buf=0;    
		H_strjoin(@buf ,'#define ', @idnt, ';');
		Ziron_Exec(@buf); 
	}
	else
	{   // it is simple #define 
Emil_halim member
Posts
639
Threads
104
Location
Alex, Egypt

yes it works fine.

but when using "\" as you suggested i got this error

    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

    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

Colin admin
Posts
928
Threads
49
Location
Bulgaria

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

zirSemi_Colon = 1,

to

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.

Colin admin
Posts
928
Threads
49
Location
Bulgaria

aha, probably " is also processing backslash for special chars, try "\\" instead, since \ is an escape character.

Emil_halim member
Posts
639
Threads
104
Location
Alex, Egypt

ok thanks , it works well now.

i have an other problem , this line give this error

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