@@ -357,6 +357,7 @@ void parse_if(TokenList* tokens, ObjectList* object_list, int* index, IfStatemen
357357 }
358358 (* index )++ ;
359359
360+ if_stmt -> line = get_token (tokens , * index )-> line ;
360361 if_stmt -> condition = parse_expression (tokens , object_list , index );
361362
362363 if (get_token (tokens , * index )-> type != TOKEN_END_OF_LINE ) {
@@ -401,6 +402,7 @@ void parse_if(TokenList* tokens, ObjectList* object_list, int* index, IfStatemen
401402
402403 ElifIfStatement elif ;
403404
405+ elif .line = get_token (tokens , * index )-> line ;
404406 elif .condition = parse_expression (tokens , object_list , index );
405407 if (get_token (tokens , * index )-> type != TOKEN_END_OF_LINE ) {
406408 printf ("Error: Invalid elif statement, expected end of line but found `%s` in line %d\n" , get_token (tokens , * index )-> value , get_token (tokens , * index )-> line );
@@ -440,6 +442,7 @@ void parse_while(TokenList* tokens, ObjectList* object_list, int* index, WhileLo
440442 }
441443 (* index )++ ;
442444
445+ while_loop -> line = get_token (tokens , * index )-> line ;
443446 while_loop -> condition = parse_expression (tokens , object_list , index );
444447
445448 if (get_token (tokens , * index )-> type != TOKEN_END_OF_LINE ) {
@@ -591,6 +594,28 @@ Node parse_expression(TokenList* tokens, ObjectList* object_list, int* index) {
591594 }
592595 } else if (token -> type == TOKEN_PARENTHESIS_OPEN ) {
593596 (* index )++ ;
597+ if (get_token (tokens , * index )-> type == TOKEN_KEYWORD_NOT ) {
598+ Token * op = get_token (tokens , * index );
599+ (* index )++ ;
600+
601+ Node inner = parse_expression (tokens , object_list , index );
602+ if (get_token (tokens , * index )-> type != TOKEN_PARENTHESIS_CLOSE ) {
603+ printf ("Error: Invalid token expression `%s` expected `)` for not operation in line %d\n" , token -> value , token -> line );
604+ exit (1 );
605+ }
606+ (* index )++ ;
607+
608+ Operation operation ;
609+ operation .is_not_operator = 1 ;
610+ operation .left = add_object (object_list , & inner , sizeof (Node ));
611+ operation .right = NULL ;
612+ operation .operator = op ;
613+
614+ node .type = NODE_OPERATION ;
615+ node .data = add_object (object_list , & operation , sizeof (Operation ));
616+ return node ;
617+ }
618+
594619 Node left = parse_expression (tokens , object_list , index );
595620 if (get_token (tokens , * index )-> type != TOKEN_PARENTHESIS_CLOSE ) {
596621 Token * op = get_token (tokens , * index );
@@ -609,6 +634,7 @@ Node parse_expression(TokenList* tokens, ObjectList* object_list, int* index) {
609634 (* index )++ ;
610635
611636 Operation operation ;
637+ operation .is_not_operator = 0 ;
612638 operation .left = add_object (object_list , & left , sizeof (Node ));
613639 operation .right = add_object (object_list , & right , sizeof (Node ));
614640 operation .operator = op ;
@@ -731,6 +757,12 @@ void debug_parser_node(Node* node) {
731757 printf (")" );
732758 } else if (node -> type == NODE_OPERATION ) {
733759 Operation * operation = (Operation * )node -> data ;
760+ if (operation -> is_not_operator ) {
761+ printf ("( not " );
762+ debug_parser_node (operation -> left );
763+ printf (") " );
764+ return ;
765+ }
734766 printf ("( " );
735767 debug_parser_node (operation -> left );
736768 printf ("%s " , operation -> operator -> value );
0 commit comments