Implement string comparison
This commit is contained in:
72
source.elna
72
source.elna
@ -174,14 +174,6 @@ begin
|
||||
return c = ' ' or c = '\n' or c = '\t'
|
||||
end
|
||||
|
||||
proc string_equals(this: String, that: String): Bool;
|
||||
begin
|
||||
if this.length <> that.length then
|
||||
return false
|
||||
end;
|
||||
return strncmp(this.ptr, that.ptr, this.length) = 0
|
||||
end
|
||||
|
||||
proc open_substring(string: String, start: Word): String;
|
||||
begin
|
||||
string.ptr := string.ptr + start;
|
||||
@ -560,67 +552,67 @@ proc categorize_identifier(token_content: String): Token;
|
||||
var
|
||||
current_token: Token;
|
||||
begin
|
||||
if string_equals("if", token_content) then
|
||||
if "if" = token_content then
|
||||
current_token.kind := TOKEN_IF
|
||||
elsif string_equals("then", token_content) then
|
||||
elsif "then" = token_content then
|
||||
current_token.kind := TOKEN_THEN
|
||||
elsif string_equals("else", token_content) then
|
||||
elsif "else" = token_content then
|
||||
current_token.kind := TOKEN_ELSE
|
||||
elsif string_equals("elsif", token_content) then
|
||||
elsif "elsif" = token_content then
|
||||
current_token.kind := TOKEN_ELSIF
|
||||
elsif string_equals("while", token_content) then
|
||||
elsif "while" = token_content then
|
||||
current_token.kind := TOKEN_WHILE
|
||||
elsif string_equals("do", token_content) then
|
||||
elsif "do" = token_content then
|
||||
current_token.kind := TOKEN_DO
|
||||
elsif string_equals("proc", token_content) then
|
||||
elsif "proc" = token_content then
|
||||
current_token.kind := TOKEN_PROC
|
||||
elsif string_equals("begin", token_content) then
|
||||
elsif "begin" = token_content then
|
||||
current_token.kind := TOKEN_BEGIN
|
||||
elsif string_equals("end", token_content) then
|
||||
elsif "end" = token_content then
|
||||
current_token.kind := TOKEN_END
|
||||
elsif string_equals("extern", token_content) then
|
||||
elsif "extern" = token_content then
|
||||
current_token.kind := TOKEN_EXTERN
|
||||
elsif string_equals("const", token_content) then
|
||||
elsif "const" = token_content then
|
||||
current_token.kind := TOKEN_CONST
|
||||
elsif string_equals("var", token_content) then
|
||||
elsif "var" = token_content then
|
||||
current_token.kind := TOKEN_VAR
|
||||
elsif string_equals("array", token_content) then
|
||||
elsif "array" = token_content then
|
||||
current_token.kind := TOKEN_ARRAY
|
||||
elsif string_equals("of", token_content) then
|
||||
elsif "of" = token_content then
|
||||
current_token.kind := TOKEN_OF
|
||||
elsif string_equals("type", token_content) then
|
||||
elsif "type" = token_content then
|
||||
current_token.kind := TOKEN_TYPE
|
||||
elsif string_equals("record", token_content) then
|
||||
elsif "record" = token_content then
|
||||
current_token.kind := TOKEN_RECORD
|
||||
elsif string_equals("union", token_content) then
|
||||
elsif "union" = token_content then
|
||||
current_token.kind := TOKEN_UNION
|
||||
elsif string_equals("pointer", token_content) then
|
||||
elsif "pointer" = token_content then
|
||||
current_token.kind := TOKEN_POINTER
|
||||
elsif string_equals("to", token_content) then
|
||||
elsif "to" = token_content then
|
||||
current_token.kind := TOKEN_TO
|
||||
elsif string_equals("true", token_content) then
|
||||
elsif "true" = token_content then
|
||||
current_token.kind := TOKEN_BOOLEAN;
|
||||
current_token.value.boolean_value := true
|
||||
elsif string_equals("false", token_content) then
|
||||
elsif "false" = token_content then
|
||||
current_token.kind := TOKEN_BOOLEAN;
|
||||
current_token.value.boolean_value := false
|
||||
elsif string_equals("nil", token_content) then
|
||||
elsif "nil" = token_content then
|
||||
current_token.kind := TOKEN_NIL
|
||||
elsif string_equals("and", token_content) then
|
||||
elsif "and" = token_content then
|
||||
current_token.kind := TOKEN_AND
|
||||
elsif string_equals("or", token_content) then
|
||||
elsif "or" = token_content then
|
||||
current_token.kind := TOKEN_OR
|
||||
elsif string_equals("not", token_content) then
|
||||
elsif "not" = token_content then
|
||||
current_token.kind := TOKEN_NOT
|
||||
elsif string_equals("return", token_content) then
|
||||
elsif "return" = token_content then
|
||||
current_token.kind := TOKEN_RETURN
|
||||
elsif string_equals("cast", token_content) then
|
||||
elsif "cast" = token_content then
|
||||
current_token.kind := TOKEN_CAST
|
||||
elsif string_equals("as", token_content) then
|
||||
elsif "as" = token_content then
|
||||
current_token.kind := TOKEN_AS
|
||||
elsif string_equals("sizeof", token_content) then
|
||||
elsif "sizeof" = token_content then
|
||||
current_token.kind := TOKEN_SIZEOF
|
||||
elsif string_equals("defer", token_content) then
|
||||
elsif "defer" = token_content then
|
||||
current_token.kind := TOKEN_DEFER
|
||||
else
|
||||
current_token.kind := TOKEN_IDENTIFIER;
|
||||
@ -650,9 +642,7 @@ begin
|
||||
|
||||
if is_alpha(first_char) or first_char = '_' then
|
||||
lex_identifier(@source_code, @token_content);
|
||||
current_token^ := categorize_identifier(token_content);
|
||||
|
||||
source_code := advance_source(source_code, 1u)
|
||||
current_token^ := categorize_identifier(token_content)
|
||||
elsif is_digit(first_char) then
|
||||
token_end := nil;
|
||||
current_token^.value.int_value := strtol(source_code.text.ptr, @token_end, 10);
|
||||
|
Reference in New Issue
Block a user