File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1010
1111int gen_header (gen_t * gen )
1212{
13- printf ("header\n" );
1413 if (fprintf (gen -> out , "section .text\n" ) < 0 )
1514 return ERROR ;
1615 if (fprintf (gen -> out , "\t\tglobal _start\n\n" ) < 0 )
Original file line number Diff line number Diff line change 1212#include <stdio.h>
1313#include <stdlib.h>
1414
15- static const char * get_keyword_token_str (token_type_t type )
16- {
17- if (type == TOK_INT )
18- return "TOK_INT" ;
19- if (type == TOK_RETURN )
20- return "TOK_RETURN" ;
21- if (type == TOK_IF )
22- return "TOK_IF" ;
23- if (type == TOK_ELSE )
24- return "TOK_ELSE" ;
25- if (type == TOK_WHILE )
26- return "TOK_WHILE" ;
27- if (type == TOK_FOR )
28- return "TOK_FOR" ;
29- if (type == TOK_IDENT )
30- return "TOK_IDENT" ;
31- return NULL ;
32- }
33-
34- static const char * get_operator_token_str (token_type_t type )
35- {
36- if (type == TOK_EQ )
37- return "TOK_EQ" ;
38- if (type == TOK_PLUS )
39- return "TOK_PLUS" ;
40- if (type == TOK_MINUS )
41- return "TOK_MINUS" ;
42- if (type == TOK_MUL )
43- return "TOK_MUL" ;
44- if (type == TOK_DIV )
45- return "TOK_DIV" ;
46- return NULL ;
47- }
48-
49- static const char * get_punctuation_token_str (token_type_t type )
50- {
51- if (type == TOK_SEMI )
52- return "TOK_SEMI" ;
53- if (type == TOK_LPAREN )
54- return "TOK_LPAREN" ;
55- if (type == TOK_RPAREN )
56- return "TOK_RPAREN" ;
57- if (type == TOK_LBRACE )
58- return "TOK_LBRACE" ;
59- if (type == TOK_RBRACE )
60- return "TOK_RBRACE" ;
61- if (type == TOK_COMMA )
62- return "TOK_COMMA" ;
63- if (type == TOK_EOF )
64- return "TOK_EOF" ;
65- if (type == TOK_VOID )
66- return "TOK_VOID" ;
67- if (type == TOK_NUMBER )
68- return "TOK_NUMBER" ;
69- return "TOK_UNKNOWN" ;
70- }
71-
72- static const char * get_token_type_str (token_type_t type )
73- {
74- const char * str = get_keyword_token_str (type );
75-
76- if (!str )
77- str = get_operator_token_str (type );
78- if (!str )
79- str = get_punctuation_token_str (type );
80- return str ;
81- }
82-
83- static int print_lexer (lexer_t * lexer )
84- {
85- token_t * token = NULL ;
86-
87- for (int i = 0 ; i < lexer -> tokens -> count ; i ++ ) {
88- token = (token_t * )lexer -> tokens -> data [i ];
89- printf ("Token %d: Type=%s, Value='%s'\n" , i ,
90- get_token_type_str (token -> type ), token -> value ? token -> value :
91- "NULL" );
92- }
93- return SUCCESS ;
94- }
95-
9615int lexer_run (char * buffer , lexer_t * lexer )
9716{
9817 if (lexer_tokenize (lexer , buffer ) == ERROR ) {
9918 free (buffer );
10019 return ERROR ;
10120 }
10221 free (buffer );
103- return print_lexer ( lexer ) ;
22+ return SUCCESS ;
10423}
Original file line number Diff line number Diff line change @@ -82,9 +82,9 @@ node_t *parse_sized_expression(parser_t *parser, int size)
8282 if (is_operator ) {
8383 node = parse_operator (parser , size );
8484 if (!node ) {
85- get_error (EPAR ,
86- "invalid operator in expression '%s'" ,
87- parser_peek ( parser ) ? parser_peek ( parser ) -> value : "end of input" );
85+ get_error (EPAR , "invalid operator in expression '%s'" ,
86+ parser_peek ( parser ) ? parser_peek ( parser ) -> value
87+ : "end of input" );
8888 return NULL ;
8989 }
9090 } else
You can’t perform that action at this time.
0 commit comments