@@ -143,10 +143,6 @@ token* lexer::read_token() {
143143 case 303295209 :
144144 return last_tok = new token (TOKEN_END_GROUP);
145145 default : {
146- if (lexer_state->constants .count (hash)) {
147- delete[] id_buf;
148- return last_tok = new value_token ((*lexer_state->constants .find (hash)).second ->clone ());
149- }
150146 return last_tok = new identifier_token (id_buf, hash);
151147 }
152148 }
@@ -309,9 +305,10 @@ std::list<token*> lexer::tokenize(bool interactive_mode) {
309305 if (tok != nullptr )
310306 tokens.push_back (tok);
311307 }
312- if (!eos ()) {
308+ if (!eos ())
313309 match_tok (last_tok, TOKEN_CLOSE_BRACE);
314- }
310+ if (interactive_mode)
311+ lexer_state->group_all_references ();
315312 return tokens;
316313}
317314
@@ -330,6 +327,7 @@ token* lexer::tokenize_statement(bool interactive_mode) {
330327 return nullptr ;
331328 }
332329 case TOKEN_END_GROUP:{
330+ delete last_tok;
333331 lexer_state->pop_group ();
334332
335333 read_token ();
@@ -340,16 +338,29 @@ token* lexer::tokenize_statement(bool interactive_mode) {
340338 delete last_tok;
341339 match_tok (read_token (), TOKEN_IDENTIFIER);
342340 identifier_token* id = (identifier_token*)last_tok;
341+ lexer_state->declare_id (id, GROUP_TYPE_VAR);
343342 match_tok (read_token (), TOKEN_SET);
344343 delete last_tok;
345344 match_tok (read_token (), TOKEN_VALUE);
346345 value_token* value_tok = (value_token*)last_tok;
347- lexer_state->constants . insert (std::pair< unsigned long , value*>( id->id_hash , value_tok-> get_value ())) ;
346+ lexer_state->constants [ id->id_hash ] = value_tok;
348347 delete id;
349- delete value_tok;
350348 read_token ();
351349 return nullptr ;
352350 }
351+ case TOKEN_STATIC_KW: {
352+ delete last_tok;
353+ match_tok (read_token (), TOKEN_IDENTIFIER);
354+ identifier_token* id = (identifier_token*)last_tok;
355+ lexer_state->declare_id (id, GROUP_TYPE_VAR);
356+ match_tok (read_token (), TOKEN_SET);
357+ delete last_tok;
358+ read_token ();
359+ token* val_tok = tokenize_expression ();
360+ std::list<token*> modifiers;
361+ modifiers.push_back (id);
362+ return new set_token (new variable_access_token (modifiers), val_tok, true );
363+ }
353364 case TOKEN_BREAK: {
354365 token* tok = last_tok;
355366 read_token ();
@@ -362,8 +373,10 @@ token* lexer::tokenize_statement(bool interactive_mode) {
362373 char * buf = new char [create_str->values .size () + 1 ];
363374 unsigned char size = 0 ;
364375 for (auto it = create_str->values .begin (); it != create_str->values .end (); ++it) {
365- value_token* val = (value_token*)*it;
366- buf[size++] = *val->get_value ()->get_char ();
376+ value_token* val_tok = (value_token*)*it;
377+ value* val = val_tok->get_value ();
378+ buf[size++] = *val->get_char ();
379+ delete val;
367380 }
368381 buf[size] = 0 ;
369382 delete create_str;
@@ -428,6 +441,7 @@ token* lexer::tokenize_statement(bool interactive_mode) {
428441 delete last_tok;
429442 match_tok (read_token (), TOKEN_IDENTIFIER);
430443 identifier_token* proto_id = (identifier_token*)last_tok;
444+ lexer_state->declare_id (proto_id, GROUP_TYPE_STRUCT);
431445 match_tok (read_token (), TOKEN_OPEN_BRACE);
432446 delete last_tok;
433447 std::list<identifier_token*> properties;
@@ -440,13 +454,13 @@ token* lexer::tokenize_statement(bool interactive_mode) {
440454 throw ERROR_UNEXPECTED_END;
441455 delete last_tok;
442456 read_token ();
443- lexer_state->declare_id (proto_id);
444457 return new structure_prototype (proto_id, properties);
445458 }
446459 case TOKEN_FUNC_KW: {
447460 delete last_tok;
448461 match_tok (read_token (), TOKEN_IDENTIFIER);
449462 identifier_token* proto_id = (identifier_token*)last_tok;
463+ lexer_state->declare_id (proto_id, GROUP_TYPE_FUNC);
450464 match_tok (read_token (), TOKEN_OPEN_PARAM);
451465 delete last_tok;
452466 std::list<identifier_token*> params;
@@ -458,26 +472,14 @@ token* lexer::tokenize_statement(bool interactive_mode) {
458472 }
459473 match_tok (last_tok, TOKEN_IDENTIFIER);
460474 params.push_back ((identifier_token*)last_tok);
475+ lexer_state->declare_id ((identifier_token*)last_tok, GROUP_TYPE_VAR);
461476 }
462477 if (eos ())
463478 throw ERROR_UNEXPECTED_TOKEN;
464479 delete last_tok;
465480 read_token ();
466- lexer_state->declare_id (proto_id);
467481 return new function_prototype (proto_id, params, tokenize_body ());
468482 }
469- case TOKEN_STATIC_KW: {
470- delete last_tok;
471- match_tok (read_token (), TOKEN_IDENTIFIER);
472- identifier_token* id = (identifier_token*)last_tok;
473- match_tok (read_token (), TOKEN_SET);
474- delete last_tok;
475- read_token ();
476- token* val_tok = tokenize_expression ();
477- std::list<token*> modifiers;
478- modifiers.push_back (id);
479- return new set_token (new variable_access_token (modifiers), val_tok, true );
480- }
481483 }
482484 throw ERROR_UNEXPECTED_TOKEN;
483485}
@@ -556,11 +558,15 @@ token* lexer::tokenize_value() {
556558 match_tok (last_tok, TOKEN_CLOSE_PARAM);
557559 delete last_tok;
558560 read_token ();
559- this ->lexer_state ->reference_id (identifier);
561+ this ->lexer_state ->reference_id (identifier, GROUP_TYPE_FUNC );
560562 return new function_call_token (identifier, arguments);
561563 }
562564 else
563565 {
566+ if (last_tok->type == TOKEN_SET)
567+ this ->lexer_state ->declare_id (identifier, GROUP_TYPE_VAR);
568+ else
569+ this ->lexer_state ->reference_id (identifier, GROUP_TYPE_VAR);
564570 variable_access_token* var_access = tokenize_var_access (identifier);
565571 if (last_tok->type == OP_INCRIMENT) {
566572 delete last_tok;
@@ -578,12 +584,19 @@ token* lexer::tokenize_value() {
578584 token* to_set = tokenize_expression ();
579585 return new set_token (var_access, to_set, false );
580586 }
587+
588+ if (var_access->modifiers .size () <= 1 && lexer_state->constants .count (identifier->id_hash )) {
589+ unsigned long hash = identifier->id_hash ;
590+ delete var_access;
591+ return new value_token (lexer_state->constants [hash]->get_value ());
592+ }
581593 return var_access;
582594 }
583595 }
584596 else if (last_tok->type == TOKEN_REF_KW) {
585597 delete last_tok;
586598 match_tok (read_token (), TOKEN_IDENTIFIER);
599+ lexer_state->reference_id ((identifier_token*)last_tok, GROUP_TYPE_VAR);
587600 get_reference_token* get_ref_tok = new get_reference_token (tokenize_var_access ());
588601 return get_ref_tok;
589602 }
@@ -622,7 +635,7 @@ token* lexer::tokenize_value() {
622635 delete last_tok;
623636 match_tok (read_token (), TOKEN_IDENTIFIER);
624637 create_struct_token* new_struct = new create_struct_token ((identifier_token*)last_tok);
625- this ->lexer_state ->reference_id (new_struct->identifier );
638+ this ->lexer_state ->reference_id (new_struct->identifier , GROUP_TYPE_STRUCT );
626639 read_token ();
627640 return new_struct;
628641 }
@@ -656,29 +669,4 @@ token* lexer::tokenize_expression(unsigned char min) {
656669 lhs = new binary_operator_token (lhs, rhs, op);
657670 }
658671 return lhs;
659- }
660-
661- void group::proc_id (identifier_token* id) {
662- std::list<char > chars;
663-
664- for (int i = 0 ; i < strlen (id->get_identifier ()); i++)
665- chars.push_back (id->get_identifier ()[i]);
666-
667- group* current = this ;
668- while (current != nullptr )
669- {
670- chars.push_back (' @' );
671- for (int i = 0 ; i < strlen (identifier->get_identifier ()); i++)
672- chars.push_back (identifier->get_identifier ()[i]);
673- current = current->parent ;
674- }
675-
676- char * new_buf = new char [chars.size () + 1 ];
677- unsigned long in = 0 ;
678- for (auto i = chars.begin (); i != chars.end (); ++i) {
679- new_buf[in++] = *i;
680- }
681- new_buf[in] = 0 ;
682-
683- id->set_c_str (new_buf);
684672}
0 commit comments