Working on euler using the compiler + squashing bugs

This commit is contained in:
Krzosa Karol
2022-06-08 09:53:13 +02:00
parent 5744da8899
commit 87d6737a10
7 changed files with 116 additions and 102 deletions

View File

@@ -35,7 +35,10 @@ int main(){
entry();
}
#line 0 "program.kl"
#line 1
#line 3
typedef struct Token{
U8 kind;
U8 *str;
@@ -44,40 +47,66 @@ 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){
#line 23
for(S64 i = 0;(i<tokens.len);(i++)){
#line 24
Token *t = (&(((Token *)tokens.data)[i]));
#line 25
printf("%d. %.*s", i, ((S32 )t->len), t->str);
}
}
#line 27
void entry(){
#line 28
String string_to_lex = LIT("Identifier 2425525 Not_Number");
#line 29
Slice token_array = (Slice){32, (Token [32]){}};
#line 30
S64 token_count = 0;
#line 32
Token t = {};
#line 33
for(S64 i = 0;(i<string_to_lex.len);i+=1){
#line 34
if(is_numeric((string_to_lex.str[i]))){
#line 35
t.kind=0;
#line 36
t.str=(&(string_to_lex.str[i]));
#line 37
t.len=i;
#line 38
for(;is_numeric((string_to_lex.str[i]));){
#line 39
i+=1;
}
#line 40
t.len=(i-t.len);
#line 41
(((Token *)token_array.data)[(token_count++)])=t;
}
}
#line 42
print_tokens(token_array);
}