Allow multiple variable declarations with a single type
This commit is contained in:
62
source.elna
62
source.elna
@ -30,8 +30,8 @@ const
|
||||
TOKEN_NOT* = 25
|
||||
TOKEN_RETURN* = 26
|
||||
TOKEN_CAST* = 27
|
||||
TOKEN_AS* = 28
|
||||
TOKEN_SIZEOF* = 29
|
||||
TOKEN_SHIFT_LEFT* = 28
|
||||
TOKEN_SHIFT_RIGHT* = 29
|
||||
TOKEN_LEFT_PAREN* = 30
|
||||
TOKEN_RIGHT_PAREN* = 31
|
||||
TOKEN_LEFT_SQUARE* = 32
|
||||
@ -172,7 +172,8 @@ end
|
||||
|
||||
proc write_i(value: Int);
|
||||
var
|
||||
digit: Int, n: Word,
|
||||
digit: Int
|
||||
n: Word
|
||||
buffer: array 10 of Char
|
||||
begin
|
||||
n := 10u;
|
||||
@ -243,16 +244,14 @@ end
|
||||
*)
|
||||
|
||||
proc make_position() -> Position;
|
||||
var
|
||||
result: Position
|
||||
begin
|
||||
return Position(1u, 1u)
|
||||
end
|
||||
|
||||
proc read_source(filename: pointer to Char, result: pointer to String) -> Bool;
|
||||
var
|
||||
input_file: pointer to FILE,
|
||||
source_size: Int,
|
||||
input_file: pointer to FILE
|
||||
source_size: Int
|
||||
input: pointer to Byte
|
||||
begin
|
||||
input_file := fopen(filename, "rb\0".ptr);
|
||||
@ -276,8 +275,7 @@ begin
|
||||
if fread(input, cast(source_size: Word), 1u, input_file) <> 1u then
|
||||
return false
|
||||
end;
|
||||
result^.length := cast(source_size: Word);
|
||||
result^.ptr := cast(input: pointer to Char);
|
||||
result^ := String(cast(input: pointer to Char), cast(source_size: Word));
|
||||
|
||||
return true
|
||||
end
|
||||
@ -398,9 +396,8 @@ end
|
||||
|
||||
proc lex_string(input: pointer to Char, current_token: pointer to Token) -> pointer to Char;
|
||||
var
|
||||
token_end: pointer to Char,
|
||||
constructed_string: pointer to Char,
|
||||
token_length: Word,
|
||||
token_end, constructed_string: pointer to Char
|
||||
token_length: Word
|
||||
is_valid: Bool
|
||||
begin
|
||||
token_end := input;
|
||||
@ -438,7 +435,7 @@ end
|
||||
|
||||
proc print_tokens(tokens: pointer to Token, tokens_size: Word);
|
||||
var
|
||||
current_token: pointer to Token,
|
||||
current_token: pointer to Token
|
||||
i: Word
|
||||
begin
|
||||
i := 0u;
|
||||
@ -499,10 +496,10 @@ begin
|
||||
write_s("RETURN")
|
||||
elsif current_token^.kind = TOKEN_CAST then
|
||||
write_s("CAST")
|
||||
elsif current_token^.kind = TOKEN_AS then
|
||||
write_s("AS")
|
||||
elsif current_token^.kind = TOKEN_SIZEOF then
|
||||
write_s("SIZEOF")
|
||||
elsif current_token^.kind = TOKEN_SHIFT_LEFT then
|
||||
write_s("<<")
|
||||
elsif current_token^.kind = TOKEN_SHIFT_RIGHT then
|
||||
write_s(">>")
|
||||
elsif current_token^.kind = TOKEN_IDENTIFIER then
|
||||
write_c('<');
|
||||
write_s(current_token^.value.string);
|
||||
@ -641,10 +638,6 @@ begin
|
||||
current_token.kind := TOKEN_RETURN
|
||||
elsif "cast" = token_content then
|
||||
current_token.kind := TOKEN_CAST
|
||||
elsif "as" = token_content then
|
||||
current_token.kind := TOKEN_AS
|
||||
elsif "sizeof" = token_content then
|
||||
current_token.kind := TOKEN_SIZEOF
|
||||
elsif "defer" = token_content then
|
||||
current_token.kind := TOKEN_DEFER
|
||||
else
|
||||
@ -657,11 +650,10 @@ end
|
||||
|
||||
proc tokenize(source_code: SourceCode, tokens_size: pointer to Word) -> pointer to Token;
|
||||
var
|
||||
token_end: pointer to Char,
|
||||
tokens: pointer to Token,
|
||||
current_token: pointer to Token,
|
||||
token_length: Word,
|
||||
first_char: Char,
|
||||
token_end: pointer to Char
|
||||
tokens, current_token: pointer to Token
|
||||
token_length: Word
|
||||
first_char: Char
|
||||
token_content: String
|
||||
begin
|
||||
tokens_size^ := 0u;
|
||||
@ -740,6 +732,9 @@ begin
|
||||
elsif source_code.text[1u] = '=' then
|
||||
current_token^.kind := TOKEN_GREATER_EQUAL;
|
||||
source_code := advance_source(source_code, 1u)
|
||||
elsif source_code.text[1u] = '>' then
|
||||
current_token^.kind := TOKEN_SHIFT_RIGHT;
|
||||
source_code := advance_source(source_code, 1u)
|
||||
else
|
||||
current_token^.kind := TOKEN_GREATER_THAN
|
||||
end
|
||||
@ -751,6 +746,9 @@ begin
|
||||
elsif source_code.text[1u] = '=' then
|
||||
current_token^.kind := TOKEN_LESS_EQUAL;
|
||||
source_code := advance_source(source_code, 1u)
|
||||
elsif source_code.text[1u] = '<' then
|
||||
current_token^.kind := TOKEN_SHIFT_LEFT;
|
||||
source_code := advance_source(source_code, 1u)
|
||||
elsif source_code.text[1u] = '>' then
|
||||
current_token^.kind := TOKEN_NOT_EQUAL;
|
||||
source_code := advance_source(source_code, 1u)
|
||||
@ -850,7 +848,7 @@ end
|
||||
|
||||
proc parse_program(tokens: pointer to pointer to Token, tokens_size: pointer to Word) -> pointer to Program;
|
||||
var
|
||||
result: pointer to Program,
|
||||
result: pointer to Program
|
||||
current_constant: pointer to pointer to ConstantDefinition
|
||||
begin
|
||||
result := cast(calloc(1u, Program.size): pointer to Program);
|
||||
@ -883,8 +881,8 @@ end
|
||||
|
||||
proc parse_command_line*(argc: Int, argv: pointer to pointer to Char) -> pointer to CommandLine;
|
||||
var
|
||||
parameter: pointer to pointer to Char,
|
||||
i: Int,
|
||||
parameter: pointer to pointer to Char
|
||||
i: Int
|
||||
result: pointer to CommandLine
|
||||
begin
|
||||
i := 1;
|
||||
@ -924,9 +922,9 @@ end
|
||||
|
||||
proc process(argc: Int, argv: pointer to pointer to Char) -> Int;
|
||||
var
|
||||
tokens: pointer to Token,
|
||||
tokens_size: Word,
|
||||
source_code: SourceCode,
|
||||
tokens: pointer to Token
|
||||
tokens_size: Word
|
||||
source_code: SourceCode
|
||||
command_line: pointer to CommandLine
|
||||
begin
|
||||
command_line := parse_command_line(argc, argv);
|
||||
|
Reference in New Issue
Block a user