Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 06-c-syntax-analyzer/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
a.out: yacc lex
gcc y.tab.c lex.yy.c print.c main.c -w
gcc -g y.tab.c lex.yy.c print.c main.c -w
yacc: yacc.y
yacc -d yacc.y
lex: lex.l
Expand Down
6 changes: 4 additions & 2 deletions 06-c-syntax-analyzer/func.h
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ A_ID *setFunctionDeclaratorSpecifier(A_ID *id, A_SPECIFIER *p) {
setDefaultSpecifier(p);

// check function identifier immediately before '('
if (id->type->kind != T_FUNC) {
if (id->type == 0 || id->type->kind != T_FUNC) {
syntax_error(21, NULL);
return (id);
} else {
Expand Down Expand Up @@ -453,7 +453,8 @@ A_TYPE *setTypeStructOrEnumIdentifier(T_KIND k, char *s, ID_KIND kk) {
a = searchIdentifierAtCurrentLevel(s, current_id);
if (a)
if (a->kind == kk && a->type->kind == k)
syntax_error(12, s);
if (a->type->field)
syntax_error(12, s);
else
return (a->type);
else
Expand Down Expand Up @@ -507,6 +508,7 @@ BOOLEAN isPointerOrArrayType(A_TYPE *t) {
return (FALSE);
}


void initialize() {
// primitive data types 노드 생성
int_type = setTypeAndKindOfDeclarator(makeType(T_ENUM), ID_TYPE, makeIdentifier("int"));
Expand Down
11 changes: 7 additions & 4 deletions 06-c-syntax-analyzer/lex.l
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ line [\n]
ws {delim}+

%{
#define YYSTYPE_IS_DECLARED 1
#define YYSTYPE long long

#include "y.tab.h"
#include "type.h"

extern int yylval;
extern YYSTYPE yylval;
extern int line_no;
extern A_ID *current_id;

Expand Down Expand Up @@ -70,9 +73,9 @@ while { return(WHILE_SYM); }
"\=" { return(ASSIGN); }

{digit}+ { yylval = atoi(yytext); return(INTEGER_CONSTANT); }
{digit}+\.{digit}+ { yylval = (int)makeString(yytext); return(FLOAT_CONSTANT); }
{digit}+\.{digit}+ { yylval = (YYSTYPE)makeString(yytext); return(FLOAT_CONSTANT); }
{letter}({letter}|{digit})* { return(checkIdentifier(yytext)); }
\"([^"\n]|\\["\n])*\" { yylval = (int)makeString(yytext); return(STRING_LITERAL); }
\"([^"\n]|\\["\n])*\" { yylval = (YYSTYPE)makeString(yytext); return(STRING_LITERAL); }
\'([^'\n]|\'\')\' { yylval = *(yytext+1); return(CHARACTER_CONSTANT); }
"//"[^\n]* { }

Expand All @@ -93,7 +96,7 @@ int checkIdentifier(char *s){
id = id->prev;
}
if (!id){
yylval = (int)makeString(s);
yylval = (YYSTYPE)makeString(s);
return(IDENTIFIER);
} else if (id->kind == ID_TYPE){
yylval = id->type;
Expand Down
Loading