83 lines
1.6 KiB
C
83 lines
1.6 KiB
C
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
typedef int8_t S8;
|
|
typedef int16_t S16;
|
|
typedef int32_t S32;
|
|
typedef int64_t S64;
|
|
typedef uint8_t U8;
|
|
typedef uint16_t U16;
|
|
typedef uint32_t U32;
|
|
typedef uint64_t U64;
|
|
typedef S8 B8;
|
|
typedef S16 B16;
|
|
typedef S32 B32;
|
|
typedef S64 B64;
|
|
typedef U64 SizeU;
|
|
typedef S64 SizeS;
|
|
typedef float F32;
|
|
typedef double F64;
|
|
typedef S32 Bool;
|
|
|
|
typedef struct Slice{
|
|
S64 len;
|
|
void *data;
|
|
}Slice;
|
|
|
|
typedef struct String{
|
|
U8 *str;
|
|
S64 len;
|
|
}String;
|
|
#define LIT(x) (String){.str=(U8 *)x, .len=sizeof(x)-1}
|
|
|
|
void entry();
|
|
int main(){
|
|
entry();
|
|
}
|
|
|
|
|
|
typedef struct Token{
|
|
U8 kind;
|
|
U8 *str;
|
|
S64 len;
|
|
/*enum Kind{
|
|
Number = 0,
|
|
};*/
|
|
}Token;
|
|
String kind_name(U8 kind){
|
|
if((kind==0)){
|
|
return LIT("<Number>");
|
|
}
|
|
else{
|
|
return LIT("<Unknown>");
|
|
}
|
|
}
|
|
Bool is_numeric(U8 c){
|
|
Bool result = ((c>=48)&&(c<=57));
|
|
return result;
|
|
}
|
|
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(){
|
|
String string_to_lex = LIT("Identifier 2425525 Not_Number");
|
|
Slice token_array = (Slice){32, (Token [32]){}};
|
|
S64 token_count = 0;
|
|
Token t = {};
|
|
for(S64 i = 0;(i<string_to_lex.len);i+=1){
|
|
if(is_numeric((string_to_lex.str[i]))){
|
|
t.kind=0;
|
|
t.str=(&(string_to_lex.str[i]));
|
|
t.len=i;
|
|
for(;is_numeric((string_to_lex.str[i]));){
|
|
i+=1;
|
|
}
|
|
t.len=(i-t.len);
|
|
(((Token *)token_array.data)[(token_count++)])=t;
|
|
}
|
|
}
|
|
print_tokens(token_array);
|
|
} |