subtypes
This commit is contained in:
parent
d65bb4ba56
commit
4acec63874
1
TODO
1
TODO
|
@ -13,6 +13,7 @@ Lexer
|
|||
* Preidentifiers --> (identifier|keyword)
|
||||
* Fix string type [DONE]
|
||||
* Fix operator type
|
||||
* EVERY lexeme should terminate at a NULL byte
|
||||
|
||||
Parser
|
||||
|
||||
|
|
8
lex.c
8
lex.c
|
@ -100,7 +100,13 @@ void lex_string(Lexer*l,char*s)
|
|||
//}
|
||||
break;
|
||||
case STRING:modematch("\"",true,false);break;
|
||||
case OPERATOR:modematch(operators,false,true);break;
|
||||
case OPERATOR:modematch(operators,false,true);
|
||||
if(s[i]==';')
|
||||
{
|
||||
((Tok*)l->tokens.buffer)[l->tokens.size-1].subtype=ENDSTATEMENT;
|
||||
// Terminate token now
|
||||
}
|
||||
break;
|
||||
case LCOMMENT:modematch("\n",true,true);break;
|
||||
|
||||
}
|
||||
|
|
5
lex.h
5
lex.h
|
@ -12,7 +12,8 @@
|
|||
|
||||
#define vec_pushl(v,l) do{Tok x=l;vec_push(v,&x);}while(0)
|
||||
|
||||
enum LEXTYPE {NONE, IDENTIFIER, INTEGER, FLOAT, STRING, OPERATOR, KEYWORD, LCOMMENT};
|
||||
enum LEXTYPE {NONE, IDENTIFIER, INTEGER, FLOAT, STRING, OPERATOR, KEYWORD, LCOMMENT, };
|
||||
enum LEXSUBTYPE {ENDSTATEMENT=55, };
|
||||
extern char*lextype_names[];
|
||||
|
||||
//typedef struct Tok
|
||||
|
@ -27,7 +28,7 @@ typedef struct Lexer
|
|||
uint32_t mode;
|
||||
} Lexer;
|
||||
|
||||
Lexer lex_new(void);
|
||||
Lexer lex_new();
|
||||
size_t lex_strchrcount(char*str,char c);
|
||||
void lex_free(Lexer*l);
|
||||
void lex_print(Lexer*l);
|
||||
|
|
17
pnode.c
17
pnode.c
|
@ -119,32 +119,23 @@ void parser_tokens(Parser*p,Vec*t)
|
|||
{
|
||||
Tok*tok=&((Tok*)t->buffer)[i];
|
||||
|
||||
// Push token
|
||||
//current_node->type=STATEMENT;
|
||||
vec_pushta(¤t_node->tokens,tok->str.buffer);
|
||||
tok_copy_nostr(&((Tok*)current_node->tokens.buffer)[current_node->tokens.size-1],tok);
|
||||
|
||||
if(tok->type==OPERATOR && tok->str.buffer[0]==';')
|
||||
{
|
||||
//current_node->type=STATEMENT;
|
||||
vec_pushta(¤t_node->tokens,tok->str.buffer);
|
||||
((Tok*)current_node->tokens.buffer)[current_node->tokens.size-1].line = tok->line;
|
||||
if(i<t->size-1)
|
||||
current_node=pnode_pushnode(&p->root);
|
||||
}
|
||||
|
||||
else if(tok->type==LCOMMENT && tok->str.buffer[0]=='#')
|
||||
else if(tok->type==LCOMMENT)
|
||||
{
|
||||
current_node->type=COMMENT;
|
||||
vec_pushta(¤t_node->tokens,tok->str.buffer);
|
||||
((Tok*)current_node->tokens.buffer)[current_node->tokens.size-1].line = tok->line;
|
||||
if(i<t->size-1)
|
||||
current_node=pnode_pushnode(&p->root);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
vec_pushta(¤t_node->tokens,tok->str.buffer);
|
||||
((Tok*)current_node->tokens.buffer)[current_node->tokens.size-1].line = tok->line;
|
||||
}
|
||||
//vec_pushta(&parser.root.tokens,(((Tok*)lexer.tokens.buffer)[i].str.buffer));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
10
tok.c
10
tok.c
|
@ -7,6 +7,7 @@ Tok tok_new(void)
|
|||
Tok t={
|
||||
.str=str_new(),
|
||||
.type=0,
|
||||
.subtype=0,
|
||||
.line=1,
|
||||
};
|
||||
|
||||
|
@ -18,3 +19,12 @@ void tok_free(Tok*t)
|
|||
if(!t)return;
|
||||
str_free(&t->str);
|
||||
}
|
||||
|
||||
// Copy everything but string !!!
|
||||
void tok_copy_nostr(Tok*dst,Tok*src)
|
||||
{
|
||||
if(!dst||!src)return;
|
||||
dst->type=src->type;
|
||||
dst->subtype=src->subtype;
|
||||
dst->line=src->line;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user