Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 5630 → Rev 5631

/programs/cmm/lib/lexer.h
4,9 → 4,14
#ifndef INCLUDE_STRING_H
#include "../lib/strings.h"
#endif
 
#ifndef INCLUDE_MEM_H
#include "../lib/mem.h"
#endif
/** Splits text into tokens
* Author :Pavel Yakovlev
* Homepage:https://vk.com/pavelyakov39
* Ver. : 1.51
*/
 
/** Example:
49,19 → 54,76
:struct lexer
{
byte cmd;
dword token,text;
dword token,text,mem_list,count,buffer_loading;
dword str_buffer;
byte type;
char quote;
signed count,length;
signed length;
dword next(void);
dword back(void);
dword list(void);
void free(void);
dword position(dword __);
void load(dword _text);
void expected(dword _text);
};
:dword back(void)
{
 
 
:void expected(dword _text)
}
:dword lexer::list(void)
{
dword count_mem,buf_loop,pos;
count_mem = 0;
buf_loop = 5000; // на тыс элементов.
count = 0;
buffer_loading = malloc(buf_loop);
pos = buffer_loading;
while(type!=LEX_END)
{
pos+=count_mem;
next();
DSDWORD[pos] = strndup(token,length);
pos+=4;
DSBYTE [pos] = type;
pos++;
count++;
if(pos-buffer_loading>buf_loop)
{
buf_loop*=2;
buffer_loading = realloc(buffer_loading,buf_loop);
}
}
return buffer_loading;
}
:void lexer::free(void)
{
dword z;
z = count;
while(z)
{
z--;
position(z);
::free(token);
}
count = 0;
::free(buffer_loading);
}
:dword lexer::position(dword __)
{
dword pos1;
if(!count)list();
if(__>=count)__=count-1;
else if(__<0)__=0;
pos1 = __*5;
pos1 += buffer_loading;
token = DSDWORD[pos1];
pos1++;
type = DSBYTE[pos1];
return token;
}
:void lexer::expected(dword _text)
{
notify(_text);
ExitProcess();
}
69,15 → 131,19
:void lexer::load(dword _text)
{
text = _text;
count = 0;
str_buffer = 0;
}
 
:dword lexer::next(void)
{
char s;
dword len_str_buf,tmp;
dword pos,in;
pos = #const_token_lexer;
in = text;
//len_str_buf = 1024;
if(str_buffer)::free(str_buffer);
NEXT_TOKEN:
length = 0;
loop()
184,6 → 250,7
{
quote = s;
in++;
tmp = in;
s = DSBYTE[in];
loop()
{
210,10 → 277,43
DSBYTE[pos] = s;
pos++;
in++;
/*if(in-tmp>len_str_buf)
{
if(str_buffer)
{
tmp = len_str_buf;
len_str_buf+=1024;
str_buffer = realloc(str_buffer,len_str_buf+1);
strlcpy(str_buffer+tmp,#const_token_lexer,1024);
pos = #const_token_lexer;
}
else {
len_str_buf+=1024;
str_buffer = malloc(len_str_buf+1);
strlcpy(str_buffer,#const_token_lexer,1024);
pos = #const_token_lexer;
}
}*/
s = DSBYTE[in];
}
in++;
/*tmp = pos-in;
if(str_buffer)
{
if(tmp)
{
str_buffer = realloc(str_buffer,tmp+1);
strlcpy(str_buffer+len_str_buf,#const_token_lexer,tmp);
}
type = LEX_STR;
length = len_str_buf+tmp;
text = in;
tmp = str_buffer+length;
DSBYTE[tmp] = 0;
token = str_buffer;
return token;
}*/
type = LEX_STR;
}
else {
in++;