1
This commit is contained in:
parent
a4dd195f82
commit
20de320558
34
lexer.c
Normal file
34
lexer.c
Normal file
@ -0,0 +1,34 @@
|
||||
|
||||
Autoarr(Token)* lexan(char* source){
|
||||
Autoarr(Token)* tokens=malloc(sizeof(Autoarr(Token)));
|
||||
*tokens=Autoarr_create(Token,64,1024);
|
||||
char c;
|
||||
string label={source,0};
|
||||
|
||||
void addlabel(){
|
||||
if(label.length!=0) return;
|
||||
Unitype token=ST_pull_str(label);
|
||||
if(token.type==Null){
|
||||
//custom token
|
||||
}
|
||||
Autoarr_add(tokens, (*token.VoidPtr));
|
||||
label={source,0};
|
||||
};
|
||||
|
||||
addtok(TokenId id){
|
||||
Autoarr_add(tokens, default_tokens[id]);
|
||||
}
|
||||
|
||||
while ((c=*source++)) switch(c){
|
||||
case ' ': case '\t':
|
||||
case '\r': case '\n':
|
||||
addlabel();
|
||||
break;
|
||||
case '(':
|
||||
addlabel();
|
||||
addtok(tok_lbracket);
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user