Allow empty var sections
This commit is contained in:
		| @@ -1 +0,0 @@ | |||||||
| 3.3.6 |  | ||||||
| @@ -530,7 +530,7 @@ variable_declarations: | |||||||
|             $$.reserve($$.size() + $3.size()); |             $$.reserve($$.size() + $3.size()); | ||||||
|             $$.insert(std::end($$), std::begin($3), std::end($3)); |             $$.insert(std::end($$), std::begin($3), std::end($3)); | ||||||
|         } |         } | ||||||
|     | variable_declaration { std::swap($$, $1); } |     | /* no variable declarations */ {} | ||||||
| variable_part: | variable_part: | ||||||
|     /* no variable declarations */ {} |     /* no variable declarations */ {} | ||||||
|     | "var" variable_declarations { std::swap($$, $2); } |     | "var" variable_declarations { std::swap($$, $2); } | ||||||
| @@ -553,9 +553,9 @@ type_definition: identifier_definition "=" type_expression | |||||||
|             $$ = new boot::type_definition(boot::make_position(@1), $1.first, $1.second, $3); |             $$ = new boot::type_definition(boot::make_position(@1), $1.first, $1.second, $3); | ||||||
|         } |         } | ||||||
| type_definitions: | type_definitions: | ||||||
|     type_definition type_definitions |     type_definition ";" type_definitions | ||||||
|         { |         { | ||||||
|             std::swap($$, $2); |             std::swap($$, $3); | ||||||
|             $$.insert($$.cbegin(), $1); |             $$.insert($$.cbegin(), $1); | ||||||
|         } |         } | ||||||
|     | /* no type definitions */ {} |     | /* no type definitions */ {} | ||||||
|   | |||||||
							
								
								
									
										52
									
								
								source.elna
									
									
									
									
									
								
							
							
						
						
									
										52
									
								
								source.elna
									
									
									
									
									
								
							| @@ -67,23 +67,23 @@ type | |||||||
