aboutsummaryrefslogtreecommitdiffstats
path: root/lexer.c
diff options
context:
space:
mode:
authorGalin Simeonov <gts@volconst.com>2021-05-17 17:29:08 +0300
committerGalin Simeonov <gts@volconst.com>2021-07-15 18:00:15 +0300
commitf768d9bdb84e846d89aac66a4f3433a44241c298 (patch)
treeb7e8248bebd80c8b1f911f666260ad52b7213b84 /lexer.c
parent679cbe58c4e53f0163588a7731154f3afe2d25aa (diff)
downloadMEGATRON-f768d9bdb84e846d89aac66a4f3433a44241c298.tar.gz
parser formed
Diffstat (limited to 'lexer.c')
-rw-r--r--lexer.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/lexer.c b/lexer.c
index 546c727..6dc348d 100644
--- a/lexer.c
+++ b/lexer.c
@@ -29,8 +29,6 @@ struct token* lex_step(struct Source *src,struct Translation_Data *translation_d
{
if(check_and_move_if_on_word("machine",sizeof("machine")-1,src,1))
return get_token(src->src+src->where_in_src-sizeof("machine")+1,sizeof("machine")-1,KW_MACHINE,src->current_row,src->current_column);
- if(check_and_move_if_on_word("state",sizeof("state")-1,src,1))
- return get_token(src->src+src->where_in_src-sizeof("state")+1,sizeof("state")-1,KW_STATE,src->current_row,src->current_column);
if(check_and_move_if_on_word("from",sizeof("from")-1,src,1))
return get_token(src->src+src->where_in_src-sizeof("from")+1,sizeof("from")-1,KW_FROM,src->current_row,src->current_column);
if(check_and_move_if_on_word("to",sizeof("to")-1,src,1))
@@ -39,6 +37,8 @@ struct token* lex_step(struct Source *src,struct Translation_Data *translation_d
return get_token(src->src+src->where_in_src-sizeof("on")+1,sizeof("on")-1,KW_ON,src->current_row,src->current_column);
if(check_and_move_if_on_word("[",sizeof("[")-1,src,0))
return get_token(src->src+src->where_in_src-sizeof("[")+1,sizeof("[")-1,KW_OPEN_SQUARE,src->current_row,src->current_column);
+ if(check_and_move_if_on_word(",",sizeof(",")-1,src,0))
+ return get_token(src->src+src->where_in_src-sizeof(",")+1,sizeof(",")-1,KW_COMMA,src->current_row,src->current_column);
if(check_and_move_if_on_word("]",sizeof("]")-1,src,0))
return get_token(src->src+src->where_in_src-sizeof("]")+1,sizeof("]")-1,KW_CLOSE_SQUARE,src->current_row,src->current_column);
if(check_and_move_if_on_word(";",sizeof(";")-1,src,0))
@@ -47,6 +47,16 @@ struct token* lex_step(struct Source *src,struct Translation_Data *translation_d
return get_token(src->src+src->where_in_src-sizeof("|")+1,sizeof("|")-1,KW_PIPE,src->current_row,src->current_column);
if(check_and_move_if_on_word("starting",sizeof("starting")-1,src,1))
return get_token(src->src+src->where_in_src-sizeof("starting")+1,sizeof("starting")-1,KW_STARTING,src->current_row,src->current_column);
+ if(check_and_move_if_on_word("states",sizeof("states")-1,src,1))
+ return get_token(src->src+src->where_in_src-sizeof("states")+1,sizeof("states")-1,KW_STATES,src->current_row,src->current_column);
+ if(check_and_move_if_on_word("events",sizeof("events")-1,src,1))
+ return get_token(src->src+src->where_in_src-sizeof("events")+1,sizeof("events")-1,KW_EVENTS,src->current_row,src->current_column);
+ if(check_and_move_if_on_word("execute",sizeof("execute")-1,src,1))
+ return get_token(src->src+src->where_in_src-sizeof("execute")+1,sizeof("execute")-1,KW_EXECUTE,src->current_row,src->current_column);
+ if(check_and_move_if_on_word("event",sizeof("event")-1,src,1))
+ return get_token(src->src+src->where_in_src-sizeof("event")+1,sizeof("event")-1,KW_EVENT,src->current_row,src->current_column);
+ if(check_and_move_if_on_word("transitions",sizeof("transitions")-1,src,1))
+ return get_token(src->src+src->where_in_src-sizeof("transitions")+1,sizeof("transitions")-1,KW_TRANSITIONS,src->current_row,src->current_column);
@@ -122,6 +132,7 @@ static char check_and_move_if_on_word(char *word,size_t word_size,struct Source
else if( (needs_space_after && isspace(src->src[src->where_in_src+i])) || !needs_space_after )
{
src->where_in_src+=i;
+ src->current_column+=i;
return 1;
}
else
@@ -132,6 +143,18 @@ static char check_and_move_if_on_word(char *word,size_t word_size,struct Source
void skip_white_space(struct Source *src)
{
while(src->where_in_src<src->src_size && isspace(src->src[src->where_in_src]))
+ {
+ if(src->src[src->where_in_src]=='\n')
+ {
+ ++src->current_row;
+ src->current_column=0;
+ }
++src->where_in_src;
+ }
+}
+
+void push_token_into_map(struct token *token,struct Map *map,void *thing)
+{
+ Map_Push(map,token->data,token->size,thing);
}
#endif