1818
1919#define NUM_RESERV_KEYWORDS 108
2020
21- char arrayPalavrasReservadas [][NUM_RESERV_KEYWORDS ] = {
21+ char array_reserverd_keywords [][NUM_RESERV_KEYWORDS ] = {
2222 "always" ,
2323 "and" ,
2424 "assign" ,
@@ -177,15 +177,15 @@ TokenClass get_token_class(const char* s_tok)
177177 int i ;
178178
179179 // IMPORTANT: keep track of the count here!
180- #define _QTD_CLASSES 48
180+ #define _QTD_CLASSES 71
181181 #define _MAX_STRLEN_IN_ARRAY 13
182182
183183 char from_str [_QTD_CLASSES ][_MAX_STRLEN_IN_ARRAY ] = {
184- "and" , // 1
185- "or" , // 2
186- "not" , // 3
187- "buf" ,
188- "nand" ,
184+ "and" , // 1
185+ "or" , // 2
186+ "not" , // 3
187+ "buf" , // 4
188+ "nand" , // 5
189189 "nor" ,
190190 "xor" ,
191191 "xnor" ,
@@ -228,6 +228,29 @@ TokenClass get_token_class(const char* s_tok)
228228 "|" , // = 45
229229 "^" ,
230230 "$" ,
231+ "**" ,
232+ ">" ,
233+ ">=" , // = 50
234+ "<" ,
235+ "<=" ,
236+ "&&" ,
237+ "||" ,
238+ "==" , // = 55
239+ "===" ,
240+ "!" ,
241+ "!=" ,
242+ "!==" ,
243+ "^~" , // = 60
244+ "~^" ,
245+ "~&" ,
246+ "~|" ,
247+ "<<" ,
248+ "<<<" , // = 65
249+ ">>" ,
250+ ">>>" ,
251+ "?:" ,
252+ "{{" ,
253+ "}}" ,
231254 "\x60" // = _QTD_CLASSES
232255 };
233256
@@ -271,14 +294,38 @@ TokenClass get_token_class(const char* s_tok)
271294 SYM_HASHTAG ,
272295 SYM_PLUS ,
273296 SYM_MINUS ,
274- SYM_ASTERISK , // = 40
297+ SYM_ASTERISK , // = 40
275298 SYM_SLASH ,
276299 SYM_PERCENT ,
277300 SYM_TILDE ,
278301 SYM_AMPERSAND ,
279- SYM_PIPE , // = 45
302+ SYM_PIPE , // = 45
280303 SYM_CIRCUMFLEX ,
281304 SYM_DOLLAR ,
305+ SYM_DOUBLE_ASTERISK ,
306+ SYM_GREATER_THAN ,
307+ SYM_GREATER_OR_EQUAL , // = 50
308+ SYM_LESS_THAN ,
309+ SYM_LESS_OR_EQUAL ,
310+ SYM_DOUBLE_AMPERSAND ,
311+ SYM_DOUBLE_PIPE ,
312+ SYM_DOUBLE_EQ , // = 55
313+ SYM_TRIPLE_EQ ,
314+ SYM_EXCLAMATION ,
315+ SYM_EXCLAMATION_EQ ,
316+ SYM_EXCLAMATION_DOUBLE_EQ ,
317+ SYM_CIRCUMFLEX_TILDE , // = 60
318+ SYM_TILDE_CIRCUMFLEX ,
319+ SYM_TILDE_AMPERSAND ,
320+ SYM_TILDE_PIPE ,
321+ SYM_DOUBLE_LESS_THAN ,
322+ SYM_TRIPLE_LESS_THAN , // = 65
323+ SYM_DOUBLE_GREATER_THAN ,
324+ SYM_TRIPLE_GREATER_THAN ,
325+ SYM_QUESTION_COLON ,
326+ SYM_DOUBLE_OPEN_BRACE ,
327+ SYM_DOUBLE_CLOSE_BRACE , // = 70
328+
282329 SYM_GRAVE_ACCENT // = _QTD_CLASSES
283330 };
284331
@@ -429,7 +476,7 @@ int remove_tokens_by_value(ListToken* lst, const char* tok)
429476 return 1 ;
430477}
431478
432- int is_symbol (char c )
479+ int is_single_char_symbol (char c )
433480{
434481 return (c == '(' ||
435482 c == ')' ||
@@ -456,8 +503,10 @@ int is_symbol(char c)
456503 c == '@' ||
457504 c == '$' ||
458505 c == '`' || // grave accent
459- c == '"' ||
460- c == '\'' );
506+ c == '"' || // double quote
507+ c == '\'' || // single quote
508+ c == '\%' || // percent sign
509+ c == '^' ); // circumflex
461510}
462511
463512void show_token_list (ListToken * tokens )
@@ -533,7 +582,7 @@ int is_reserverd_word(Token* tk)
533582
534583 for (i = 0 ; i < NUM_RESERV_KEYWORDS ; ++ i )
535584 {
536- if ( iguais (tk -> valor , arrayPalavrasReservadas [i ]) )
585+ if ( iguais (tk -> valor , array_reserverd_keywords [i ]) )
537586 return 1 ;
538587 }
539588
@@ -710,12 +759,172 @@ ListToken* tokeniza(FILE* arquivo)
710759
711760// B: a parte B do automato (na folha de papel)
712761
713- if (is_symbol (c )) {
714- // TODO: capture symbols larger than 1 char
762+ if ( is_single_char_symbol (c ) ) {
715763 symbols_capture_state :
716764 coluna ++ ;
717- insert_token_of_char (tokens , c , linha , coluna );
718- goto start_state ;
765+ char previous_c = c ;
766+
767+ switch (c )
768+ {
769+ case '*' :
770+ c = fgetc (arquivo );
771+ if (c == '*' ) {
772+ insert_token_of_string (tokens , "**" , linha , coluna );
773+ coluna += 2 ;
774+ goto start_state ;
775+ }
776+ break ;
777+ case '<' :
778+ c = fgetc (arquivo );
779+ if (c == '=' ) {
780+ insert_token_of_string (tokens , "<=" , linha , coluna );
781+ coluna += 2 ;
782+ goto start_state ;
783+ }
784+ else if (c == '<' ) {
785+ c = fgetc (arquivo );
786+ if (c == '<' ) {
787+ insert_token_of_string (tokens , "<<<" , linha , coluna );
788+ coluna += 3 ;
789+ goto start_state ;
790+ }
791+ else {
792+ ungetc (c , arquivo );
793+ }
794+ insert_token_of_string (tokens , "<<" , linha , coluna );
795+ coluna += 2 ;
796+ goto start_state ;
797+ }
798+ break ;
799+ case '>' :
800+ c = fgetc (arquivo );
801+ if (c == '=' ) {
802+ insert_token_of_string (tokens , ">=" , linha , coluna );
803+ coluna += 2 ;
804+ goto start_state ;
805+ }
806+ else if (c == '>' ) {
807+ c = fgetc (arquivo );
808+ if (c == '>' ) {
809+ insert_token_of_string (tokens , ">>>" , linha , coluna );
810+ coluna += 3 ;
811+ goto start_state ;
812+ }
813+ else {
814+ ungetc (c , arquivo );
815+ }
816+ insert_token_of_string (tokens , ">>" , linha , coluna );
817+ coluna += 2 ;
818+ goto start_state ;
819+ }
820+ break ;
821+ case '&' :
822+ c = fgetc (arquivo );
823+ if (c == '&' ) {
824+ insert_token_of_string (tokens , "&&" , linha , coluna );
825+ coluna += 2 ;
826+ goto start_state ;
827+ }
828+ break ;
829+ case '|' :
830+ c = fgetc (arquivo );
831+ if (c == '|' ) {
832+ insert_token_of_string (tokens , "||" , linha , coluna );
833+ coluna += 2 ;
834+ goto start_state ;
835+ }
836+ break ;
837+ case '=' :
838+ c = fgetc (arquivo );
839+ if (c == '=' ) {
840+ c = fgetc (arquivo );
841+ if (c == '=' ) {
842+ insert_token_of_string (tokens , "===" , linha , coluna );
843+ coluna += 3 ;
844+ goto start_state ;
845+ }
846+ else {
847+ ungetc (c , arquivo );
848+ }
849+ insert_token_of_string (tokens , "==" , linha , coluna );
850+ coluna += 2 ;
851+ goto start_state ;
852+ }
853+ break ;
854+ case '!' :
855+ c = fgetc (arquivo );
856+ if (c == '=' ) {
857+ c = fgetc (arquivo );
858+ if (c == '=' ) {
859+ insert_token_of_string (tokens , "!==" , linha , coluna );
860+ coluna += 3 ;
861+ goto start_state ;
862+ }
863+ else {
864+ ungetc (c , arquivo );
865+ }
866+ insert_token_of_string (tokens , "!=" , linha , coluna );
867+ coluna += 2 ;
868+ goto start_state ;
869+ }
870+ break ;
871+ case '^' :
872+ c = fgetc (arquivo );
873+ if (c == '~' ) {
874+ insert_token_of_string (tokens , "^~" , linha , coluna );
875+ coluna += 2 ;
876+ goto start_state ;
877+ }
878+ break ;
879+ case '~' :
880+ c = fgetc (arquivo );
881+ if (c == '^' ) {
882+ insert_token_of_string (tokens , "~^" , linha , coluna );
883+ coluna += 2 ;
884+ goto start_state ;
885+ }
886+ else if (c == '&' ) {
887+ insert_token_of_string (tokens , "~&" , linha , coluna );
888+ coluna += 2 ;
889+ goto start_state ;
890+ }
891+ else if (c == '|' ) {
892+ insert_token_of_string (tokens , "~|" , linha , coluna );
893+ coluna += 2 ;
894+ goto start_state ;
895+ }
896+ break ;
897+ case '?' :
898+ c = fgetc (arquivo );
899+ if (c == ':' ) {
900+ insert_token_of_string (tokens , "?:" , linha , coluna );
901+ coluna += 2 ;
902+ goto start_state ;
903+ }
904+ break ;
905+ case '{' :
906+ c = fgetc (arquivo );
907+ if (c == '{' ) {
908+ insert_token_of_string (tokens , "{{" , linha , coluna );
909+ coluna += 2 ;
910+ goto start_state ;
911+ }
912+ break ;
913+ case '}' :
914+ c = fgetc (arquivo );
915+ if (c == '}' ) {
916+ insert_token_of_string (tokens , "}}" , linha , coluna );
917+ coluna += 2 ;
918+ goto start_state ;
919+ }
920+ break ;
921+ default :
922+ insert_token_of_char (tokens , c , linha , coluna );
923+ goto start_state ;
924+ }
925+
926+ insert_token_of_char (tokens , previous_c , linha , coluna );
927+ goto start_after_getc_state ;
719928 }
720929
721930 if ( !isalnum (c ) && c != '_' ) {
@@ -746,7 +955,7 @@ ListToken* tokeniza(FILE* arquivo)
746955 insert_token_of_string (tokens , tok , linha , coluna - len (tok ));
747956 goto comments_state ;
748957 }
749- else if (is_symbol (c )) {
958+ else if (is_single_char_symbol (c )) {
750959 insert_token_of_string (tokens , tok , linha , coluna - len (tok ));
751960 goto symbols_capture_state ;
752961 }
0 commit comments