Parse escape sequences in strings
This commit is contained in:
+37
-4
@@ -9,6 +9,7 @@ program;
|
||||
|
||||
(* - Allow assigning variables refering to aggregates. *)
|
||||
(* - Cast expressions. *)
|
||||
(* - Strings are typed as records with a pointer and length. *)
|
||||
|
||||
type
|
||||
ElnaListNode = record
|
||||
@@ -58,7 +59,7 @@ type
|
||||
kind: ElnaTypeKind;
|
||||
size: Word;
|
||||
alignment: Word;
|
||||
members: Word;
|
||||
members: ^ElnaTypeField;
|
||||
length: Word
|
||||
end;
|
||||
ElnaTypePointer = record
|
||||
@@ -692,6 +693,7 @@ var
|
||||
word_type: ^ElnaType;
|
||||
char_type: ^ElnaType;
|
||||
bool_type: ^ElnaType;
|
||||
string_type: ^ElnaTypeRecord;
|
||||
|
||||
source_code: Word;
|
||||
compiler_strings_position: Word;
|
||||
@@ -4934,7 +4936,7 @@ end;
|
||||
|
||||
proc elna_type_string_literal(parser_node: ^ElnaTreeStringLiteral);
|
||||
begin
|
||||
parser_node^.type_decoration := word_type
|
||||
parser_node^.type_decoration := string_type
|
||||
end;
|
||||
|
||||
proc elna_type_boolean_literal(parser_node: ^ElnaTreeBooleanLiteral);
|
||||
@@ -5291,12 +5293,39 @@ begin
|
||||
symbol_table^.count := symbol_table^.count + 1
|
||||
end;
|
||||
|
||||
proc elna_symbol_string_build();
|
||||
var
|
||||
current_field: ^ElnaTypeField;
|
||||
char_pointer: ^ElnaTypePointer;
|
||||
begin
|
||||
string_type := malloc(#size(ElnaTypeRecord));
|
||||
string_type^.kind := ElnaTypeKind._record;
|
||||
string_type^.size := 8;
|
||||
string_type^.alignment := 4;
|
||||
string_type^.members := malloc(2 * #size(ElnaTypeField));
|
||||
|
||||
char_pointer := malloc(#size(ElnaTypePointer));
|
||||
char_pointer^.kind := ElnaTypeKind.pointer;
|
||||
char_pointer^.size := 4;
|
||||
char_pointer^.alignment := 4;
|
||||
char_pointer^.base := char_type;
|
||||
|
||||
current_field := string_type^.members;
|
||||
current_field^.name := "ptr";
|
||||
current_field^.length := 3;
|
||||
current_field^.field_type := char_pointer;
|
||||
|
||||
current_field := current_field + 1;
|
||||
current_field^.name := "length";
|
||||
current_field^.length := 6;
|
||||
current_field^.field_type := word_type
|
||||
end;
|
||||
|
||||
(* Build global symbol table with predefined symbols. *)
|
||||
proc elna_symbol_table_build();
|
||||
var
|
||||
current_info: ^ElnaSymbolTypeInfo;
|
||||
current_type: ^ElnaType;
|
||||
global_pointer: ^Word;
|
||||
begin
|
||||
symbol_table_global := elna_symbol_table_create(nil);
|
||||
|
||||
@@ -5327,7 +5356,11 @@ begin
|
||||
char_type^.size := 1;
|
||||
char_type^.alignment := 1;
|
||||
current_info := type_info_create(char_type);
|
||||
elna_symbol_table_enter(symbol_table_global, "Char", 4, current_info)
|
||||
elna_symbol_table_enter(symbol_table_global, "Char", 4, current_info);
|
||||
|
||||
elna_symbol_string_build();
|
||||
current_info := type_info_create(string_type);
|
||||
elna_symbol_table_enter(symbol_table_global, "String", 6, current_info)
|
||||
end;
|
||||
|
||||
proc elna_lexer_classifications1();
|
||||
|
||||
Reference in New Issue
Block a user