|   Position* = record |   Position* = record | ||||||
|     line: Word; |     line: Word; | ||||||
| 	column: Word | 	column: Word | ||||||
|   end |   end; | ||||||
|   Location* = record |   Location* = record | ||||||
|     first: Position; |     first: Position; | ||||||
| 	last: Position | 	last: Position | ||||||
|   end |   end; | ||||||
|   SourceFile* = record |   SourceFile* = record | ||||||
| 	buffer: [1024]Char; | 	buffer: [1024]Char; | ||||||
| 	handle: ^FILE; | 	handle: ^FILE; | ||||||
| 	size: Word; | 	size: Word; | ||||||
| 	index: Word | 	index: Word | ||||||
|   end |   end; | ||||||
|   FILE* = record end |   FILE* = record end; | ||||||
|   StringBuffer* = record |   StringBuffer* = record | ||||||
|     data: ^Byte; |     data: ^Byte; | ||||||
|     size: Word; |     size: Word; | ||||||
|     capacity: Word |     capacity: Word | ||||||
|   end |   end; | ||||||
|   SourceCode = record |   SourceCode = record | ||||||
|     position: Position; |     position: Position; | ||||||
|  |  | ||||||
| @@ -91,7 +91,7 @@ type | |||||||
| 	empty: proc(^Byte) -> Bool; | 	empty: proc(^Byte) -> Bool; | ||||||
| 	advance: proc(^Byte); | 	advance: proc(^Byte); | ||||||
| 	head: proc(^Byte) -> Char | 	head: proc(^Byte) -> Char | ||||||
|   end |   end; | ||||||
|   Token* = record |   Token* = record | ||||||
|     kind: Int; |     kind: Int; | ||||||
|     value: union |     value: union | ||||||
| @@ -101,12 +101,12 @@ type | |||||||
| 	  char_value: Char | 	  char_value: Char | ||||||
|     end; |     end; | ||||||
| 	location: Location | 	location: Location | ||||||
|   end |   end; | ||||||
|   CommandLine* = record |   CommandLine* = record | ||||||
|     input: ^Char; |     input: ^Char; | ||||||
| 	tokenize: Bool; | 	tokenize: Bool; | ||||||
| 	syntax_tree: Bool | 	syntax_tree: Bool | ||||||
|   end |   end; | ||||||
|  |  | ||||||
| (* | (* | ||||||
|   External procedures. |   External procedures. | ||||||
| @@ -171,7 +171,7 @@ proc write_i(value: Int); | |||||||
| var | var | ||||||
|   digit: Int; |   digit: Int; | ||||||
|   n: Word; |   n: Word; | ||||||
|   buffer: [10]Char |   buffer: [10]Char; | ||||||
| begin | begin | ||||||
|   n := 10u; |   n := 10u; | ||||||
|  |  | ||||||
| @@ -228,7 +228,7 @@ end | |||||||
|  |  | ||||||
| proc string_dup(origin: String) -> String; | proc string_dup(origin: String) -> String; | ||||||
| var | var | ||||||
|   copy: ^Char |   copy: ^Char; | ||||||
| begin | begin | ||||||
|   copy := cast(malloc(origin.length): ^Char); |   copy := cast(malloc(origin.length): ^Char); | ||||||
|   strncpy(copy, origin.ptr, origin.length); |   strncpy(copy, origin.ptr, origin.length); | ||||||
| @@ -238,7 +238,7 @@ end | |||||||
|  |  | ||||||
| proc string_buffer_new() -> StringBuffer; | proc string_buffer_new() -> StringBuffer; | ||||||
| var | var | ||||||
|   result: StringBuffer |   result: StringBuffer; | ||||||
| begin | begin | ||||||
|   result.capacity := 64u; |   result.capacity := 64u; | ||||||
|   result.data := malloc(result.capacity); |   result.data := malloc(result.capacity); | ||||||
| @@ -264,7 +264,7 @@ end | |||||||
|  |  | ||||||
| proc string_buffer_clear(buffer: ^StringBuffer) -> String; | proc string_buffer_clear(buffer: ^StringBuffer) -> String; | ||||||
| var | var | ||||||
|   result: String |   result: String; | ||||||
| begin | begin | ||||||
|   result := String(cast(buffer^.data: ^Char), buffer^.size); |   result := String(cast(buffer^.data: ^Char), buffer^.size); | ||||||
|   buffer^.size := 0u; |   buffer^.size := 0u; | ||||||
| @@ -283,7 +283,7 @@ end | |||||||
| proc read_source(filename: ^Char) -> ^SourceFile; | proc read_source(filename: ^Char) -> ^SourceFile; | ||||||
| var | var | ||||||
|   result: ^SourceFile; |   result: ^SourceFile; | ||||||
|   file_handle: ^FILE |   file_handle: ^FILE; | ||||||
| begin | begin | ||||||
|   file_handle := fopen(filename, "rb\0".ptr); |   file_handle := fopen(filename, "rb\0".ptr); | ||||||
|  |  | ||||||
| @@ -298,7 +298,7 @@ end | |||||||
|  |  | ||||||
| proc escape_char(escape: Char, result: ^Char) -> Bool; | proc escape_char(escape: Char, result: ^Char) -> Bool; | ||||||
| var | var | ||||||
|   successful: Bool |   successful: Bool; | ||||||
| begin | begin | ||||||
|   if escape = 'n' then |   if escape = 'n' then | ||||||
| 	result^ := '\n'; | 	result^ := '\n'; | ||||||
| @@ -344,7 +344,7 @@ end | |||||||
|  |  | ||||||
| proc source_file_empty(source_input: ^Byte) -> Bool; | proc source_file_empty(source_input: ^Byte) -> Bool; | ||||||
| var | var | ||||||
|   source_file: ^SourceFile |   source_file: ^SourceFile; | ||||||
| begin | begin | ||||||
|   source_file := cast(source_input: ^SourceFile); |   source_file := cast(source_input: ^SourceFile); | ||||||
|  |  | ||||||
| @@ -358,7 +358,7 @@ end | |||||||
|  |  | ||||||
| proc source_file_head(source_input: ^Byte) -> Char; | proc source_file_head(source_input: ^Byte) -> Char; | ||||||
| var | var | ||||||
|   source_file: ^SourceFile |   source_file: ^SourceFile; | ||||||
| begin | begin | ||||||
|   source_file := cast(source_input: ^SourceFile); |   source_file := cast(source_input: ^SourceFile); | ||||||
|  |  | ||||||
| @@ -367,7 +367,7 @@ end | |||||||
|  |  | ||||||
| proc source_file_advance(source_input: ^Byte); | proc source_file_advance(source_input: ^Byte); | ||||||
| var | var | ||||||
|   source_file: ^SourceFile |   source_file: ^SourceFile; | ||||||
| begin | begin | ||||||
|   source_file := cast(source_input: ^SourceFile); |   source_file := cast(source_input: ^SourceFile); | ||||||
|  |  | ||||||
| @@ -418,7 +418,7 @@ end | |||||||
|  |  | ||||||
| proc lex_identifier(source_code: ^SourceCode, token_content: ^StringBuffer); | proc lex_identifier(source_code: ^SourceCode, token_content: ^StringBuffer); | ||||||
| var | var | ||||||
|   content_length: Word |   content_length: Word; | ||||||
| begin | begin | ||||||
|   while ~source_code_empty(source_code) & is_ident(source_code_head(source_code^)) do |   while ~source_code_empty(source_code) & is_ident(source_code_head(source_code^)) do | ||||||
|     string_buffer_push(token_content, source_code_head(source_code^)); |     string_buffer_push(token_content, source_code_head(source_code^)); | ||||||
| @@ -428,7 +428,7 @@ end | |||||||
|  |  | ||||||
| proc lex_comment(source_code: ^SourceCode, token_content: ^StringBuffer) -> Bool; | proc lex_comment(source_code: ^SourceCode, token_content: ^StringBuffer) -> Bool; | ||||||
| var | var | ||||||
|   trailing: Word |   trailing: Word; | ||||||
| begin | begin | ||||||
|   trailing := 0u; |   trailing := 0u; | ||||||
|  |  | ||||||
| @@ -451,7 +451,7 @@ end | |||||||
|  |  | ||||||
| proc lex_character(source_code: ^SourceCode, token_content: ^Char) -> Bool; | proc lex_character(source_code: ^SourceCode, token_content: ^Char) -> Bool; | ||||||
| var | var | ||||||
|   successful: Bool |   successful: Bool; | ||||||
| begin | begin | ||||||
|   successful := ~source_code_empty(source_code); |   successful := ~source_code_empty(source_code); | ||||||
|  |  | ||||||
| @@ -476,7 +476,7 @@ var | |||||||
|   token_end, constructed_string: ^Char; |   token_end, constructed_string: ^Char; | ||||||
|   token_length: Word; |   token_length: Word; | ||||||
|   is_valid: Bool; |   is_valid: Bool; | ||||||
|   next_char: Char |   next_char: Char; | ||||||
| begin | begin | ||||||
|   is_valid := true; |   is_valid := true; | ||||||
|  |  | ||||||
| @@ -510,7 +510,7 @@ end | |||||||
| proc print_tokens(tokens: ^Token, tokens_size: Word); | proc print_tokens(tokens: ^Token, tokens_size: Word); | ||||||
| var | var | ||||||
|   current_token: ^Token; |   current_token: ^Token; | ||||||
|   i: Word |   i: Word; | ||||||
| begin | begin | ||||||
|   i := 0u; |   i := 0u; | ||||||
|   while i < tokens_size do |   while i < tokens_size do | ||||||
| @@ -658,7 +658,7 @@ end | |||||||
|  |  | ||||||
| proc categorize_identifier(token_content: String) -> Token; | proc categorize_identifier(token_content: String) -> Token; | ||||||
| var | var | ||||||
|   current_token: Token |   current_token: Token; | ||||||
| begin | begin | ||||||
|   if "if" = token_content then |   if "if" = token_content then | ||||||
| 	current_token.kind := TOKEN_IF | 	current_token.kind := TOKEN_IF | ||||||
| @@ -730,7 +730,7 @@ proc tokenize(source_code: SourceCode, tokens_size: ^Word) -> ^Token; | |||||||
| var | var | ||||||
|   tokens, current_token: ^Token; |   tokens, current_token: ^Token; | ||||||
|   first_char: Char; |   first_char: Char; | ||||||
|   token_buffer: StringBuffer |   token_buffer: StringBuffer; | ||||||
| begin | begin | ||||||
|   tokens_size^ := 0u; |   tokens_size^ := 0u; | ||||||
|   tokens := nil; |   tokens := nil; | ||||||
| @@ -907,7 +907,7 @@ proc parse_command_line*(argc: Int, argv: ^^Char) -> ^CommandLine; | |||||||
| var | var | ||||||
|   parameter: ^^Char; |   parameter: ^^Char; | ||||||
|   i: Int; |   i: Int; | ||||||
|   result: ^CommandLine |   result: ^CommandLine; | ||||||
| begin | begin | ||||||
|   i := 1; |   i := 1; | ||||||
|   result := cast(malloc(#size(CommandLine)): ^CommandLine); |   result := cast(malloc(#size(CommandLine)): ^CommandLine); | ||||||
| @@ -950,7 +950,7 @@ var | |||||||
|   tokens_size: Word; |   tokens_size: Word; | ||||||
|   source_code: SourceCode; |   source_code: SourceCode; | ||||||
|   command_line: ^CommandLine; |   command_line: ^CommandLine; | ||||||
|   return_code: Int |   return_code: Int; | ||||||
| begin | begin | ||||||
|   return_code := 0; |   return_code := 0; | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user