Passing arrays as arguments to functions working

This commit is contained in:
Krzosa Karol
2022-06-07 21:34:02 +02:00
parent b65a5f78bf
commit 5744da8899
4 changed files with 57 additions and 54 deletions

View File

@@ -35,10 +35,7 @@ int main(){
entry();
}
#line 0 "program.kl"
#line 1
#line 3
typedef struct Token{
U8 kind;
U8 *str;
@@ -47,61 +44,40 @@ typedef struct Token{
Number = 0,
};*/
}Token;
#line 12
String kind_name(U8 kind){
#line 15
if((kind==0)){
#line 14
return LIT("<Number>");
}
else{
#line 16
return LIT("<Unknown>");
}
}
#line 18
Bool is_numeric(U8 c){
#line 19
Bool result = ((c>=48)&&(c<=57));
#line 20
return result;
}
#line 22
void print_tokens(Slice tokens){
for(S64 i = 0;(i<tokens.len);(i++)){
Token *t = (&(((Token *)tokens.data)[i]));
printf("%d. %.*s", i, ((S32 )t->len), t->str);
}
}
void entry(){
#line 23
String string_to_lex = LIT("Identifier 2425525 Not_Number");
#line 24
Slice token_array = (Slice){32, (Token [32]){}};
#line 25
S64 token_count = 0;
#line 27
Token t;
#line 28
Token t = {};
for(S64 i = 0;(i<string_to_lex.len);i+=1){
#line 29
if(is_numeric((string_to_lex.str[i]))){
#line 30
t.kind=0;
#line 31
t.str=(&(string_to_lex.str[i]));
#line 32
t.len=i;
#line 33
for(;is_numeric((string_to_lex.str[i]));){
#line 34
i+=1;
}
#line 35
t.len=(i-t.len);
#line 36
(((Token *)token_array.data)[(token_count++)])=t;
}
}
#line 38
for(S64 i = 0;(i<token_count);(i++)){
#line 39
Token *tk = (&(((Token *)token_array.data)[i]));
#line 40
printf("%.*s", ((S32 )tk->len), tk->str);
}
print_tokens(token_array);
}