Skip to content
Low-level programming · Higher-level thinking
Login Register
Forum / Bugs and Fixes

Ziron_PeekNextToken problem

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

Emil_halim member
Posts
639
Threads
104
Location
Alex, Egypt

Ziron_PeekNextToken problem

Hi Mr Colin.

i used this code to check of double hash EG. '##'

   Tok  = Ziron_GetNextToken();  
   .....
   .....
   if ( (Tok == zirDirective) or (Tok == zirHash) ) // so we found '#'
    {
        nxTok  =  Ziron_PeekNextToken();
        if( (nxTok == zirDirective) or (nxTok == zirHash)) check for another '#'
         {

but it seem's Ziron_PeekNextToken updates internal zrion state, so that Ziron_GetStringValue brings next Token in program and it should brings the one that belong to Tok.

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

Replies

Colin admin
Posts
928
Threads
49
Location
Bulgaria

it will return the peeked token string

Emil_halim member
Posts
639
Threads
104
Location
Alex, Egypt

ok , can i have a flag that allow Ziron_GetStringValue to return the previous one.

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

Emil_halim member
Posts
639
Threads
104
Location
Alex, Egypt

or , can you make a new pf that return the string belong to Ziron_GetNextToken and one for

Ziron_PeekNextToken.

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

Colin admin
Posts
928
Threads
49
Location
Bulgaria

To do this i will need to add a seperate buffer for current/peeked token strings, however since alot of plugins will not require this, it may be best for you to allocate your own buffer for token strings before calling peeknexttoken.

you could use something like this:

/////////////

const maxTokenLength = 256; //i will add this to framework.zir and will update it accordingly at later releases.

inline function Ziron_GetNextTokenEx() {
   global char tokString[maxTokenLength];

   eax = Ziron_GetNextToken();
   push eax
   eax = Ziron_GetStringValue();
   strcpy(@tokString, eax);
   pop eax

   $return eax;
}

inline function Ziron_GetStringValueEx() {
   $return @tokString;
}

//////

   Tok  = Ziron_GetNextTokenEx();  
   .....
   .....
   if ( (Tok == zirDirective) or (Tok == zirHash) ) // so we found '#'
    {
        nxTok  =  Ziron_PeekNextToken();
        if( (nxTok == zirDirective) or (nxTok == zirHash)) check for another '#'
         {
Emil_halim member
Posts
639
Threads
104
Location
Alex, Egypt

ok , thanks for your good solution.

now i am stuck , first thing is.

   #define  string(x)  #x

this means when you find this term string(Ziron) you must replace it with this term 'Ziron'

so how can i do this in ziron , const & inline function do not help hear.

so what do you suggests ?

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

Colin admin
Posts
928
Threads
49
Location
Bulgaria

i do not understand, can you explain in detail?

Emil_halim member
Posts
639
Threads
104
Location
Alex, Egypt

ok ,

 #define  string(x)  #x

when putting '#' before token in define body directive like this '#x' , you force ziron when

found string() inside the program it will replace the string() with what in between () and

add '|'' in front and at the end of what in between() , i mean force it to be literal string.

Eax.

  #define  string(x)  #x

  .........
  ......... 
  .........

  // later

  print(string(ziron)); // this should convert to be print('ziron'); 
      

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