Index strings

This commit is contained in:
2025-02-12 20:47:47 +01:00
parent f991686330
commit 62d9398772
10 changed files with 166 additions and 76 deletions

View File

@ -127,11 +127,10 @@ end
proc write_i(value: Int);
var
digit: Int, n: Int,
digit: Int, n: Word,
buffer: array 10 of Char;
begin
n := 9;
buffer[9] := '0';
n := 10u;
if value = 0 then
write_c('0')
@ -141,10 +140,10 @@ begin
value := value / 10;
buffer[n] := cast(cast('0' as Int) + digit as Char);
n := n - 1
n := n - 1u
end;
while n < 9 do
n := n + 1;
while n < 10u do
n := n + 1u;
write_c(buffer[n])
end
end
@ -184,7 +183,8 @@ end
proc substring(string: String, start: Word, count: Word) -> String;
begin
string.ptr := string.ptr + start;
string.length := count
string.length := count;
return string
end
proc string_dup(origin: String) -> String;
@ -198,11 +198,6 @@ begin
return origin
end
proc char_at(string: String, position: Word) -> Char;
begin
return (string.ptr + position)^
end
(*
End of standard procedures.
*)
@ -302,8 +297,8 @@ end
proc skip_spaces(source_code: SourceCode) -> SourceCode;
begin
while source_code.text.length > 0u and is_space(char_at(source_code.text, 0)) do
if char_at(source_code.text, 0) = '\n' then
while source_code.text.length > 0u and is_space(source_code.text[1u]) do
if source_code.text[1u] = '\n' then
source_code.position.line := source_code.position.line + 1u;
source_code.position.column := 1u
else
@ -321,7 +316,7 @@ begin
content_length := 0u;
token_content^ := source_code^.text;
while is_alnum(char_at(source_code^.text, 0)) or char_at(source_code^.text, 0) = '_' do
while is_alnum(source_code^.text[1u]) or source_code^.text[1u] = '_' do
content_length := content_length + 1u;
source_code^ := advance_source(source_code^, 1u)
end;
@ -336,7 +331,7 @@ begin
token_content^ := source_code^.text;
while source_code^.text.length > 1u do
if char_at(source_code^.text, 0) = '*' and char_at(source_code^.text, 1) = ')' then
if source_code^.text[1u] = '*' and source_code^.text[2u] = ')' then
source_code^ := advance_source(source_code^, 2u);
token_content^ := substring(token_content^, 0, content_length);
@ -638,7 +633,7 @@ begin
while source_code.text.length <> 0u do
tokens := cast(reallocarray(tokens, tokens_size^ + 1u, sizeof(Token)) as pointer to Token);
current_token := tokens + tokens_size^;
first_char := char_at(source_code.text, 0);
first_char := source_code.text[1u];
if is_alpha(first_char) or first_char = '_' then
lex_identifier(@source_code, @token_content);
@ -660,7 +655,7 @@ begin
if source_code.text.length = 0u then
current_token^.kind := TOKEN_LEFT_PAREN
elsif char_at(source_code.text, 0u) = '*' then
elsif source_code.text[1u] = '*' then
source_code := advance_source(source_code, 1u);
if lex_comment(@source_code, @token_content) then
@ -704,7 +699,7 @@ begin
if source_code.text.length = 0u then
current_token^.kind := TOKEN_GREATER_THAN
elsif char_at(source_code.text, 0) = '=' then
elsif source_code.text[1u] = '=' then
current_token^.kind := TOKEN_GREATER_EQUAL;
source_code := advance_source(source_code, 1u)
else
@ -715,10 +710,10 @@ begin
if source_code.text.length = 0u then
current_token^.kind := TOKEN_LESS_THAN
elsif char_at(source_code.text, 0) = '=' then
elsif source_code.text[1u] = '=' then
current_token^.kind := TOKEN_LESS_EQUAL;
source_code := advance_source(source_code, 1u)
elsif char_at(source_code.text, 0) = '>' then
elsif source_code.text[1u] = '>' then
current_token^.kind := TOKEN_NOT_EQUAL;
source_code := advance_source(source_code, 1u)
else
@ -756,7 +751,7 @@ begin
if source_code.text.length = 0u then
current_token^.kind := TOKEN_COLON
elsif char_at(source_code.text, 0) = '=' then
elsif source_code.text[1u] = '=' then
current_token^.kind := TOKEN_ASSIGNMENT;
source_code := advance_source(source_code, 1u)
else