From c57b2c85d2377f201645ee0603e532c1151b98af Mon Sep 17 00:00:00 2001 From: daeun Date: Wed, 17 Dec 2025 19:34:18 +0900 Subject: [PATCH 1/9] feat(gen): initial commit --- 08-code-generator/Makefile | 9 + 08-code-generator/func.c | 567 +++++ 08-code-generator/func.h | 42 + 08-code-generator/gen_func.c | 0 08-code-generator/gen_func.h | 0 08-code-generator/interp | Bin 0 -> 50360 bytes 08-code-generator/interpreter/interp.c | 289 +++ 08-code-generator/interpreter/interp.l | 57 + 08-code-generator/interpreter/interp.y | 253 +++ 08-code-generator/interpreter/lex.yy.c | 1861 +++++++++++++++ 08-code-generator/interpreter/lib.c | 119 + 08-code-generator/interpreter/type.h | 14 + 08-code-generator/interpreter/y.tab.c | 1606 +++++++++++++ 08-code-generator/interpreter/y.tab.h | 106 + 08-code-generator/lex.l | 108 + 08-code-generator/lex.yy.c | 2143 ++++++++++++++++++ 08-code-generator/main.c | 53 + 08-code-generator/sem_func.c | 1324 +++++++++++ 08-code-generator/sem_func.h | 55 + 08-code-generator/type.h | 124 + 08-code-generator/y.tab.c | 2885 ++++++++++++++++++++++++ 08-code-generator/y.tab.h | 192 ++ 08-code-generator/yacc.y | 358 +++ 23 files changed, 12165 insertions(+) create mode 100644 08-code-generator/Makefile create mode 100644 08-code-generator/func.c create mode 100644 08-code-generator/func.h create mode 100644 08-code-generator/gen_func.c create mode 100644 08-code-generator/gen_func.h create mode 100755 08-code-generator/interp create mode 100644 08-code-generator/interpreter/interp.c create mode 100644 08-code-generator/interpreter/interp.l create mode 100644 08-code-generator/interpreter/interp.y create mode 100644 08-code-generator/interpreter/lex.yy.c create mode 100644 08-code-generator/interpreter/lib.c create mode 100644 08-code-generator/interpreter/type.h create mode 100644 08-code-generator/interpreter/y.tab.c create mode 100644 08-code-generator/interpreter/y.tab.h create mode 100644 08-code-generator/lex.l create mode 100644 08-code-generator/lex.yy.c create mode 100644 08-code-generator/main.c create mode 100644 08-code-generator/sem_func.c create mode 100644 08-code-generator/sem_func.h create mode 100644 08-code-generator/type.h create mode 100644 08-code-generator/y.tab.c create mode 100644 08-code-generator/y.tab.h create mode 100644 08-code-generator/yacc.y diff --git a/08-code-generator/Makefile b/08-code-generator/Makefile new file mode 100644 index 0000000..0ba6866 --- /dev/null +++ b/08-code-generator/Makefile @@ -0,0 +1,9 @@ +a.out: yacc lex + gcc -g y.tab.c lex.yy.c func.c sem_func.c gen_func.c main.c -w +yacc: yacc.y + yacc -d yacc.y +lex: lex.l + lex lex.l + +make clean: + rm a.out \ No newline at end of file diff --git a/08-code-generator/func.c b/08-code-generator/func.c new file mode 100644 index 0000000..94cc0f7 --- /dev/null +++ b/08-code-generator/func.c @@ -0,0 +1,567 @@ +#include +#include +#include "type.h" +#include "func.h" + +extern char *yytext; + +A_TYPE *int_type, *char_type, *void_type, *float_type, *string_type; +A_NODE *root; +A_ID *current_id = NIL; + +int syntax_err = 0; +int line_no = 1; +int current_level = 0; + +// Make new node for syntax tree +A_NODE *makeNode(NODE_NAME n, A_NODE *a, A_NODE *b, A_NODE *c) { + A_NODE *m; + // allocate new node + m = (A_NODE *)malloc(sizeof(A_NODE)); + // node 초기화 + m->name = n; + // link + m->llink = a; + m->clink = b; + m->rlink = c; + + m->type = NIL; // 초기값 + m->line = line_no; // 현재 line number + m->value = 0; // 초기값 + + return (m); // 초기화한 node 반환 +} +// Node를 리스트 형태로 구현 +/* + a + ... + / \ + k (name: n) (leaf-> list) + / \ + b m (m->name = k->name) +*/ +A_NODE *makeNodeList(NODE_NAME n, A_NODE *a, A_NODE *b){ + A_NODE *m, *k; + k = a; + while (k -> rlink) + k = k-> rlink; // leaf 노드로 이동 + m = (A_NODE*) malloc(sizeof(A_NODE)); // new node + m -> name = k -> name; + m -> llink = NIL; + m -> clink = NIL; + m -> rlink = NIL; + m -> type = NIL; + m -> line = line_no; + m -> value = 0; + k -> name = n; + k -> llink = b; + k -> rlink = m; + return(a); +} +// make a new declarator for identifier +A_ID *makeIdentifier(char *s) { + A_ID *id; + id = (A_ID*)malloc(sizeof(A_ID)); // new id 생성 + // 초기화 + id->name = s; + id->kind = (ID_KIND)0; + id->specifier = (S_KIND)0; + id->level = current_level; + id->address = 0; + id->init = NIL; + id->type = NIL; + id->link = NIL; + id->line = line_no; + id->value = 0; + // linked list 연결 + id->prev = current_id; + current_id = id; + + return(id); +} +// make a new declarator for dummy identifier +A_ID *makeDummyIdentifier() { + A_ID *id; + id = (A_ID*)malloc(sizeof(A_ID)); // new id 생성 + // 초기화 + id->name = ""; + id->kind = (ID_KIND)0; + id->specifier = (S_KIND)0; + id->level = current_level; + id->address = 0; + id->init = NIL; + id->type = NIL; + id->link = NIL; + id->line = line_no; + id->value = 0; + id->prev = 0; + + return(id); +} +// make a new type +A_TYPE *makeType(T_KIND k) { // 새로운 타입테이블 생성 + A_TYPE *t; + t = (A_TYPE *)malloc(sizeof(A_TYPE)); + // 초기화 + t->kind = k; + t->size = 0; + t->local_var_size = 0; + t->element_type = NIL; + t->field = NIL; + t->expr = NIL; + t->check = FALSE; + t->prt = FALSE; + t->line = line_no; + return(t); +} +// make a new specifier +A_SPECIFIER *makeSpecifier(A_TYPE *t, S_KIND s) { + A_SPECIFIER *p; + p = (A_SPECIFIER *)malloc(sizeof(A_SPECIFIER)); + p->type = t; + p->stor = s; + p->line = line_no; + return(p); +} +A_ID *searchIdentifier(char *s, A_ID *id) { + while (id) { // id list 조회 + if (strcmp(id->name, s) == 0) // 일치하면 탐색 종료 + break; + id = id->prev; + } + return(id); +} +// current level에서 일치하는 identifier 찾기 +A_ID *searchIdentifierAtCurrentLevel(char *s, A_ID *id) { + while (id) { + if (id->level < current_level) + return(NIL); // id의 level이 current level보다 낮으면 탐색 종료 + if (strcmp(id->name, s) == 0) + break; + id = id->prev; + } + return(id); +} +void checkForwardReference() { // 전방 참조 + A_ID *id; + A_TYPE *t; + id = current_id; + while (id) { + if (id->level < current_level) + break; // id의 level이 current level보다 낮으면 탐색 종료 + t = id->type; + if (id->kind == ID_NULL) + syntax_error(31, id->name); + else if ((id->kind == ID_STRUCT || id->kind == ID_ENUM) && t->field == NIL) + syntax_error(32, id->name); + id = id->prev; + } +} +// set default specifier +void setDefaultSpecifier(A_SPECIFIER *p) { + A_TYPE *t; + if (p->type == NIL) + p->type = int_type; // default: int + if (p->stor == S_NULL) + p->stor = S_AUTO; // default: AUTO +} +// merge & update specifier +A_SPECIFIER *updateSpecifier(A_SPECIFIER *p, A_TYPE *t, S_KIND s) { + if (t) + if (p->type) + if (p->type == t) + ; + else + syntax_error(24, NULL); + else + p->type = t; + if (s) { + if (p->stor) + if (s == p->stor) + ; + else + syntax_error(24, NULL); + else + p->stor = s; + } + return(p); +} +// link two declarator list id1 & id2 +A_ID *linkDeclaratorList(A_ID *id1, A_ID *id2) { + A_ID *m = id1; + if (id1 == NIL) + return(id2); + while (m->link) + m = m->link; + m->link = id2; + return(id1); +} + +// check if identifier is already declared in primary expression +A_ID *getIdentifierDeclared(char *s) { // 선언 여부 + // 이미 선언된 identifier를 리턴하여 노드에 연결 + A_ID *id; + id = searchIdentifier(s, current_id); + if (id == NIL) + syntax_error(13, s); + return(id); +} + +// get type of struct identifier +A_TYPE *getTypeOfStructOrEnumRefIdentifier(T_KIND k, char *s, ID_KIND kk) { + A_TYPE *t; + A_ID *id; + id = searchIdentifier(s, current_id); + if (id) + if (id->kind == kk && id->type->kind == k) // 이전에 불완전 선언한 struct, enum과 동일하면 + return(id->type); + else + syntax_error(11, s); + // make a new struct (or enum) identifier + t = makeType(k); + id = makeIdentifier(s); + id->kind = (ID_KIND)k; + id->type = (A_TYPE *)t; + return(t); +} + +// set declarator init (expression tree) +A_ID *setDeclaratorInit(A_ID *id, A_NODE *n) { + id->init = n; + return(id); +} + +// set declarator kind +A_ID *setDeclaratorKind(A_ID *id, ID_KIND k) { + A_ID *a; + a= searchIdentifierAtCurrentLevel(id->name, id->prev); + if (a) // 선언 x + syntax_error(12, id->name); + id->kind = k; + return(id); +} + +// set declarator type +A_ID *setDeclaratorType(A_ID *id, A_TYPE *t) { + id->type = t; + return(id); +} + +// set declarator type (or element type) +A_ID *setDeclaratorElementType(A_ID *id, A_TYPE *t) { + A_TYPE *tt; + if (id->type == NIL) + id->type = t; + else { + tt = id->type; + while (tt->element_type) + tt = tt->element_type; + tt->element_type = t; + } + return(id); +} + +// set declarator element type and kind +A_ID *setDeclaratorTypeAndKind(A_ID *id, A_TYPE *t, ID_KIND k) { + id = setDeclaratorElementType(id, t); + id = setDeclaratorKind(id, k); + return(id); +} + +// check function declarator and return type +A_ID *setFunctionDeclaratorSpecifier(A_ID *id, A_SPECIFIER *p) { + A_ID *a; + + // check storage class + if (p->stor) + syntax_error(25, NULL); + setDefaultSpecifier(p); // return type이 없는 경우 int형으로 지정 + + // check function identifier immediately before '(' + if (id->type == 0 || id->type->kind != T_FUNC) { + syntax_error(21, NULL); + return(id); + } else { + id = setDeclaratorElementType(id, p->type); // 함수의 리턴 타입 결정 + id->kind = ID_FUNC; + } + + // check redeclaration + a = searchIdentifierAtCurrentLevel(id->name, id->prev); + if (a) + if (a->kind != ID_FUNC || a->type->expr) + syntax_error(12, id->name); + else { // check prototype: parameters and return type + if (isNotSameFormalParameters(a->type->field, id->type->field)) + syntax_error(22, id->name); + if (isNotSameType(a->type->element_type, id->type->element_type)) + syntax_error(26, a->name); + } + + // change parameter scope and check empty name + a = id->type->field; + while (a) { + if (strlen(a->name)) + current_id = a; + else if (a->type) + syntax_error(23, NULL); + a = a->link; + } + return(id); +} + +A_ID *setFunctionDeclaratorBody(A_ID *id, A_NODE *n) { + id->type->expr = n; + return(id); +} + +// set declarator_list type and kind based on storage class +A_ID *setDeclaratorListSpecifier(A_ID *id, A_SPECIFIER *p) { + A_ID *a; + setDefaultSpecifier(p); + + a = id; + while (a) { + if (strlen(a->name) && searchIdentifierAtCurrentLevel(a->name, a->prev)) + syntax_error(12, a->name); // 중복 error + a = setDeclaratorElementType(a, p->type); + if (p->stor == S_TYPEDEF) + a->kind = ID_TYPE; // typedef 키워드 -> ID_TYPE + else if (a->type->kind == T_FUNC) + a->kind = ID_FUNC; + else + a->kind = ID_VAR; + a->specifier = p->stor; + + if (a->specifier == S_NULL) + a->specifier = S_AUTO; // default storage_class auto + a = a->link; + } + return(id); +} + +// set declarator_list type and kind +A_ID *setParameterDeclaratorSpecifier(A_ID *id, A_SPECIFIER *p) { + // check redeclaration + if (searchIdentifierAtCurrentLevel(id->name, id->prev)) + syntax_error(12, id->name); + + // check parameter storage class && void type + if (p->stor || p->type == void_type) + syntax_error(14, NULL); + + setDefaultSpecifier(p); + id = setDeclaratorElementType(id, p->type); + id->kind = ID_PARM; + return(id); +} + +A_ID *setStructDeclaratorListSpecifier(A_ID *id, A_TYPE *t){ + A_ID *a; + a = id; + + while (a) { + if (searchIdentifierAtCurrentLevel(a->name, a->prev)) + syntax_error(12, a->name); + a = setDeclaratorElementType(a, t); + a->kind = ID_FIELD; + a = a->link; + } + return(id); +} + +// set type name specifier +A_TYPE *setTypeNameSpecifier(A_TYPE *t, A_SPECIFIER *p) { + // check storage class in type name + if (p->stor) + syntax_error(20, NULL); + setDefaultSpecifier(p); + t = setTypeElementType(t, p->type); + return(t); +} + +// set type element type +A_TYPE *setTypeElementType(A_TYPE *t, A_TYPE *s) { + A_TYPE *q; + if (t == NIL) + return(s); + + q = t; + while (q->element_type) + q = q->element_type; + q->element_type = s; + + return(t); +} + +// set type field +A_TYPE *setTypeField(A_TYPE *t, A_ID *n) { + t->field = n; + return(t); +} + +// set type initial value (expression tree) +A_TYPE *setTypeExpr(A_TYPE *t, A_NODE *n) { + t->expr = n; + return(t); +} + +// set type of struct identifier +A_TYPE *setTypeStructOrEnumIdentifier(T_KIND k, char *s, ID_KIND kk) { + A_TYPE *t; + A_ID *id, *a; + + // check redeclaration or forward declaration + a = searchIdentifierAtCurrentLevel(s, current_id); + if (a) + if (a->kind == kk && a->type->kind == k) + if (a->type->field) + syntax_error(12, s); + else + return(a->type); + else + syntax_error(12,s); + + // make a new struct (or enum) identifier + id = makeIdentifier(s); + t = makeType(k); + id->type = t; + id->kind = kk; + return(t); +} + +// set type and kind of identifier +A_TYPE *setTypeAndKindOfDeclarator(A_TYPE *t, ID_KIND k, A_ID *id) { + if (searchIdentifierAtCurrentLevel(id->name, id->prev)) + syntax_error(12, id->name); + id->type = t; + id->kind = k; + return(t); +} + +// check function parameters with prototype +BOOLEAN isNotSameFormalParameters(A_ID *a, A_ID *b) { + if (a == NIL) // no parameters in prototype + return(FALSE); + while (a) { + if (b == NIL || isNotSameType(a->type, b->type)) + return(TRUE); + a = a->link; + b = b->link; + } + if (b) + return(TRUE); + else + return(FALSE); +} +BOOLEAN isNotSameType(A_TYPE *t1, A_TYPE *t2) { + // pointer, array 타입이면 element의 타입 비교 + if (isPointerOrArrayType(t1) || isPointerOrArrayType(t2)) + return(isNotSameType(t1->element_type, t2->element_type)); + else + return (BOOLEAN)(t1 != t2); +} +BOOLEAN isPointerOrArrayType(A_TYPE *t) { + if (t) { + if (t->kind == T_POINTER || t->kind == T_ARRAY) + return(TRUE); + else return(FALSE); + } + return(FALSE); +} + + +void initialize() { + // primitive data types 노드 생성 + int_type = setTypeAndKindOfDeclarator(makeType(T_ENUM), ID_TYPE, makeIdentifier("int")); + float_type = setTypeAndKindOfDeclarator(makeType(T_ENUM), ID_TYPE, makeIdentifier("float")); + char_type = setTypeAndKindOfDeclarator(makeType(T_ENUM), ID_TYPE, makeIdentifier("char")); + void_type = setTypeAndKindOfDeclarator(makeType(T_VOID), ID_TYPE, makeIdentifier("void")); + string_type = setTypeElementType(makeType(T_POINTER), char_type); + + // size, check 초기화 + int_type->size = 4; int_type->check = TRUE; + float_type->size = 4; float_type->check = TRUE; + char_type->size = 1; char_type->check = TRUE; + void_type->size = 0; void_type->check = TRUE; + string_type->size = 4; string_type->check = TRUE; + + // // printf(char *, ...) library function + // setDeclaratorTypeAndKind(makeIdentifier("printf"), + // setTypeField( + // setTypeElementType(makeType(T_FUNC),void_type), + // linkDeclaratorList( + // setDeclaratorTypeAndKind(makeDummyIdentifier(),string_type,ID_PARM), + // setDeclaratorKind(makeDummyIdentifier(),ID_PARM))), + // ID_FUNC); + + // // scanf(char *, ...) library function + // setDeclaratorTypeAndKind(makeIdentifier("scanf"), + // setTypeField( + // setTypeElementType(makeType(T_FUNC),void_type), + // linkDeclaratorList( + // setDeclaratorTypeAndKind(makeDummyIdentifier(),string_type,ID_PARM), + // setDeclaratorKind(makeDummyIdentifier(),ID_PARM))), + // ID_FUNC); + + // // malloc(int) library function + // setDeclaratorTypeAndKind(makeIdentifier("malloc"), + // setTypeField( + // setTypeElementType(makeType(T_FUNC),string_type), + // setDeclaratorTypeAndKind( + // makeDummyIdentifier(),int_type,ID_PARM)), + // ID_FUNC); +} +void syntax_error(int i,char *s) { + syntax_err++; + printf("line %d: syntax error: ", line_no); + switch (i) { + case 11: + printf("illegal referencing struct or union identifier %s",s); + break; + case 12: + printf("redeclaration of identifier %s",s); + break; + case 13: + printf("undefined identifier %s",s); + break; + case 14: + printf("illegal type specifier in formal parameter"); + break; + case 20: + printf("illegal storage class in type specifiers"); + break; + case 21: + printf("illegal function declarator"); + break; + case 22: + printf("conflicting parm type in prototype function %s",s); + break; + case 23: + printf("empty parameter name"); + break; + case 24: + printf("illegal declaration specifiers"); + break; + case 25: + printf("illegal function specifiers"); + break; + case 26: + printf("illegal or conflicting return type in function %s",s); + break; + case 31: + printf("undefined type for identifier %s",s); + break; + case 32: + printf("incomplete forward reference for identifier %s",s); + break; + default: + printf("unknown"); + break; + } + + if (strlen(yytext)==0) + printf(" at end\n"); + else + printf(" near %s\n", yytext); +} \ No newline at end of file diff --git a/08-code-generator/func.h b/08-code-generator/func.h new file mode 100644 index 0000000..9de8692 --- /dev/null +++ b/08-code-generator/func.h @@ -0,0 +1,42 @@ +#ifndef _FUNC_H_ +#define _FUNC_H_ + +// Function Signature +A_NODE *makeNode (NODE_NAME, A_NODE *, A_NODE *, A_NODE *); +A_NODE *makeNodeList (NODE_NAME, A_NODE *, A_NODE *); +A_ID *makeIdentifier(char *); +A_ID *makeDummyIdentifier(); +A_TYPE *makeType(T_KIND); +A_SPECIFIER *makeSpecifier(A_TYPE *, S_KIND); +A_ID *searchIdentifier(char *, A_ID *); +A_ID *searchIdentifierAtCurrentLevel(char *, A_ID *); +A_SPECIFIER *updateSpecifier(A_SPECIFIER *, A_TYPE *, S_KIND); +void checkForwardReference(); +void setDefaultSpecifier(A_SPECIFIER *); +A_ID *linkDeclaratorList(A_ID *, A_ID *); +A_ID *getIdentifierDeclared(char *); +A_TYPE *getTypeOfStructOrEnumRefIdentifier(T_KIND, char *, ID_KIND); +A_ID *setDeclaratorInit(A_ID *, A_NODE *); +A_ID *setDeclaratorKind(A_ID *, ID_KIND); +A_ID *setDeclaratorType(A_ID *, A_TYPE *); +A_ID *setDeclaratorElementType(A_ID *, A_TYPE *); +A_ID *setDeclaratorTypeAndKind(A_ID *, A_TYPE *, ID_KIND); +A_ID *setDeclaratorListSpecifier(A_ID *, A_SPECIFIER *); +A_ID *setFunctionDeclaratorSpecifier(A_ID *, A_SPECIFIER *); +A_ID *setFunctionDeclaratorBody(A_ID *, A_NODE *); +A_ID *setParameterDeclaratorSpecifier(A_ID *, A_SPECIFIER *); +A_ID *setStructDeclaratorListSpecifier(A_ID *, A_TYPE *); +A_TYPE *setTypeNameSpecifier(A_TYPE *, A_SPECIFIER *); +A_TYPE *setTypeElementType(A_TYPE *, A_TYPE *); +A_TYPE *setTypeField(A_TYPE *, A_ID *); +A_TYPE *setTypeExpr(A_TYPE *, A_NODE *); +A_TYPE *setTypeAndKindOfDeclarator(A_TYPE *, ID_KIND, A_ID *); +A_TYPE *setTypeStructOrEnumIdentifier(T_KIND, char *, ID_KIND); +BOOLEAN isNotSameFormalParameters(A_ID *, A_ID *); +BOOLEAN isNotSameType(A_TYPE *, A_TYPE *); +BOOLEAN isPointerOrArrayType(A_TYPE *); + +void syntax_error(int i, char *s); +void initialize(); + +#endif diff --git a/08-code-generator/gen_func.c b/08-code-generator/gen_func.c new file mode 100644 index 0000000..e69de29 diff --git a/08-code-generator/gen_func.h b/08-code-generator/gen_func.h new file mode 100644 index 0000000..e69de29 diff --git a/08-code-generator/interp b/08-code-generator/interp new file mode 100755 index 0000000000000000000000000000000000000000..27f9f1c316e26f254e7b07a6636092681ee25caa GIT binary patch literal 50360 zcmeIb33wD$+BRIBq#$AIur!24XcZJhBOod$XapJ>1q=#`j@pDQBrn+}>6XM1L7NEu zmeJ_A;J6_(I_~1mxL`me=qQ5Q;K+;_*KUJOMi|LBX#e+p&Z+9EBJrL7`>+4{zU%s^ zTwTvO&vu^koaZcc>U4T#V9v}mk4H1FbnPsSx%J0NOr9ciysQ!cdD{VL~ABAEhMB|S68r~q?l04mU+tQO!|4lcPcQvP(qaiH-spFaPPK+^Jol%Im5f-0`Q}tDRh4w&b*lCzltUR9;pYsXM7|(rG81HZixhDtCe~ zfp+=vVKdH}w@`!G&BQ4;YH6!v-qc6h07WPNn4vc|%)EQ&>GKlf!pk3;>@Tf4`VsQb zZpx5{7xgKZSb0BEh^9S_1TJ&@dje^*-w1-bkxu?>7yo?`ON+yWWGyT$sL@J_Yig=$w8HY@f*K^X zlB(+BN@^_!ASaoiy($vcprX9Is!%JdEeMC}wSsU}32$Xug~W$K7`+Nvd`&o1Q2>J= zD3n&$lvRdHU|L~aL8zpxvY@=|s$#98xT3Z=3~X6#RpI2xq1wWN$`WE(qmnXMP^FbD zuPF-`)1bnNYOq3GWmO1P6okvFDm50!(eX5G)|}bXriUivo^GYaPqdP$)G4XtgxpiL z(Ch_sL$I-UX<2Q!xMsoJ>E%_G#S03SlozA0r4?0`syZRb+9@O2CJle-_;^H$Ir*1i zr6f(a^4(O*F2V5?BRgWuoJR(gmG$O`+e6`Qz4>+wzq&R+rU9IoO(jH_ME_a;71;WIZ%x`{XQeiuGHD)~mc@I4iNoD1(&_(?8& ze}&I;;d2x|=)wQpKULw^ zy71E!zR883rSR)q_&Ex{-i4p9@DI80ixhsN3xB!7Z*t+6D15UEU!w3kT=-=QzsrTM zR`@+Gd_>_}UHGdMKJLP=RQPrmezn4PxbQKB*Pe35?Treb>B9e7;j>-%bqb&3!r!Ct zeiwd&!jE?0A5{2pF8sp^KgorET;cOv_@@;<=)%9C@cAzMOA5cpg>P2)#V-6dg)epC zcPMTl&_$C*=RpHmU@LwqWdKW&S@DI80-zfY>7ydhi z-{iu7ukg(-{ErI1!-daSE#qvL3!ka*dtCV5CjLn&hrwK|wPjAzT5Wjss3u5p8=h-J z^J=%@hnq;i4jcYx8{S-pP`BTPH`g1)+t(%LdV~05ZTy2P;{5CwxFt5=zyg4V4HqM5}glAooZ1^4)R@3rq_?|X=(1!12!{^)Zn2@b& zkqysh2=iKO!+T96V5tqCZNpdF@O^FgIvd{p+_K7s=kuL;t+nBOCK9m8h979due0F? z+3@Rac(v6as1MojgKhj9ZFsD9t!tAFKh(l%TC)vre^A_E!yjei-(|y(u;Gs+k9gpS z2ab5)hzE{%;D`r~c;JW!j(FgR2ab5)hzI`9_P~Dc@E?NFeVIW+|L7)73pO-|(~`S_ z(QTQp3B!}8zKJ)r$x(0N?j4b*k-wCb#HYz*vZP7mx$%&AH#CY9%gLt;rP&y9w}1*tqY7!uP`d2TEuCZzJ*P)Hn; z%5x(j(Jz(f20|h&mG?6L-A`71xnYp_G?nK@LE_z1o*M*-t*JaWiV{z!^4us$Y)Iv~ zL6Ep5mFLDl;<{9x8v==%RGu3Fi6yB#HvkeBr1E_5PfWA&$x(gKdL`ZwGc?hD$x+=J zo%x?`aOS^v<-c|1zjWpQ>dJrU%I|dLx4ZJ2UHRu-`6pcY2VMDlUHRKx`5RsN>s|S4 zT=^?q`AS#5#Ff9omA}Z9pXbWYbmh--`D41HstBcrd!6 zLyPo8UGBM@Is+X|m%nE5UAwOd<3dr;$QU(R6dC9k-`vtr*O5#jtF<&-ty003hIL5p zAX8(*IFuEPHLM3FXh;xic!;^ihIWEj!$wIHAl9%6xt4~txT8ZMbpukO06mP_5Z9I& zj0zPVLlhs|3e8lxHX8|+9c;|EO7rXrP8L+}b$`adsaS(!r7h8B4=iY=%(bsj)O$Pz z-kUDMkQdzjfY2rJ*}z}ZQ`L=`RBd)p+PFMf z0>U})!~P#ceMFU=t)s$0naUCy^E)6Z?0_R>NB|)$a>}Zfjq>Gi^p!dkn(bX(hm4pg zWq1VF1si?aE`io3{9{Z(F}*vG zhVH?=p?T%N7JdJJlgLIt-oN zlK**aQ>kqmYhwvGjiK?I=`O2)i)jDN|C0z~%@R2lB5egfTLf2^7XN6!n@+16H z{I8Lp!NJBwYp}Z?+!OQ&A6i&}c?cY-;Xf66(%r^wY;}a5EqYomvicC(GS<)};(~Y4 z?#EbU#EqO1p4TuScy`4aZUs~H72dVFX)-ZvZi%Jb;Z)!@SRHleR{3Yz*(> z0HGRT+6Ee;Y$5nm3NJfR;;et6hj3ms^arjN!%p}#L;nqua)4+;${HY|$Ot{3UYOF~ zOAHVgCpaC-aYA+5h~LojsI=J=(@&>tK9vnB=t{V`TFh`cWbk zIYC6b9C9#d-h^<9ZHI>6LPPw`gJ=)^@90r1wMkC+3(>YJX1{O-qms_Fqp*O|Bj~7Z9!vhM^W&UUSgFQ*5jA%PbS|;EkmRG{8+Na4gJ&WFnR_KwdERt zL$Gd3YX({o$9WRA==^ea)8=us6&82VCKw5{MR@b$H#V9ICowUKC3B}gq9X^e`>WI`4vX4m8~T&is%kulgrTp; z-Sixpo53vgq5}GLF6twes-~3RF2r6&PHe@#SOnHAY>lpndm>}t`PQJ(`zaO@*w_88TF|p2mYv}FC9tPOCSfsgyJ8Ir)-5U4#$jm3K&v&~ob(TD3V5$+ zj-_LvvLcRAOp)Wqf+CmwVE63Wj;c|xF(19U_s&1i4f{~OXNQW3U$o}#kDK;=GyEw@2f?Yd#7OH!Z@%k=NGnTqUgSC^yLin!uW;I*Ah77fk4|VTPv{n ztEjkFnhQH0*q||hXfZ7PDc@|$<@3b#z0#tA4!CafHFRBv_Xa;laGU!Ove|H9EYg9HZ8!AWz&Q0CJds^9 z;8o0z%78gAAc1if{Ui*A!@a{EvlEj6n~(ivUYA^t39b&oHJV(;!uHti!!S zD90ul9f0w*)7aR9$;Fr`!n#xXv!u(g@08v|I%13K^w(J&>VN1eS}!`qIk9%pFAmHz z+av_bWWV?uzE^;L;k_Z`Zrn!w5;!av(gUPaM46i^bDN*@XqzF45o78DP#<50 zr_;?`)&OxA5tkByM|UD_CSo=a_U#ZEM8R039sSG`8A$Ju@4S7U~P7>(sREIRcHuyKwV4?65T0ad|{&#?pz%^W>b%%c9|z%M&R$kIIuvJ#gL8{-$F zfernAv^?g99!cq}s zzQ&w1bda9N2vZ-NYnu9Oo2lzgXm!Rfd!KS#k1#f!4)s`>PbY>m>8|iFE#Mk5qJvowNvH-o05sZJsuE?++o3%U^*b@H&Tin4|dVC(Cp${id zEYRwG-q%w|1zNcm#)&f!NBaO53+zItCk~G;-shV!7dHC(z(ss!SsQrA2<#$i0Q=1H zIY7UVkye6eg2b+vzPp~~P@n!Ll5G?0?4<}$vadrK(G|NUTrf>te9}jqOZmXBy>#V;4J5iIqe<=6Dzm4yMwX+RRi2Q_muWGM>d30vTwJ z#W6^&Lmi_VJ=&&Ba@-<0Zjl_D&{MSdHA88Veg&Db$W$SjD(p;?@!TtPoenmXF^&L% zKMLs?cE)j1TQ;@n)HXtDOFjt!bNA$1Jj`&k+ti&LKVl)gsT))Kk%Geg{Y3?&d7lgs z=DiB}P5eelVy9%4-!`Dvpqg%iuBC%-t1@dt!k-XvRt?V>F0nyhLPt(+I4Az{r~fk1Rn! zXGrp~F7mLLexji0gC#?ng8|Ffk0P{;fpU;3!`Dh+mC%wmN!V`adn9>_gB&#SGY$O> z;;>rY3N3;@d20=Z0^dFTFy06Dkc8Eu{vg=mf5Os9_7S+_UwE301@=O$2CP90KhYI? zweV;l>ZudXhFm3+c#a}qAP4p`ibI&4fSs?fi3Qk6jE{w}(T+6l>L=k|CT?Olqv6Y< z9UgB3pR!x@6ClDXe&%378w)kx^=0{bI!K0|g*#he>z1!acy{gXh&Fp;f%g+(lwj!X zVLANY3k?vw6Ir%wuov1B+p~1x15jqG_Y+`=e}V@tm<@^hghZef$*V=Ffq3E;vEQwS zNiuww6Ie|keT;8_2_Msuq{nZx6wV_Fj)B6lrox%y9lVJ1sxT$Ln# zV8@DXn`C=5;mj6<_<>qc{$B`e<>zHW{T|TY$`-A}lHQQ4Pano=_+BKg@ZDf^t4GGf z<3vo}TFZI1FU{!=bD*O^>Zo++F!ClMrgPzjD+O7$f&L8h94-z_Vutc3k}@ z7`CrQsQiGy@&h^>A}TTtb3X9Az`0d&KI-K3y?}fye^}xuITYP3xf+~Yc{yVPJA{=l zC$do~sH>HXmpK?=aU2y~DriiiJ%m4EfwxeTxRK{ag#S_|b3DxmGfb@7%8>$-FP{F5 zyqv~hcRpIqN+F`nX2k!l)sOuU5eANUtC#ReeUGcK!z41#-!q+0@$0Jww zmVijWQ?sS?1ef$kK6L&S2DJp5PY_@m?poXF5E&>%lGXMCSvzClj$q-N#=>okTF;vp zt&D}u42o?Cifv~GUS2UA;!jczJ^kR{xZBelUD2H6V{>zl$Zy3RTNC;-+ z`Y56u+OWkCLqTvwJGK{OInWdt0qMD_gg~o&0)roC2I0p&eL3}Si|LEOka!67iGTMA z9=ljGtghl;AY)*-%fM^h#;N@&@&H8QZ(B@I-d-imUkBwd@o&f)ftO*3(fdb|j8nfP z*zzS7ng0kHSwZ8MnZ{gLjknoT`ULR^8rzB|W~ki`wK4sDD$sZ0jwT<30&b!>{IdpR zu8)h8Vt`&xwBd^pq?*}x8}jHOhJFJQ&@eN)Vuu#VX$gq#4Rv`GfV#h9oNGH7c+8bh zq~{ZF_$Cur`Y=tA+=c)VGppe{6?8bgu~!;ohDjOSA%iY4d5ibPCn0C}x=D7=Rzv@H zrKaufz&3y2eXh6I3G|PFgQK<)Y{BXp8$$*V=!iz|R|W0VhXhS|Z?M`on$r&gvFTvb z*9kV?wSvuB$y0^uGAn1ox8HbKkiJYZFK{p$3*V1^orYd(_$~$kwS$rR9KotjmJ-J} zB;?d_0&(nn+l6kgbL3X+t>iO&Zyd%RjOj1;;6%3xvq{i4n;7~I zFvkK1P?6t&BZ#vBi4M_v*kO5ITiqPSCYnf^j~375VPTC&3v4|x#MTD(8xS{_`94xp zPZ$ScdX+E=J3BGG6iGf|q}aPnvsUQ`qAL!_Cyf2n<~#2kS&plK1w>m<82fEc7(=Ej zU6TU`_=J%v#owijy?i`jbYM?Wf215<1y!V(g5{zwJ)aEl9RhyF})l~);-1ELs^BVt9{WG`|Nc;U-?+nJteV7IafYi+3P;s z^yB2fKGr=YGqOt=clq91o6*LI1vG>f(V?WX-NkXS6?^fF&z^SeGU10f*S}0+UXklx zk?~CX6kOGhi((cFyfY=CxQ`n^)Y8kYj}d<4Yu z7V-thqCKIDlc+66hb)%TvmMefGp1i4DEirwVYHLMHxYRZu+T7EGIVz^h`~#_PAtsE zp|#_cJyF+aMI0fxHzpPdtO1s-F@0Az^klS#cu;+>j6Q+2z$0nfB;kH3%6t)6G~uHF z!UvCtJi5NOVXsD6eJwC>>n{mx4a(<7@!OKQ8GCm0Jny_#SXXCcA5G$pbSVo5Xwk-nh$ED!KB=g_U7(cPM zcpT_1W{|czL)RgW!I?!rtr!c)n2ni@;=Y%4j(?)%=%UxbB(_cTmym*^MCc!a_@l_n z(f58TlGfeMB<4-YyH>vj32dLb-k0$G6}T=TGmPh^&|D$tJB=XaI#@a(UeitJOqU!Z z1?b&dFuFE{cA>XmQwZvQS}Ii!LHawU4d2HEmTJ{yv4Tc}^T0#=Ma;HwK23G{k^`H6 z@q}2F>lO{k-qKDAo{KF8b^{EyX>m-=czWCi0$j(2PPG&iZ<2EN zTXN{UnvsVm@J9qize6&taxkD9W+QS8$+DUtrWdEPtLY_D;Cz<=IgXY53jjoaoQ{NZ zzuC{Y!JEQY^I&WI!7M69HN>Gkt`ZB*0(xb4)-}*!Ec_hH3X#go;h?aNjr>ar84FSO zX&5irw^EChVhwzASEW1E5ooQogK{=E}HN=Au2P|nT>Tn=al31TO(#}>>uZJ=9w8q!J&qXv| z<3b!^-V&Fi3`b<_%y5S!5O2v7{~-i+yoq;xrs12JHhjM)=)~}Nc%YO$Q96lg#tD<7 zD_XTM9xVdU-x4430hZM*@kOwsq4}EbV$Y~ee^FHqPirINhu(vY3lGJz?V-o>;igl) z;y*q>V@FHgFw-q;x9!ReY(k7aR+cj%qnmw$LZg+9NKTUS`X_~{s=miG#yx^gs@f6B zj3=;5;`VZ?)xE2~hT8ZaQ4GAeTB&A7ual|^9IDNZz6@A&^veK5M?X(8PjoUHzUf5B zjy_tl^mVWpzN3(r9lbj#h`p0h_`jFX9^dB#R=r5<2jWg*<&gcF;M3od?9W;3))>)- zeU}z}2MBbe(+`GzD+Tz3x&uVkU+Sr_^l;1&48NBQg;GHDkBcR9o`cyOnh`j+!|~8L zPO=TQv6($Y&mdCOs-u9ligSbQ8zylMnLs(@Yk~5;N8ofwJX2Kh3s5|=im9cnn*1N9 z6sDt^Al@32NyHeBkig8LI`T0+Mjo6SP^=u1ewvKP*q5f*&9{7peg$|oLkq-O;&<+5 zEg7==+mQVw%S| zgt4*Jb0yv@U{Gkx{|PV-E5%b2UK>g*9bjRxr>)^iJdT?j?EjEXqv0ZJu-}Wm9KXfG zN(5S?@wAwTS2g6zXmwgmG5R6`~t)&=_g*IL42ODXbbwsJA7) z8wa1L&{2OmLWq)E;tlU$B$OtKnFL;TdTSiKwI>$g^SPR>I85UM^)InaxN?uKXxGGE zR3Fy=v@rdVafM@acJ&r9I;Yn+{?A!sBbRbxK1&E^iGXn#D~3|b;VtpLZ@Uh*$sU6f1tM}qvxv^p@m8md zs%!n`kM8&DelhZ>&eIdZa;j^I-^a9gq{6a4rGG6nFq`VWV#_AwW?GK(Cajn`G=#DJ zQ;Y`j%OPr>BU%SCw20UC`#_W-{wO#M{r+Ew!#I&%ubx2feE%j^6g^(`GyOHvaOAJS z!5)IWsx6=LS$)4Z8{eL~w3&8t>!bn9d^vp;8F@fNpnI9WF2^S)F0(1SD3m`X+Ii0!Fk(8C4BZP~@GZsmS21&I@gEVZ zHZLef932BuYwKp{pIu@feZ-l+7X4cwd9~L!JJP{f#$Pdj-jsymYd|hJCNWg zefTl6hIM=+jGf)s+|P{}X_?sT!f+k!INiG@YcQ5~%{K3Dfo9XY&mk?ni~Y7m+$QqG z^i@b8`q3-LpsizDu|?IGI$4P6!FL5X7*tmDjDlr|9!6hduiIEHY%OL3i9=h7`*KWu zkBObWebBstDSe>QV+H45Sae2OW4<`ZxD^K(4c|X5b``csFu4l*Es!j1LXKJ3*;Zkv zB8A~9^Jbiv(l@x(l__=HxWZ&-_*Q{~Z?hehnXdG|I|%yq%fTXiwEzj}t6ey!15crD z+nLhOAPW|g_P+NMxn0%k2b{x~9|RmX9#sBppRs07?$l~W)#m_XsOm#T?T_9QGf`MlFm6R18E)rUJE}u&`{T(Fm{uTGe zAddbu6OZ@gcF(V75f0B|q$|W3L@V@`NRD9Phqe%&tBly|GmS`KtuKxEgem<(7Dgk^ zMFQtAMA_m5ilsS|nkS~AO|HL@ZQ>U^!al1_KBqJ~5Zfg7-P-KLfBDQ3ms=%Ph!X#{ zfF;81dyp{ncX7vyTht#3N1dC5PJ3r^*SS)1IO}`~kZ?SnKUq+-$M97t&6c&N2{~7Y z9xde(8wZ${zkBmzcEgz1Aq31B`YNx%V2wz>=NM9Ye(A7I$B7@CQhQ1pt z!pt3R-kTJ!Bd)Fjl5v$az%+B9Wo9p7<|-^%UP!ch{ z>SuuH>JCYu*d1={Zx($QP98`P-OQA(gTv8=Zvlb0#Us`bL%#zV8YU0=#vAzkifPoP zzkPu+c^eWquZO!sO@mZp_|t%u3zD!PJ17JUPVW1NH6d{uO7U$f|Mu=OA>9d z$dp_!$nPq$Nm{gJzqhZJI3e3K;B?D?lY{~HLqHg?j*@tfAk-KxHQ6McB}mnZBt zjS%GdF3HQJ0S|jk1D?n07U=Go_zE z#q`0^NErH1+#MEtN;EC-kkMtq>m&*v+y@IjIj<87Hh_gb7~jjZ;4I66iNb=1ASNuh z4+)%8#NA=RVirORR+7-JsnHeSCzc)jS=dlgnW+i5h z2pA8C^fZk+-ZJVaVbslF7Dlb56xQ)V#jji{#0ZfqNQ)KeaHDh>6&6NKu^V*|0)}sl zOCyYG=wTXl3%;@?J++o8{m^V>)P5vj)U!gxm(18b#ZmZ9LHeU2IgHZ0CvUk@*z?#Z zo0FCbi921&V9!6ZOncHSdpiD3d&%e1G4R*2qID(u-CRQ9}w1njw0sMyYo-9IGN3(}*CbeKKTKQ~~< z+6tmsLZaTK4EB7GY1;ECzcC~1*(1I?GY8DVKhr5?=ov!AX)YDnY_9~6hHt1MIqYG3 zN&g%=)@IKOLLxECSvlAf$TaP_z_KSO?0Ff?!k%Z4!1;5^+Gm|GRf?~Ij>dTdGRyvM zE%Gn47`o$ohA>9|1GhEs{S&vUG2rA9byIiKnAh>uA?ci#n9@(Ces=rgkih)!*6+-3?9}Gq$^F%p}X0Tw%-xw@8_(T+FdikPjQ#W>PE0 z)(^UwT0h-qR&ftfXx0AI;tNo@BLEHGc;NPXPi!VWwK=pOSgO3vQhAf5vVkf6UjbL$ znjykHE<=BiDc>G4*a|yAE=9&!8mB6a`W4_$mszUHEL9<-5DUMdr0=ci&R7s5%}POf%1zSm8^MTF z4+YYiwbF_`2PsjSaCeiwDNh>T~_!t)L)JOe?SUW9)K>xcbwZ4 z4wWAXQcpLj_rHeIO7%4Hi*!?UDOLOSPGf%Gn5{VDrN4trVzR|C(<*$5EPS~r;bCyu zyNj5tE)%31-K5^DQMmVF*`Yp3Gt1tGZ!^hieae)65#{W|>QPk3CDas9V!IE1EGiXZBBP6c@Zq=7I>(tl=vMSL3A~?C$!YBv|;KEp|ssW<#Gv zrhL@?J0zULU53eXtl&wQRg558^8I|?I+DtGC~xTjQIwVRo{kt+X_R^1a#Em9U!3l;GSqldUy@THphN~s8 z54D5XvlPpRs~@Gh=JXhj1T^YbLMVtAnP@ME!>?e;j$LvG`D}{GQ@{zlFV|MB`0BFA z9B~YQ#{ux)0C-p+@D=ct5wG}X0P*vlz)Y}HGKYc8f?4s?h~%=$yE*U`V&ypIAC^p` zybZS^b-32H6YW@4pME`&=@r3qY&w= zDSs^sLHl{|rk8Jfg^62pOcO7lmPt_jw1qmGsB=V{usU~HgyTSHYU?Q|E%Ca?IHlq2 zhr7`=Z$kp_h*Iyt(RWt4|KnlcR@4EJIb@28%)Us7$ZRqKO^$eb2b7-)$BiJ%a9o!t z!XUqD#TvhN^`$bEh5t+^Q$4(^XUY^pYdBJ{9X&_{>^c#!Yf!N@jEmLhiYP#U>@@>q zFI$HJ@}?s|@UIs{fZ)p+X> z!Nhr}K`D>F^(g*LW8nI>%=lKBTD9VOfA~Axv%>pu?-BkI@0o^&@$N)A)7nbAPLwC! zFm1(`#;;$SmN+?O@(t4D^#e_lKZAN`nnEd;rb$wh?VT`MP5fgT9y$ozAogG1qu=0; z_z=tD?5-?s8)^h@MT5i^-Wo)UEWCd00)2h_Z;yzoiVF4<73?J{*bVn&+e*M)oU;uu~*yBm_fHeb` z$1|h2yf|D|xm2sIuM8K|`Q?vU2l$iLXZVZC@PpDd_+9L!n!;39RaY~MpO~(ysrMJx zl@>(sv(H7^bo~5vWu)3J<1eqOT2@fXU(L3tro5)@d@z~(9-mWxkK?fTJde+p_zZj~ znVhOFe{FrmlB#mQnV+hSnpkv(-#@B0YgADW?fm@EyoGb-Xmie=q0O1Gh@WY=oukc} zy;ezw|nTFdUevnu=4d{i_W@|jGn==W z+FYu=@WR==&D3TsxL`JKGqpK^`M?F{1IH9@Gqrh4;WkqX%!fQ~z@5K9JO2XhoOv^} z=@-Eu+-7R$=1=G60`1(n`A96_=K^i^yao77pUoSr3m}EtOc|apNxt`^(EJi~Xa}N|pFMbc;*V zL|~oak5m>Fhd!DGlx}|zq zW!3UZM@Q*{F3ORzH~zYddnUSR5ApRR(JjG^S7+kN1iq)%OQbvNaqRG^E5q@tvnjll z@~A5<-Ap-Png_klf z*91ht1od}{HqlB?fc6QHlOL0V@Kk}dV}3rZDV?2{pMhVY?}n(%M6G4yaXQJsr>nod z@J?UUFGm}U-?tyC^+T?o$en;1_tVDXGY-DWg=fZs<3xP=Yh&;ktsSo&2TzQ|Zx9~? zFCMM=aUTw!`am6~c>xFDJ^@kv^L6Ts+Ijsv@bCY-zwYRN*`g2jLQVR?H$#yhj6b$` zKh$ifsN0Dm22Me{v)zuzCsnsp&2r$WfudghQL`TKv;MzSy9uItB?aMva(_vAah;zd zW+jHLvdVCAO(n2m06OWU$|`?BVYsZS(qB@AaSmUQ+L%l}{4C}+z<2QZ2%pdJ`39eZ z_;{X5CXdA@h|gAhzQU)+)5&BWKBwWsg8zeZiz|!#RVDrnkv6v zE2ya{sP`+sE@8y_HEEgINPaC+DdtqA4)v^EUKTDa)ym4ti;9BXzWL{5^6ov!C? zOb$W*Qsf7Mek$mw$qsx@#%If?$z(M?1M%62`W%J28~_h?^YOAtT&olmU{sMdsze)A zi$Q(Vs6sq{3{5{1|N4@z7PahKFs2~A>(|f;*b2B7u<5pBavWg&?XVs2e!ynH(f22l zt$-^5xvcpf&=2^+28>03&;2%;ECM|7cgf^xz$(Ds0WNzWncN0A2J86G0apTMWZ=C5 z*6||&Hv-N8ya#LgBESUTYQQV86Z{ZhKE}Ye0PlT1nQRAq`vv^$4whMOZ-SkGcfFWQ z<^z8966yi?o0s8tz?)x5CZ7fLZ%!uP2YdnW0N|`wlgR;i3hULJOil!R9B={Pb6fBm zLV)YGLLTs)*C0>04f23L0v-T-?{&y`hx~Sw4>$}kAMhl=YQVDqn*iqlZUhVg?gG3L zupO`oFdNIsM*znGz6h8PxErt<@U#}l1AYd$5zw;(@_;7*wgb)v%*N95M!<1^_WV03QQ<6!0y;vd7YTUqN0j&oQgZ%X8HQnx`(?GqhLt zOnf0q;D>><2(fV-S!Q&{L2(T$1P$}4rZwM$*Z`l_Cwpd}oO8WBmuIfh&K@%Pgi}Ty z1FVq03~5t*_5$J1Z zyGc*KrUyAle+!?ydy`4N-L~jy^MnG@_u;b~^yLnErA6mI{M-rp76*Nkp!Av-;7zhxtRb|3oRW(WN_ zi@po=spyyZDwWL#b1iy1=(V7~;h;BLbo>uYZ5aA*Xfj;E;Pz3rn4*KVod_L&o z(f{W-=+gz=4_r0qmxJEupsyBmqWt*W3ZCuY`7`>Q)sFCU`di&BJ^Y`3S3ioe(#?}6 zd1&ii@I3ew#!uAQ(vyCihe}941p0GaN7?CV2SpjA55t&s+cU`|-^!=tU$^9^fIj^> z)YU=uHm#8jFqx3T^BklF8Q{^p`EVAM{xC&&N2NY4<@| z(xNX0eKN-9&m8i9w&<%sKLq;ecKP&N%g5_M?~n1kt2Sx|eLv{AcKyXdy=dcB&^;Lc zKeW@+-WCjaZLeX`FXo5Ib~@6c{Xu&lvSR!)$D3Ix-TbMJZJ=|1&T8LaihddB&;1Pj zYS1728U1&Ie*4eJzYO{s&^lT{-Otd6p>NfI-evtk zU-C2MUk3UmpcmWAPrFPQK>uD1`n{k(?x6q9qTdbrSj^eO?ev8y`(Flq4CrI*^u;Oq zUeG6iKEh7FC`CU6`gqU-cKX#R`Y_Dd7lAHzht2k%nW9etJpg*#E}!;^U|?)r26}I- zF+Q@>k!IcNKzkFklkBvjl}xOPS7xX6poB)std zcd7_Ca*V`2+ld|u~e zKEJ8ru%{`nX7x(b#Mj~ZkC$n8P#LDs*d>;im}_l(|Hk$QDKJ-v{-p9bN-&wC3kB^e zzf%?TFO|npxc^_S4%IGh<>UMklc!+5f{PWbR&bSqO$x48aHE3F3hq*{Rl#-zu~jav zYz6%aj#DsC!F&Z5D_E`IDg~PqT(96p1)CMzrJyYBKfh;g?3_0}D)BuP^eWh2!5jsL zDR{JkqZB+r!CVDTQE-xiQx%-1;4B5_C^%oiMG9W7;1UH(6kMiYwSo}^uTpTOf~ysb zDR`rTzgBRag7+x6LBR(Vd|1K96?|I37ZiL+!Da=wDY!$yw-wy2;D-u+tYE8xUnrPR z@EZlcQ}BBQe^fAIwQQ$M1$!�h%B5zodU2_O_-^Kf^zI;S%icM*Nd=Pt6^7(rFQq zn=nS^rJk>f@Eitr@*CKp8cyD8l#{!AlN_<$ZIUksK0|^gCRdakd@sA+Unf)xz zgLg^(Rg%-I3f`>ndDlw(F%oF6EBq=Key753P;Q{9J{vR(NE^b*aLK6+T1Zixs}krKeiqSGoA>6n?b}f33o=b>Z(3 zc(i+iEU-kC`+J37ukfh6xE?q0*UP-QPQVZT3I8`Me7Vx|io)lukq8sN&E!}3w-i7B z%`Mw;{aT4I@$U-!5bXw+{a-75lfs+r;z^V3`%u2rBlcO49Hj8~pC|D*NuZsm@K4N; z2(fpD8JatX8(6#gIwSX|FYpiNZxZsR0ki^88R@G4^i`M~$ZII!Lo zZ~W#B%e{*OH7>unW8CgSPr1_bkSm_UUGU%B1^x+v&(@}@c<8Ij-2}X8gF*@LKJc_( zbJ_o(PJTQUxYkWyby4mQs@(b-seOYgM909@&t9NP59|Uz26);t$>oRBy5OJP1^yRG zPqwRG6B`PEO3&RcdpHjDg@58tNk*`VD~1HmVzeu~LTiJp1D@^G>T0jE1%8N@?`oI1LXXW5 zm0Ya!U*YOs%as0oF8!5?e?R`&9WSm6d0naSXQ+CKy;4!&DJgh%favrAy_lz7!GwHk$AIYHw2{J^VT;akSZ z{7({S*D3taT8R+v6p(BLp5xEwuJPeE#Xn5N!~IIn0|KuyHt>SbGekSl6(>3HC;i;4 z@T(@t27a*%J@0ja|6J+MYm@Tk`ngT;>uZ<*YUvnO<@~6N9fPi?o|!tRkWbOU!w2ieeXFPOg+ zJ`Z_bB}&hm$`6AiTB}j`^$Kr}Z&w3V7&9(i1` zWMJJz``7`^v;<= zIKo~Q5(nr)IF?pZua(pkR1}ABq_3hLBDP!zoM8uReQvm532dsb5991yZ8?rQB3+H6 zqX0M^FB8>EtHMYDl9FiVWv`~SX!u%(jlRSH6uzK-(#YvtjN+W&IyL9 zDnrFpC8QM;78X|v_F`5&R8br*AY4*V%Swe%ae~S^!Bbeu8ivXXYT-K}iEo{-AmJ-F zzOY(&qLXu=LP=FY$}Cd@kE~YL;7DXuq&B4&Ey=Hxghazo)^)O#C~?#=Bo5Xh8{tASuq4Fwxodc&jEgH4g*VD5&d#Z(IFPMwQH@oM8xzpJ>7l>G| z4HtpMA&3Ystgd&UU;_#-M>#aM)vw$9XwG`abt)+w;)!jv1hwOIcWtrL@v_B438n1)vWWV61`e`dM=%Ig>;q*5<@{z2V=;Bc z8g-*jvGt-xp` z0w4WNR!3P3yK1XKr8vlp0k#m|WUE2jxpXmJ(Q3js_6Qt5QGInz#8YVY`6vS65{mE; zJ{lh<->orG4L)L26w(2`m)EMkygzZQ~pnlezG>lOph1Tlz+h-VC|ua?oT zAv3B{9?(koH8Mv@)f@=RYO4w-PnI3PqMojymz7yrIck(&Sx~Op4ptS{l{tg7WO+?l z*g1}cLKsriAX`)?hnr3ZoBI0YH3ikE?y}+wWps(k$U#;0NfgaMmz_kW#TXVUtSeyO z7E$jonW5}JunpMF5W!XT2!0HG&QQ~G(TbSs0mC&CmYOL!g=o1r7+;*bv@()gUBe+D zTyH}yiIkNWom5t&Q0GjWeG(T#g1xk$wp7c-cQ{algy9-V!B;_QdGubesZ0p8n&R>T z3aC_dd05L8^L{RpxmcNKB2kM;Jy#44xm+57yGq1FZgHtv43!o^o0*e3=l6JLZ`R*D z*I+{R7-5}jaNA!1d7f!7<;`;sCS0uQLmTO5Q$7c2US;@@#gsSCQJBy?H$h%ra`i9M zy#Ep(o=Gs}&2tDQ3@TRjSYwrA@?Qfw&p4QQ^PGbT7b|(U{R*vdzn(rd<;`;!CN$4o znB}|ce}|HvrWBgzI811s`=C61=9a%7IQqoYulbST^ab>kHfTxM7n_BP9;|vU3ZhkXw!he8=dlII+`JTT0Ka~FwvW#6* z-h7|dq2&4f1zzlbyv%aVc6<~#vY7JbxvBWQj we8Cia%zB&SZx(Qt?NUVCv(<~jH%tLVGs`tuxj)vK{6{ZIjv+1qS62If006vPpa1{> literal 0 HcmV?d00001 diff --git a/08-code-generator/interpreter/interp.c b/08-code-generator/interpreter/interp.c new file mode 100644 index 0000000..5a31597 --- /dev/null +++ b/08-code-generator/interpreter/interp.c @@ -0,0 +1,289 @@ +#include "type.h" +extern char *opcode_name[]; +extern INSTRUCTION code[]; +extern int stack[]; + +extern float *stack_f; +extern char *stack_c; +void runtime_error(int,int); +int base(int); +void interp(); +void lib_printf(); +void lib_scanf(); +void lib_malloc(); +void dump_stack(),check_operand_zero(); +int p=0, // program counter + b=0, // base register + t=-1, // stack top register + hp=STACK_MAX; // heap pointer register + +void dump_stack() +{ + int j=0,i=0; + printf("\n===========stack dump================\n"); + for (i=0;i<=t; i++){ + printf("%08x", i); + if (i==b) printf("*"); else printf(" "); + printf(": %08x %d,%f\n", stack[i], stack[i], *(stack_f+i)); + } + printf("\n=====================================\n"); + +} + +void runtime_error(int i,int a) +{ + printf("runtime error at pc %d : ",a); + switch (i) { + case 1: printf("devide by zero \n");break; + case 2: printf("array out of bound \n");break; + case 3: printf("stack overflow \n");break; + case 4: printf("unknown error in switch\n");break; + case 5: printf("illegal operand\n");break; + case 100: printf("fatal error: unknown opcode\n");break; + default: printf("unknown\n");break; + } + exit(1); +} + +void check_operand_zero(int opr) { + if (opr) runtime_error(5,p-1); +} +int base(int l) +{ + if (l==0) + return (0); + else + return(b); +} + +void interp() +{ + INSTRUCTION i; + int j,k,l,m; + stack[0] = 0; stack[1] = 0; stack[2] = 0; + + printf("start execution\n"); + + do { + i=code[p++]; + // dump_stack(); printf("%d : %s, %d, %d\n", p-1, opcode_name[i.f], i.l, i.a); + switch (i.f) { + case LOD: + t++; stack[t]=stack[base(i.l)+i.a/4]; break; + case LDI: + check_operand_zero(i.l); check_operand_zero(i.a); + stack[t]=stack[stack[t]/4]; + break; + case LDIB: + check_operand_zero(i.l); check_operand_zero(i.a); + stack[t]=*(stack_c+stack[t]); + break; + case LDX: t++; + check_operand_zero(i.l); check_operand_zero(i.a); + stack[t]=stack[stack[t-1]/4]; + break; + case LDXB: t++; + check_operand_zero(i.l); check_operand_zero(i.a); + stack[t]=*(stack_c+stack[t-1]); + break; + case LDA: + stack[++t]=base(i.l)*4+i.a; break; + case LITI: + check_operand_zero(i.l); + stack[++t]=i.a; break; + case STO: + check_operand_zero(i.l); check_operand_zero(i.a); + t=t-2; + stack[stack[t+1]/4]=stack[t+2]; + break; + case STOB: + check_operand_zero(i.l); check_operand_zero(i.a); + t=t-2; + *(stack_c+stack[t+1])=stack[t+2]; + break; + case STX: + check_operand_zero(i.l); check_operand_zero(i.a); + t--; + stack[stack[t]/4]=stack[t+1]; + stack[t]=stack[t+1]; + break; + case STXB: + check_operand_zero(i.l); check_operand_zero(i.a); + t--; + *(stack_c+stack[t])=stack[t+1]; + stack[t]=stack[t+1]; + break; + case OFFSET: + check_operand_zero(i.l); check_operand_zero(i.a); + t--; stack[t]=stack[t]+stack[t+1];break; + case MOD: + check_operand_zero(i.l); check_operand_zero(i.a); + if (stack[t]==0) + runtime_error(1,p-1); + else { t--; stack[t]=stack[t]%stack[t+1];} + break; + case ADDI: + check_operand_zero(i.l); check_operand_zero(i.a); + t--; stack[t]=stack[t]+stack[t+1];break; + case SUBI: + check_operand_zero(i.l); check_operand_zero(i.a); + t--; stack[t]=stack[t]-stack[t+1];break; + case MULI: + check_operand_zero(i.l); check_operand_zero(i.a); + t--; stack[t]=stack[t]*stack[t+1];break; + case DIVI: + check_operand_zero(i.l); check_operand_zero(i.a); + if (stack[t]==0) + runtime_error(1,p-1); + else { t--; stack[t]=stack[t]/stack[t+1];} + break; + case ADDF: + check_operand_zero(i.l); check_operand_zero(i.a); + t--; *(stack_f+t)= *(stack_f+t) + *(stack_f+t+1); break; + case SUBF: + check_operand_zero(i.l); check_operand_zero(i.a); + t--; *(stack_f+t)= *(stack_f+t) - *(stack_f+t+1); break; + case MULF: + check_operand_zero(i.l); check_operand_zero(i.a); + t--; *(stack_f+t)= *(stack_f+t) * *(stack_f+t+1); break; + case DIVF: + t--; *(stack_f+t)= *(stack_f+t) / *(stack_f+t+1); break; + + case EQLI: + check_operand_zero(i.l); check_operand_zero(i.a); + t--; stack[t]=(stack[t]==stack[t+1])? 1:0;break; + case NEQI: + check_operand_zero(i.l); check_operand_zero(i.a); + t--; stack[t]=(stack[t]!=stack[t+1])? 1:0;break; + case LSSI: + check_operand_zero(i.l); check_operand_zero(i.a); + t--; stack[t]=(stack[t]=stack[t+1])? 1:0;break; + case GTRI: + check_operand_zero(i.l); check_operand_zero(i.a); + t--; stack[t]=(stack[t]>stack[t+1])? 1:0;break; + case LEQI: + check_operand_zero(i.l); check_operand_zero(i.a); + t--; stack[t]=(stack[t]<=stack[t+1])? 1:0;break; + case EQLF: + check_operand_zero(i.l); check_operand_zero(i.a); + t--; *(stack_f+t) = (*(stack_f+t) == *(stack_f+t+1))? 1:0;break; + case NEQF: + check_operand_zero(i.l); check_operand_zero(i.a); + t--; *(stack_f+t) = (*(stack_f+t) != *(stack_f+t+1))? 1:0;break; + case LSSF: + check_operand_zero(i.l); check_operand_zero(i.a); + t--; *(stack_f+t) = (*(stack_f+t) < *(stack_f+t+1))? 1:0;break; + case GEQF: + check_operand_zero(i.l); check_operand_zero(i.a); + t--; *(stack_f+t) = (*(stack_f+t) >= *(stack_f+t+1))? 1:0;break; + case GTRF: + check_operand_zero(i.l); check_operand_zero(i.a); + t--; *(stack_f+t) = (*(stack_f+t) > *(stack_f+t+1))? 1:0;break; + case LEQF: + check_operand_zero(i.l); check_operand_zero(i.a); + t--; *(stack_f+t) = (*(stack_f+t) <= *(stack_f+t+1))? 1:0;break; + case AND: + check_operand_zero(i.l); check_operand_zero(i.a); + t--; stack[t]=stack[t]&&stack[t+1];break; + case OR : + check_operand_zero(i.l); check_operand_zero(i.a); + t--; stack[t]=stack[t]||stack[t+1];break; + case NOT: + check_operand_zero(i.l); check_operand_zero(i.a); + stack[t]=(stack[t]==0) ? 1: 0; break; + case CVTI: + check_operand_zero(i.l); check_operand_zero(i.a); + stack[t]=(int) (*(stack_f+t)); break; + case CVTF: + check_operand_zero(i.l); check_operand_zero(i.a); + *(stack_f+t)= (float)stack[t]; break; + + case JMP: + check_operand_zero(i.l); + p=i.a; break; + case JPC: + check_operand_zero(i.l); + if (stack[t]==0) p=i.a; t--; break; + case JPCR: + check_operand_zero(i.l); + if (stack[t]==0) p=i.a; else t--; break; + case JPT: + check_operand_zero(i.l); + if (stack[t]!=0) p=i.a; t--; break; + case JPTR: + check_operand_zero(i.l); + if (stack[t]!=0) p=i.a; else t--; break; + case INT: + check_operand_zero(i.l); + t=t+i.a/4; + if(t>=20000) + runtime_error(3,p-1); + break; + case INCI: + check_operand_zero(i.l); check_operand_zero(i.a); + stack[t]++; break; + case INCF: + check_operand_zero(i.l); check_operand_zero(i.a); + *(stack_f+t)+=1.0; break; + case DECI: + check_operand_zero(i.l); check_operand_zero(i.a); + stack[t]--; break; + case DECF: + check_operand_zero(i.l); check_operand_zero(i.a); + *(stack_f+t)-=1.0; break; + case POP: + check_operand_zero(i.l); + t=t-i.a; break; + case MINUSF: + check_operand_zero(i.l); check_operand_zero(i.a); + *(stack_f+t)=-*(stack_f+t); break; + case MINUSI: + check_operand_zero(i.l); check_operand_zero(i.a); + stack[t]=-stack[t]; break; + case RET: + check_operand_zero(i.l); check_operand_zero(i.a); + t=b-1;p=stack[t+3];b=stack[t+2]; break; + case ADDR: + check_operand_zero(i.l); + t++; stack[t]=i.a; break; + case SUP: + stack[t+1]=base(i.l); + stack[t+2]=b; + stack[t+3]=p; + b=t+1; + p=i.a; + break; + case CAL: + check_operand_zero(i.l); check_operand_zero(i.a); + if (stack[t]>0) { + stack[t+1]=b; + stack[t+2]=p; + p=stack[t]; + stack[t]=base(i.l); + b=t--; + break;} + else switch (-stack[t]) { // library functions + case 1: // printf + lib_printf(); + break; + case 2: // malloc + lib_malloc(); + break; + case 3: // scanf + lib_scanf(); + break; + default: printf("library not yet implemented\n"); + break; + } + break; + default: runtime_error(100,p-1); + break; + } + } while (p); + + printf("end execution\n"); + +} diff --git a/08-code-generator/interpreter/interp.l b/08-code-generator/interpreter/interp.l new file mode 100644 index 0000000..ac530c1 --- /dev/null +++ b/08-code-generator/interpreter/interp.l @@ -0,0 +1,57 @@ +digit [0-9] +letter [a-zA-Z_] +delim [ \t] +line [\n] +ws {delim}+ + +%{ +#define YYSTYPE_IS_DECLARED 1 +typedef long YYSTYPE; +#include "y.tab.h" + +int line_no=1; + +int search_opcode(); +int is_inst2(); +char *makeString(); +%} + +%% + +{ws} { } +{line} { line_no++; return(NEW_LINE);}; +"\.global_word" { return(GLOBAL_WORD_SYM);} +"\.global_byte" { return(GLOBAL_BYTE_SYM);} +"\.literal" { return(LITERAL_SYM);} +"\:" { return(COLON); } +"\," { return(COMMA); } + + +(\-)?{digit}+ { yylval=atoi(yytext); return(INTEGER);} +{digit}+\.{digit}+ { yylval=makeString(yytext); return(FLOAT);} +{letter}({letter}|{digit})* { yylval=search_opcode(yytext); + if (yylval==0) { + yylval=makeString(yytext); + return(IDENTIFIER);} + else if (is_inst2(yylval)) return (INST2); + else return(INST1);} +\"([^"\n]|\\["\n])*\" { yylval=makeString(yytext); return(STRING);} +\'([^'\n]|\'\')\' { yylval=*(yytext+1); return(CHAR);} + +%% + +char *makeString(char *s) +{ + char *t; + t=malloc(strlen(s)+1); + strcpy(t,s); + return(t); + + +} + + +yywrap() +{ + return(1); +} diff --git a/08-code-generator/interpreter/interp.y b/08-code-generator/interpreter/interp.y new file mode 100644 index 0000000..4ac0f59 --- /dev/null +++ b/08-code-generator/interpreter/interp.y @@ -0,0 +1,253 @@ +%{ +#define YYSTYPE_IS_DECLARED 1 +typedef long YYSTYPE; +#include +#include +#include "type.h" +float atof(); +extern FILE *yyin; +extern char *yytext; +extern int line_no; +int pc=0; +struct {char *name; int addr;} symbol[SYMBOL_MAX]; +int dx=0; +int stack[STACK_MAX]; +INSTRUCTION code[CODE_MAX]; +float *stack_f; +int *stack_i; +char *stack_c; +int syntax_err=0; +int semantic_err=0; + +int search_symbol(); +int search_opcode(); +void put_symbol(); +int get_symbol(); +void put_data(); +void print_code(); +void print_symbol(); +int is_inst2(); +void assem2(); +void gen_code(); +void interp(); +void assemble_error(); +void dump_statck(); +void runtime_error(); +void initialize(); +int base(); + +%} + +%token NEW_LINE COLON COMMA + IDENTIFIER INST1 INST2 INTEGER FLOAT STRING CHAR + GLOBAL_WORD_SYM GLOBAL_BYTE_SYM LITERAL_SYM + +%% +program + : command_list + ; +command_list + : command + | command_list command +command + : NEW_LINE + | IDENTIFIER COLON NEW_LINE + { put_symbol($1,pc);} + | INST1 INTEGER COMMA INTEGER NEW_LINE + { gen_code($1,$2,$4);} + | INST2 INTEGER COMMA IDENTIFIER NEW_LINE + { gen_code($1,$2,get_symbol($4));} + | directive INTEGER INTEGER NEW_LINE + { put_data($2,1,$3);} + | directive INTEGER FLOAT NEW_LINE + { put_data($2,2,$3);} + | directive INTEGER STRING NEW_LINE + { put_data($2,3,$3);} + | GLOBAL_BYTE_SYM INTEGER INTEGER NEW_LINE + { put_data($2,4,$3);} + ; +directive + : GLOBAL_WORD_SYM + | LITERAL_SYM + ; + +%% + + +int search_symbol(char *s) +{ + int i; + for (i=dx; i>0; i--) { + if (strcmp(symbol[i].name,s)==0) break; + } + return (i); + +} + +int get_symbol(char *s) +{ + int i; + i=search_symbol(s); + if (i==0) { + i=++dx; + symbol[i].name=s; + symbol[i].addr=0; } + return(i); +} + +void put_symbol(char *s, int p) +{ + int i; + i=search_symbol(s); + if (i) + if (symbol[i].addr) + assemble_error(2,s); + else + symbol[i].addr=p; + else { + dx++; + symbol[dx].name=s; + symbol[dx].addr=p; + } +} + +void put_data(int i,int k, char *s) +{ + int a; + if (k==1) + *(stack_i+i/4)= (int)s; + else if (k==2) + *(stack_f+i/4)=atof(s); + else if (k==3){ + *(s+strlen(s)-1)=0; + strcpy(stack_c+i,s+1);} + else if (k==4) + *(stack_c+i)=(int)s; + else + assemble_error(100); +} + +void print_symbol() +{ + int i; + printf("======== symbol =========\n"); + for (i=1; i<=dx; i++) { + printf("%4d: %s\t%d\n",i,symbol[i].name, symbol[i].addr); + } +} + +int is_inst2(OPCODE op) +{ + if (op==JMP || op==JPC || op==JPT || op==JPCR || op==JPTR + || op==ADDR || op==SUP ) + return(1); + else + return(0); + +} + +void assem2() +{ + int i,j; + for (i=0; i=CODE_MAX) + assemble_error(10); + else { + code[pc].f=op; + code[pc].l=l; + code[pc].a=a; + pc++; + } +} + +char *opcode_name[]={"OP_NULL", "LOD","LDX","LDXB", "LDA", "LITI", + "STO","STOB","STX","STXB", + "SUBI","SUBF","DIVI","DIVF","ADDI","ADDF","OFFSET","MULI","MULF", "MOD", + "LSSI","LSSF","GTRI","GTRF", "LEQI","LEQF","GEQI","GEQF","NEQI","NEQF","EQLI","EQLF", + "NOT", "OR", "AND", "CVTI","CVTF", + "JPC","JPCR","JMP","JPT","JPTR", + "INT","INCI","INCF","DECI","DECF", "SUP","CAL","ADDR", + "RET", "MINUSI","MINUSF","LDI","LDIB","POP"} ; + +int search_opcode(char *s) +{ + int i; + for (i=NOP-1; i>0;i--) { + if (strcmp(opcode_name[i],s)==0) break; + } + return(i); +} + +void print_code() +{ + OPCODE op; + int i; + printf("======== code ==========\n"); + for (i=0; i 0 +#define FLEX_BETA +#endif + +/* First, we deal with platform-specific or compiler-specific issues. */ + +/* begin standard C headers. */ +#include +#include +#include +#include + +/* end standard C headers. */ + +/* flex integer type definitions */ + +#ifndef FLEXINT_H +#define FLEXINT_H + +/* C99 systems have . Non-C99 systems may or may not. */ + +#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + +/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, + * if you want the limit (max/min) macros for int types. + */ +#ifndef __STDC_LIMIT_MACROS +#define __STDC_LIMIT_MACROS 1 +#endif + +#include +typedef int8_t flex_int8_t; +typedef uint8_t flex_uint8_t; +typedef int16_t flex_int16_t; +typedef uint16_t flex_uint16_t; +typedef int32_t flex_int32_t; +typedef uint32_t flex_uint32_t; +#else +typedef signed char flex_int8_t; +typedef short int flex_int16_t; +typedef int flex_int32_t; +typedef unsigned char flex_uint8_t; +typedef unsigned short int flex_uint16_t; +typedef unsigned int flex_uint32_t; + +/* Limits of integral types. */ +#ifndef INT8_MIN +#define INT8_MIN (-128) +#endif +#ifndef INT16_MIN +#define INT16_MIN (-32767-1) +#endif +#ifndef INT32_MIN +#define INT32_MIN (-2147483647-1) +#endif +#ifndef INT8_MAX +#define INT8_MAX (127) +#endif +#ifndef INT16_MAX +#define INT16_MAX (32767) +#endif +#ifndef INT32_MAX +#define INT32_MAX (2147483647) +#endif +#ifndef UINT8_MAX +#define UINT8_MAX (255U) +#endif +#ifndef UINT16_MAX +#define UINT16_MAX (65535U) +#endif +#ifndef UINT32_MAX +#define UINT32_MAX (4294967295U) +#endif + +#ifndef SIZE_MAX +#define SIZE_MAX (~(size_t)0) +#endif + +#endif /* ! C99 */ + +#endif /* ! FLEXINT_H */ + +/* begin standard C++ headers. */ + +/* TODO: this is always defined, so inline it */ +#define yyconst const + +#if defined(__GNUC__) && __GNUC__ >= 3 +#define yynoreturn __attribute__((__noreturn__)) +#else +#define yynoreturn +#endif + +/* Returned upon end-of-file. */ +#define YY_NULL 0 + +/* Promotes a possibly negative, possibly signed char to an + * integer in range [0..255] for use as an array index. + */ +#define YY_SC_TO_UI(c) ((YY_CHAR) (c)) + +/* Enter a start condition. This macro really ought to take a parameter, + * but we do it the disgusting crufty way forced on us by the ()-less + * definition of BEGIN. + */ +#define BEGIN (yy_start) = 1 + 2 * +/* Translate the current start state into a value that can be later handed + * to BEGIN to return to the state. The YYSTATE alias is for lex + * compatibility. + */ +#define YY_START (((yy_start) - 1) / 2) +#define YYSTATE YY_START +/* Action number for EOF rule of a given start state. */ +#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) +/* Special action meaning "start processing a new file". */ +#define YY_NEW_FILE yyrestart( yyin ) +#define YY_END_OF_BUFFER_CHAR 0 + +/* Size of default input buffer. */ +#ifndef YY_BUF_SIZE +#ifdef __ia64__ +/* On IA-64, the buffer size is 16k, not 8k. + * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case. + * Ditto for the __ia64__ case accordingly. + */ +#define YY_BUF_SIZE 32768 +#else +#define YY_BUF_SIZE 16384 +#endif /* __ia64__ */ +#endif + +/* The state buf must be large enough to hold one state per character in the main buffer. + */ +#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type)) + +#ifndef YY_TYPEDEF_YY_BUFFER_STATE +#define YY_TYPEDEF_YY_BUFFER_STATE +typedef struct yy_buffer_state *YY_BUFFER_STATE; +#endif + +#ifndef YY_TYPEDEF_YY_SIZE_T +#define YY_TYPEDEF_YY_SIZE_T +typedef size_t yy_size_t; +#endif + +extern int yyleng; + +extern FILE *yyin, *yyout; + +#define EOB_ACT_CONTINUE_SCAN 0 +#define EOB_ACT_END_OF_FILE 1 +#define EOB_ACT_LAST_MATCH 2 + + #define YY_LESS_LINENO(n) + #define YY_LINENO_REWIND_TO(ptr) + +/* Return all but the first "n" matched characters back to the input stream. */ +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up yytext. */ \ + int yyless_macro_arg = (n); \ + YY_LESS_LINENO(yyless_macro_arg);\ + *yy_cp = (yy_hold_char); \ + YY_RESTORE_YY_MORE_OFFSET \ + (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ + YY_DO_BEFORE_ACTION; /* set up yytext again */ \ + } \ + while ( 0 ) +#define unput(c) yyunput( c, (yytext_ptr) ) + +#ifndef YY_STRUCT_YY_BUFFER_STATE +#define YY_STRUCT_YY_BUFFER_STATE +struct yy_buffer_state + { + FILE *yy_input_file; + + char *yy_ch_buf; /* input buffer */ + char *yy_buf_pos; /* current position in input buffer */ + + /* Size of input buffer in bytes, not including room for EOB + * characters. + */ + int yy_buf_size; + + /* Number of characters read into yy_ch_buf, not including EOB + * characters. + */ + int yy_n_chars; + + /* Whether we "own" the buffer - i.e., we know we created it, + * and can realloc() it to grow it, and should free() it to + * delete it. + */ + int yy_is_our_buffer; + + /* Whether this is an "interactive" input source; if so, and + * if we're using stdio for input, then we want to use getc() + * instead of fread(), to make sure we stop fetching input after + * each newline. + */ + int yy_is_interactive; + + /* Whether we're considered to be at the beginning of a line. + * If so, '^' rules will be active on the next match, otherwise + * not. + */ + int yy_at_bol; + + int yy_bs_lineno; /**< The line count. */ + int yy_bs_column; /**< The column count. */ + + /* Whether to try to fill the input buffer when we reach the + * end of it. + */ + int yy_fill_buffer; + + int yy_buffer_status; + +#define YY_BUFFER_NEW 0 +#define YY_BUFFER_NORMAL 1 + /* When an EOF's been seen but there's still some text to process + * then we mark the buffer as YY_EOF_PENDING, to indicate that we + * shouldn't try reading from the input source any more. We might + * still have a bunch of tokens to match, though, because of + * possible backing-up. + * + * When we actually see the EOF, we change the status to "new" + * (via yyrestart()), so that the user can continue scanning by + * just pointing yyin at a new input file. + */ +#define YY_BUFFER_EOF_PENDING 2 + + }; +#endif /* !YY_STRUCT_YY_BUFFER_STATE */ + +/* Stack of input buffers. */ +static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */ +static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */ +static YY_BUFFER_STATE * yy_buffer_stack = NULL; /**< Stack as an array. */ + +/* We provide macros for accessing buffer states in case in the + * future we want to put the buffer states in a more general + * "scanner state". + * + * Returns the top of the stack, or NULL. + */ +#define YY_CURRENT_BUFFER ( (yy_buffer_stack) \ + ? (yy_buffer_stack)[(yy_buffer_stack_top)] \ + : NULL) +/* Same as previous macro, but useful when we know that the buffer stack is not + * NULL or when we need an lvalue. For internal use only. + */ +#define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)] + +/* yy_hold_char holds the character lost when yytext is formed. */ +static char yy_hold_char; +static int yy_n_chars; /* number of characters read into yy_ch_buf */ +int yyleng; + +/* Points to current character in buffer. */ +static char *yy_c_buf_p = NULL; +static int yy_init = 0; /* whether we need to initialize */ +static int yy_start = 0; /* start state number */ + +/* Flag which is used to allow yywrap()'s to do buffer switches + * instead of setting up a fresh yyin. A bit of a hack ... + */ +static int yy_did_buffer_switch_on_eof; + +void yyrestart ( FILE *input_file ); +void yy_switch_to_buffer ( YY_BUFFER_STATE new_buffer ); +YY_BUFFER_STATE yy_create_buffer ( FILE *file, int size ); +void yy_delete_buffer ( YY_BUFFER_STATE b ); +void yy_flush_buffer ( YY_BUFFER_STATE b ); +void yypush_buffer_state ( YY_BUFFER_STATE new_buffer ); +void yypop_buffer_state ( void ); + +static void yyensure_buffer_stack ( void ); +static void yy_load_buffer_state ( void ); +static void yy_init_buffer ( YY_BUFFER_STATE b, FILE *file ); +#define YY_FLUSH_BUFFER yy_flush_buffer( YY_CURRENT_BUFFER ) + +YY_BUFFER_STATE yy_scan_buffer ( char *base, yy_size_t size ); +YY_BUFFER_STATE yy_scan_string ( const char *yy_str ); +YY_BUFFER_STATE yy_scan_bytes ( const char *bytes, int len ); + +void *yyalloc ( yy_size_t ); +void *yyrealloc ( void *, yy_size_t ); +void yyfree ( void * ); + +#define yy_new_buffer yy_create_buffer +#define yy_set_interactive(is_interactive) \ + { \ + if ( ! YY_CURRENT_BUFFER ){ \ + yyensure_buffer_stack (); \ + YY_CURRENT_BUFFER_LVALUE = \ + yy_create_buffer( yyin, YY_BUF_SIZE ); \ + } \ + YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ + } +#define yy_set_bol(at_bol) \ + { \ + if ( ! YY_CURRENT_BUFFER ){\ + yyensure_buffer_stack (); \ + YY_CURRENT_BUFFER_LVALUE = \ + yy_create_buffer( yyin, YY_BUF_SIZE ); \ + } \ + YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ + } +#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol) + +/* Begin user sect3 */ +typedef flex_uint8_t YY_CHAR; + +FILE *yyin = NULL, *yyout = NULL; + +typedef int yy_state_type; + +extern int yylineno; +int yylineno = 1; + +extern char *yytext; +#ifdef yytext_ptr +#undef yytext_ptr +#endif +#define yytext_ptr yytext + +static yy_state_type yy_get_previous_state ( void ); +static yy_state_type yy_try_NUL_trans ( yy_state_type current_state ); +static int yy_get_next_buffer ( void ); +static void yynoreturn yy_fatal_error ( const char* msg ); + +/* Done after the current pattern has been matched and before the + * corresponding action - sets up yytext. + */ +#define YY_DO_BEFORE_ACTION \ + (yytext_ptr) = yy_bp; \ + yyleng = (int) (yy_cp - yy_bp); \ + (yy_hold_char) = *yy_cp; \ + *yy_cp = '\0'; \ + (yy_c_buf_p) = yy_cp; +#define YY_NUM_RULES 13 +#define YY_END_OF_BUFFER 14 +/* This struct is not used in this scanner, + but its presence is necessary. */ +struct yy_trans_info + { + flex_int32_t yy_verify; + flex_int32_t yy_nxt; + }; +static const flex_int16_t yy_accept[51] = + { 0, + 0, 0, 14, 13, 1, 2, 13, 13, 7, 13, + 13, 8, 6, 10, 1, 0, 11, 0, 0, 0, + 8, 0, 0, 0, 8, 10, 11, 12, 0, 0, + 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 5, 0, 0, 0, 0, 0, 0, 4, 3, 0 + } ; + +static const YY_CHAR yy_ec[256] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 2, 1, 4, 1, 1, 1, 1, 5, 1, + 1, 1, 1, 6, 7, 8, 1, 9, 9, 9, + 9, 9, 9, 9, 9, 9, 9, 10, 1, 1, + 1, 1, 1, 1, 11, 11, 11, 11, 11, 11, + 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, + 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, + 1, 12, 1, 1, 13, 1, 14, 15, 11, 16, + + 17, 11, 18, 11, 19, 11, 11, 20, 11, 11, + 21, 11, 11, 22, 11, 23, 11, 11, 24, 11, + 25, 11, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1 + } ; + +static const YY_CHAR yy_meta[26] = + { 0, + 1, 1, 2, 1, 1, 1, 1, 1, 3, 1, + 3, 1, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3 + } ; + +static const flex_int16_t yy_base[54] = + { 0, + 0, 0, 75, 76, 72, 76, 22, 68, 76, 63, + 9, 22, 76, 0, 69, 24, 76, 29, 65, 64, + 59, 47, 47, 56, 29, 0, 31, 76, 43, 40, + 53, 46, 43, 45, 36, 37, 42, 42, 33, 24, + 76, 25, 26, 23, 23, 27, 26, 76, 76, 76, + 48, 51, 37 + } ; + +static const flex_int16_t yy_def[54] = + { 0, + 50, 1, 50, 50, 50, 50, 51, 52, 50, 50, + 50, 50, 50, 53, 50, 51, 50, 51, 50, 50, + 50, 50, 50, 50, 50, 53, 51, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 0, + 50, 50, 50 + } ; + +static const flex_int16_t yy_nxt[102] = + { 0, + 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, + 14, 4, 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 17, 22, 17, 23, 24, + 25, 16, 27, 18, 17, 18, 24, 25, 42, 26, + 18, 49, 18, 48, 47, 46, 45, 43, 16, 44, + 16, 19, 41, 19, 40, 39, 38, 37, 36, 35, + 34, 31, 33, 32, 31, 30, 29, 21, 19, 28, + 15, 21, 20, 15, 50, 3, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + + 50 + } ; + +static const flex_int16_t yy_chk[102] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 7, 11, 16, 11, 12, + 12, 18, 18, 7, 27, 16, 25, 25, 40, 53, + 18, 47, 27, 46, 45, 44, 43, 40, 51, 42, + 51, 52, 39, 52, 38, 37, 36, 35, 34, 33, + 32, 31, 30, 29, 24, 23, 22, 21, 20, 19, + 15, 10, 8, 5, 3, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + + 50 + } ; + +static yy_state_type yy_last_accepting_state; +static char *yy_last_accepting_cpos; + +extern int yy_flex_debug; +int yy_flex_debug = 0; + +/* The intent behind this definition is that it'll catch + * any uses of REJECT which flex missed. + */ +#define REJECT reject_used_but_not_detected +#define yymore() yymore_used_but_not_detected +#define YY_MORE_ADJ 0 +#define YY_RESTORE_YY_MORE_OFFSET +char *yytext; +#line 1 "interp.l" +#line 8 "interp.l" +#define YYSTYPE_IS_DECLARED 1 +typedef long YYSTYPE; +#include "y.tab.h" + +int line_no=1; + +int search_opcode(); +int is_inst2(); +char *makeString(); +#line 489 "lex.yy.c" +#line 490 "lex.yy.c" + +#define INITIAL 0 + +#ifndef YY_NO_UNISTD_H +/* Special case for "unistd.h", since it is non-ANSI. We include it way + * down here because we want the user's section 1 to have been scanned first. + * The user has a chance to override it with an option. + */ +#include +#endif + +#ifndef YY_EXTRA_TYPE +#define YY_EXTRA_TYPE void * +#endif + +static int yy_init_globals ( void ); + +/* Accessor methods to globals. + These are made visible to non-reentrant scanners for convenience. */ + +int yylex_destroy ( void ); + +int yyget_debug ( void ); + +void yyset_debug ( int debug_flag ); + +YY_EXTRA_TYPE yyget_extra ( void ); + +void yyset_extra ( YY_EXTRA_TYPE user_defined ); + +FILE *yyget_in ( void ); + +void yyset_in ( FILE * _in_str ); + +FILE *yyget_out ( void ); + +void yyset_out ( FILE * _out_str ); + + int yyget_leng ( void ); + +char *yyget_text ( void ); + +int yyget_lineno ( void ); + +void yyset_lineno ( int _line_number ); + +/* Macros after this point can all be overridden by user definitions in + * section 1. + */ + +#ifndef YY_SKIP_YYWRAP +#ifdef __cplusplus +extern "C" int yywrap ( void ); +#else +extern int yywrap ( void ); +#endif +#endif + +#ifndef YY_NO_UNPUT + + static void yyunput ( int c, char *buf_ptr ); + +#endif + +#ifndef yytext_ptr +static void yy_flex_strncpy ( char *, const char *, int ); +#endif + +#ifdef YY_NEED_STRLEN +static int yy_flex_strlen ( const char * ); +#endif + +#ifndef YY_NO_INPUT +#ifdef __cplusplus +static int yyinput ( void ); +#else +static int input ( void ); +#endif + +#endif + +/* Amount of stuff to slurp up with each read. */ +#ifndef YY_READ_BUF_SIZE +#ifdef __ia64__ +/* On IA-64, the buffer size is 16k, not 8k */ +#define YY_READ_BUF_SIZE 16384 +#else +#define YY_READ_BUF_SIZE 8192 +#endif /* __ia64__ */ +#endif + +/* Copy whatever the last rule matched to the standard output. */ +#ifndef ECHO +/* This used to be an fputs(), but since the string might contain NUL's, + * we now use fwrite(). + */ +#define ECHO do { if (fwrite( yytext, (size_t) yyleng, 1, yyout )) {} } while (0) +#endif + +/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, + * is returned in "result". + */ +#ifndef YY_INPUT +#define YY_INPUT(buf,result,max_size) \ + if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ + { \ + int c = '*'; \ + int n; \ + for ( n = 0; n < max_size && \ + (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ + buf[n] = (char) c; \ + if ( c == '\n' ) \ + buf[n++] = (char) c; \ + if ( c == EOF && ferror( yyin ) ) \ + YY_FATAL_ERROR( "input in flex scanner failed" ); \ + result = n; \ + } \ + else \ + { \ + errno=0; \ + while ( (result = (int) fread(buf, 1, (yy_size_t) max_size, yyin)) == 0 && ferror(yyin)) \ + { \ + if( errno != EINTR) \ + { \ + YY_FATAL_ERROR( "input in flex scanner failed" ); \ + break; \ + } \ + errno=0; \ + clearerr(yyin); \ + } \ + }\ +\ + +#endif + +/* No semi-colon after return; correct usage is to write "yyterminate();" - + * we don't want an extra ';' after the "return" because that will cause + * some compilers to complain about unreachable statements. + */ +#ifndef yyterminate +#define yyterminate() return YY_NULL +#endif + +/* Number of entries by which start-condition stack grows. */ +#ifndef YY_START_STACK_INCR +#define YY_START_STACK_INCR 25 +#endif + +/* Report a fatal error. */ +#ifndef YY_FATAL_ERROR +#define YY_FATAL_ERROR(msg) yy_fatal_error( msg ) +#endif + +/* end tables serialization structures and prototypes */ + +/* Default declaration of generated scanner - a define so the user can + * easily add parameters. + */ +#ifndef YY_DECL +#define YY_DECL_IS_OURS 1 + +extern int yylex (void); + +#define YY_DECL int yylex (void) +#endif /* !YY_DECL */ + +/* Code executed at the beginning of each rule, after yytext and yyleng + * have been set up. + */ +#ifndef YY_USER_ACTION +#define YY_USER_ACTION +#endif + +/* Code executed at the end of each rule. */ +#ifndef YY_BREAK +#define YY_BREAK /*LINTED*/break; +#endif + +#define YY_RULE_SETUP \ + YY_USER_ACTION + +/** The main scanner function which does all the work. + */ +YY_DECL +{ + yy_state_type yy_current_state; + char *yy_cp, *yy_bp; + int yy_act; + + if ( !(yy_init) ) + { + (yy_init) = 1; + +#ifdef YY_USER_INIT + YY_USER_INIT; +#endif + + if ( ! (yy_start) ) + (yy_start) = 1; /* first start state */ + + if ( ! yyin ) + yyin = stdin; + + if ( ! yyout ) + yyout = stdout; + + if ( ! YY_CURRENT_BUFFER ) { + yyensure_buffer_stack (); + YY_CURRENT_BUFFER_LVALUE = + yy_create_buffer( yyin, YY_BUF_SIZE ); + } + + yy_load_buffer_state( ); + } + + { +#line 19 "interp.l" + + +#line 710 "lex.yy.c" + + while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */ + { + yy_cp = (yy_c_buf_p); + + /* Support of yytext. */ + *yy_cp = (yy_hold_char); + + /* yy_bp points to the position in yy_ch_buf of the start of + * the current run. + */ + yy_bp = yy_cp; + + yy_current_state = (yy_start); +yy_match: + do + { + YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ; + if ( yy_accept[yy_current_state] ) + { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 51 ) + yy_c = yy_meta[yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; + ++yy_cp; + } + while ( yy_base[yy_current_state] != 76 ); + +yy_find_action: + yy_act = yy_accept[yy_current_state]; + if ( yy_act == 0 ) + { /* have to back up */ + yy_cp = (yy_last_accepting_cpos); + yy_current_state = (yy_last_accepting_state); + yy_act = yy_accept[yy_current_state]; + } + + YY_DO_BEFORE_ACTION; + +do_action: /* This label is used only to access EOF actions. */ + + switch ( yy_act ) + { /* beginning of action switch */ + case 0: /* must back up */ + /* undo the effects of YY_DO_BEFORE_ACTION */ + *yy_cp = (yy_hold_char); + yy_cp = (yy_last_accepting_cpos); + yy_current_state = (yy_last_accepting_state); + goto yy_find_action; + +case 1: +YY_RULE_SETUP +#line 21 "interp.l" +{ } + YY_BREAK +case 2: +/* rule 2 can match eol */ +YY_RULE_SETUP +#line 22 "interp.l" +{ line_no++; return(NEW_LINE);}; + YY_BREAK +case 3: +YY_RULE_SETUP +#line 23 "interp.l" +{ return(GLOBAL_WORD_SYM);} + YY_BREAK +case 4: +YY_RULE_SETUP +#line 24 "interp.l" +{ return(GLOBAL_BYTE_SYM);} + YY_BREAK +case 5: +YY_RULE_SETUP +#line 25 "interp.l" +{ return(LITERAL_SYM);} + YY_BREAK +case 6: +YY_RULE_SETUP +#line 26 "interp.l" +{ return(COLON); } + YY_BREAK +case 7: +YY_RULE_SETUP +#line 27 "interp.l" +{ return(COMMA); } + YY_BREAK +case 8: +YY_RULE_SETUP +#line 30 "interp.l" +{ yylval=atoi(yytext); return(INTEGER);} + YY_BREAK +case 9: +YY_RULE_SETUP +#line 31 "interp.l" +{ yylval=makeString(yytext); return(FLOAT);} + YY_BREAK +case 10: +YY_RULE_SETUP +#line 32 "interp.l" +{ yylval=search_opcode(yytext); + if (yylval==0) { + yylval=makeString(yytext); + return(IDENTIFIER);} + else if (is_inst2(yylval)) return (INST2); + else return(INST1);} + YY_BREAK +case 11: +/* rule 11 can match eol */ +YY_RULE_SETUP +#line 38 "interp.l" +{ yylval=makeString(yytext); return(STRING);} + YY_BREAK +case 12: +YY_RULE_SETUP +#line 39 "interp.l" +{ yylval=*(yytext+1); return(CHAR);} + YY_BREAK +case 13: +YY_RULE_SETUP +#line 41 "interp.l" +ECHO; + YY_BREAK +#line 839 "lex.yy.c" +case YY_STATE_EOF(INITIAL): + yyterminate(); + + case YY_END_OF_BUFFER: + { + /* Amount of text matched not including the EOB char. */ + int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1; + + /* Undo the effects of YY_DO_BEFORE_ACTION. */ + *yy_cp = (yy_hold_char); + YY_RESTORE_YY_MORE_OFFSET + + if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW ) + { + /* We're scanning a new file or input source. It's + * possible that this happened because the user + * just pointed yyin at a new source and called + * yylex(). If so, then we have to assure + * consistency between YY_CURRENT_BUFFER and our + * globals. Here is the right place to do so, because + * this is the first action (other than possibly a + * back-up) that will match for the new input source. + */ + (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin; + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; + } + + /* Note that here we test for yy_c_buf_p "<=" to the position + * of the first EOB in the buffer, since yy_c_buf_p will + * already have been incremented past the NUL character + * (since all states make transitions on EOB to the + * end-of-buffer state). Contrast this with the test + * in input(). + */ + if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) + { /* This was really a NUL. */ + yy_state_type yy_next_state; + + (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state( ); + + /* Okay, we're now positioned to make the NUL + * transition. We couldn't have + * yy_get_previous_state() go ahead and do it + * for us because it doesn't know how to deal + * with the possibility of jamming (and we don't + * want to build jamming into it because then it + * will run more slowly). + */ + + yy_next_state = yy_try_NUL_trans( yy_current_state ); + + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + + if ( yy_next_state ) + { + /* Consume the NUL. */ + yy_cp = ++(yy_c_buf_p); + yy_current_state = yy_next_state; + goto yy_match; + } + + else + { + yy_cp = (yy_c_buf_p); + goto yy_find_action; + } + } + + else switch ( yy_get_next_buffer( ) ) + { + case EOB_ACT_END_OF_FILE: + { + (yy_did_buffer_switch_on_eof) = 0; + + if ( yywrap( ) ) + { + /* Note: because we've taken care in + * yy_get_next_buffer() to have set up + * yytext, we can now set up + * yy_c_buf_p so that if some total + * hoser (like flex itself) wants to + * call the scanner after we return the + * YY_NULL, it'll still work - another + * YY_NULL will get returned. + */ + (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ; + + yy_act = YY_STATE_EOF(YY_START); + goto do_action; + } + + else + { + if ( ! (yy_did_buffer_switch_on_eof) ) + YY_NEW_FILE; + } + break; + } + + case EOB_ACT_CONTINUE_SCAN: + (yy_c_buf_p) = + (yytext_ptr) + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state( ); + + yy_cp = (yy_c_buf_p); + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + goto yy_match; + + case EOB_ACT_LAST_MATCH: + (yy_c_buf_p) = + &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)]; + + yy_current_state = yy_get_previous_state( ); + + yy_cp = (yy_c_buf_p); + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + goto yy_find_action; + } + break; + } + + default: + YY_FATAL_ERROR( + "fatal flex scanner internal error--no action found" ); + } /* end of action switch */ + } /* end of scanning one token */ + } /* end of user's declarations */ +} /* end of yylex */ + +/* yy_get_next_buffer - try to read in a new buffer + * + * Returns a code representing an action: + * EOB_ACT_LAST_MATCH - + * EOB_ACT_CONTINUE_SCAN - continue scanning from current position + * EOB_ACT_END_OF_FILE - end of file + */ +static int yy_get_next_buffer (void) +{ + char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; + char *source = (yytext_ptr); + int number_to_move, i; + int ret_val; + + if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] ) + YY_FATAL_ERROR( + "fatal flex scanner internal error--end of buffer missed" ); + + if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 ) + { /* Don't try to fill the buffer, so this is an EOF. */ + if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 ) + { + /* We matched a single character, the EOB, so + * treat this as a final EOF. + */ + return EOB_ACT_END_OF_FILE; + } + + else + { + /* We matched some text prior to the EOB, first + * process it. + */ + return EOB_ACT_LAST_MATCH; + } + } + + /* Try to read more data. */ + + /* First move last chars to start of buffer. */ + number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr) - 1); + + for ( i = 0; i < number_to_move; ++i ) + *(dest++) = *(source++); + + if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING ) + /* don't do the read, it's not guaranteed to return an EOF, + * just force an EOF + */ + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0; + + else + { + int num_to_read = + YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; + + while ( num_to_read <= 0 ) + { /* Not enough room in the buffer - grow it. */ + + /* just a shorter name for the current buffer */ + YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE; + + int yy_c_buf_p_offset = + (int) ((yy_c_buf_p) - b->yy_ch_buf); + + if ( b->yy_is_our_buffer ) + { + int new_size = b->yy_buf_size * 2; + + if ( new_size <= 0 ) + b->yy_buf_size += b->yy_buf_size / 8; + else + b->yy_buf_size *= 2; + + b->yy_ch_buf = (char *) + /* Include room in for 2 EOB chars. */ + yyrealloc( (void *) b->yy_ch_buf, + (yy_size_t) (b->yy_buf_size + 2) ); + } + else + /* Can't grow it, we don't own it. */ + b->yy_ch_buf = NULL; + + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( + "fatal error - scanner input buffer overflow" ); + + (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset]; + + num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - + number_to_move - 1; + + } + + if ( num_to_read > YY_READ_BUF_SIZE ) + num_to_read = YY_READ_BUF_SIZE; + + /* Read in more data. */ + YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), + (yy_n_chars), num_to_read ); + + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } + + if ( (yy_n_chars) == 0 ) + { + if ( number_to_move == YY_MORE_ADJ ) + { + ret_val = EOB_ACT_END_OF_FILE; + yyrestart( yyin ); + } + + else + { + ret_val = EOB_ACT_LAST_MATCH; + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = + YY_BUFFER_EOF_PENDING; + } + } + + else + ret_val = EOB_ACT_CONTINUE_SCAN; + + if (((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { + /* Extend the array by 50%, plus the number we really need. */ + int new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1); + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc( + (void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf, (yy_size_t) new_size ); + if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); + /* "- 2" to take care of EOB's */ + YY_CURRENT_BUFFER_LVALUE->yy_buf_size = (int) (new_size - 2); + } + + (yy_n_chars) += number_to_move; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR; + + (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; + + return ret_val; +} + +/* yy_get_previous_state - get the state just before the EOB char was reached */ + + static yy_state_type yy_get_previous_state (void) +{ + yy_state_type yy_current_state; + char *yy_cp; + + yy_current_state = (yy_start); + + for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp ) + { + YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); + if ( yy_accept[yy_current_state] ) + { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 51 ) + yy_c = yy_meta[yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; + } + + return yy_current_state; +} + +/* yy_try_NUL_trans - try to make a transition on the NUL character + * + * synopsis + * next_state = yy_try_NUL_trans( current_state ); + */ + static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state ) +{ + int yy_is_jam; + char *yy_cp = (yy_c_buf_p); + + YY_CHAR yy_c = 1; + if ( yy_accept[yy_current_state] ) + { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 51 ) + yy_c = yy_meta[yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; + yy_is_jam = (yy_current_state == 50); + + return yy_is_jam ? 0 : yy_current_state; +} + +#ifndef YY_NO_UNPUT + + static void yyunput (int c, char * yy_bp ) +{ + char *yy_cp; + + yy_cp = (yy_c_buf_p); + + /* undo effects of setting up yytext */ + *yy_cp = (yy_hold_char); + + if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) + { /* need to shift things up to make room */ + /* +2 for EOB chars. */ + int number_to_move = (yy_n_chars) + 2; + char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[ + YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2]; + char *source = + &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]; + + while ( source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) + *--dest = *--source; + + yy_cp += (int) (dest - source); + yy_bp += (int) (dest - source); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = + (yy_n_chars) = (int) YY_CURRENT_BUFFER_LVALUE->yy_buf_size; + + if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) + YY_FATAL_ERROR( "flex scanner push-back overflow" ); + } + + *--yy_cp = (char) c; + + (yytext_ptr) = yy_bp; + (yy_hold_char) = *yy_cp; + (yy_c_buf_p) = yy_cp; +} + +#endif + +#ifndef YY_NO_INPUT +#ifdef __cplusplus + static int yyinput (void) +#else + static int input (void) +#endif + +{ + int c; + + *(yy_c_buf_p) = (yy_hold_char); + + if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR ) + { + /* yy_c_buf_p now points to the character we want to return. + * If this occurs *before* the EOB characters, then it's a + * valid NUL; if not, then we've hit the end of the buffer. + */ + if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) + /* This was really a NUL. */ + *(yy_c_buf_p) = '\0'; + + else + { /* need more input */ + int offset = (int) ((yy_c_buf_p) - (yytext_ptr)); + ++(yy_c_buf_p); + + switch ( yy_get_next_buffer( ) ) + { + case EOB_ACT_LAST_MATCH: + /* This happens because yy_g_n_b() + * sees that we've accumulated a + * token and flags that we need to + * try matching the token before + * proceeding. But for input(), + * there's no matching to consider. + * So convert the EOB_ACT_LAST_MATCH + * to EOB_ACT_END_OF_FILE. + */ + + /* Reset buffer status. */ + yyrestart( yyin ); + + /*FALLTHROUGH*/ + + case EOB_ACT_END_OF_FILE: + { + if ( yywrap( ) ) + return 0; + + if ( ! (yy_did_buffer_switch_on_eof) ) + YY_NEW_FILE; +#ifdef __cplusplus + return yyinput(); +#else + return input(); +#endif + } + + case EOB_ACT_CONTINUE_SCAN: + (yy_c_buf_p) = (yytext_ptr) + offset; + break; + } + } + } + + c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */ + *(yy_c_buf_p) = '\0'; /* preserve yytext */ + (yy_hold_char) = *++(yy_c_buf_p); + + return c; +} +#endif /* ifndef YY_NO_INPUT */ + +/** Immediately switch to a different input stream. + * @param input_file A readable stream. + * + * @note This function does not reset the start condition to @c INITIAL . + */ + void yyrestart (FILE * input_file ) +{ + + if ( ! YY_CURRENT_BUFFER ){ + yyensure_buffer_stack (); + YY_CURRENT_BUFFER_LVALUE = + yy_create_buffer( yyin, YY_BUF_SIZE ); + } + + yy_init_buffer( YY_CURRENT_BUFFER, input_file ); + yy_load_buffer_state( ); +} + +/** Switch to a different input buffer. + * @param new_buffer The new input buffer. + * + */ + void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ) +{ + + /* TODO. We should be able to replace this entire function body + * with + * yypop_buffer_state(); + * yypush_buffer_state(new_buffer); + */ + yyensure_buffer_stack (); + if ( YY_CURRENT_BUFFER == new_buffer ) + return; + + if ( YY_CURRENT_BUFFER ) + { + /* Flush out information for old buffer. */ + *(yy_c_buf_p) = (yy_hold_char); + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } + + YY_CURRENT_BUFFER_LVALUE = new_buffer; + yy_load_buffer_state( ); + + /* We don't actually know whether we did this switch during + * EOF (yywrap()) processing, but the only time this flag + * is looked at is after yywrap() is called, so it's safe + * to go ahead and always set it. + */ + (yy_did_buffer_switch_on_eof) = 1; +} + +static void yy_load_buffer_state (void) +{ + (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; + yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file; + (yy_hold_char) = *(yy_c_buf_p); +} + +/** Allocate and initialize an input buffer state. + * @param file A readable stream. + * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE. + * + * @return the allocated buffer state. + */ + YY_BUFFER_STATE yy_create_buffer (FILE * file, int size ) +{ + YY_BUFFER_STATE b; + + b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) ); + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); + + b->yy_buf_size = size; + + /* yy_ch_buf has to be 2 characters longer than the size given because + * we need to put in 2 end-of-buffer characters. + */ + b->yy_ch_buf = (char *) yyalloc( (yy_size_t) (b->yy_buf_size + 2) ); + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); + + b->yy_is_our_buffer = 1; + + yy_init_buffer( b, file ); + + return b; +} + +/** Destroy the buffer. + * @param b a buffer created with yy_create_buffer() + * + */ + void yy_delete_buffer (YY_BUFFER_STATE b ) +{ + + if ( ! b ) + return; + + if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */ + YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; + + if ( b->yy_is_our_buffer ) + yyfree( (void *) b->yy_ch_buf ); + + yyfree( (void *) b ); +} + +/* Initializes or reinitializes a buffer. + * This function is sometimes called more than once on the same buffer, + * such as during a yyrestart() or at EOF. + */ + static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file ) + +{ + int oerrno = errno; + + yy_flush_buffer( b ); + + b->yy_input_file = file; + b->yy_fill_buffer = 1; + + /* If b is the current buffer, then yy_init_buffer was _probably_ + * called from yyrestart() or through yy_get_next_buffer. + * In that case, we don't want to reset the lineno or column. + */ + if (b != YY_CURRENT_BUFFER){ + b->yy_bs_lineno = 1; + b->yy_bs_column = 0; + } + + b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0; + + errno = oerrno; +} + +/** Discard all buffered characters. On the next scan, YY_INPUT will be called. + * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER. + * + */ + void yy_flush_buffer (YY_BUFFER_STATE b ) +{ + if ( ! b ) + return; + + b->yy_n_chars = 0; + + /* We always need two end-of-buffer characters. The first causes + * a transition to the end-of-buffer state. The second causes + * a jam in that state. + */ + b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; + b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; + + b->yy_buf_pos = &b->yy_ch_buf[0]; + + b->yy_at_bol = 1; + b->yy_buffer_status = YY_BUFFER_NEW; + + if ( b == YY_CURRENT_BUFFER ) + yy_load_buffer_state( ); +} + +/** Pushes the new state onto the stack. The new state becomes + * the current state. This function will allocate the stack + * if necessary. + * @param new_buffer The new state. + * + */ +void yypush_buffer_state (YY_BUFFER_STATE new_buffer ) +{ + if (new_buffer == NULL) + return; + + yyensure_buffer_stack(); + + /* This block is copied from yy_switch_to_buffer. */ + if ( YY_CURRENT_BUFFER ) + { + /* Flush out information for old buffer. */ + *(yy_c_buf_p) = (yy_hold_char); + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } + + /* Only push if top exists. Otherwise, replace top. */ + if (YY_CURRENT_BUFFER) + (yy_buffer_stack_top)++; + YY_CURRENT_BUFFER_LVALUE = new_buffer; + + /* copied from yy_switch_to_buffer. */ + yy_load_buffer_state( ); + (yy_did_buffer_switch_on_eof) = 1; +} + +/** Removes and deletes the top of the stack, if present. + * The next element becomes the new top. + * + */ +void yypop_buffer_state (void) +{ + if (!YY_CURRENT_BUFFER) + return; + + yy_delete_buffer(YY_CURRENT_BUFFER ); + YY_CURRENT_BUFFER_LVALUE = NULL; + if ((yy_buffer_stack_top) > 0) + --(yy_buffer_stack_top); + + if (YY_CURRENT_BUFFER) { + yy_load_buffer_state( ); + (yy_did_buffer_switch_on_eof) = 1; + } +} + +/* Allocates the stack if it does not exist. + * Guarantees space for at least one push. + */ +static void yyensure_buffer_stack (void) +{ + yy_size_t num_to_alloc; + + if (!(yy_buffer_stack)) { + + /* First allocation is just for 2 elements, since we don't know if this + * scanner will even need a stack. We use 2 instead of 1 to avoid an + * immediate realloc on the next call. + */ + num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */ + (yy_buffer_stack) = (struct yy_buffer_state**)yyalloc + (num_to_alloc * sizeof(struct yy_buffer_state*) + ); + if ( ! (yy_buffer_stack) ) + YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); + + memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*)); + + (yy_buffer_stack_max) = num_to_alloc; + (yy_buffer_stack_top) = 0; + return; + } + + if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){ + + /* Increase the buffer to prepare for a possible push. */ + yy_size_t grow_size = 8 /* arbitrary grow size */; + + num_to_alloc = (yy_buffer_stack_max) + grow_size; + (yy_buffer_stack) = (struct yy_buffer_state**)yyrealloc + ((yy_buffer_stack), + num_to_alloc * sizeof(struct yy_buffer_state*) + ); + if ( ! (yy_buffer_stack) ) + YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); + + /* zero only the new slots.*/ + memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*)); + (yy_buffer_stack_max) = num_to_alloc; + } +} + +/** Setup the input buffer state to scan directly from a user-specified character buffer. + * @param base the character buffer + * @param size the size in bytes of the character buffer + * + * @return the newly allocated buffer state object. + */ +YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size ) +{ + YY_BUFFER_STATE b; + + if ( size < 2 || + base[size-2] != YY_END_OF_BUFFER_CHAR || + base[size-1] != YY_END_OF_BUFFER_CHAR ) + /* They forgot to leave room for the EOB's. */ + return NULL; + + b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) ); + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" ); + + b->yy_buf_size = (int) (size - 2); /* "- 2" to take care of EOB's */ + b->yy_buf_pos = b->yy_ch_buf = base; + b->yy_is_our_buffer = 0; + b->yy_input_file = NULL; + b->yy_n_chars = b->yy_buf_size; + b->yy_is_interactive = 0; + b->yy_at_bol = 1; + b->yy_fill_buffer = 0; + b->yy_buffer_status = YY_BUFFER_NEW; + + yy_switch_to_buffer( b ); + + return b; +} + +/** Setup the input buffer state to scan a string. The next call to yylex() will + * scan from a @e copy of @a str. + * @param yystr a NUL-terminated string to scan + * + * @return the newly allocated buffer state object. + * @note If you want to scan bytes that may contain NUL values, then use + * yy_scan_bytes() instead. + */ +YY_BUFFER_STATE yy_scan_string (const char * yystr ) +{ + + return yy_scan_bytes( yystr, (int) strlen(yystr) ); +} + +/** Setup the input buffer state to scan the given bytes. The next call to yylex() will + * scan from a @e copy of @a bytes. + * @param yybytes the byte buffer to scan + * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes. + * + * @return the newly allocated buffer state object. + */ +YY_BUFFER_STATE yy_scan_bytes (const char * yybytes, int _yybytes_len ) +{ + YY_BUFFER_STATE b; + char *buf; + yy_size_t n; + int i; + + /* Get memory for full buffer, including space for trailing EOB's. */ + n = (yy_size_t) (_yybytes_len + 2); + buf = (char *) yyalloc( n ); + if ( ! buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" ); + + for ( i = 0; i < _yybytes_len; ++i ) + buf[i] = yybytes[i]; + + buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR; + + b = yy_scan_buffer( buf, n ); + if ( ! b ) + YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" ); + + /* It's okay to grow etc. this buffer, and we should throw it + * away when we're done. + */ + b->yy_is_our_buffer = 1; + + return b; +} + +#ifndef YY_EXIT_FAILURE +#define YY_EXIT_FAILURE 2 +#endif + +static void yynoreturn yy_fatal_error (const char* msg ) +{ + fprintf( stderr, "%s\n", msg ); + exit( YY_EXIT_FAILURE ); +} + +/* Redefine yyless() so it works in section 3 code. */ + +#undef yyless +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up yytext. */ \ + int yyless_macro_arg = (n); \ + YY_LESS_LINENO(yyless_macro_arg);\ + yytext[yyleng] = (yy_hold_char); \ + (yy_c_buf_p) = yytext + yyless_macro_arg; \ + (yy_hold_char) = *(yy_c_buf_p); \ + *(yy_c_buf_p) = '\0'; \ + yyleng = yyless_macro_arg; \ + } \ + while ( 0 ) + +/* Accessor methods (get/set functions) to struct members. */ + +/** Get the current line number. + * + */ +int yyget_lineno (void) +{ + + return yylineno; +} + +/** Get the input stream. + * + */ +FILE *yyget_in (void) +{ + return yyin; +} + +/** Get the output stream. + * + */ +FILE *yyget_out (void) +{ + return yyout; +} + +/** Get the length of the current token. + * + */ +int yyget_leng (void) +{ + return yyleng; +} + +/** Get the current token. + * + */ + +char *yyget_text (void) +{ + return yytext; +} + +/** Set the current line number. + * @param _line_number line number + * + */ +void yyset_lineno (int _line_number ) +{ + + yylineno = _line_number; +} + +/** Set the input stream. This does not discard the current + * input buffer. + * @param _in_str A readable stream. + * + * @see yy_switch_to_buffer + */ +void yyset_in (FILE * _in_str ) +{ + yyin = _in_str ; +} + +void yyset_out (FILE * _out_str ) +{ + yyout = _out_str ; +} + +int yyget_debug (void) +{ + return yy_flex_debug; +} + +void yyset_debug (int _bdebug ) +{ + yy_flex_debug = _bdebug ; +} + +static int yy_init_globals (void) +{ + /* Initialization is the same as for the non-reentrant scanner. + * This function is called from yylex_destroy(), so don't allocate here. + */ + + (yy_buffer_stack) = NULL; + (yy_buffer_stack_top) = 0; + (yy_buffer_stack_max) = 0; + (yy_c_buf_p) = NULL; + (yy_init) = 0; + (yy_start) = 0; + +/* Defined in main.c */ +#ifdef YY_STDINIT + yyin = stdin; + yyout = stdout; +#else + yyin = NULL; + yyout = NULL; +#endif + + /* For future reference: Set errno on error, since we are called by + * yylex_init() + */ + return 0; +} + +/* yylex_destroy is for both reentrant and non-reentrant scanners. */ +int yylex_destroy (void) +{ + + /* Pop the buffer stack, destroying each element. */ + while(YY_CURRENT_BUFFER){ + yy_delete_buffer( YY_CURRENT_BUFFER ); + YY_CURRENT_BUFFER_LVALUE = NULL; + yypop_buffer_state(); + } + + /* Destroy the stack itself. */ + yyfree((yy_buffer_stack) ); + (yy_buffer_stack) = NULL; + + /* Reset the globals. This is important in a non-reentrant scanner so the next time + * yylex() is called, initialization will occur. */ + yy_init_globals( ); + + return 0; +} + +/* + * Internal utility routines. + */ + +#ifndef yytext_ptr +static void yy_flex_strncpy (char* s1, const char * s2, int n ) +{ + + int i; + for ( i = 0; i < n; ++i ) + s1[i] = s2[i]; +} +#endif + +#ifdef YY_NEED_STRLEN +static int yy_flex_strlen (const char * s ) +{ + int n; + for ( n = 0; s[n]; ++n ) + ; + + return n; +} +#endif + +void *yyalloc (yy_size_t size ) +{ + return malloc(size); +} + +void *yyrealloc (void * ptr, yy_size_t size ) +{ + + /* The cast to (char *) in the following accommodates both + * implementations that use char* generic pointers, and those + * that use void* generic pointers. It works with the latter + * because both ANSI C and C++ allow castless assignment from + * any pointer type to void*, and deal with argument conversions + * as though doing an assignment. + */ + return realloc(ptr, size); +} + +void yyfree (void * ptr ) +{ + free( (char *) ptr ); /* see yyrealloc() for (char *) cast */ +} + +#define YYTABLES_NAME "yytables" + +#line 41 "interp.l" + + +char *makeString(char *s) +{ + char *t; + t=malloc(strlen(s)+1); + strcpy(t,s); + return(t); + + +} + + +yywrap() +{ + return(1); +} + diff --git a/08-code-generator/interpreter/lib.c b/08-code-generator/interpreter/lib.c new file mode 100644 index 0000000..087ef4a --- /dev/null +++ b/08-code-generator/interpreter/lib.c @@ -0,0 +1,119 @@ +#include +extern float *stack_f; +extern char *stack_c; +extern int stack[]; +extern int t,b,hp; + +void lib_printf(); +void lib_scanf(); +void lib_malloc(); + +void lib_malloc() +{ + int j; + j=stack[t+3]; + if (j%4) j=j/4*4+4; + hp=hp-j/4; + stack[--t]=hp*4; +} +void lib_printf() +{ + char *s,c,*ss; + int i,w=0; + i=(t--)+3; + ss=stack; + s=&stack[stack[i]/4]; + while (c=*(s++)) { + if (c=='\\') { + c=*(s++); + if (c=='n') + printf("\n"); + else if (c=='t') + printf("\t"); + else + printf("%c",c); } + else if (c=='%'){ + c=*(s++); + while (isdigit(c)) { + w=w*10+c-'0'; c=*(s++);} + switch (c) { + case 'd': + i++; + printf("%d",stack[i]); + break; + case 'c': + i++; + printf("%c",stack[i]); + break; + case 'f': + i++; + printf("%f",*(stack_f+i)); + break; + case 's': + i++; + ss=stack; + ss=ss+stack[i]; + printf("%s",ss); + break; + case 0: + printf("\%"); + return; + default: + printf("\%%c",c); + break; + }} + else + printf("%c",c); + } +} + +void lib_scanf() +{ + char *s,c,ch; + int temp_i; float temp_f; char temp_s[80]; + int i,j=0; + i=(t--)+3; + s=&stack[stack[i]/4]; + while (c=*(s++)) { + if (c==' '||c=='\t'||c=='\n'); + else if (c=='%'){ + c=*(s++); + switch (c) { + case 'd': + i++; + scanf("%d",&temp_i); + stack[stack[i]/4]=temp_i; + break; + case 'c': + i++; + ch=getchar(); + while (ch==' '||ch=='\t'||ch=='\n') ch=getchar(); + *(stack_c+stack[i])=ch; + break; + case 'f': + i++; + scanf("%f",&temp_f); + *(stack_f+stack[i]/4)=temp_f; + break; + case 's': + i++; + ch=getchar(); + while (ch==' '||ch=='\t'||ch=='\n') ch=getchar(); + while (ch!=' '&& ch!='\t'&& ch!='\n'&& ch!=EOF){ + temp_s[j++]=ch; + ch=getchar();} + temp_s[j]=0; + strcpy(stack_c+stack[i],temp_s); + break; + case 0: + return; + default: + printf("\%%c",c); + break; }} + else { + while ((ch=getchar())!=EOF && ch!=c); + if (ch==EOF) + return;} + } +} + diff --git a/08-code-generator/interpreter/type.h b/08-code-generator/interpreter/type.h new file mode 100644 index 0000000..e1b0b9b --- /dev/null +++ b/08-code-generator/interpreter/type.h @@ -0,0 +1,14 @@ +#define SYMBOL_MAX 100 +#define STACK_MAX 20000 +#define CODE_MAX 2000 +#define NOP 56 +typedef enum op {OP_NULL, LOD,LDX,LDXB, LDA, LITI, + STO,STOB,STX,STXB, + SUBI,SUBF,DIVI,DIVF,ADDI,ADDF,OFFSET,MULI,MULF, MOD, + LSSI,LSSF,GTRI,GTRF, LEQI,LEQF,GEQI,GEQF,NEQI,NEQF,EQLI,EQLF, + NOT, OR, AND, CVTI,CVTF, + JPC,JPCR,JMP,JPT,JPTR,INT,INCI,INCF,DECI,DECF,SUP,CAL,ADDR, + RET, MINUSI,MINUSF,LDI,LDIB,POP} OPCODE; + +typedef struct {OPCODE f; int l; int a;} INSTRUCTION; + diff --git a/08-code-generator/interpreter/y.tab.c b/08-code-generator/interpreter/y.tab.c new file mode 100644 index 0000000..77efb14 --- /dev/null +++ b/08-code-generator/interpreter/y.tab.c @@ -0,0 +1,1606 @@ +/* A Bison parser, made by GNU Bison 3.8.2. */ + +/* Bison implementation for Yacc-like parsers in C + + Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 Free Software Foundation, + Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* As a special exception, you may create a larger work that contains + part or all of the Bison parser skeleton and distribute that work + under terms of your choice, so long as that work isn't itself a + parser generator using the skeleton or a modified version thereof + as a parser skeleton. Alternatively, if you modify or redistribute + the parser skeleton itself, you may (at your option) remove this + special exception, which will cause the skeleton and the resulting + Bison output files to be licensed under the GNU General Public + License without this special exception. + + This special exception was added by the Free Software Foundation in + version 2.2 of Bison. */ + +/* C LALR(1) parser skeleton written by Richard Stallman, by + simplifying the original so-called "semantic" parser. */ + +/* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual, + especially those whose name start with YY_ or yy_. They are + private implementation details that can be changed or removed. */ + +/* All symbols defined below should begin with yy or YY, to avoid + infringing on user name space. This should be done even for local + variables, as they might otherwise be expanded by user macros. + There are some unavoidable exceptions within include files to + define necessary library symbols; they are noted "INFRINGES ON + USER NAME SPACE" below. */ + +/* Identify Bison output, and Bison version. */ +#define YYBISON 30802 + +/* Bison version string. */ +#define YYBISON_VERSION "3.8.2" + +/* Skeleton name. */ +#define YYSKELETON_NAME "yacc.c" + +/* Pure parsers. */ +#define YYPURE 0 + +/* Push parsers. */ +#define YYPUSH 0 + +/* Pull parsers. */ +#define YYPULL 1 + + + + +/* First part of user prologue. */ +#line 1 "interp.y" + +#define YYSTYPE_IS_DECLARED 1 +typedef long YYSTYPE; +#include +#include +#include "type.h" +float atof(); +extern FILE *yyin; +extern char *yytext; +extern int line_no; +int pc=0; +struct {char *name; int addr;} symbol[SYMBOL_MAX]; +int dx=0; +int stack[STACK_MAX]; +INSTRUCTION code[CODE_MAX]; +float *stack_f; +int *stack_i; +char *stack_c; +int syntax_err=0; +int semantic_err=0; + +int search_symbol(); +int search_opcode(); +void put_symbol(); +int get_symbol(); +void put_data(); +void print_code(); +void print_symbol(); +int is_inst2(); +void assem2(); +void gen_code(); +void interp(); +void assemble_error(); +void dump_statck(); +void runtime_error(); +void initialize(); +int base(); + + +#line 111 "y.tab.c" + +# ifndef YY_CAST +# ifdef __cplusplus +# define YY_CAST(Type, Val) static_cast (Val) +# define YY_REINTERPRET_CAST(Type, Val) reinterpret_cast (Val) +# else +# define YY_CAST(Type, Val) ((Type) (Val)) +# define YY_REINTERPRET_CAST(Type, Val) ((Type) (Val)) +# endif +# endif +# ifndef YY_NULLPTR +# if defined __cplusplus +# if 201103L <= __cplusplus +# define YY_NULLPTR nullptr +# else +# define YY_NULLPTR 0 +# endif +# else +# define YY_NULLPTR ((void*)0) +# endif +# endif + +/* Use api.header.include to #include this header + instead of duplicating it here. */ +#ifndef YY_YY_Y_TAB_H_INCLUDED +# define YY_YY_Y_TAB_H_INCLUDED +/* Debug traces. */ +#ifndef YYDEBUG +# define YYDEBUG 0 +#endif +#if YYDEBUG +extern int yydebug; +#endif + +/* Token kinds. */ +#ifndef YYTOKENTYPE +# define YYTOKENTYPE + enum yytokentype + { + YYEMPTY = -2, + YYEOF = 0, /* "end of file" */ + YYerror = 256, /* error */ + YYUNDEF = 257, /* "invalid token" */ + NEW_LINE = 258, /* NEW_LINE */ + COLON = 259, /* COLON */ + COMMA = 260, /* COMMA */ + IDENTIFIER = 261, /* IDENTIFIER */ + INST1 = 262, /* INST1 */ + INST2 = 263, /* INST2 */ + INTEGER = 264, /* INTEGER */ + FLOAT = 265, /* FLOAT */ + STRING = 266, /* STRING */ + CHAR = 267, /* CHAR */ + GLOBAL_WORD_SYM = 268, /* GLOBAL_WORD_SYM */ + GLOBAL_BYTE_SYM = 269, /* GLOBAL_BYTE_SYM */ + LITERAL_SYM = 270 /* LITERAL_SYM */ + }; + typedef enum yytokentype yytoken_kind_t; +#endif +/* Token kinds. */ +#define YYEMPTY -2 +#define YYEOF 0 +#define YYerror 256 +#define YYUNDEF 257 +#define NEW_LINE 258 +#define COLON 259 +#define COMMA 260 +#define IDENTIFIER 261 +#define INST1 262 +#define INST2 263 +#define INTEGER 264 +#define FLOAT 265 +#define STRING 266 +#define CHAR 267 +#define GLOBAL_WORD_SYM 268 +#define GLOBAL_BYTE_SYM 269 +#define LITERAL_SYM 270 + +/* Value type. */ +#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED +typedef int YYSTYPE; +# define YYSTYPE_IS_TRIVIAL 1 +# define YYSTYPE_IS_DECLARED 1 +#endif + + +extern YYSTYPE yylval; + + +int yyparse (void); + + +#endif /* !YY_YY_Y_TAB_H_INCLUDED */ +/* Symbol kind. */ +enum yysymbol_kind_t +{ + YYSYMBOL_YYEMPTY = -2, + YYSYMBOL_YYEOF = 0, /* "end of file" */ + YYSYMBOL_YYerror = 1, /* error */ + YYSYMBOL_YYUNDEF = 2, /* "invalid token" */ + YYSYMBOL_NEW_LINE = 3, /* NEW_LINE */ + YYSYMBOL_COLON = 4, /* COLON */ + YYSYMBOL_COMMA = 5, /* COMMA */ + YYSYMBOL_IDENTIFIER = 6, /* IDENTIFIER */ + YYSYMBOL_INST1 = 7, /* INST1 */ + YYSYMBOL_INST2 = 8, /* INST2 */ + YYSYMBOL_INTEGER = 9, /* INTEGER */ + YYSYMBOL_FLOAT = 10, /* FLOAT */ + YYSYMBOL_STRING = 11, /* STRING */ + YYSYMBOL_CHAR = 12, /* CHAR */ + YYSYMBOL_GLOBAL_WORD_SYM = 13, /* GLOBAL_WORD_SYM */ + YYSYMBOL_GLOBAL_BYTE_SYM = 14, /* GLOBAL_BYTE_SYM */ + YYSYMBOL_LITERAL_SYM = 15, /* LITERAL_SYM */ + YYSYMBOL_YYACCEPT = 16, /* $accept */ + YYSYMBOL_program = 17, /* program */ + YYSYMBOL_command_list = 18, /* command_list */ + YYSYMBOL_command = 19, /* command */ + YYSYMBOL_directive = 20 /* directive */ +}; +typedef enum yysymbol_kind_t yysymbol_kind_t; + + + + +#ifdef short +# undef short +#endif + +/* On compilers that do not define __PTRDIFF_MAX__ etc., make sure + and (if available) are included + so that the code can choose integer types of a good width. */ + +#ifndef __PTRDIFF_MAX__ +# include /* INFRINGES ON USER NAME SPACE */ +# if defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__ +# include /* INFRINGES ON USER NAME SPACE */ +# define YY_STDINT_H +# endif +#endif + +/* Narrow types that promote to a signed type and that can represent a + signed or unsigned integer of at least N bits. In tables they can + save space and decrease cache pressure. Promoting to a signed type + helps avoid bugs in integer arithmetic. */ + +#ifdef __INT_LEAST8_MAX__ +typedef __INT_LEAST8_TYPE__ yytype_int8; +#elif defined YY_STDINT_H +typedef int_least8_t yytype_int8; +#else +typedef signed char yytype_int8; +#endif + +#ifdef __INT_LEAST16_MAX__ +typedef __INT_LEAST16_TYPE__ yytype_int16; +#elif defined YY_STDINT_H +typedef int_least16_t yytype_int16; +#else +typedef short yytype_int16; +#endif + +/* Work around bug in HP-UX 11.23, which defines these macros + incorrectly for preprocessor constants. This workaround can likely + be removed in 2023, as HPE has promised support for HP-UX 11.23 + (aka HP-UX 11i v2) only through the end of 2022; see Table 2 of + . */ +#ifdef __hpux +# undef UINT_LEAST8_MAX +# undef UINT_LEAST16_MAX +# define UINT_LEAST8_MAX 255 +# define UINT_LEAST16_MAX 65535 +#endif + +#if defined __UINT_LEAST8_MAX__ && __UINT_LEAST8_MAX__ <= __INT_MAX__ +typedef __UINT_LEAST8_TYPE__ yytype_uint8; +#elif (!defined __UINT_LEAST8_MAX__ && defined YY_STDINT_H \ + && UINT_LEAST8_MAX <= INT_MAX) +typedef uint_least8_t yytype_uint8; +#elif !defined __UINT_LEAST8_MAX__ && UCHAR_MAX <= INT_MAX +typedef unsigned char yytype_uint8; +#else +typedef short yytype_uint8; +#endif + +#if defined __UINT_LEAST16_MAX__ && __UINT_LEAST16_MAX__ <= __INT_MAX__ +typedef __UINT_LEAST16_TYPE__ yytype_uint16; +#elif (!defined __UINT_LEAST16_MAX__ && defined YY_STDINT_H \ + && UINT_LEAST16_MAX <= INT_MAX) +typedef uint_least16_t yytype_uint16; +#elif !defined __UINT_LEAST16_MAX__ && USHRT_MAX <= INT_MAX +typedef unsigned short yytype_uint16; +#else +typedef int yytype_uint16; +#endif + +#ifndef YYPTRDIFF_T +# if defined __PTRDIFF_TYPE__ && defined __PTRDIFF_MAX__ +# define YYPTRDIFF_T __PTRDIFF_TYPE__ +# define YYPTRDIFF_MAXIMUM __PTRDIFF_MAX__ +# elif defined PTRDIFF_MAX +# ifndef ptrdiff_t +# include /* INFRINGES ON USER NAME SPACE */ +# endif +# define YYPTRDIFF_T ptrdiff_t +# define YYPTRDIFF_MAXIMUM PTRDIFF_MAX +# else +# define YYPTRDIFF_T long +# define YYPTRDIFF_MAXIMUM LONG_MAX +# endif +#endif + +#ifndef YYSIZE_T +# ifdef __SIZE_TYPE__ +# define YYSIZE_T __SIZE_TYPE__ +# elif defined size_t +# define YYSIZE_T size_t +# elif defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__ +# include /* INFRINGES ON USER NAME SPACE */ +# define YYSIZE_T size_t +# else +# define YYSIZE_T unsigned +# endif +#endif + +#define YYSIZE_MAXIMUM \ + YY_CAST (YYPTRDIFF_T, \ + (YYPTRDIFF_MAXIMUM < YY_CAST (YYSIZE_T, -1) \ + ? YYPTRDIFF_MAXIMUM \ + : YY_CAST (YYSIZE_T, -1))) + +#define YYSIZEOF(X) YY_CAST (YYPTRDIFF_T, sizeof (X)) + + +/* Stored state numbers (used for stacks). */ +typedef yytype_int8 yy_state_t; + +/* State numbers in computations. */ +typedef int yy_state_fast_t; + +#ifndef YY_ +# if defined YYENABLE_NLS && YYENABLE_NLS +# if ENABLE_NLS +# include /* INFRINGES ON USER NAME SPACE */ +# define YY_(Msgid) dgettext ("bison-runtime", Msgid) +# endif +# endif +# ifndef YY_ +# define YY_(Msgid) Msgid +# endif +#endif + + +#ifndef YY_ATTRIBUTE_PURE +# if defined __GNUC__ && 2 < __GNUC__ + (96 <= __GNUC_MINOR__) +# define YY_ATTRIBUTE_PURE __attribute__ ((__pure__)) +# else +# define YY_ATTRIBUTE_PURE +# endif +#endif + +#ifndef YY_ATTRIBUTE_UNUSED +# if defined __GNUC__ && 2 < __GNUC__ + (7 <= __GNUC_MINOR__) +# define YY_ATTRIBUTE_UNUSED __attribute__ ((__unused__)) +# else +# define YY_ATTRIBUTE_UNUSED +# endif +#endif + +/* Suppress unused-variable warnings by "using" E. */ +#if ! defined lint || defined __GNUC__ +# define YY_USE(E) ((void) (E)) +#else +# define YY_USE(E) /* empty */ +#endif + +/* Suppress an incorrect diagnostic about yylval being uninitialized. */ +#if defined __GNUC__ && ! defined __ICC && 406 <= __GNUC__ * 100 + __GNUC_MINOR__ +# if __GNUC__ * 100 + __GNUC_MINOR__ < 407 +# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ + _Pragma ("GCC diagnostic push") \ + _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") +# else +# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ + _Pragma ("GCC diagnostic push") \ + _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") \ + _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") +# endif +# define YY_IGNORE_MAYBE_UNINITIALIZED_END \ + _Pragma ("GCC diagnostic pop") +#else +# define YY_INITIAL_VALUE(Value) Value +#endif +#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN +# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN +# define YY_IGNORE_MAYBE_UNINITIALIZED_END +#endif +#ifndef YY_INITIAL_VALUE +# define YY_INITIAL_VALUE(Value) /* Nothing. */ +#endif + +#if defined __cplusplus && defined __GNUC__ && ! defined __ICC && 6 <= __GNUC__ +# define YY_IGNORE_USELESS_CAST_BEGIN \ + _Pragma ("GCC diagnostic push") \ + _Pragma ("GCC diagnostic ignored \"-Wuseless-cast\"") +# define YY_IGNORE_USELESS_CAST_END \ + _Pragma ("GCC diagnostic pop") +#endif +#ifndef YY_IGNORE_USELESS_CAST_BEGIN +# define YY_IGNORE_USELESS_CAST_BEGIN +# define YY_IGNORE_USELESS_CAST_END +#endif + + +#define YY_ASSERT(E) ((void) (0 && (E))) + +#if !defined yyoverflow + +/* The parser invokes alloca or malloc; define the necessary symbols. */ + +# ifdef YYSTACK_USE_ALLOCA +# if YYSTACK_USE_ALLOCA +# ifdef __GNUC__ +# define YYSTACK_ALLOC __builtin_alloca +# elif defined __BUILTIN_VA_ARG_INCR +# include /* INFRINGES ON USER NAME SPACE */ +# elif defined _AIX +# define YYSTACK_ALLOC __alloca +# elif defined _MSC_VER +# include /* INFRINGES ON USER NAME SPACE */ +# define alloca _alloca +# else +# define YYSTACK_ALLOC alloca +# if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS +# include /* INFRINGES ON USER NAME SPACE */ + /* Use EXIT_SUCCESS as a witness for stdlib.h. */ +# ifndef EXIT_SUCCESS +# define EXIT_SUCCESS 0 +# endif +# endif +# endif +# endif +# endif + +# ifdef YYSTACK_ALLOC + /* Pacify GCC's 'empty if-body' warning. */ +# define YYSTACK_FREE(Ptr) do { /* empty */; } while (0) +# ifndef YYSTACK_ALLOC_MAXIMUM + /* The OS might guarantee only one guard page at the bottom of the stack, + and a page size can be as small as 4096 bytes. So we cannot safely + invoke alloca (N) if N exceeds 4096. Use a slightly smaller number + to allow for a few compiler-allocated temporary stack slots. */ +# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */ +# endif +# else +# define YYSTACK_ALLOC YYMALLOC +# define YYSTACK_FREE YYFREE +# ifndef YYSTACK_ALLOC_MAXIMUM +# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM +# endif +# if (defined __cplusplus && ! defined EXIT_SUCCESS \ + && ! ((defined YYMALLOC || defined malloc) \ + && (defined YYFREE || defined free))) +# include /* INFRINGES ON USER NAME SPACE */ +# ifndef EXIT_SUCCESS +# define EXIT_SUCCESS 0 +# endif +# endif +# ifndef YYMALLOC +# define YYMALLOC malloc +# if ! defined malloc && ! defined EXIT_SUCCESS +void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ +# endif +# endif +# ifndef YYFREE +# define YYFREE free +# if ! defined free && ! defined EXIT_SUCCESS +void free (void *); /* INFRINGES ON USER NAME SPACE */ +# endif +# endif +# endif +#endif /* !defined yyoverflow */ + +#if (! defined yyoverflow \ + && (! defined __cplusplus \ + || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) + +/* A type that is properly aligned for any stack member. */ +union yyalloc +{ + yy_state_t yyss_alloc; + YYSTYPE yyvs_alloc; +}; + +/* The size of the maximum gap between one aligned stack and the next. */ +# define YYSTACK_GAP_MAXIMUM (YYSIZEOF (union yyalloc) - 1) + +/* The size of an array large to enough to hold all stacks, each with + N elements. */ +# define YYSTACK_BYTES(N) \ + ((N) * (YYSIZEOF (yy_state_t) + YYSIZEOF (YYSTYPE)) \ + + YYSTACK_GAP_MAXIMUM) + +# define YYCOPY_NEEDED 1 + +/* Relocate STACK from its old location to the new one. The + local variables YYSIZE and YYSTACKSIZE give the old and new number of + elements in the stack, and YYPTR gives the new location of the + stack. Advance YYPTR to a properly aligned location for the next + stack. */ +# define YYSTACK_RELOCATE(Stack_alloc, Stack) \ + do \ + { \ + YYPTRDIFF_T yynewbytes; \ + YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \ + Stack = &yyptr->Stack_alloc; \ + yynewbytes = yystacksize * YYSIZEOF (*Stack) + YYSTACK_GAP_MAXIMUM; \ + yyptr += yynewbytes / YYSIZEOF (*yyptr); \ + } \ + while (0) + +#endif + +#if defined YYCOPY_NEEDED && YYCOPY_NEEDED +/* Copy COUNT objects from SRC to DST. The source and destination do + not overlap. */ +# ifndef YYCOPY +# if defined __GNUC__ && 1 < __GNUC__ +# define YYCOPY(Dst, Src, Count) \ + __builtin_memcpy (Dst, Src, YY_CAST (YYSIZE_T, (Count)) * sizeof (*(Src))) +# else +# define YYCOPY(Dst, Src, Count) \ + do \ + { \ + YYPTRDIFF_T yyi; \ + for (yyi = 0; yyi < (Count); yyi++) \ + (Dst)[yyi] = (Src)[yyi]; \ + } \ + while (0) +# endif +# endif +#endif /* !YYCOPY_NEEDED */ + +/* YYFINAL -- State number of the termination state. */ +#define YYFINAL 16 +/* YYLAST -- Last index in YYTABLE. */ +#define YYLAST 28 + +/* YYNTOKENS -- Number of terminals. */ +#define YYNTOKENS 16 +/* YYNNTS -- Number of nonterminals. */ +#define YYNNTS 5 +/* YYNRULES -- Number of rules. */ +#define YYNRULES 14 +/* YYNSTATES -- Number of states. */ +#define YYNSTATES 34 + +/* YYMAXUTOK -- Last valid token kind. */ +#define YYMAXUTOK 270 + + +/* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM + as returned by yylex, with out-of-bounds checking. */ +#define YYTRANSLATE(YYX) \ + (0 <= (YYX) && (YYX) <= YYMAXUTOK \ + ? YY_CAST (yysymbol_kind_t, yytranslate[YYX]) \ + : YYSYMBOL_YYUNDEF) + +/* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM + as returned by yylex. */ +static const yytype_int8 yytranslate[] = +{ + 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, + 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 15 +}; + +#if YYDEBUG +/* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ +static const yytype_int8 yyrline[] = +{ + 0, 47, 47, 50, 51, 53, 54, 56, 58, 60, + 62, 64, 66, 70, 71 +}; +#endif + +/** Accessing symbol of state STATE. */ +#define YY_ACCESSING_SYMBOL(State) YY_CAST (yysymbol_kind_t, yystos[State]) + +#if YYDEBUG || 0 +/* The user-facing name of the symbol whose (internal) number is + YYSYMBOL. No bounds checking. */ +static const char *yysymbol_name (yysymbol_kind_t yysymbol) YY_ATTRIBUTE_UNUSED; + +/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. + First, the terminals, then, starting at YYNTOKENS, nonterminals. */ +static const char *const yytname[] = +{ + "\"end of file\"", "error", "\"invalid token\"", "NEW_LINE", "COLON", + "COMMA", "IDENTIFIER", "INST1", "INST2", "INTEGER", "FLOAT", "STRING", + "CHAR", "GLOBAL_WORD_SYM", "GLOBAL_BYTE_SYM", "LITERAL_SYM", "$accept", + "program", "command_list", "command", "directive", YY_NULLPTR +}; + +static const char * +yysymbol_name (yysymbol_kind_t yysymbol) +{ + return yytname[yysymbol]; +} +#endif + +#define YYPACT_NINF (-9) + +#define yypact_value_is_default(Yyn) \ + ((Yyn) == YYPACT_NINF) + +#define YYTABLE_NINF (-1) + +#define yytable_value_is_error(Yyn) \ + 0 + +/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing + STATE-NUM. */ +static const yytype_int8 yypact[] = +{ + -3, -9, 2, -8, -7, -9, 4, -9, 14, -3, + -9, 6, 13, 12, 15, 9, -9, -9, -2, -9, + 10, 16, 18, 20, 21, 22, 23, 24, -9, -9, + -9, -9, -9, -9 +}; + +/* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM. + Performed when YYTABLE does not specify something else to do. Zero + means the default is an error. */ +static const yytype_int8 yydefact[] = +{ + 0, 5, 0, 0, 0, 13, 0, 14, 0, 2, + 3, 0, 0, 0, 0, 0, 1, 4, 0, 6, + 0, 0, 0, 0, 0, 0, 0, 0, 12, 9, + 10, 11, 7, 8 +}; + +/* YYPGOTO[NTERM-NUM]. */ +static const yytype_int8 yypgoto[] = +{ + -9, -9, -9, 19, -9 +}; + +/* YYDEFGOTO[NTERM-NUM]. */ +static const yytype_int8 yydefgoto[] = +{ + 0, 8, 9, 10, 11 +}; + +/* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If + positive, shift that token. If negative, reduce the rule whose + number is the opposite. If YYTABLE_NINF, syntax error. */ +static const yytype_int8 yytable[] = +{ + 1, 13, 14, 2, 3, 4, 12, 23, 24, 25, + 5, 6, 7, 15, 16, 18, 19, 20, 22, 26, + 21, 28, 27, 29, 30, 31, 32, 33, 17 +}; + +static const yytype_int8 yycheck[] = +{ + 3, 9, 9, 6, 7, 8, 4, 9, 10, 11, + 13, 14, 15, 9, 0, 9, 3, 5, 9, 9, + 5, 3, 6, 3, 3, 3, 3, 3, 9 +}; + +/* YYSTOS[STATE-NUM] -- The symbol kind of the accessing symbol of + state STATE-NUM. */ +static const yytype_int8 yystos[] = +{ + 0, 3, 6, 7, 8, 13, 14, 15, 17, 18, + 19, 20, 4, 9, 9, 9, 0, 19, 9, 3, + 5, 5, 9, 9, 10, 11, 9, 6, 3, 3, + 3, 3, 3, 3 +}; + +/* YYR1[RULE-NUM] -- Symbol kind of the left-hand side of rule RULE-NUM. */ +static const yytype_int8 yyr1[] = +{ + 0, 16, 17, 18, 18, 19, 19, 19, 19, 19, + 19, 19, 19, 20, 20 +}; + +/* YYR2[RULE-NUM] -- Number of symbols on the right-hand side of rule RULE-NUM. */ +static const yytype_int8 yyr2[] = +{ + 0, 2, 1, 1, 2, 1, 3, 5, 5, 4, + 4, 4, 4, 1, 1 +}; + + +enum { YYENOMEM = -2 }; + +#define yyerrok (yyerrstatus = 0) +#define yyclearin (yychar = YYEMPTY) + +#define YYACCEPT goto yyacceptlab +#define YYABORT goto yyabortlab +#define YYERROR goto yyerrorlab +#define YYNOMEM goto yyexhaustedlab + + +#define YYRECOVERING() (!!yyerrstatus) + +#define YYBACKUP(Token, Value) \ + do \ + if (yychar == YYEMPTY) \ + { \ + yychar = (Token); \ + yylval = (Value); \ + YYPOPSTACK (yylen); \ + yystate = *yyssp; \ + goto yybackup; \ + } \ + else \ + { \ + yyerror (YY_("syntax error: cannot back up")); \ + YYERROR; \ + } \ + while (0) + +/* Backward compatibility with an undocumented macro. + Use YYerror or YYUNDEF. */ +#define YYERRCODE YYUNDEF + + +/* Enable debugging if requested. */ +#if YYDEBUG + +# ifndef YYFPRINTF +# include /* INFRINGES ON USER NAME SPACE */ +# define YYFPRINTF fprintf +# endif + +# define YYDPRINTF(Args) \ +do { \ + if (yydebug) \ + YYFPRINTF Args; \ +} while (0) + + + + +# define YY_SYMBOL_PRINT(Title, Kind, Value, Location) \ +do { \ + if (yydebug) \ + { \ + YYFPRINTF (stderr, "%s ", Title); \ + yy_symbol_print (stderr, \ + Kind, Value); \ + YYFPRINTF (stderr, "\n"); \ + } \ +} while (0) + + +/*-----------------------------------. +| Print this symbol's value on YYO. | +`-----------------------------------*/ + +static void +yy_symbol_value_print (FILE *yyo, + yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep) +{ + FILE *yyoutput = yyo; + YY_USE (yyoutput); + if (!yyvaluep) + return; + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN + YY_USE (yykind); + YY_IGNORE_MAYBE_UNINITIALIZED_END +} + + +/*---------------------------. +| Print this symbol on YYO. | +`---------------------------*/ + +static void +yy_symbol_print (FILE *yyo, + yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep) +{ + YYFPRINTF (yyo, "%s %s (", + yykind < YYNTOKENS ? "token" : "nterm", yysymbol_name (yykind)); + + yy_symbol_value_print (yyo, yykind, yyvaluep); + YYFPRINTF (yyo, ")"); +} + +/*------------------------------------------------------------------. +| yy_stack_print -- Print the state stack from its BOTTOM up to its | +| TOP (included). | +`------------------------------------------------------------------*/ + +static void +yy_stack_print (yy_state_t *yybottom, yy_state_t *yytop) +{ + YYFPRINTF (stderr, "Stack now"); + for (; yybottom <= yytop; yybottom++) + { + int yybot = *yybottom; + YYFPRINTF (stderr, " %d", yybot); + } + YYFPRINTF (stderr, "\n"); +} + +# define YY_STACK_PRINT(Bottom, Top) \ +do { \ + if (yydebug) \ + yy_stack_print ((Bottom), (Top)); \ +} while (0) + + +/*------------------------------------------------. +| Report that the YYRULE is going to be reduced. | +`------------------------------------------------*/ + +static void +yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp, + int yyrule) +{ + int yylno = yyrline[yyrule]; + int yynrhs = yyr2[yyrule]; + int yyi; + YYFPRINTF (stderr, "Reducing stack by rule %d (line %d):\n", + yyrule - 1, yylno); + /* The symbols being reduced. */ + for (yyi = 0; yyi < yynrhs; yyi++) + { + YYFPRINTF (stderr, " $%d = ", yyi + 1); + yy_symbol_print (stderr, + YY_ACCESSING_SYMBOL (+yyssp[yyi + 1 - yynrhs]), + &yyvsp[(yyi + 1) - (yynrhs)]); + YYFPRINTF (stderr, "\n"); + } +} + +# define YY_REDUCE_PRINT(Rule) \ +do { \ + if (yydebug) \ + yy_reduce_print (yyssp, yyvsp, Rule); \ +} while (0) + +/* Nonzero means print parse trace. It is left uninitialized so that + multiple parsers can coexist. */ +int yydebug; +#else /* !YYDEBUG */ +# define YYDPRINTF(Args) ((void) 0) +# define YY_SYMBOL_PRINT(Title, Kind, Value, Location) +# define YY_STACK_PRINT(Bottom, Top) +# define YY_REDUCE_PRINT(Rule) +#endif /* !YYDEBUG */ + + +/* YYINITDEPTH -- initial size of the parser's stacks. */ +#ifndef YYINITDEPTH +# define YYINITDEPTH 200 +#endif + +/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only + if the built-in stack extension method is used). + + Do not make this value too large; the results are undefined if + YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH) + evaluated with infinite-precision integer arithmetic. */ + +#ifndef YYMAXDEPTH +# define YYMAXDEPTH 10000 +#endif + + + + + + +/*-----------------------------------------------. +| Release the memory associated to this symbol. | +`-----------------------------------------------*/ + +static void +yydestruct (const char *yymsg, + yysymbol_kind_t yykind, YYSTYPE *yyvaluep) +{ + YY_USE (yyvaluep); + if (!yymsg) + yymsg = "Deleting"; + YY_SYMBOL_PRINT (yymsg, yykind, yyvaluep, yylocationp); + + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN + YY_USE (yykind); + YY_IGNORE_MAYBE_UNINITIALIZED_END +} + + +/* Lookahead token kind. */ +int yychar; + +/* The semantic value of the lookahead symbol. */ +YYSTYPE yylval; +/* Number of syntax errors so far. */ +int yynerrs; + + + + +/*----------. +| yyparse. | +`----------*/ + +int +yyparse (void) +{ + yy_state_fast_t yystate = 0; + /* Number of tokens to shift before error messages enabled. */ + int yyerrstatus = 0; + + /* Refer to the stacks through separate pointers, to allow yyoverflow + to reallocate them elsewhere. */ + + /* Their size. */ + YYPTRDIFF_T yystacksize = YYINITDEPTH; + + /* The state stack: array, bottom, top. */ + yy_state_t yyssa[YYINITDEPTH]; + yy_state_t *yyss = yyssa; + yy_state_t *yyssp = yyss; + + /* The semantic value stack: array, bottom, top. */ + YYSTYPE yyvsa[YYINITDEPTH]; + YYSTYPE *yyvs = yyvsa; + YYSTYPE *yyvsp = yyvs; + + int yyn; + /* The return value of yyparse. */ + int yyresult; + /* Lookahead symbol kind. */ + yysymbol_kind_t yytoken = YYSYMBOL_YYEMPTY; + /* The variables used to return semantic value and location from the + action routines. */ + YYSTYPE yyval; + + + +#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)) + + /* The number of symbols on the RHS of the reduced rule. + Keep to zero when no symbol should be popped. */ + int yylen = 0; + + YYDPRINTF ((stderr, "Starting parse\n")); + + yychar = YYEMPTY; /* Cause a token to be read. */ + + goto yysetstate; + + +/*------------------------------------------------------------. +| yynewstate -- push a new state, which is found in yystate. | +`------------------------------------------------------------*/ +yynewstate: + /* In all cases, when you get here, the value and location stacks + have just been pushed. So pushing a state here evens the stacks. */ + yyssp++; + + +/*--------------------------------------------------------------------. +| yysetstate -- set current state (the top of the stack) to yystate. | +`--------------------------------------------------------------------*/ +yysetstate: + YYDPRINTF ((stderr, "Entering state %d\n", yystate)); + YY_ASSERT (0 <= yystate && yystate < YYNSTATES); + YY_IGNORE_USELESS_CAST_BEGIN + *yyssp = YY_CAST (yy_state_t, yystate); + YY_IGNORE_USELESS_CAST_END + YY_STACK_PRINT (yyss, yyssp); + + if (yyss + yystacksize - 1 <= yyssp) +#if !defined yyoverflow && !defined YYSTACK_RELOCATE + YYNOMEM; +#else + { + /* Get the current used size of the three stacks, in elements. */ + YYPTRDIFF_T yysize = yyssp - yyss + 1; + +# if defined yyoverflow + { + /* Give user a chance to reallocate the stack. Use copies of + these so that the &'s don't force the real ones into + memory. */ + yy_state_t *yyss1 = yyss; + YYSTYPE *yyvs1 = yyvs; + + /* Each stack pointer address is followed by the size of the + data in use in that stack, in bytes. This used to be a + conditional around just the two extra args, but that might + be undefined if yyoverflow is a macro. */ + yyoverflow (YY_("memory exhausted"), + &yyss1, yysize * YYSIZEOF (*yyssp), + &yyvs1, yysize * YYSIZEOF (*yyvsp), + &yystacksize); + yyss = yyss1; + yyvs = yyvs1; + } +# else /* defined YYSTACK_RELOCATE */ + /* Extend the stack our own way. */ + if (YYMAXDEPTH <= yystacksize) + YYNOMEM; + yystacksize *= 2; + if (YYMAXDEPTH < yystacksize) + yystacksize = YYMAXDEPTH; + + { + yy_state_t *yyss1 = yyss; + union yyalloc *yyptr = + YY_CAST (union yyalloc *, + YYSTACK_ALLOC (YY_CAST (YYSIZE_T, YYSTACK_BYTES (yystacksize)))); + if (! yyptr) + YYNOMEM; + YYSTACK_RELOCATE (yyss_alloc, yyss); + YYSTACK_RELOCATE (yyvs_alloc, yyvs); +# undef YYSTACK_RELOCATE + if (yyss1 != yyssa) + YYSTACK_FREE (yyss1); + } +# endif + + yyssp = yyss + yysize - 1; + yyvsp = yyvs + yysize - 1; + + YY_IGNORE_USELESS_CAST_BEGIN + YYDPRINTF ((stderr, "Stack size increased to %ld\n", + YY_CAST (long, yystacksize))); + YY_IGNORE_USELESS_CAST_END + + if (yyss + yystacksize - 1 <= yyssp) + YYABORT; + } +#endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */ + + + if (yystate == YYFINAL) + YYACCEPT; + + goto yybackup; + + +/*-----------. +| yybackup. | +`-----------*/ +yybackup: + /* Do appropriate processing given the current state. Read a + lookahead token if we need one and don't already have one. */ + + /* First try to decide what to do without reference to lookahead token. */ + yyn = yypact[yystate]; + if (yypact_value_is_default (yyn)) + goto yydefault; + + /* Not known => get a lookahead token if don't already have one. */ + + /* YYCHAR is either empty, or end-of-input, or a valid lookahead. */ + if (yychar == YYEMPTY) + { + YYDPRINTF ((stderr, "Reading a token\n")); + yychar = yylex (); + } + + if (yychar <= YYEOF) + { + yychar = YYEOF; + yytoken = YYSYMBOL_YYEOF; + YYDPRINTF ((stderr, "Now at end of input.\n")); + } + else if (yychar == YYerror) + { + /* The scanner already issued an error message, process directly + to error recovery. But do not keep the error token as + lookahead, it is too special and may lead us to an endless + loop in error recovery. */ + yychar = YYUNDEF; + yytoken = YYSYMBOL_YYerror; + goto yyerrlab1; + } + else + { + yytoken = YYTRANSLATE (yychar); + YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); + } + + /* If the proper action on seeing token YYTOKEN is to reduce or to + detect an error, take that action. */ + yyn += yytoken; + if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken) + goto yydefault; + yyn = yytable[yyn]; + if (yyn <= 0) + { + if (yytable_value_is_error (yyn)) + goto yyerrlab; + yyn = -yyn; + goto yyreduce; + } + + /* Count tokens shifted since error; after three, turn off error + status. */ + if (yyerrstatus) + yyerrstatus--; + + /* Shift the lookahead token. */ + YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); + yystate = yyn; + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN + *++yyvsp = yylval; + YY_IGNORE_MAYBE_UNINITIALIZED_END + + /* Discard the shifted token. */ + yychar = YYEMPTY; + goto yynewstate; + + +/*-----------------------------------------------------------. +| yydefault -- do the default action for the current state. | +`-----------------------------------------------------------*/ +yydefault: + yyn = yydefact[yystate]; + if (yyn == 0) + goto yyerrlab; + goto yyreduce; + + +/*-----------------------------. +| yyreduce -- do a reduction. | +`-----------------------------*/ +yyreduce: + /* yyn is the number of a rule to reduce with. */ + yylen = yyr2[yyn]; + + /* If YYLEN is nonzero, implement the default value of the action: + '$$ = $1'. + + Otherwise, the following line sets YYVAL to garbage. + This behavior is undocumented and Bison + users should not rely upon it. Assigning to YYVAL + unconditionally makes the parser a bit smaller, and it avoids a + GCC warning that YYVAL may be used uninitialized. */ + yyval = yyvsp[1-yylen]; + + + YY_REDUCE_PRINT (yyn); + switch (yyn) + { + case 6: /* command: IDENTIFIER COLON NEW_LINE */ +#line 55 "interp.y" + { put_symbol(yyvsp[-2],pc);} +#line 1194 "y.tab.c" + break; + + case 7: /* command: INST1 INTEGER COMMA INTEGER NEW_LINE */ +#line 57 "interp.y" + { gen_code(yyvsp[-4],yyvsp[-3],yyvsp[-1]);} +#line 1200 "y.tab.c" + break; + + case 8: /* command: INST2 INTEGER COMMA IDENTIFIER NEW_LINE */ +#line 59 "interp.y" + { gen_code(yyvsp[-4],yyvsp[-3],get_symbol(yyvsp[-1]));} +#line 1206 "y.tab.c" + break; + + case 9: /* command: directive INTEGER INTEGER NEW_LINE */ +#line 61 "interp.y" + { put_data(yyvsp[-2],1,yyvsp[-1]);} +#line 1212 "y.tab.c" + break; + + case 10: /* command: directive INTEGER FLOAT NEW_LINE */ +#line 63 "interp.y" + { put_data(yyvsp[-2],2,yyvsp[-1]);} +#line 1218 "y.tab.c" + break; + + case 11: /* command: directive INTEGER STRING NEW_LINE */ +#line 65 "interp.y" + { put_data(yyvsp[-2],3,yyvsp[-1]);} +#line 1224 "y.tab.c" + break; + + case 12: /* command: GLOBAL_BYTE_SYM INTEGER INTEGER NEW_LINE */ +#line 67 "interp.y" + { put_data(yyvsp[-2],4,yyvsp[-1]);} +#line 1230 "y.tab.c" + break; + + +#line 1234 "y.tab.c" + + default: break; + } + /* User semantic actions sometimes alter yychar, and that requires + that yytoken be updated with the new translation. We take the + approach of translating immediately before every use of yytoken. + One alternative is translating here after every semantic action, + but that translation would be missed if the semantic action invokes + YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or + if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an + incorrect destructor might then be invoked immediately. In the + case of YYERROR or YYBACKUP, subsequent parser actions might lead + to an incorrect destructor call or verbose syntax error message + before the lookahead is translated. */ + YY_SYMBOL_PRINT ("-> $$ =", YY_CAST (yysymbol_kind_t, yyr1[yyn]), &yyval, &yyloc); + + YYPOPSTACK (yylen); + yylen = 0; + + *++yyvsp = yyval; + + /* Now 'shift' the result of the reduction. Determine what state + that goes to, based on the state we popped back to and the rule + number reduced by. */ + { + const int yylhs = yyr1[yyn] - YYNTOKENS; + const int yyi = yypgoto[yylhs] + *yyssp; + yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyssp + ? yytable[yyi] + : yydefgoto[yylhs]); + } + + goto yynewstate; + + +/*--------------------------------------. +| yyerrlab -- here on detecting error. | +`--------------------------------------*/ +yyerrlab: + /* Make sure we have latest lookahead translation. See comments at + user semantic actions for why this is necessary. */ + yytoken = yychar == YYEMPTY ? YYSYMBOL_YYEMPTY : YYTRANSLATE (yychar); + /* If not already recovering from an error, report this error. */ + if (!yyerrstatus) + { + ++yynerrs; + yyerror (YY_("syntax error")); + } + + if (yyerrstatus == 3) + { + /* If just tried and failed to reuse lookahead token after an + error, discard it. */ + + if (yychar <= YYEOF) + { + /* Return failure if at end of input. */ + if (yychar == YYEOF) + YYABORT; + } + else + { + yydestruct ("Error: discarding", + yytoken, &yylval); + yychar = YYEMPTY; + } + } + + /* Else will try to reuse lookahead token after shifting the error + token. */ + goto yyerrlab1; + + +/*---------------------------------------------------. +| yyerrorlab -- error raised explicitly by YYERROR. | +`---------------------------------------------------*/ +yyerrorlab: + /* Pacify compilers when the user code never invokes YYERROR and the + label yyerrorlab therefore never appears in user code. */ + if (0) + YYERROR; + ++yynerrs; + + /* Do not reclaim the symbols of the rule whose action triggered + this YYERROR. */ + YYPOPSTACK (yylen); + yylen = 0; + YY_STACK_PRINT (yyss, yyssp); + yystate = *yyssp; + goto yyerrlab1; + + +/*-------------------------------------------------------------. +| yyerrlab1 -- common code for both syntax error and YYERROR. | +`-------------------------------------------------------------*/ +yyerrlab1: + yyerrstatus = 3; /* Each real token shifted decrements this. */ + + /* Pop stack until we find a state that shifts the error token. */ + for (;;) + { + yyn = yypact[yystate]; + if (!yypact_value_is_default (yyn)) + { + yyn += YYSYMBOL_YYerror; + if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYSYMBOL_YYerror) + { + yyn = yytable[yyn]; + if (0 < yyn) + break; + } + } + + /* Pop the current state because it cannot handle the error token. */ + if (yyssp == yyss) + YYABORT; + + + yydestruct ("Error: popping", + YY_ACCESSING_SYMBOL (yystate), yyvsp); + YYPOPSTACK (1); + yystate = *yyssp; + YY_STACK_PRINT (yyss, yyssp); + } + + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN + *++yyvsp = yylval; + YY_IGNORE_MAYBE_UNINITIALIZED_END + + + /* Shift the error token. */ + YY_SYMBOL_PRINT ("Shifting", YY_ACCESSING_SYMBOL (yyn), yyvsp, yylsp); + + yystate = yyn; + goto yynewstate; + + +/*-------------------------------------. +| yyacceptlab -- YYACCEPT comes here. | +`-------------------------------------*/ +yyacceptlab: + yyresult = 0; + goto yyreturnlab; + + +/*-----------------------------------. +| yyabortlab -- YYABORT comes here. | +`-----------------------------------*/ +yyabortlab: + yyresult = 1; + goto yyreturnlab; + + +/*-----------------------------------------------------------. +| yyexhaustedlab -- YYNOMEM (memory exhaustion) comes here. | +`-----------------------------------------------------------*/ +yyexhaustedlab: + yyerror (YY_("memory exhausted")); + yyresult = 2; + goto yyreturnlab; + + +/*----------------------------------------------------------. +| yyreturnlab -- parsing is finished, clean up and return. | +`----------------------------------------------------------*/ +yyreturnlab: + if (yychar != YYEMPTY) + { + /* Make sure we have latest lookahead translation. See comments at + user semantic actions for why this is necessary. */ + yytoken = YYTRANSLATE (yychar); + yydestruct ("Cleanup: discarding lookahead", + yytoken, &yylval); + } + /* Do not reclaim the symbols of the rule whose action triggered + this YYABORT or YYACCEPT. */ + YYPOPSTACK (yylen); + YY_STACK_PRINT (yyss, yyssp); + while (yyssp != yyss) + { + yydestruct ("Cleanup: popping", + YY_ACCESSING_SYMBOL (+*yyssp), yyvsp); + YYPOPSTACK (1); + } +#ifndef yyoverflow + if (yyss != yyssa) + YYSTACK_FREE (yyss); +#endif + + return yyresult; +} + +#line 74 "interp.y" + + + +int search_symbol(char *s) +{ + int i; + for (i=dx; i>0; i--) { + if (strcmp(symbol[i].name,s)==0) break; + } + return (i); + +} + +int get_symbol(char *s) +{ + int i; + i=search_symbol(s); + if (i==0) { + i=++dx; + symbol[i].name=s; + symbol[i].addr=0; } + return(i); +} + +void put_symbol(char *s, int p) +{ + int i; + i=search_symbol(s); + if (i) + if (symbol[i].addr) + assemble_error(2,s); + else + symbol[i].addr=p; + else { + dx++; + symbol[dx].name=s; + symbol[dx].addr=p; + } +} + +void put_data(int i,int k, char *s) +{ + int a; + if (k==1) + *(stack_i+i/4)= (int)s; + else if (k==2) + *(stack_f+i/4)=atof(s); + else if (k==3){ + *(s+strlen(s)-1)=0; + strcpy(stack_c+i,s+1);} + else if (k==4) + *(stack_c+i)=(int)s; + else + assemble_error(100); +} + +void print_symbol() +{ + int i; + printf("======== symbol =========\n"); + for (i=1; i<=dx; i++) { + printf("%4d: %s\t%d\n",i,symbol[i].name, symbol[i].addr); + } +} + +int is_inst2(OPCODE op) +{ + if (op==JMP || op==JPC || op==JPT || op==JPCR || op==JPTR + || op==ADDR || op==SUP ) + return(1); + else + return(0); + +} + +void assem2() +{ + int i,j; + for (i=0; i=CODE_MAX) + assemble_error(10); + else { + code[pc].f=op; + code[pc].l=l; + code[pc].a=a; + pc++; + } +} + +char *opcode_name[]={"OP_NULL", "LOD","LDX","LDXB", "LDA", "LITI", + "STO","STOB","STX","STXB", + "SUBI","SUBF","DIVI","DIVF","ADDI","ADDF","OFFSET","MULI","MULF", "MOD", + "LSSI","LSSF","GTRI","GTRF", "LEQI","LEQF","GEQI","GEQF","NEQI","NEQF","EQLI","EQLF", + "NOT", "OR", "AND", "CVTI","CVTF", + "JPC","JPCR","JMP","JPT","JPTR", + "INT","INCI","INCF","DECI","DECF", "SUP","CAL","ADDR", + "RET", "MINUSI","MINUSF","LDI","LDIB","POP"} ; + +int search_opcode(char *s) +{ + int i; + for (i=NOP-1; i>0;i--) { + if (strcmp(opcode_name[i],s)==0) break; + } + return(i); +} + +void print_code() +{ + OPCODE op; + int i; + printf("======== code ==========\n"); + for (i=0; i. */ + +/* As a special exception, you may create a larger work that contains + part or all of the Bison parser skeleton and distribute that work + under terms of your choice, so long as that work isn't itself a + parser generator using the skeleton or a modified version thereof + as a parser skeleton. Alternatively, if you modify or redistribute + the parser skeleton itself, you may (at your option) remove this + special exception, which will cause the skeleton and the resulting + Bison output files to be licensed under the GNU General Public + License without this special exception. + + This special exception was added by the Free Software Foundation in + version 2.2 of Bison. */ + +/* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual, + especially those whose name start with YY_ or yy_. They are + private implementation details that can be changed or removed. */ + +#ifndef YY_YY_Y_TAB_H_INCLUDED +# define YY_YY_Y_TAB_H_INCLUDED +/* Debug traces. */ +#ifndef YYDEBUG +# define YYDEBUG 0 +#endif +#if YYDEBUG +extern int yydebug; +#endif + +/* Token kinds. */ +#ifndef YYTOKENTYPE +# define YYTOKENTYPE + enum yytokentype + { + YYEMPTY = -2, + YYEOF = 0, /* "end of file" */ + YYerror = 256, /* error */ + YYUNDEF = 257, /* "invalid token" */ + NEW_LINE = 258, /* NEW_LINE */ + COLON = 259, /* COLON */ + COMMA = 260, /* COMMA */ + IDENTIFIER = 261, /* IDENTIFIER */ + INST1 = 262, /* INST1 */ + INST2 = 263, /* INST2 */ + INTEGER = 264, /* INTEGER */ + FLOAT = 265, /* FLOAT */ + STRING = 266, /* STRING */ + CHAR = 267, /* CHAR */ + GLOBAL_WORD_SYM = 268, /* GLOBAL_WORD_SYM */ + GLOBAL_BYTE_SYM = 269, /* GLOBAL_BYTE_SYM */ + LITERAL_SYM = 270 /* LITERAL_SYM */ + }; + typedef enum yytokentype yytoken_kind_t; +#endif +/* Token kinds. */ +#define YYEMPTY -2 +#define YYEOF 0 +#define YYerror 256 +#define YYUNDEF 257 +#define NEW_LINE 258 +#define COLON 259 +#define COMMA 260 +#define IDENTIFIER 261 +#define INST1 262 +#define INST2 263 +#define INTEGER 264 +#define FLOAT 265 +#define STRING 266 +#define CHAR 267 +#define GLOBAL_WORD_SYM 268 +#define GLOBAL_BYTE_SYM 269 +#define LITERAL_SYM 270 + +/* Value type. */ +#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED +typedef int YYSTYPE; +# define YYSTYPE_IS_TRIVIAL 1 +# define YYSTYPE_IS_DECLARED 1 +#endif + + +extern YYSTYPE yylval; + + +int yyparse (void); + + +#endif /* !YY_YY_Y_TAB_H_INCLUDED */ diff --git a/08-code-generator/lex.l b/08-code-generator/lex.l new file mode 100644 index 0000000..d138b8a --- /dev/null +++ b/08-code-generator/lex.l @@ -0,0 +1,108 @@ +digit [0-9] +letter [a-zA-Z_] +delim [ \t] +line [\n] +ws {delim}+ + +%{ +#define YYSTYPE_IS_DECLARED 1 +typedef long YYSTYPE; + +#include "y.tab.h" +#include "type.h" + +extern YYSTYPE yylval; +extern int line_no; +extern A_ID *current_id; + +char *makeString(); +int checkIdentifier(); +%} + +%% +{ws} { } +{line} { line_no++; } +auto { return(AUTO_SYM); } +break { return(BREAK_SYM); } +case { return(CASE_SYM); } +continue { return(CONTINUE_SYM); } +default { return(DEFAULT_SYM); } +do { return(DO_SYM); } +else { return(ELSE_SYM); } +enum { return(ENUM_SYM); } +for { return(FOR_SYM); } +if { return(IF_SYM); } +return { return(RETURN_SYM); } +sizeof { return(SIZEOF_SYM); } +static { return(STATIC_SYM); } +struct { return(STRUCT_SYM); } +switch { return(SWITCH_SYM); } +typedef { return(TYPEDEF_SYM); } +union { return(UNION_SYM); } +while { return(WHILE_SYM); } + +"\+\+" { return(PLUSPLUS); } +"\-\-" { return(MINUSMINUS); } +"\->" { return(ARROW); } +"<" { return(LSS); } +">" { return(GTR); } +"<=" { return(LEQ); } +">=" { return(GEQ); } +"==" { return(EQL); } +"!=" { return(NEQ); } +"&&" { return(AMPAMP); } +"||" { return(BARBAR); } +"\.\.\." { return(DOTDOTDOT); } +"\(" { return(LP); } +"\)" { return(RP); } +"\[" { return(LB); } +"\]" { return(RB); } +"\{" { return(LR); } +"\}" { return(RR); } +"\:" { return(COLON); } +"\." { return(PERIOD); } +"\," { return(COMMA); } +"\!" { return(EXCL); } +"\*" { return(STAR); } +"\/" { return(SLASH); } +"\%" { return(PERCENT); } +"\&" { return(AMP); } +"\;" { return(SEMICOLON); } +"\+" { return(PLUS); } +"\-" { return(MINUS); } +"\=" { return(ASSIGN); } + +{digit}+ { yylval = atoi(yytext); return(INTEGER_CONSTANT); } +{digit}+\.{digit}+ { yylval = makeString(yytext); return(FLOAT_CONSTANT); } +{letter}({letter}|{digit})* { return(checkIdentifier(yytext)); } +\"([^"\n]|\\["\n])*\" { yylval = makeString(yytext); return(STRING_LITERAL); } +\'([^'\n]|\'\')\' { yylval = *(yytext+1); return(CHARACTER_CONSTANT); } +"//"[^\n]* { } + +%% +char *makeString(char *s){ + char *t; + t=(char *)malloc(strlen(s)+1); + strcpy(t,s); + return(t); +} +int checkIdentifier(char *s){ + A_ID *id; + char *t; + + id = current_id; + while (id){ + if (!strcmp(id->name, s)) break; + id = id->prev; + } + if (!id){ + yylval = (YYSTYPE)makeString(s); + return(IDENTIFIER); + } else if (id->kind == ID_TYPE){ + yylval = id->type; + return(TYPE_IDENTIFIER); + } else { + yylval = id->name; + return(IDENTIFIER); + } +} \ No newline at end of file diff --git a/08-code-generator/lex.yy.c b/08-code-generator/lex.yy.c new file mode 100644 index 0000000..e3eedf5 --- /dev/null +++ b/08-code-generator/lex.yy.c @@ -0,0 +1,2143 @@ + +#line 3 "lex.yy.c" + +#define YY_INT_ALIGNED short int + +/* A lexical scanner generated by flex */ + +#define FLEX_SCANNER +#define YY_FLEX_MAJOR_VERSION 2 +#define YY_FLEX_MINOR_VERSION 6 +#define YY_FLEX_SUBMINOR_VERSION 4 +#if YY_FLEX_SUBMINOR_VERSION > 0 +#define FLEX_BETA +#endif + +/* First, we deal with platform-specific or compiler-specific issues. */ + +/* begin standard C headers. */ +#include +#include +#include +#include + +/* end standard C headers. */ + +/* flex integer type definitions */ + +#ifndef FLEXINT_H +#define FLEXINT_H + +/* C99 systems have . Non-C99 systems may or may not. */ + +#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + +/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, + * if you want the limit (max/min) macros for int types. + */ +#ifndef __STDC_LIMIT_MACROS +#define __STDC_LIMIT_MACROS 1 +#endif + +#include +typedef int8_t flex_int8_t; +typedef uint8_t flex_uint8_t; +typedef int16_t flex_int16_t; +typedef uint16_t flex_uint16_t; +typedef int32_t flex_int32_t; +typedef uint32_t flex_uint32_t; +#else +typedef signed char flex_int8_t; +typedef short int flex_int16_t; +typedef int flex_int32_t; +typedef unsigned char flex_uint8_t; +typedef unsigned short int flex_uint16_t; +typedef unsigned int flex_uint32_t; + +/* Limits of integral types. */ +#ifndef INT8_MIN +#define INT8_MIN (-128) +#endif +#ifndef INT16_MIN +#define INT16_MIN (-32767-1) +#endif +#ifndef INT32_MIN +#define INT32_MIN (-2147483647-1) +#endif +#ifndef INT8_MAX +#define INT8_MAX (127) +#endif +#ifndef INT16_MAX +#define INT16_MAX (32767) +#endif +#ifndef INT32_MAX +#define INT32_MAX (2147483647) +#endif +#ifndef UINT8_MAX +#define UINT8_MAX (255U) +#endif +#ifndef UINT16_MAX +#define UINT16_MAX (65535U) +#endif +#ifndef UINT32_MAX +#define UINT32_MAX (4294967295U) +#endif + +#ifndef SIZE_MAX +#define SIZE_MAX (~(size_t)0) +#endif + +#endif /* ! C99 */ + +#endif /* ! FLEXINT_H */ + +/* begin standard C++ headers. */ + +/* TODO: this is always defined, so inline it */ +#define yyconst const + +#if defined(__GNUC__) && __GNUC__ >= 3 +#define yynoreturn __attribute__((__noreturn__)) +#else +#define yynoreturn +#endif + +/* Returned upon end-of-file. */ +#define YY_NULL 0 + +/* Promotes a possibly negative, possibly signed char to an + * integer in range [0..255] for use as an array index. + */ +#define YY_SC_TO_UI(c) ((YY_CHAR) (c)) + +/* Enter a start condition. This macro really ought to take a parameter, + * but we do it the disgusting crufty way forced on us by the ()-less + * definition of BEGIN. + */ +#define BEGIN (yy_start) = 1 + 2 * +/* Translate the current start state into a value that can be later handed + * to BEGIN to return to the state. The YYSTATE alias is for lex + * compatibility. + */ +#define YY_START (((yy_start) - 1) / 2) +#define YYSTATE YY_START +/* Action number for EOF rule of a given start state. */ +#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) +/* Special action meaning "start processing a new file". */ +#define YY_NEW_FILE yyrestart( yyin ) +#define YY_END_OF_BUFFER_CHAR 0 + +/* Size of default input buffer. */ +#ifndef YY_BUF_SIZE +#ifdef __ia64__ +/* On IA-64, the buffer size is 16k, not 8k. + * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case. + * Ditto for the __ia64__ case accordingly. + */ +#define YY_BUF_SIZE 32768 +#else +#define YY_BUF_SIZE 16384 +#endif /* __ia64__ */ +#endif + +/* The state buf must be large enough to hold one state per character in the main buffer. + */ +#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type)) + +#ifndef YY_TYPEDEF_YY_BUFFER_STATE +#define YY_TYPEDEF_YY_BUFFER_STATE +typedef struct yy_buffer_state *YY_BUFFER_STATE; +#endif + +#ifndef YY_TYPEDEF_YY_SIZE_T +#define YY_TYPEDEF_YY_SIZE_T +typedef size_t yy_size_t; +#endif + +extern int yyleng; + +extern FILE *yyin, *yyout; + +#define EOB_ACT_CONTINUE_SCAN 0 +#define EOB_ACT_END_OF_FILE 1 +#define EOB_ACT_LAST_MATCH 2 + + #define YY_LESS_LINENO(n) + #define YY_LINENO_REWIND_TO(ptr) + +/* Return all but the first "n" matched characters back to the input stream. */ +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up yytext. */ \ + int yyless_macro_arg = (n); \ + YY_LESS_LINENO(yyless_macro_arg);\ + *yy_cp = (yy_hold_char); \ + YY_RESTORE_YY_MORE_OFFSET \ + (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ + YY_DO_BEFORE_ACTION; /* set up yytext again */ \ + } \ + while ( 0 ) +#define unput(c) yyunput( c, (yytext_ptr) ) + +#ifndef YY_STRUCT_YY_BUFFER_STATE +#define YY_STRUCT_YY_BUFFER_STATE +struct yy_buffer_state + { + FILE *yy_input_file; + + char *yy_ch_buf; /* input buffer */ + char *yy_buf_pos; /* current position in input buffer */ + + /* Size of input buffer in bytes, not including room for EOB + * characters. + */ + int yy_buf_size; + + /* Number of characters read into yy_ch_buf, not including EOB + * characters. + */ + int yy_n_chars; + + /* Whether we "own" the buffer - i.e., we know we created it, + * and can realloc() it to grow it, and should free() it to + * delete it. + */ + int yy_is_our_buffer; + + /* Whether this is an "interactive" input source; if so, and + * if we're using stdio for input, then we want to use getc() + * instead of fread(), to make sure we stop fetching input after + * each newline. + */ + int yy_is_interactive; + + /* Whether we're considered to be at the beginning of a line. + * If so, '^' rules will be active on the next match, otherwise + * not. + */ + int yy_at_bol; + + int yy_bs_lineno; /**< The line count. */ + int yy_bs_column; /**< The column count. */ + + /* Whether to try to fill the input buffer when we reach the + * end of it. + */ + int yy_fill_buffer; + + int yy_buffer_status; + +#define YY_BUFFER_NEW 0 +#define YY_BUFFER_NORMAL 1 + /* When an EOF's been seen but there's still some text to process + * then we mark the buffer as YY_EOF_PENDING, to indicate that we + * shouldn't try reading from the input source any more. We might + * still have a bunch of tokens to match, though, because of + * possible backing-up. + * + * When we actually see the EOF, we change the status to "new" + * (via yyrestart()), so that the user can continue scanning by + * just pointing yyin at a new input file. + */ +#define YY_BUFFER_EOF_PENDING 2 + + }; +#endif /* !YY_STRUCT_YY_BUFFER_STATE */ + +/* Stack of input buffers. */ +static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */ +static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */ +static YY_BUFFER_STATE * yy_buffer_stack = NULL; /**< Stack as an array. */ + +/* We provide macros for accessing buffer states in case in the + * future we want to put the buffer states in a more general + * "scanner state". + * + * Returns the top of the stack, or NULL. + */ +#define YY_CURRENT_BUFFER ( (yy_buffer_stack) \ + ? (yy_buffer_stack)[(yy_buffer_stack_top)] \ + : NULL) +/* Same as previous macro, but useful when we know that the buffer stack is not + * NULL or when we need an lvalue. For internal use only. + */ +#define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)] + +/* yy_hold_char holds the character lost when yytext is formed. */ +static char yy_hold_char; +static int yy_n_chars; /* number of characters read into yy_ch_buf */ +int yyleng; + +/* Points to current character in buffer. */ +static char *yy_c_buf_p = NULL; +static int yy_init = 0; /* whether we need to initialize */ +static int yy_start = 0; /* start state number */ + +/* Flag which is used to allow yywrap()'s to do buffer switches + * instead of setting up a fresh yyin. A bit of a hack ... + */ +static int yy_did_buffer_switch_on_eof; + +void yyrestart ( FILE *input_file ); +void yy_switch_to_buffer ( YY_BUFFER_STATE new_buffer ); +YY_BUFFER_STATE yy_create_buffer ( FILE *file, int size ); +void yy_delete_buffer ( YY_BUFFER_STATE b ); +void yy_flush_buffer ( YY_BUFFER_STATE b ); +void yypush_buffer_state ( YY_BUFFER_STATE new_buffer ); +void yypop_buffer_state ( void ); + +static void yyensure_buffer_stack ( void ); +static void yy_load_buffer_state ( void ); +static void yy_init_buffer ( YY_BUFFER_STATE b, FILE *file ); +#define YY_FLUSH_BUFFER yy_flush_buffer( YY_CURRENT_BUFFER ) + +YY_BUFFER_STATE yy_scan_buffer ( char *base, yy_size_t size ); +YY_BUFFER_STATE yy_scan_string ( const char *yy_str ); +YY_BUFFER_STATE yy_scan_bytes ( const char *bytes, int len ); + +void *yyalloc ( yy_size_t ); +void *yyrealloc ( void *, yy_size_t ); +void yyfree ( void * ); + +#define yy_new_buffer yy_create_buffer +#define yy_set_interactive(is_interactive) \ + { \ + if ( ! YY_CURRENT_BUFFER ){ \ + yyensure_buffer_stack (); \ + YY_CURRENT_BUFFER_LVALUE = \ + yy_create_buffer( yyin, YY_BUF_SIZE ); \ + } \ + YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ + } +#define yy_set_bol(at_bol) \ + { \ + if ( ! YY_CURRENT_BUFFER ){\ + yyensure_buffer_stack (); \ + YY_CURRENT_BUFFER_LVALUE = \ + yy_create_buffer( yyin, YY_BUF_SIZE ); \ + } \ + YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ + } +#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol) + +/* Begin user sect3 */ +typedef flex_uint8_t YY_CHAR; + +FILE *yyin = NULL, *yyout = NULL; + +typedef int yy_state_type; + +extern int yylineno; +int yylineno = 1; + +extern char *yytext; +#ifdef yytext_ptr +#undef yytext_ptr +#endif +#define yytext_ptr yytext + +static yy_state_type yy_get_previous_state ( void ); +static yy_state_type yy_try_NUL_trans ( yy_state_type current_state ); +static int yy_get_next_buffer ( void ); +static void yynoreturn yy_fatal_error ( const char* msg ); + +/* Done after the current pattern has been matched and before the + * corresponding action - sets up yytext. + */ +#define YY_DO_BEFORE_ACTION \ + (yytext_ptr) = yy_bp; \ + yyleng = (int) (yy_cp - yy_bp); \ + (yy_hold_char) = *yy_cp; \ + *yy_cp = '\0'; \ + (yy_c_buf_p) = yy_cp; +#define YY_NUM_RULES 57 +#define YY_END_OF_BUFFER 58 +/* This struct is not used in this scanner, + but its presence is necessary. */ +struct yy_trans_info + { + flex_int32_t yy_verify; + flex_int32_t yy_nxt; + }; +static const flex_int16_t yy_accept[141] = + { 0, + 0, 0, 58, 57, 1, 2, 42, 57, 45, 46, + 57, 33, 34, 43, 48, 41, 49, 40, 44, 51, + 39, 47, 24, 50, 25, 53, 35, 36, 53, 53, + 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, + 37, 57, 38, 1, 29, 0, 54, 0, 30, 0, + 0, 21, 22, 23, 0, 56, 0, 51, 26, 28, + 27, 53, 53, 53, 53, 53, 53, 8, 53, 53, + 53, 12, 53, 53, 53, 53, 53, 53, 53, 31, + 54, 55, 32, 56, 52, 53, 53, 53, 53, 53, + 53, 53, 11, 53, 53, 53, 53, 53, 53, 53, + + 53, 3, 53, 5, 53, 53, 9, 10, 53, 53, + 53, 53, 53, 53, 53, 53, 4, 53, 53, 53, + 53, 53, 53, 53, 53, 19, 20, 53, 53, 13, + 14, 15, 16, 17, 53, 53, 7, 18, 6, 0 + } ; + +static const YY_CHAR yy_ec[256] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 2, 4, 5, 1, 1, 6, 7, 8, 9, + 10, 11, 12, 13, 14, 15, 16, 17, 17, 17, + 17, 17, 17, 17, 17, 17, 17, 18, 19, 20, + 21, 22, 1, 1, 23, 23, 23, 23, 23, 23, + 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, + 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, + 24, 25, 26, 1, 23, 1, 27, 28, 29, 30, + + 31, 32, 23, 33, 34, 23, 35, 36, 37, 38, + 39, 40, 23, 41, 42, 43, 44, 23, 45, 23, + 46, 47, 48, 49, 50, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1 + } ; + +static const YY_CHAR yy_meta[51] = + { 0, + 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, + 1, 1, 3, 1, 1, 1, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 1, 1, 1 + } ; + +static const flex_int16_t yy_base[145] = + { 0, + 0, 0, 161, 162, 158, 162, 138, 46, 162, 151, + 149, 162, 162, 162, 144, 162, 38, 140, 138, 38, + 162, 162, 132, 131, 130, 0, 162, 162, 106, 108, + 27, 25, 21, 109, 115, 115, 24, 99, 106, 110, + 162, 93, 162, 139, 162, 56, 162, 60, 162, 132, + 131, 162, 162, 162, 123, 0, 120, 53, 162, 162, + 162, 0, 93, 104, 92, 95, 100, 0, 89, 86, + 88, 0, 85, 80, 35, 92, 85, 90, 89, 162, + 67, 162, 162, 0, 105, 82, 93, 88, 75, 90, + 85, 78, 0, 70, 82, 69, 67, 67, 78, 69, + + 71, 0, 71, 0, 71, 60, 0, 0, 62, 63, + 66, 68, 65, 61, 52, 58, 0, 50, 51, 48, + 52, 54, 39, 47, 48, 0, 0, 34, 34, 0, + 0, 0, 0, 0, 43, 43, 0, 0, 0, 162, + 92, 95, 70, 98 + } ; + +static const flex_int16_t yy_def[145] = + { 0, + 140, 1, 140, 140, 140, 140, 140, 141, 140, 140, + 142, 140, 140, 140, 140, 140, 140, 140, 140, 140, + 140, 140, 140, 140, 140, 143, 140, 140, 143, 143, + 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, + 140, 140, 140, 140, 140, 141, 140, 141, 140, 140, + 140, 140, 140, 140, 140, 144, 140, 140, 140, 140, + 140, 143, 143, 143, 143, 143, 143, 143, 143, 143, + 143, 143, 143, 143, 143, 143, 143, 143, 143, 140, + 141, 140, 140, 144, 140, 143, 143, 143, 143, 143, + 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, + + 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, + 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, + 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, + 143, 143, 143, 143, 143, 143, 143, 143, 143, 0, + 140, 140, 140, 140 + } ; + +static const flex_int16_t yy_nxt[213] = + { 0, + 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, + 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, + 24, 25, 26, 27, 4, 28, 29, 30, 31, 32, + 33, 34, 26, 35, 26, 26, 26, 26, 26, 26, + 36, 37, 38, 39, 40, 26, 26, 41, 42, 43, + 47, 53, 57, 65, 58, 67, 69, 74, 70, 54, + 47, 96, 46, 68, 81, 66, 75, 57, 76, 58, + 48, 47, 62, 139, 138, 97, 137, 136, 135, 134, + 48, 133, 132, 131, 48, 130, 129, 128, 127, 126, + 125, 48, 46, 124, 46, 50, 123, 50, 84, 122, + + 84, 121, 120, 119, 118, 117, 116, 115, 114, 113, + 112, 111, 110, 109, 108, 107, 106, 105, 104, 103, + 102, 85, 101, 100, 99, 98, 95, 94, 93, 92, + 91, 90, 89, 88, 87, 86, 85, 83, 50, 82, + 44, 80, 79, 78, 77, 73, 72, 71, 64, 63, + 61, 60, 59, 56, 55, 52, 51, 49, 45, 44, + 140, 3, 140, 140, 140, 140, 140, 140, 140, 140, + 140, 140, 140, 140, 140, 140, 140, 140, 140, 140, + 140, 140, 140, 140, 140, 140, 140, 140, 140, 140, + 140, 140, 140, 140, 140, 140, 140, 140, 140, 140, + + 140, 140, 140, 140, 140, 140, 140, 140, 140, 140, + 140, 140 + } ; + +static const flex_int16_t yy_chk[213] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 8, 17, 20, 31, 20, 32, 33, 37, 33, 17, + 46, 75, 48, 32, 48, 31, 37, 58, 37, 58, + 8, 81, 143, 136, 135, 75, 129, 128, 125, 124, + 46, 123, 122, 121, 48, 120, 119, 118, 116, 115, + 114, 81, 141, 113, 141, 142, 112, 142, 144, 111, + + 144, 110, 109, 106, 105, 103, 101, 100, 99, 98, + 97, 96, 95, 94, 92, 91, 90, 89, 88, 87, + 86, 85, 79, 78, 77, 76, 74, 73, 71, 70, + 69, 67, 66, 65, 64, 63, 57, 55, 51, 50, + 44, 42, 40, 39, 38, 36, 35, 34, 30, 29, + 25, 24, 23, 19, 18, 15, 11, 10, 7, 5, + 3, 140, 140, 140, 140, 140, 140, 140, 140, 140, + 140, 140, 140, 140, 140, 140, 140, 140, 140, 140, + 140, 140, 140, 140, 140, 140, 140, 140, 140, 140, + 140, 140, 140, 140, 140, 140, 140, 140, 140, 140, + + 140, 140, 140, 140, 140, 140, 140, 140, 140, 140, + 140, 140 + } ; + +static yy_state_type yy_last_accepting_state; +static char *yy_last_accepting_cpos; + +extern int yy_flex_debug; +int yy_flex_debug = 0; + +/* The intent behind this definition is that it'll catch + * any uses of REJECT which flex missed. + */ +#define REJECT reject_used_but_not_detected +#define yymore() yymore_used_but_not_detected +#define YY_MORE_ADJ 0 +#define YY_RESTORE_YY_MORE_OFFSET +char *yytext; +#line 1 "lex.l" +#line 8 "lex.l" +#define YYSTYPE_IS_DECLARED 1 +typedef long YYSTYPE; + +#include "y.tab.h" +#include "type.h" + +extern YYSTYPE yylval; +extern int line_no; +extern A_ID *current_id; + +char *makeString(); +int checkIdentifier(); +#line 548 "lex.yy.c" +#line 549 "lex.yy.c" + +#define INITIAL 0 + +#ifndef YY_NO_UNISTD_H +/* Special case for "unistd.h", since it is non-ANSI. We include it way + * down here because we want the user's section 1 to have been scanned first. + * The user has a chance to override it with an option. + */ +#include +#endif + +#ifndef YY_EXTRA_TYPE +#define YY_EXTRA_TYPE void * +#endif + +static int yy_init_globals ( void ); + +/* Accessor methods to globals. + These are made visible to non-reentrant scanners for convenience. */ + +int yylex_destroy ( void ); + +int yyget_debug ( void ); + +void yyset_debug ( int debug_flag ); + +YY_EXTRA_TYPE yyget_extra ( void ); + +void yyset_extra ( YY_EXTRA_TYPE user_defined ); + +FILE *yyget_in ( void ); + +void yyset_in ( FILE * _in_str ); + +FILE *yyget_out ( void ); + +void yyset_out ( FILE * _out_str ); + + int yyget_leng ( void ); + +char *yyget_text ( void ); + +int yyget_lineno ( void ); + +void yyset_lineno ( int _line_number ); + +/* Macros after this point can all be overridden by user definitions in + * section 1. + */ + +#ifndef YY_SKIP_YYWRAP +#ifdef __cplusplus +extern "C" int yywrap ( void ); +#else +extern int yywrap ( void ); +#endif +#endif + +#ifndef YY_NO_UNPUT + + static void yyunput ( int c, char *buf_ptr ); + +#endif + +#ifndef yytext_ptr +static void yy_flex_strncpy ( char *, const char *, int ); +#endif + +#ifdef YY_NEED_STRLEN +static int yy_flex_strlen ( const char * ); +#endif + +#ifndef YY_NO_INPUT +#ifdef __cplusplus +static int yyinput ( void ); +#else +static int input ( void ); +#endif + +#endif + +/* Amount of stuff to slurp up with each read. */ +#ifndef YY_READ_BUF_SIZE +#ifdef __ia64__ +/* On IA-64, the buffer size is 16k, not 8k */ +#define YY_READ_BUF_SIZE 16384 +#else +#define YY_READ_BUF_SIZE 8192 +#endif /* __ia64__ */ +#endif + +/* Copy whatever the last rule matched to the standard output. */ +#ifndef ECHO +/* This used to be an fputs(), but since the string might contain NUL's, + * we now use fwrite(). + */ +#define ECHO do { if (fwrite( yytext, (size_t) yyleng, 1, yyout )) {} } while (0) +#endif + +/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, + * is returned in "result". + */ +#ifndef YY_INPUT +#define YY_INPUT(buf,result,max_size) \ + if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ + { \ + int c = '*'; \ + int n; \ + for ( n = 0; n < max_size && \ + (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ + buf[n] = (char) c; \ + if ( c == '\n' ) \ + buf[n++] = (char) c; \ + if ( c == EOF && ferror( yyin ) ) \ + YY_FATAL_ERROR( "input in flex scanner failed" ); \ + result = n; \ + } \ + else \ + { \ + errno=0; \ + while ( (result = (int) fread(buf, 1, (yy_size_t) max_size, yyin)) == 0 && ferror(yyin)) \ + { \ + if( errno != EINTR) \ + { \ + YY_FATAL_ERROR( "input in flex scanner failed" ); \ + break; \ + } \ + errno=0; \ + clearerr(yyin); \ + } \ + }\ +\ + +#endif + +/* No semi-colon after return; correct usage is to write "yyterminate();" - + * we don't want an extra ';' after the "return" because that will cause + * some compilers to complain about unreachable statements. + */ +#ifndef yyterminate +#define yyterminate() return YY_NULL +#endif + +/* Number of entries by which start-condition stack grows. */ +#ifndef YY_START_STACK_INCR +#define YY_START_STACK_INCR 25 +#endif + +/* Report a fatal error. */ +#ifndef YY_FATAL_ERROR +#define YY_FATAL_ERROR(msg) yy_fatal_error( msg ) +#endif + +/* end tables serialization structures and prototypes */ + +/* Default declaration of generated scanner - a define so the user can + * easily add parameters. + */ +#ifndef YY_DECL +#define YY_DECL_IS_OURS 1 + +extern int yylex (void); + +#define YY_DECL int yylex (void) +#endif /* !YY_DECL */ + +/* Code executed at the beginning of each rule, after yytext and yyleng + * have been set up. + */ +#ifndef YY_USER_ACTION +#define YY_USER_ACTION +#endif + +/* Code executed at the end of each rule. */ +#ifndef YY_BREAK +#define YY_BREAK /*LINTED*/break; +#endif + +#define YY_RULE_SETUP \ + YY_USER_ACTION + +/** The main scanner function which does all the work. + */ +YY_DECL +{ + yy_state_type yy_current_state; + char *yy_cp, *yy_bp; + int yy_act; + + if ( !(yy_init) ) + { + (yy_init) = 1; + +#ifdef YY_USER_INIT + YY_USER_INIT; +#endif + + if ( ! (yy_start) ) + (yy_start) = 1; /* first start state */ + + if ( ! yyin ) + yyin = stdin; + + if ( ! yyout ) + yyout = stdout; + + if ( ! YY_CURRENT_BUFFER ) { + yyensure_buffer_stack (); + YY_CURRENT_BUFFER_LVALUE = + yy_create_buffer( yyin, YY_BUF_SIZE ); + } + + yy_load_buffer_state( ); + } + + { +#line 22 "lex.l" + +#line 768 "lex.yy.c" + + while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */ + { + yy_cp = (yy_c_buf_p); + + /* Support of yytext. */ + *yy_cp = (yy_hold_char); + + /* yy_bp points to the position in yy_ch_buf of the start of + * the current run. + */ + yy_bp = yy_cp; + + yy_current_state = (yy_start); +yy_match: + do + { + YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ; + if ( yy_accept[yy_current_state] ) + { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 141 ) + yy_c = yy_meta[yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; + ++yy_cp; + } + while ( yy_base[yy_current_state] != 162 ); + +yy_find_action: + yy_act = yy_accept[yy_current_state]; + if ( yy_act == 0 ) + { /* have to back up */ + yy_cp = (yy_last_accepting_cpos); + yy_current_state = (yy_last_accepting_state); + yy_act = yy_accept[yy_current_state]; + } + + YY_DO_BEFORE_ACTION; + +do_action: /* This label is used only to access EOF actions. */ + + switch ( yy_act ) + { /* beginning of action switch */ + case 0: /* must back up */ + /* undo the effects of YY_DO_BEFORE_ACTION */ + *yy_cp = (yy_hold_char); + yy_cp = (yy_last_accepting_cpos); + yy_current_state = (yy_last_accepting_state); + goto yy_find_action; + +case 1: +YY_RULE_SETUP +#line 23 "lex.l" +{ } + YY_BREAK +case 2: +/* rule 2 can match eol */ +YY_RULE_SETUP +#line 24 "lex.l" +{ line_no++; } + YY_BREAK +case 3: +YY_RULE_SETUP +#line 25 "lex.l" +{ return(AUTO_SYM); } + YY_BREAK +case 4: +YY_RULE_SETUP +#line 26 "lex.l" +{ return(BREAK_SYM); } + YY_BREAK +case 5: +YY_RULE_SETUP +#line 27 "lex.l" +{ return(CASE_SYM); } + YY_BREAK +case 6: +YY_RULE_SETUP +#line 28 "lex.l" +{ return(CONTINUE_SYM); } + YY_BREAK +case 7: +YY_RULE_SETUP +#line 29 "lex.l" +{ return(DEFAULT_SYM); } + YY_BREAK +case 8: +YY_RULE_SETUP +#line 30 "lex.l" +{ return(DO_SYM); } + YY_BREAK +case 9: +YY_RULE_SETUP +#line 31 "lex.l" +{ return(ELSE_SYM); } + YY_BREAK +case 10: +YY_RULE_SETUP +#line 32 "lex.l" +{ return(ENUM_SYM); } + YY_BREAK +case 11: +YY_RULE_SETUP +#line 33 "lex.l" +{ return(FOR_SYM); } + YY_BREAK +case 12: +YY_RULE_SETUP +#line 34 "lex.l" +{ return(IF_SYM); } + YY_BREAK +case 13: +YY_RULE_SETUP +#line 35 "lex.l" +{ return(RETURN_SYM); } + YY_BREAK +case 14: +YY_RULE_SETUP +#line 36 "lex.l" +{ return(SIZEOF_SYM); } + YY_BREAK +case 15: +YY_RULE_SETUP +#line 37 "lex.l" +{ return(STATIC_SYM); } + YY_BREAK +case 16: +YY_RULE_SETUP +#line 38 "lex.l" +{ return(STRUCT_SYM); } + YY_BREAK +case 17: +YY_RULE_SETUP +#line 39 "lex.l" +{ return(SWITCH_SYM); } + YY_BREAK +case 18: +YY_RULE_SETUP +#line 40 "lex.l" +{ return(TYPEDEF_SYM); } + YY_BREAK +case 19: +YY_RULE_SETUP +#line 41 "lex.l" +{ return(UNION_SYM); } + YY_BREAK +case 20: +YY_RULE_SETUP +#line 42 "lex.l" +{ return(WHILE_SYM); } + YY_BREAK +case 21: +YY_RULE_SETUP +#line 44 "lex.l" +{ return(PLUSPLUS); } + YY_BREAK +case 22: +YY_RULE_SETUP +#line 45 "lex.l" +{ return(MINUSMINUS); } + YY_BREAK +case 23: +YY_RULE_SETUP +#line 46 "lex.l" +{ return(ARROW); } + YY_BREAK +case 24: +YY_RULE_SETUP +#line 47 "lex.l" +{ return(LSS); } + YY_BREAK +case 25: +YY_RULE_SETUP +#line 48 "lex.l" +{ return(GTR); } + YY_BREAK +case 26: +YY_RULE_SETUP +#line 49 "lex.l" +{ return(LEQ); } + YY_BREAK +case 27: +YY_RULE_SETUP +#line 50 "lex.l" +{ return(GEQ); } + YY_BREAK +case 28: +YY_RULE_SETUP +#line 51 "lex.l" +{ return(EQL); } + YY_BREAK +case 29: +YY_RULE_SETUP +#line 52 "lex.l" +{ return(NEQ); } + YY_BREAK +case 30: +YY_RULE_SETUP +#line 53 "lex.l" +{ return(AMPAMP); } + YY_BREAK +case 31: +YY_RULE_SETUP +#line 54 "lex.l" +{ return(BARBAR); } + YY_BREAK +case 32: +YY_RULE_SETUP +#line 55 "lex.l" +{ return(DOTDOTDOT); } + YY_BREAK +case 33: +YY_RULE_SETUP +#line 56 "lex.l" +{ return(LP); } + YY_BREAK +case 34: +YY_RULE_SETUP +#line 57 "lex.l" +{ return(RP); } + YY_BREAK +case 35: +YY_RULE_SETUP +#line 58 "lex.l" +{ return(LB); } + YY_BREAK +case 36: +YY_RULE_SETUP +#line 59 "lex.l" +{ return(RB); } + YY_BREAK +case 37: +YY_RULE_SETUP +#line 60 "lex.l" +{ return(LR); } + YY_BREAK +case 38: +YY_RULE_SETUP +#line 61 "lex.l" +{ return(RR); } + YY_BREAK +case 39: +YY_RULE_SETUP +#line 62 "lex.l" +{ return(COLON); } + YY_BREAK +case 40: +YY_RULE_SETUP +#line 63 "lex.l" +{ return(PERIOD); } + YY_BREAK +case 41: +YY_RULE_SETUP +#line 64 "lex.l" +{ return(COMMA); } + YY_BREAK +case 42: +YY_RULE_SETUP +#line 65 "lex.l" +{ return(EXCL); } + YY_BREAK +case 43: +YY_RULE_SETUP +#line 66 "lex.l" +{ return(STAR); } + YY_BREAK +case 44: +YY_RULE_SETUP +#line 67 "lex.l" +{ return(SLASH); } + YY_BREAK +case 45: +YY_RULE_SETUP +#line 68 "lex.l" +{ return(PERCENT); } + YY_BREAK +case 46: +YY_RULE_SETUP +#line 69 "lex.l" +{ return(AMP); } + YY_BREAK +case 47: +YY_RULE_SETUP +#line 70 "lex.l" +{ return(SEMICOLON); } + YY_BREAK +case 48: +YY_RULE_SETUP +#line 71 "lex.l" +{ return(PLUS); } + YY_BREAK +case 49: +YY_RULE_SETUP +#line 72 "lex.l" +{ return(MINUS); } + YY_BREAK +case 50: +YY_RULE_SETUP +#line 73 "lex.l" +{ return(ASSIGN); } + YY_BREAK +case 51: +YY_RULE_SETUP +#line 75 "lex.l" +{ yylval = atoi(yytext); return(INTEGER_CONSTANT); } + YY_BREAK +case 52: +YY_RULE_SETUP +#line 76 "lex.l" +{ yylval = makeString(yytext); return(FLOAT_CONSTANT); } + YY_BREAK +case 53: +YY_RULE_SETUP +#line 77 "lex.l" +{ return(checkIdentifier(yytext)); } + YY_BREAK +case 54: +/* rule 54 can match eol */ +YY_RULE_SETUP +#line 78 "lex.l" +{ yylval = makeString(yytext); return(STRING_LITERAL); } + YY_BREAK +case 55: +YY_RULE_SETUP +#line 79 "lex.l" +{ yylval = *(yytext+1); return(CHARACTER_CONSTANT); } + YY_BREAK +case 56: +YY_RULE_SETUP +#line 80 "lex.l" +{ } + YY_BREAK +case 57: +YY_RULE_SETUP +#line 82 "lex.l" +ECHO; + YY_BREAK +#line 1112 "lex.yy.c" +case YY_STATE_EOF(INITIAL): + yyterminate(); + + case YY_END_OF_BUFFER: + { + /* Amount of text matched not including the EOB char. */ + int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1; + + /* Undo the effects of YY_DO_BEFORE_ACTION. */ + *yy_cp = (yy_hold_char); + YY_RESTORE_YY_MORE_OFFSET + + if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW ) + { + /* We're scanning a new file or input source. It's + * possible that this happened because the user + * just pointed yyin at a new source and called + * yylex(). If so, then we have to assure + * consistency between YY_CURRENT_BUFFER and our + * globals. Here is the right place to do so, because + * this is the first action (other than possibly a + * back-up) that will match for the new input source. + */ + (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin; + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; + } + + /* Note that here we test for yy_c_buf_p "<=" to the position + * of the first EOB in the buffer, since yy_c_buf_p will + * already have been incremented past the NUL character + * (since all states make transitions on EOB to the + * end-of-buffer state). Contrast this with the test + * in input(). + */ + if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) + { /* This was really a NUL. */ + yy_state_type yy_next_state; + + (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state( ); + + /* Okay, we're now positioned to make the NUL + * transition. We couldn't have + * yy_get_previous_state() go ahead and do it + * for us because it doesn't know how to deal + * with the possibility of jamming (and we don't + * want to build jamming into it because then it + * will run more slowly). + */ + + yy_next_state = yy_try_NUL_trans( yy_current_state ); + + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + + if ( yy_next_state ) + { + /* Consume the NUL. */ + yy_cp = ++(yy_c_buf_p); + yy_current_state = yy_next_state; + goto yy_match; + } + + else + { + yy_cp = (yy_c_buf_p); + goto yy_find_action; + } + } + + else switch ( yy_get_next_buffer( ) ) + { + case EOB_ACT_END_OF_FILE: + { + (yy_did_buffer_switch_on_eof) = 0; + + if ( yywrap( ) ) + { + /* Note: because we've taken care in + * yy_get_next_buffer() to have set up + * yytext, we can now set up + * yy_c_buf_p so that if some total + * hoser (like flex itself) wants to + * call the scanner after we return the + * YY_NULL, it'll still work - another + * YY_NULL will get returned. + */ + (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ; + + yy_act = YY_STATE_EOF(YY_START); + goto do_action; + } + + else + { + if ( ! (yy_did_buffer_switch_on_eof) ) + YY_NEW_FILE; + } + break; + } + + case EOB_ACT_CONTINUE_SCAN: + (yy_c_buf_p) = + (yytext_ptr) + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state( ); + + yy_cp = (yy_c_buf_p); + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + goto yy_match; + + case EOB_ACT_LAST_MATCH: + (yy_c_buf_p) = + &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)]; + + yy_current_state = yy_get_previous_state( ); + + yy_cp = (yy_c_buf_p); + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + goto yy_find_action; + } + break; + } + + default: + YY_FATAL_ERROR( + "fatal flex scanner internal error--no action found" ); + } /* end of action switch */ + } /* end of scanning one token */ + } /* end of user's declarations */ +} /* end of yylex */ + +/* yy_get_next_buffer - try to read in a new buffer + * + * Returns a code representing an action: + * EOB_ACT_LAST_MATCH - + * EOB_ACT_CONTINUE_SCAN - continue scanning from current position + * EOB_ACT_END_OF_FILE - end of file + */ +static int yy_get_next_buffer (void) +{ + char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; + char *source = (yytext_ptr); + int number_to_move, i; + int ret_val; + + if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] ) + YY_FATAL_ERROR( + "fatal flex scanner internal error--end of buffer missed" ); + + if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 ) + { /* Don't try to fill the buffer, so this is an EOF. */ + if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 ) + { + /* We matched a single character, the EOB, so + * treat this as a final EOF. + */ + return EOB_ACT_END_OF_FILE; + } + + else + { + /* We matched some text prior to the EOB, first + * process it. + */ + return EOB_ACT_LAST_MATCH; + } + } + + /* Try to read more data. */ + + /* First move last chars to start of buffer. */ + number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr) - 1); + + for ( i = 0; i < number_to_move; ++i ) + *(dest++) = *(source++); + + if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING ) + /* don't do the read, it's not guaranteed to return an EOF, + * just force an EOF + */ + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0; + + else + { + int num_to_read = + YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; + + while ( num_to_read <= 0 ) + { /* Not enough room in the buffer - grow it. */ + + /* just a shorter name for the current buffer */ + YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE; + + int yy_c_buf_p_offset = + (int) ((yy_c_buf_p) - b->yy_ch_buf); + + if ( b->yy_is_our_buffer ) + { + int new_size = b->yy_buf_size * 2; + + if ( new_size <= 0 ) + b->yy_buf_size += b->yy_buf_size / 8; + else + b->yy_buf_size *= 2; + + b->yy_ch_buf = (char *) + /* Include room in for 2 EOB chars. */ + yyrealloc( (void *) b->yy_ch_buf, + (yy_size_t) (b->yy_buf_size + 2) ); + } + else + /* Can't grow it, we don't own it. */ + b->yy_ch_buf = NULL; + + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( + "fatal error - scanner input buffer overflow" ); + + (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset]; + + num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - + number_to_move - 1; + + } + + if ( num_to_read > YY_READ_BUF_SIZE ) + num_to_read = YY_READ_BUF_SIZE; + + /* Read in more data. */ + YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), + (yy_n_chars), num_to_read ); + + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } + + if ( (yy_n_chars) == 0 ) + { + if ( number_to_move == YY_MORE_ADJ ) + { + ret_val = EOB_ACT_END_OF_FILE; + yyrestart( yyin ); + } + + else + { + ret_val = EOB_ACT_LAST_MATCH; + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = + YY_BUFFER_EOF_PENDING; + } + } + + else + ret_val = EOB_ACT_CONTINUE_SCAN; + + if (((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { + /* Extend the array by 50%, plus the number we really need. */ + int new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1); + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc( + (void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf, (yy_size_t) new_size ); + if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); + /* "- 2" to take care of EOB's */ + YY_CURRENT_BUFFER_LVALUE->yy_buf_size = (int) (new_size - 2); + } + + (yy_n_chars) += number_to_move; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR; + + (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; + + return ret_val; +} + +/* yy_get_previous_state - get the state just before the EOB char was reached */ + + static yy_state_type yy_get_previous_state (void) +{ + yy_state_type yy_current_state; + char *yy_cp; + + yy_current_state = (yy_start); + + for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp ) + { + YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); + if ( yy_accept[yy_current_state] ) + { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 141 ) + yy_c = yy_meta[yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; + } + + return yy_current_state; +} + +/* yy_try_NUL_trans - try to make a transition on the NUL character + * + * synopsis + * next_state = yy_try_NUL_trans( current_state ); + */ + static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state ) +{ + int yy_is_jam; + char *yy_cp = (yy_c_buf_p); + + YY_CHAR yy_c = 1; + if ( yy_accept[yy_current_state] ) + { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 141 ) + yy_c = yy_meta[yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; + yy_is_jam = (yy_current_state == 140); + + return yy_is_jam ? 0 : yy_current_state; +} + +#ifndef YY_NO_UNPUT + + static void yyunput (int c, char * yy_bp ) +{ + char *yy_cp; + + yy_cp = (yy_c_buf_p); + + /* undo effects of setting up yytext */ + *yy_cp = (yy_hold_char); + + if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) + { /* need to shift things up to make room */ + /* +2 for EOB chars. */ + int number_to_move = (yy_n_chars) + 2; + char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[ + YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2]; + char *source = + &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]; + + while ( source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) + *--dest = *--source; + + yy_cp += (int) (dest - source); + yy_bp += (int) (dest - source); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = + (yy_n_chars) = (int) YY_CURRENT_BUFFER_LVALUE->yy_buf_size; + + if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) + YY_FATAL_ERROR( "flex scanner push-back overflow" ); + } + + *--yy_cp = (char) c; + + (yytext_ptr) = yy_bp; + (yy_hold_char) = *yy_cp; + (yy_c_buf_p) = yy_cp; +} + +#endif + +#ifndef YY_NO_INPUT +#ifdef __cplusplus + static int yyinput (void) +#else + static int input (void) +#endif + +{ + int c; + + *(yy_c_buf_p) = (yy_hold_char); + + if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR ) + { + /* yy_c_buf_p now points to the character we want to return. + * If this occurs *before* the EOB characters, then it's a + * valid NUL; if not, then we've hit the end of the buffer. + */ + if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) + /* This was really a NUL. */ + *(yy_c_buf_p) = '\0'; + + else + { /* need more input */ + int offset = (int) ((yy_c_buf_p) - (yytext_ptr)); + ++(yy_c_buf_p); + + switch ( yy_get_next_buffer( ) ) + { + case EOB_ACT_LAST_MATCH: + /* This happens because yy_g_n_b() + * sees that we've accumulated a + * token and flags that we need to + * try matching the token before + * proceeding. But for input(), + * there's no matching to consider. + * So convert the EOB_ACT_LAST_MATCH + * to EOB_ACT_END_OF_FILE. + */ + + /* Reset buffer status. */ + yyrestart( yyin ); + + /*FALLTHROUGH*/ + + case EOB_ACT_END_OF_FILE: + { + if ( yywrap( ) ) + return 0; + + if ( ! (yy_did_buffer_switch_on_eof) ) + YY_NEW_FILE; +#ifdef __cplusplus + return yyinput(); +#else + return input(); +#endif + } + + case EOB_ACT_CONTINUE_SCAN: + (yy_c_buf_p) = (yytext_ptr) + offset; + break; + } + } + } + + c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */ + *(yy_c_buf_p) = '\0'; /* preserve yytext */ + (yy_hold_char) = *++(yy_c_buf_p); + + return c; +} +#endif /* ifndef YY_NO_INPUT */ + +/** Immediately switch to a different input stream. + * @param input_file A readable stream. + * + * @note This function does not reset the start condition to @c INITIAL . + */ + void yyrestart (FILE * input_file ) +{ + + if ( ! YY_CURRENT_BUFFER ){ + yyensure_buffer_stack (); + YY_CURRENT_BUFFER_LVALUE = + yy_create_buffer( yyin, YY_BUF_SIZE ); + } + + yy_init_buffer( YY_CURRENT_BUFFER, input_file ); + yy_load_buffer_state( ); +} + +/** Switch to a different input buffer. + * @param new_buffer The new input buffer. + * + */ + void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ) +{ + + /* TODO. We should be able to replace this entire function body + * with + * yypop_buffer_state(); + * yypush_buffer_state(new_buffer); + */ + yyensure_buffer_stack (); + if ( YY_CURRENT_BUFFER == new_buffer ) + return; + + if ( YY_CURRENT_BUFFER ) + { + /* Flush out information for old buffer. */ + *(yy_c_buf_p) = (yy_hold_char); + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } + + YY_CURRENT_BUFFER_LVALUE = new_buffer; + yy_load_buffer_state( ); + + /* We don't actually know whether we did this switch during + * EOF (yywrap()) processing, but the only time this flag + * is looked at is after yywrap() is called, so it's safe + * to go ahead and always set it. + */ + (yy_did_buffer_switch_on_eof) = 1; +} + +static void yy_load_buffer_state (void) +{ + (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; + yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file; + (yy_hold_char) = *(yy_c_buf_p); +} + +/** Allocate and initialize an input buffer state. + * @param file A readable stream. + * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE. + * + * @return the allocated buffer state. + */ + YY_BUFFER_STATE yy_create_buffer (FILE * file, int size ) +{ + YY_BUFFER_STATE b; + + b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) ); + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); + + b->yy_buf_size = size; + + /* yy_ch_buf has to be 2 characters longer than the size given because + * we need to put in 2 end-of-buffer characters. + */ + b->yy_ch_buf = (char *) yyalloc( (yy_size_t) (b->yy_buf_size + 2) ); + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); + + b->yy_is_our_buffer = 1; + + yy_init_buffer( b, file ); + + return b; +} + +/** Destroy the buffer. + * @param b a buffer created with yy_create_buffer() + * + */ + void yy_delete_buffer (YY_BUFFER_STATE b ) +{ + + if ( ! b ) + return; + + if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */ + YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; + + if ( b->yy_is_our_buffer ) + yyfree( (void *) b->yy_ch_buf ); + + yyfree( (void *) b ); +} + +/* Initializes or reinitializes a buffer. + * This function is sometimes called more than once on the same buffer, + * such as during a yyrestart() or at EOF. + */ + static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file ) + +{ + int oerrno = errno; + + yy_flush_buffer( b ); + + b->yy_input_file = file; + b->yy_fill_buffer = 1; + + /* If b is the current buffer, then yy_init_buffer was _probably_ + * called from yyrestart() or through yy_get_next_buffer. + * In that case, we don't want to reset the lineno or column. + */ + if (b != YY_CURRENT_BUFFER){ + b->yy_bs_lineno = 1; + b->yy_bs_column = 0; + } + + b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0; + + errno = oerrno; +} + +/** Discard all buffered characters. On the next scan, YY_INPUT will be called. + * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER. + * + */ + void yy_flush_buffer (YY_BUFFER_STATE b ) +{ + if ( ! b ) + return; + + b->yy_n_chars = 0; + + /* We always need two end-of-buffer characters. The first causes + * a transition to the end-of-buffer state. The second causes + * a jam in that state. + */ + b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; + b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; + + b->yy_buf_pos = &b->yy_ch_buf[0]; + + b->yy_at_bol = 1; + b->yy_buffer_status = YY_BUFFER_NEW; + + if ( b == YY_CURRENT_BUFFER ) + yy_load_buffer_state( ); +} + +/** Pushes the new state onto the stack. The new state becomes + * the current state. This function will allocate the stack + * if necessary. + * @param new_buffer The new state. + * + */ +void yypush_buffer_state (YY_BUFFER_STATE new_buffer ) +{ + if (new_buffer == NULL) + return; + + yyensure_buffer_stack(); + + /* This block is copied from yy_switch_to_buffer. */ + if ( YY_CURRENT_BUFFER ) + { + /* Flush out information for old buffer. */ + *(yy_c_buf_p) = (yy_hold_char); + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } + + /* Only push if top exists. Otherwise, replace top. */ + if (YY_CURRENT_BUFFER) + (yy_buffer_stack_top)++; + YY_CURRENT_BUFFER_LVALUE = new_buffer; + + /* copied from yy_switch_to_buffer. */ + yy_load_buffer_state( ); + (yy_did_buffer_switch_on_eof) = 1; +} + +/** Removes and deletes the top of the stack, if present. + * The next element becomes the new top. + * + */ +void yypop_buffer_state (void) +{ + if (!YY_CURRENT_BUFFER) + return; + + yy_delete_buffer(YY_CURRENT_BUFFER ); + YY_CURRENT_BUFFER_LVALUE = NULL; + if ((yy_buffer_stack_top) > 0) + --(yy_buffer_stack_top); + + if (YY_CURRENT_BUFFER) { + yy_load_buffer_state( ); + (yy_did_buffer_switch_on_eof) = 1; + } +} + +/* Allocates the stack if it does not exist. + * Guarantees space for at least one push. + */ +static void yyensure_buffer_stack (void) +{ + yy_size_t num_to_alloc; + + if (!(yy_buffer_stack)) { + + /* First allocation is just for 2 elements, since we don't know if this + * scanner will even need a stack. We use 2 instead of 1 to avoid an + * immediate realloc on the next call. + */ + num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */ + (yy_buffer_stack) = (struct yy_buffer_state**)yyalloc + (num_to_alloc * sizeof(struct yy_buffer_state*) + ); + if ( ! (yy_buffer_stack) ) + YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); + + memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*)); + + (yy_buffer_stack_max) = num_to_alloc; + (yy_buffer_stack_top) = 0; + return; + } + + if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){ + + /* Increase the buffer to prepare for a possible push. */ + yy_size_t grow_size = 8 /* arbitrary grow size */; + + num_to_alloc = (yy_buffer_stack_max) + grow_size; + (yy_buffer_stack) = (struct yy_buffer_state**)yyrealloc + ((yy_buffer_stack), + num_to_alloc * sizeof(struct yy_buffer_state*) + ); + if ( ! (yy_buffer_stack) ) + YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); + + /* zero only the new slots.*/ + memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*)); + (yy_buffer_stack_max) = num_to_alloc; + } +} + +/** Setup the input buffer state to scan directly from a user-specified character buffer. + * @param base the character buffer + * @param size the size in bytes of the character buffer + * + * @return the newly allocated buffer state object. + */ +YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size ) +{ + YY_BUFFER_STATE b; + + if ( size < 2 || + base[size-2] != YY_END_OF_BUFFER_CHAR || + base[size-1] != YY_END_OF_BUFFER_CHAR ) + /* They forgot to leave room for the EOB's. */ + return NULL; + + b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) ); + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" ); + + b->yy_buf_size = (int) (size - 2); /* "- 2" to take care of EOB's */ + b->yy_buf_pos = b->yy_ch_buf = base; + b->yy_is_our_buffer = 0; + b->yy_input_file = NULL; + b->yy_n_chars = b->yy_buf_size; + b->yy_is_interactive = 0; + b->yy_at_bol = 1; + b->yy_fill_buffer = 0; + b->yy_buffer_status = YY_BUFFER_NEW; + + yy_switch_to_buffer( b ); + + return b; +} + +/** Setup the input buffer state to scan a string. The next call to yylex() will + * scan from a @e copy of @a str. + * @param yystr a NUL-terminated string to scan + * + * @return the newly allocated buffer state object. + * @note If you want to scan bytes that may contain NUL values, then use + * yy_scan_bytes() instead. + */ +YY_BUFFER_STATE yy_scan_string (const char * yystr ) +{ + + return yy_scan_bytes( yystr, (int) strlen(yystr) ); +} + +/** Setup the input buffer state to scan the given bytes. The next call to yylex() will + * scan from a @e copy of @a bytes. + * @param yybytes the byte buffer to scan + * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes. + * + * @return the newly allocated buffer state object. + */ +YY_BUFFER_STATE yy_scan_bytes (const char * yybytes, int _yybytes_len ) +{ + YY_BUFFER_STATE b; + char *buf; + yy_size_t n; + int i; + + /* Get memory for full buffer, including space for trailing EOB's. */ + n = (yy_size_t) (_yybytes_len + 2); + buf = (char *) yyalloc( n ); + if ( ! buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" ); + + for ( i = 0; i < _yybytes_len; ++i ) + buf[i] = yybytes[i]; + + buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR; + + b = yy_scan_buffer( buf, n ); + if ( ! b ) + YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" ); + + /* It's okay to grow etc. this buffer, and we should throw it + * away when we're done. + */ + b->yy_is_our_buffer = 1; + + return b; +} + +#ifndef YY_EXIT_FAILURE +#define YY_EXIT_FAILURE 2 +#endif + +static void yynoreturn yy_fatal_error (const char* msg ) +{ + fprintf( stderr, "%s\n", msg ); + exit( YY_EXIT_FAILURE ); +} + +/* Redefine yyless() so it works in section 3 code. */ + +#undef yyless +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up yytext. */ \ + int yyless_macro_arg = (n); \ + YY_LESS_LINENO(yyless_macro_arg);\ + yytext[yyleng] = (yy_hold_char); \ + (yy_c_buf_p) = yytext + yyless_macro_arg; \ + (yy_hold_char) = *(yy_c_buf_p); \ + *(yy_c_buf_p) = '\0'; \ + yyleng = yyless_macro_arg; \ + } \ + while ( 0 ) + +/* Accessor methods (get/set functions) to struct members. */ + +/** Get the current line number. + * + */ +int yyget_lineno (void) +{ + + return yylineno; +} + +/** Get the input stream. + * + */ +FILE *yyget_in (void) +{ + return yyin; +} + +/** Get the output stream. + * + */ +FILE *yyget_out (void) +{ + return yyout; +} + +/** Get the length of the current token. + * + */ +int yyget_leng (void) +{ + return yyleng; +} + +/** Get the current token. + * + */ + +char *yyget_text (void) +{ + return yytext; +} + +/** Set the current line number. + * @param _line_number line number + * + */ +void yyset_lineno (int _line_number ) +{ + + yylineno = _line_number; +} + +/** Set the input stream. This does not discard the current + * input buffer. + * @param _in_str A readable stream. + * + * @see yy_switch_to_buffer + */ +void yyset_in (FILE * _in_str ) +{ + yyin = _in_str ; +} + +void yyset_out (FILE * _out_str ) +{ + yyout = _out_str ; +} + +int yyget_debug (void) +{ + return yy_flex_debug; +} + +void yyset_debug (int _bdebug ) +{ + yy_flex_debug = _bdebug ; +} + +static int yy_init_globals (void) +{ + /* Initialization is the same as for the non-reentrant scanner. + * This function is called from yylex_destroy(), so don't allocate here. + */ + + (yy_buffer_stack) = NULL; + (yy_buffer_stack_top) = 0; + (yy_buffer_stack_max) = 0; + (yy_c_buf_p) = NULL; + (yy_init) = 0; + (yy_start) = 0; + +/* Defined in main.c */ +#ifdef YY_STDINIT + yyin = stdin; + yyout = stdout; +#else + yyin = NULL; + yyout = NULL; +#endif + + /* For future reference: Set errno on error, since we are called by + * yylex_init() + */ + return 0; +} + +/* yylex_destroy is for both reentrant and non-reentrant scanners. */ +int yylex_destroy (void) +{ + + /* Pop the buffer stack, destroying each element. */ + while(YY_CURRENT_BUFFER){ + yy_delete_buffer( YY_CURRENT_BUFFER ); + YY_CURRENT_BUFFER_LVALUE = NULL; + yypop_buffer_state(); + } + + /* Destroy the stack itself. */ + yyfree((yy_buffer_stack) ); + (yy_buffer_stack) = NULL; + + /* Reset the globals. This is important in a non-reentrant scanner so the next time + * yylex() is called, initialization will occur. */ + yy_init_globals( ); + + return 0; +} + +/* + * Internal utility routines. + */ + +#ifndef yytext_ptr +static void yy_flex_strncpy (char* s1, const char * s2, int n ) +{ + + int i; + for ( i = 0; i < n; ++i ) + s1[i] = s2[i]; +} +#endif + +#ifdef YY_NEED_STRLEN +static int yy_flex_strlen (const char * s ) +{ + int n; + for ( n = 0; s[n]; ++n ) + ; + + return n; +} +#endif + +void *yyalloc (yy_size_t size ) +{ + return malloc(size); +} + +void *yyrealloc (void * ptr, yy_size_t size ) +{ + + /* The cast to (char *) in the following accommodates both + * implementations that use char* generic pointers, and those + * that use void* generic pointers. It works with the latter + * because both ANSI C and C++ allow castless assignment from + * any pointer type to void*, and deal with argument conversions + * as though doing an assignment. + */ + return realloc(ptr, size); +} + +void yyfree (void * ptr ) +{ + free( (char *) ptr ); /* see yyrealloc() for (char *) cast */ +} + +#define YYTABLES_NAME "yytables" + +#line 82 "lex.l" + +char *makeString(char *s){ + char *t; + t=(char *)malloc(strlen(s)+1); + strcpy(t,s); + return(t); +} +int checkIdentifier(char *s){ + A_ID *id; + char *t; + + id = current_id; + while (id){ + if (!strcmp(id->name, s)) break; + id = id->prev; + } + if (!id){ + yylval = (YYSTYPE)makeString(s); + return(IDENTIFIER); + } else if (id->kind == ID_TYPE){ + yylval = id->type; + return(TYPE_IDENTIFIER); + } else { + yylval = id->name; + return(IDENTIFIER); + } +} diff --git a/08-code-generator/main.c b/08-code-generator/main.c new file mode 100644 index 0000000..7a48930 --- /dev/null +++ b/08-code-generator/main.c @@ -0,0 +1,53 @@ +#include +#include +#include "type.h" + +extern FILE *yyin; +extern A_NODE *root; +extern int syntax_err; +extern int semantic_err; + +FILE *fout; + +void main(int argc, char *argv[]){ + if (argc < 2){ + printf("source file not given.\n"); + exit(1); + } + if (strcmp(argv[1], "-o") == 0){ + if (argc > 3){ + if ((fout = fopen(argv[2], "w")) == NULL){ + printf("cannot open output file: %s\n", argv[3]); + exit(1); + } else ; + } else { + printf("out file not given.\n"); + exit(1); + } + } else if (argc == 2){ + if ((fout = fopen("a.asm", "w")) == NULL){ + printf("cannot open output file: a.asm\n"); + exit(1); + } + } + + if ((yyin = fopen(argv[argc-1], "r")) == NULL){ + printf("cannot open input file: %s\n", argv[argc-1]); + exit(1); + } + + printf("\nStart Syntax Analysis\n"); + + initialize(); + yyparse(); + if (syntax_err) exit(1); + + printf("\nStart Semantic Analysis\n"); + semantic_analysis(root); + if (semantic_err) exit(1); + + printf("\nStart Code Generation\n"); + code_genaration(root); + + exit(0); +} \ No newline at end of file diff --git a/08-code-generator/sem_func.c b/08-code-generator/sem_func.c new file mode 100644 index 0000000..8baa88f --- /dev/null +++ b/08-code-generator/sem_func.c @@ -0,0 +1,1324 @@ +#include "type.h" +#include "sem_func.h" + +extern A_TYPE *int_type, *float_type, *char_type, *string_type, *void_type; + +int global_address = 12; +int semantic_err = 0; +A_LITERAL literal_table[LIT_MAX]; +int literal_no = 0; +int literal_size = 0; + +double atof(); + +void semantic_analysis(A_NODE *node) { + sem_program(node); + set_literal_address(node); +} + +void set_literal_address(A_NODE *node) { + int i; + for (i=1;i<=literal_no; i++) + literal_table[i].addr += node->value; + node->value+=literal_size; +} + +void sem_program(A_NODE *node) { // 원시 프로그램에서 선언된 전역 변수 크기 계산 + int i; + switch(node->name) { + case N_PROGRAM : + i = sem_declaration_list(node->clink, 12); + node->value = global_address; + break; + default : + semantic_error(90, node->line); + break; + } +} + +int put_literal(A_LITERAL lit, int ll) { + float ff; + if (literal_no >= LIT_MAX) + semantic_error(93, ll); + else + literal_no++; + literal_table[literal_no] = lit; + literal_table[literal_no].addr = literal_size; + if (lit.type->kind == T_ENUM) + literal_size += 4; + else if (isStringType(lit.type)) + literal_size += strlen(lit.value.s) + 1; + if (literal_size % 4) + literal_size = literal_size/4 * 4 + 4; + return(literal_no); +} + +A_TYPE *sem_expression(A_NODE *node) { +// 수식 분석, 필요한 경우 변환 +// 수식의 타입 계산하여 node에 저장하고 리턴 + A_TYPE *result=NIL, *t, *t1, *t2; + A_ID *id; + A_LITERAL lit = {0}; + int i; + BOOLEAN lvalue=FALSE; + switch(node->name) { + case N_EXP_IDENT : + id=node->clink; + switch (id->kind) { + case ID_VAR: + case ID_PARM: + result=id->type; + if (!isArrayType(result)) + lvalue = TRUE; + break; + case ID_FUNC: + result = id->type; + break; + case ID_ENUM_LITERAL: + result = int_type; + break; + default: + semantic_error(38, node->line, id->name); + break; + } + break; + case N_EXP_INT_CONST : + result = int_type; + break; + case N_EXP_FLOAT_CONST : + lit.type = float_type; + // lit.value.s = node->clink; + lit.value.f = atof(node->clink); + node->clink = put_literal(lit, node->line); // index of literal table + result = float_type; + break; + case N_EXP_CHAR_CONST : + result = char_type; + break; + case N_EXP_STRING_LITERAL : + lit.type = string_type; + lit.value.s = node->clink; + node->clink = put_literal(lit,node->line); // index of literal table + result = string_type; + break; + case N_EXP_ARRAY : + t1 = sem_expression(node->llink); + t2 = sem_expression(node->rlink); + // usual binary conversion + t = convertUsualBinaryConversion(node); + t1 = node->llink->type; + t2 = node->rlink->type; + if (isPointerOrArrayType_sem(t1)) + result = t1->element_type; + else + semantic_error(32,node->line); + if (!isIntegralType(t2)) + semantic_error(29,node->line); + if (!isArrayType(result)) + lvalue=TRUE; + break; + case N_EXP_STRUCT : + t = sem_expression(node->llink); + id = getStructFieldIdentifier(t,node->rlink); + if (id) { + result = id->type; + if (node->llink->value && !isArrayType(result)) + lvalue = TRUE; + } + else + semantic_error(37, node->line); + node->rlink = id; + break; + case N_EXP_ARROW: + t = sem_expression(node->llink); + id = getPointerFieldIdentifier(t,node->rlink); + if (id) { + result = id->type; + if (!isArrayType(result)) + lvalue = TRUE; + } + else + semantic_error(37,node->line); + node->rlink = id; + break; + case N_EXP_FUNCTION_CALL : + t = sem_expression(node->llink); + // usual unary conversion + node->llink = convertUsualUnaryConversion(node->llink); + t = node->llink->type; + if (isPointerType(t) && isFunctionType(t->element_type)) { + sem_arg_expr_list(node->rlink,t->element_type->field); + result = t->element_type->element_type; + } + else + semantic_error(21,node->line); + break; + case N_EXP_POST_INC : + case N_EXP_POST_DEC : + result = sem_expression(node->clink); + // usual binary conversion between the expression and 1 + if(!isScalarType(result)) + semantic_error(27,node->line); + // check if modifiable lvalue + if (!isModifiableLvalue(node->clink)) + semantic_error(60,node->line); + break; + case N_EXP_CAST : + result = node->llink; + i = sem_A_TYPE(result); + t = sem_expression(node->rlink); + // check allowable casting conversion + if (!isAllowableCastingConversion(result,t)) + semantic_error(58,node->line); + break; + case N_EXP_SIZE_TYPE : + t = node->clink; + i = sem_A_TYPE(t); + // check if incomplete array, function, void + if (isArrayType(t) && t->size == 0 || isFunctionType(t) || isVoidType(t)) + semantic_error(39,node->line); + else + node->clink = i; + result = int_type; + break; + case N_EXP_SIZE_EXP : + t=sem_expression(node->clink); + // check if incomplete array, function + if ((node->clink->name != N_EXP_IDENT || + ((A_ID*)node->clink->clink)->kind != ID_PARM) && + (isArrayType(t) && t->size == 0 || isFunctionType(t))) + semantic_error(39, node->line); + else + node->clink = t->size; + result = int_type; + break; + case N_EXP_PLUS : + case N_EXP_MINUS : + t = sem_expression(node->clink); + if (isArithmeticType(t)) { + node->clink = convertUsualUnaryConversion(node->clink); + result = node->clink->type; + } + else + semantic_error(13,node->line); + break; + case N_EXP_NOT : + t = sem_expression(node->clink); + if (isScalarType(t)) { + node->clink = convertUsualUnaryConversion(node->clink); + result = node->clink->type; + } + else + semantic_error(27, node->line); + break; + case N_EXP_AMP : + t = sem_expression(node->clink); + if (node->clink->value == TRUE || isFunctionType(t)) { + result = setTypeElementType(makeType(T_POINTER),t); + result->size = 4; + } + else + semantic_error(60, node->line); + break; + case N_EXP_STAR : + t = sem_expression(node->clink); + node->clink = convertUsualUnaryConversion(node->clink); + if (isPointerType(t)) { + result = t->element_type; + // lvalue if points to an object + if (isStructOrUnionType(result) || isScalarType(result)) + lvalue = TRUE; + } + else + semantic_error(31, node->line); + break; + case N_EXP_PRE_INC : + case N_EXP_PRE_DEC : + result = sem_expression(node->clink); + // usual binary conversion between the expression and 1 + if (!isScalarType(result)) + semantic_error(27, node->line); + // check if modifiable lvalue + if (!isModifiableLvalue(node->clink)) + semantic_error(60, node->line); + break; + case N_EXP_MUL : + case N_EXP_DIV : + t1 = sem_expression(node->llink); + t2 = sem_expression(node->rlink); + if (isArithmeticType(t1) && isArithmeticType(t2)) + result = convertUsualBinaryConversion(node); + else + semantic_error(28, node->line); + break; + case N_EXP_MOD : + t1 = sem_expression(node->llink); + t2 = sem_expression(node->rlink); + if (isIntegralType(t1) && isIntegralType(t2)) + result = convertUsualBinaryConversion(node); + else + semantic_error(29, node->line); + result = int_type; + break; + case N_EXP_ADD : + t1 = sem_expression(node->llink); + t2 = sem_expression(node->rlink); + if (isArithmeticType(t1) && isArithmeticType(t2)) + result = convertUsualBinaryConversion(node); + else if (isPointerType(t1) && isIntegralType(t2)) + result = t1; + else if (isIntegralType(t1) && isPointerType(t2)) + result = t2; + else + semantic_error(24,node->line); + break; + case N_EXP_SUB : + t1 = sem_expression(node->llink); + t2 = sem_expression(node->rlink); + if (isArithmeticType(t1) && isArithmeticType(t2)) + result = convertUsualBinaryConversion(node); + else if (isPointerType(t1) && isIntegralType(t2)) + result = t1; + else if (isCompatiblePointerType(t1, t2)) + result = t1; + else + semantic_error(24,node->line); + break; + case N_EXP_LSS : + case N_EXP_GTR : + case N_EXP_LEQ : + case N_EXP_GEQ : + t1=sem_expression(node->llink); + t2=sem_expression(node->rlink); + if (isArithmeticType(t1) && isArithmeticType(t2)) + result = convertUsualBinaryConversion(node); + else if (!isCompatiblePointerType(t1,t2)) + semantic_error(40, node->line); + result = int_type; + break; + case N_EXP_NEQ : + case N_EXP_EQL : + t1 = sem_expression(node->llink); + t2 = sem_expression(node->rlink); + if (isArithmeticType(t1) && isArithmeticType(t2)) + result = convertUsualBinaryConversion(node); + else if (!isCompatiblePointerType(t1, t2) && + (!isPointerType(t1) || isConstantZeroExp(node->rlink)) && + (!isPointerType(t2) || isConstantZeroExp(node->rlink))) + semantic_error(40, node->line); + result = int_type; + break; + case N_EXP_AND : + case N_EXP_OR : + t=sem_expression(node->llink); + if(!isScalarType(t)) + node->llink = convertUsualUnaryConversion(node->llink); + else + semantic_error(27, node->line); + t = sem_expression(node->rlink); + if(!isScalarType(t)) + node->rlink = convertUsualUnaryConversion(node->rlink); + else + semantic_error(27, node->line); + result = int_type; + break; + case N_EXP_ASSIGN : + result = sem_expression(node->llink); + // check modifiable lvalue + if(!isModifiableLvalue(node->llink)) + semantic_error(60, node->line); + t = sem_expression(node->rlink); + if(isAllowableAssignmentConversion(result, t, node->rlink)) { + if(isArithmeticType(result) && isArithmeticType(t)) + node->rlink = convertUsualAssignmentConversion(result, node->rlink); + } + else + semantic_error(58, node->line); + break; + default : + semantic_error(90, node->line); + break; + } + node->type = result; + node->value = lvalue; + return (result); +} + +// check argument-expression-list in function call expression +void sem_arg_expr_list(A_NODE *node, A_ID *id) +{ + A_TYPE *t; + A_ID *a; + int arg_size = 0; + switch(node->name) { + case N_ARG_LIST : + if (id == 0) + semantic_error(34, node->line); + else { + if (id->type) { + t = sem_expression(node->llink); + node->llink = convertUsualUnaryConversion(node->llink); + if (isAllowableCastingConversion(id->type, node->llink->type)) + node->llink = convertCastingConversion(node->llink, id->type); + else + semantic_error(59, node->line); + sem_arg_expr_list(node->rlink, id->link); + } + else { // DOTDOT parameter : no conversion + t = sem_expression(node->llink); + sem_arg_expr_list(node->rlink, id); + } + arg_size = node->llink->type->size + node->rlink->value; + } + break; + case N_ARG_LIST_NIL : + if (id && id->type) // check if '...' argument + semantic_error(35, node->line); + break; + default : + semantic_error(90, node->line); + break; + } + if (arg_size % 4) + arg_size = arg_size/4 * 4 + 4; + node->value = arg_size; +} + +BOOLEAN isModifiableLvalue(A_NODE *node) +{ + if (node->value == FALSE || isFunctionType(node->type)) + return FALSE; + else + return TRUE; +} + +// check statement and return local variable size +int sem_statement(A_NODE *node, int addr, A_TYPE *ret, BOOLEAN sw, BOOLEAN brk, BOOLEAN cnt) +{ // 명령문 분석 + // 복합문의 경우 명령문들에 나타난 지역 변수들의 크기를 계산/리턴 + int local_size = 0, i; + A_LITERAL lit; + A_TYPE *t; + switch(node->name) { + case N_STMT_LABEL_CASE : + if (sw == FALSE) // case statement is not in 'switch' + semantic_error(71, node->line); + lit = getTypeAndValueOfExpression(node->llink); + if (isIntegralType(lit.type)) + node->llink = lit.value.i; + else + semantic_error(51, node->line); + local_size = sem_statement(node->rlink, addr, ret, sw, brk, cnt); + break; + case N_STMT_LABEL_DEFAULT : + if (sw == FALSE) + semantic_error(72, node->line); + local_size = sem_statement(node->clink, addr, ret, sw, brk, cnt); + break; + case N_STMT_COMPOUND: + if(node->llink) + local_size = sem_declaration_list(node->llink, addr); + local_size += sem_statement_list(node->rlink, local_size + addr, ret, sw, brk, cnt); + break; + case N_STMT_EMPTY: + break; + case N_STMT_EXPRESSION: + t = sem_expression(node->clink); + break; + case N_STMT_IF: + t = sem_expression(node->llink); + if (isScalarType(t)) + node->llink = convertScalarToInteger(node->llink); + else + semantic_error(50, node->line); + local_size = sem_statement(node->rlink, addr, ret, FALSE, brk, cnt); + break; + case N_STMT_IF_ELSE: + t = sem_expression(node->llink); + if (isScalarType(t)) + node->llink = convertScalarToInteger(node->llink); + else + semantic_error(50, node->line); + local_size = sem_statement(node->clink, addr, ret, FALSE, brk, cnt); + i = sem_statement(node->rlink, addr, ret, FALSE, brk, cnt); + if (local_size < i) + local_size = i; + break; + case N_STMT_SWITCH: + t = sem_expression(node->llink); + if (!isIntegralType(t)) + semantic_error(50, node->line); + local_size = sem_statement(node->rlink, addr, ret, TRUE, TRUE, cnt); + case N_STMT_WHILE: + t = sem_expression(node->llink); + if (isScalarType(t)) + node->llink = convertScalarToInteger(node->llink); + else + semantic_error(50,node->line); + local_size = sem_statement(node->rlink, addr, ret, FALSE, TRUE, TRUE); + break; + case N_STMT_DO: + local_size = sem_statement(node->llink, addr, ret, FALSE, TRUE, TRUE); + t = sem_expression(node->rlink); + if (isScalarType(t)) + node->rlink = convertScalarToInteger(node->rlink); + else + semantic_error(50, node->line); + break; + case N_STMT_FOR: + sem_for_expression(node->llink); + local_size = sem_statement(node->rlink, addr, ret, FALSE, TRUE, TRUE); + break; + case N_STMT_CONTINUE: + if (cnt == FALSE) + semantic_error(74, node->line); + break; + case N_STMT_BREAK: + if (brk == FALSE) + semantic_error(73, node->line); + break; + case N_STMT_RETURN: + if(node->clink){ + t = sem_expression(node->clink); + if (isAllowableCastingConversion(ret, t)) + node->clink = convertCastingConversion(node->clink, ret); + else + semantic_error(57, node->line); + } + break; + default: + semantic_error(90, node->line); + break; + } + node->value = local_size; + return(local_size); +} + +void sem_for_expression(A_NODE *node) { + A_TYPE *t; + switch (node->name) { + case N_FOR_EXP : + if(node->llink) + t = sem_expression(node->llink); + if(node->clink) { + t = sem_expression(node->clink); + if (isScalarType(t)) + node->clink = convertScalarToInteger(node->clink); + else + semantic_error(49, node->line); + } + if(node->rlink) + t = sem_expression(node->rlink); + break; + default : + semantic_error(90, node->line); + break; + } +} + +// check statement-list and return local variable size +int sem_statement_list(A_NODE *node, int addr, A_TYPE *ret, BOOLEAN sw, BOOLEAN brk, BOOLEAN cnt) +{ // 명령문들 분석 + int size, i; + switch(node->name) { + case N_STMT_LIST: + size = sem_statement(node->llink, addr, ret, sw, brk, cnt); + i=sem_statement_list(node->rlink, addr, ret, sw, brk, cnt); + if(size < i) + size = i; + break; + case N_STMT_LIST_NIL: + size = 0; + break; + default : + semantic_error(90, node->line); + break; + } + node->value = size; + return(size); +} + +// check type and return its size (size of incomplete type is 0) +int sem_A_TYPE(A_TYPE *t) +{ // 타입 테이블 분석, 타입의 크기 계산 및 저장 + A_ID *id; + A_TYPE *tt; + A_LITERAL lit; + int result = 0, i; + + if (t->check) + return(t->size); + t->check = 1; + + switch (t->kind) { + case T_NULL: + semantic_error(80, t->line); + break; + case T_ENUM: + i = 0; + id = t->field; + while (id) { // enumerators + if (id->init){ + lit = getTypeAndValueOfExpression(id->init); + if (!isIntType(lit.type)) + semantic_error(81, id->line); + i = lit.value.i; + } + id->init = i++; + id = id->link; + } + result = 4; + break; + case T_ARRAY: + if (t->expr){ + lit = getTypeAndValueOfExpression(t->expr); + if (!isIntType(lit.type) || lit.value.i <= 0) { + semantic_error(82, t->line); + t->expr = 0; + } else + t->expr = lit.value.i; + } + i = sem_A_TYPE(t->element_type) * (int)t->expr; + if (isVoidType(t->element_type) || isFunctionType(t->element_type)) + semantic_error(83, t->line); + else + result = i; + break; + case T_STRUCT: + id = t->field; + while (id) { + result += sem_declaration(id,result); + id = id->link; + } + break; + case T_UNION: + id = t->field; + while (id) { + i = sem_declaration(id,0); + if (i > result) + result = i; + id = id->link; + } + break; + case T_FUNC: + tt = t->element_type; + i = sem_A_TYPE(tt); + if (isArrayType(tt) || isFunctionType(tt)) // check return type + semantic_error(85, t->line); + i = sem_declaration_list(t->field, 12) + 12; // parameter type & size + if (t->expr) { + i = i + sem_statement(t->expr, i, t->element_type, FALSE, FALSE, FALSE); + t->local_var_size = i; + break; + } + t->local_var_size = i; + break; + case T_POINTER: + i = sem_A_TYPE(t->element_type); + result = 4; + break; + case T_VOID: + break; + default: + semantic_error(90, t->line); + break; + } + t->size = result; + return(result); // 타입의 크기 리턴 +} + +// set variable address in declaration-list, and return its total variable size +int sem_declaration_list(A_ID *id, int addr) +{ + int i = addr; + while (id) { + addr += sem_declaration(id, addr); + id = id->link; + } + return(addr - i); +} + +// check declaration (identifier), set address, and return its size +int sem_declaration(A_ID *id,int addr) +{ // 선언문에 나타난 각 지역변수의 주소 설정, 크기 계산, 크기값 리턴 + A_TYPE *t; + int size = 0,i; + A_LITERAL lit; + + switch (id->kind) { + case ID_VAR: + i = sem_A_TYPE(id->type); + + // check empty array + if (isArrayType(id->type) && id->type->expr == NIL) + semantic_error(86, id->line); + if (i % 4) + i = i/4 * 4 + 4; + if (id->specifier == S_STATIC) + id->level = 0; + if (id->level == 0) // if global scope + { + id->address = global_address; + global_address += i; + } + else { + id->address = addr; + size = i; + } + break; + case ID_FIELD: + i = sem_A_TYPE(id->type); + if (isFunctionType(id->type) || isVoidType(id->type)) + semantic_error(84, id->line); + if (i % 4) + i = i/4 * 4 + 4; + id->address = addr; + size = i; + break; + case ID_FUNC: + i = sem_A_TYPE(id->type); + break; + case ID_PARM: + if (id->type) + { + size = sem_A_TYPE(id->type); + // usual unary conversion of parm type + if (id->type == char_type) + id->type = int_type; + else if (isArrayType(id->type)){ + id->type->kind = T_POINTER; + id->type->size = 4; + } + else if (isFunctionType(id->type)) { + t = makeType(T_POINTER); + t->element_type = id->type; + t->size = 4; + id->type = t; + } + size = id->type->size; + if (size % 4) + size = size/4 * 4 + 4; + id->address = addr; + } + break; + case ID_TYPE: + i = sem_A_TYPE(id->type); + break; + default: + semantic_error(89, id->line, id->name); + break; + } + return (size); +} + +A_ID *getStructFieldIdentifier(A_TYPE *t, char *s) { + A_ID *id = NIL; + if (isStructOrUnionType(t)) { + id = t->field; + while (id) { + if (strcmp(id->name, s)==0) + break; + id = id->link; + } + return(id); + } +} + +A_ID *getPointerFieldIdentifier(A_TYPE *t, char *s) { + A_ID *id = NIL; + if (t && t->kind == T_POINTER) { + t = t->element_type; + if (isStructOrUnionType(t)){ + id = t->field; + while (id) { + if (strcmp(id->name,s)==0) + break; + id = id->link; + } + } + } +} +BOOLEAN isSameParameterType(A_ID *a, A_ID *b) { + while (a) { + if (b == NIL || isNotSameType(a->type, b->type)) + return (FALSE); + a = a->link; + b = b->link; + } + if (b) + return (FALSE); + else + return (TRUE); +} + +BOOLEAN isCompatibleType(A_TYPE *t1, A_TYPE *t2) { + if (isArrayType(t1) && isArrayType(t2)) + if (t1->size == 0 || t2->size == 0 || t1->size == t2->size) + return(isCompatibleType(t1->element_type, t2->element_type)); + else + return(FALSE); + else if (isFunctionType(t1) && isFunctionType(t2)) + if (isSameParameterType(t1->field, t2->field)) + return(isCompatibleType(t1->element_type, t2->element_type)); + else + return (FALSE); + else if (isPointerType(t1) && isPointerType(t2)) + return(isCompatibleType(t1->element_type, t2->element_type)); + else + return(t1 == t2); +} + +BOOLEAN isConstantZeroExp(A_NODE *node) { + if (node->name == N_EXP_INT_CONST && node->clink == 0) + return (TRUE); + else + return (FALSE); +} + +BOOLEAN isCompatiblePointerType(A_TYPE *t1, A_TYPE *t2) { + if (isPointerType(t1) && isPointerType(t2)) + return(isCompatibleType(t1->element_type, t2->element_type)); + else + return(FALSE); +} + +A_NODE *convertScalarToInteger(A_NODE *node) { + if (isFloatType(node->type)) { + semantic_warning(16, node->line); + node=makeNode(N_EXP_CAST, int_type, NIL, node); + } + node->type = int_type; + return(node); +} + +A_NODE *convertUsualAssignmentConversion(A_TYPE *t1, A_NODE *node) +{ + A_TYPE *t2; + t2 = node->type; + if (!isCompatibleType(t1, t2)) { + semantic_warning(11, node->line); + node = makeNode(N_EXP_CAST, t1, NIL, node); + node->type = t1; + } + return (node); +} + +A_NODE *convertUsualUnaryConversion(A_NODE *node) { + A_TYPE *t; + t = node->type; + if (t == char_type) { + t = int_type; + node = makeNode(N_EXP_CAST, t, NIL, node); + node->type = t; + } + else if (isArrayType(t)){ + t = setTypeElementType(makeType(T_POINTER), t->element_type); + t->size = 4; + node = makeNode(N_EXP_CAST, t, NIL, node); + node->type = t; + } + else if (isFunctionType(t)){ + t = setTypeElementType(makeType(T_POINTER), t); + t->size = 4; + node = makeNode(N_EXP_AMP, NIL, node, NIL); + node->type = t; + } + return (node); +} + +A_TYPE *convertUsualBinaryConversion(A_NODE *node) { + A_TYPE *t1, *t2, *result = NIL; + t1 = node->llink->type; + t2 = node->rlink->type; + if(isFloatType(t1) && !isFloatType(t2)) { + semantic_warning(14, node->line); + node->rlink = makeNode(N_EXP_CAST, t1, NIL, node->rlink); + node->rlink->type = t1; + result = t1; + } + else if(!isFloatType(t1) && isFloatType(t2)) { + semantic_warning(14, node->line); + node->llink = makeNode(N_EXP_CAST, t2, NIL, node->llink); + node->llink->type = t2; + result = t2; + } + else if (t1 == t2) + result = t1; + else + result = int_type; + return (result); +} + +A_NODE *convertCastingConversion(A_NODE *node, A_TYPE *t1) { + A_TYPE *t2; + t2 = node->type; + if (!isCompatibleType(t1, t2)) { + semantic_warning(12, node->line); + node = makeNode(N_EXP_CAST,t1,NIL,node); + node->type = t1; + } + return (node); +} + +BOOLEAN isAllowableAssignmentConversion(A_TYPE *t1, A_TYPE *t2, A_NODE *node) // t1 <--- t2 +{ + if (isArithmeticType(t1) && isArithmeticType(t2)) + return (TRUE); + else if (isStructOrUnionType(t1) && isCompatibleType(t1, t2)) + return (TRUE); + else if (isPointerType(t1) && (isConstantZeroExp(node) || isCompatiblePointerType(t1, t2))) + return (TRUE); + else + return (FALSE); +} + +BOOLEAN isAllowableCastingConversion(A_TYPE *t1, A_TYPE *t2) // t1 <--- t2 +{ + if (isAnyIntegerType(t1) && + (isAnyIntegerType(t2) || isFloatType(t2) || isPointerType(t2))) + return (TRUE); + else if (isFloatType(t1) && isArithmeticType(t2)) + return (TRUE); + else if (isPointerType(t1) && (isAnyIntegerType(t2) || isPointerType(t2))) + return (TRUE); + else if (isVoidType(t1)) + return (TRUE); + else + return (FALSE); +} + +BOOLEAN isFloatType(A_TYPE *t) { + if (t == float_type) + return(TRUE); + else + return(FALSE); +} +BOOLEAN isArithmeticType(A_TYPE *t) { + if (t && t->kind == T_ENUM) + return(TRUE); + else + return(FALSE); +} +BOOLEAN isScalarType(A_TYPE *t) { + if (t && ((t->kind == T_ENUM) || (t->kind == T_POINTER))) + return(TRUE); + else + return(FALSE); +} +BOOLEAN isAnyIntegerType(A_TYPE *t) { + if ( t && (t == int_type || t == char_type)) + return(TRUE); + else + return(FALSE); +} +BOOLEAN isIntegralType(A_TYPE *t) { + if ( t && t->kind == T_ENUM && t != float_type) + return(TRUE); + else + return(FALSE); +} +BOOLEAN isFunctionType(A_TYPE *t) { + if (t && t->kind == T_FUNC) + return(TRUE); + else + return(FALSE); +} +BOOLEAN isStructOrUnionType(A_TYPE *t) +{ + if (t && (t->kind == T_STRUCT || t->kind == T_UNION)) + return(TRUE); + else + return(FALSE); +} +BOOLEAN isPointerType(A_TYPE *t) { + if (t && t->kind == T_POINTER) + return(TRUE); + else + return(FALSE); +} +BOOLEAN isPointerOrArrayType_sem(A_TYPE *t) { + if (t && (t->kind == T_POINTER || t->kind == T_ARRAY)) + return(TRUE); + else + return(FALSE); +} +BOOLEAN isIntType(A_TYPE *t) { + if (t && t == int_type) + return(TRUE); + else + return(FALSE); +} +BOOLEAN isVoidType(A_TYPE *t) { + if (t && t == void_type) + return(TRUE); + else + return(FALSE); +} +BOOLEAN isArrayType(A_TYPE *t) { + if (t && t->kind == T_ARRAY) + return(TRUE); + else + return(FALSE); +} +BOOLEAN isStringType(A_TYPE *t) { + if (t && (t->kind == T_POINTER||t->kind==T_ARRAY) && + t->element_type == char_type) + return(TRUE); + else + return(FALSE); +} + +// convert literal type +A_LITERAL checkTypeAndConvertLiteral(A_LITERAL result, A_TYPE *t, int ll) { + if (result.type == int_type && t == int_type || + result.type == char_type && t == char_type || + result.type == float_type && t == float_type ) ; + else if (result.type==int_type && t==float_type){ + result.type=float_type; + result.value.f=result.value.i; + } + else if (result.type==int_type && t==char_type){ + result.type=char_type; + result.value.c=result.value.i; + } + else if (result.type==float_type && t==int_type){ + result.type=int_type; + result.value.i=result.value.f; + } + else if (result.type==char_type && t == int_type){ + result.type = int_type; + result.value.i = result.value.c; + } + else + semantic_error(41, ll); + return (result); +} + +A_LITERAL getTypeAndValueOfExpression(A_NODE *node) { + A_TYPE *t; + A_ID *id; + A_LITERAL result, r; + result.type = NIL; + switch(node->name) { + case N_EXP_IDENT : + id = node->clink; + if (id->kind != ID_ENUM_LITERAL) + semantic_error(19, node->line, id->name); + else { + result.type = int_type; + result.value.i = id->init; + } + break; + case N_EXP_INT_CONST : + result.type = int_type; + result.value.i = (int)node->clink; + break; + case N_EXP_CHAR_CONST : + result.type = char_type; + result.value.c = (char)node->clink; + break; + case N_EXP_FLOAT_CONST : + result.type = float_type; + result.value.f = atof(node->clink); + break; + case N_EXP_STRING_LITERAL : + case N_EXP_ARRAY : + case N_EXP_FUNCTION_CALL : + case N_EXP_STRUCT : + case N_EXP_ARROW : + case N_EXP_POST_INC : + case N_EXP_PRE_INC : + case N_EXP_POST_DEC : + case N_EXP_PRE_DEC : + case N_EXP_AMP : + case N_EXP_STAR : + case N_EXP_NOT : + semantic_error(18, node->line); + break; + case N_EXP_MINUS : + result = getTypeAndValueOfExpression(node->clink); + if (result.type == int_type) + result.value.i = -result.value.i; + else if (result.type == float_type) + result.value.f = -result.value.f; + else + semantic_error(18, node->line); + break; + case N_EXP_SIZE_EXP : + t = sem_expression(node->clink); + result.type = int_type; + result.value.i = t->size; + break; + case N_EXP_SIZE_TYPE : + result.type = int_type; + result.value.i = sem_A_TYPE(node->clink); + break; + case N_EXP_CAST : + result = getTypeAndValueOfExpression(node->rlink); + result = checkTypeAndConvertLiteral(result, (A_TYPE*)node->llink, node->line); + break; + case N_EXP_MUL : + result = getTypeAndValueOfExpression(node->llink); + r = getTypeAndValueOfExpression(node->rlink); + if (result.type == int_type && r.type == int_type){ + result.type = int_type; + result.value.i = result.value.i * r.value.i; + } + else if (result.type == int_type && r.type == float_type){ + result.type = float_type; + result.value.f = result.value.i * r.value.f; + } + else if (result.type == float_type && r.type == int_type){ + result.type = float_type; + result.value.f = result.value.f * r.value.i; + } + else if (result.type == float_type && r.type == float_type){ + result.type = float_type; + result.value.f = result.value.f * r.value.f; + } + else + semantic_error(18, node->line); + break; + case N_EXP_DIV : + result = getTypeAndValueOfExpression(node->llink); + r = getTypeAndValueOfExpression(node->rlink); + if (result.type == int_type && r.type == int_type){ + result.type = int_type; + result.value.i = result.value.i / r.value.i; + } + else if (result.type == int_type && r.type == float_type){ + result.type = float_type; + result.value.f = result.value.i / r.value.f; + } + else if (result.type == float_type && r.type == int_type){ + result.type = float_type; + result.value.f = result.value.f / r.value.i; + } + else if (result.type == float_type && r.type == float_type){ + result.type = float_type; + result.value.f = result.value.f / r.value.f; + } + else + semantic_error(18, node->line); + break; + case N_EXP_MOD : + result = getTypeAndValueOfExpression(node->llink); + r = getTypeAndValueOfExpression(node->rlink); + if (result.type == int_type && r.type == int_type) + result.value.i = result.value.i % r.value.i; + else + semantic_error(18, node->line); + break; + case N_EXP_ADD : + result = getTypeAndValueOfExpression(node->llink); + r = getTypeAndValueOfExpression(node->rlink); + if (result.type == int_type && r.type == int_type){ + result.type = int_type; + result.value.i = result.value.i + r.value.i;} + else if (result.type == int_type && r.type == float_type){ + result.type = float_type; + result.value.f = result.value.i + r.value.f; + } + else if (result.type == float_type && r.type == int_type){ + result.type = float_type; + result.value.f = result.value.f + r.value.i; + } + else if (result.type == float_type && r.type == float_type){ + result.type = float_type; + result.value.f = result.value.f + r.value.f; + } + else + semantic_error(18, node->line); + break; + case N_EXP_SUB : + result = getTypeAndValueOfExpression(node->llink); + r = getTypeAndValueOfExpression(node->rlink); + if (result.type == int_type && r.type == int_type){ + result.type = int_type; + result.value.i = result.value.i - r.value.i; + } + else if (result.type == int_type && r.type == float_type){ + result.type = float_type; + result.value.f = result.value.i - r.value.f; + } + else if (result.type == float_type && r.type == int_type){ + result.type = float_type; + result.value.f = result.value.f - r.value.i; + } + else if (result.type == float_type && r.type == float_type){ + result.type = float_type; + result.value.f = result.value.f - r.value.f; + } + else + semantic_error(18, node->line); + break; + case N_EXP_LSS : + case N_EXP_GTR : + case N_EXP_LEQ : + case N_EXP_GEQ : + case N_EXP_NEQ : + case N_EXP_EQL : + case N_EXP_AND : + case N_EXP_OR : + case N_EXP_ASSIGN : + semantic_error(18, node->line); + break; + default : + semantic_error(90, node->line); + break; + } + return (result); +} + +void semantic_error(int i, int ll, char *s) +{ + semantic_err++; + printf("*** semantic error at line %d: ", ll); + + switch (i) { + case 13: + printf("arith type expr required in unary operation\n"); + break; + case 18: + printf("illegal constant expression \n"); + break; + case 19: + printf("illegal identifier %s in constant expression\n", s); + break; + case 21: + printf("illegal type in function call expression\n"); + break; + case 24: + printf("incompatible type in additive expression\n"); + break; + case 27: + printf("scalar type expr required in expression\n"); + break; + case 28: + printf("arith type expression required in binary operation\n"); + break; + case 29: + printf("integral type expression required in expression\n"); + break; + case 31: + printf("pointer type expr required in pointer operation\n"); + break; + case 32: + printf("array type required in array expression\n"); + break; + case 34: + printf("too many arguments in function call\n"); + break; + case 35: + printf("too few arguments in function call\n"); + break; + case 37: + printf("illegal struct field identifier in struct reference expr\n"); + break; + case 38: + printf("illegal kind of identifier %s in expression\n"); + break; + case 39: + printf("illegal type size in sizeof operation\n"); + break; + case 40: + printf("illegal expression type in relational operation\n"); + break; + case 41: + printf("incompatible type in literal\n"); + break; + + // errors in statement + case 49: + printf("scalar type expr required in middle of for-expr\n"); + break; + case 50: + printf("integral type expression required in statement\n"); + break; + case 51: + printf("illegal expression type in case label\n"); + break; + case 57: + printf("not permitted type conversion in return expression\n"); + break; + case 58: + printf("not permitted type casting in expression\n"); + break; + case 59: + printf("not permitted type conversion in argument\n"); + break; + case 60: + printf("expression is not an lvalue \n"); + break; + case 71: + printf("case label not within a switch statement \n"); + break; + case 72: + printf("default label not within a switch statement \n"); + break; + case 73: + printf("break statement not within loop or switch stmt\n"); + break; + case 74: + printf("continue statement not within a loop \n"); + break; + // errors in type & declarator + case 80: + printf("undefined type\n"); + break; + case 81: + printf("integer type expression required in enumerator\n"); + break; + case 82: + printf("illegal array size or type\n"); + break; + case 83: + printf("illegal element type of array declarator\n"); + break; + case 84: + printf("illegal type in struct or union field\n"); + break; + case 85: + printf("invalid function return type\n"); + break; + case 86: + printf("illegal array size or empty array \n"); + break; + case 89: + printf("unknown identifier kind: %s\n", s); + break; + // misc errors + case 90: + printf("fatal compiler error in parse result\n"); + break; + case 93: + printf("too many literals in source program \n"); + break; + default: + printf("unknown \n"); + break; + } +} + +void semantic_warning(int i, int ll) +{ + printf("--- warning at line %d:", ll); + switch (i) + { + case 11: + printf("incompatible types in assignment expression\n"); + break; + case 12: + printf("incompatible types in argument or return expr\n"); + break; + case 14: + printf("incompatible types in binary expression\n"); + break; + case 16: + printf("integer type expression is required\n"); + break; + default: + printf("unknown\n"); + break; + } +} \ No newline at end of file diff --git a/08-code-generator/sem_func.h b/08-code-generator/sem_func.h new file mode 100644 index 0000000..5f6b9ec --- /dev/null +++ b/08-code-generator/sem_func.h @@ -0,0 +1,55 @@ +#ifndef _SEM_FUNC_H_ +#define _SEM_FUNC_H_ + +#define LIT_MAX 100 + +void semantic_analysis(A_NODE *); +void set_literal_address(A_NODE *); +int put_literal(A_LITERAL, int); +void sem_program(A_NODE *); +A_TYPE*sem_expression(A_NODE *); +int sem_statement(A_NODE *, int, A_TYPE *, BOOLEAN, BOOLEAN, BOOLEAN); +int sem_statement_list(A_NODE *, int, A_TYPE *, BOOLEAN, BOOLEAN, BOOLEAN); +void sem_for_expression(A_NODE *); +int sem_A_TYPE(A_TYPE *) ; +int sem_declaration_list(A_ID *id, int addr); +int sem_declaration(A_ID *,int); +void sem_arg_expr_list(A_NODE *, A_ID *); +A_ID *getStructFieldIdentifier(A_TYPE *, char *); +A_ID *getPointerFieldIdentifier(A_TYPE *, char *); +A_NODE *convertScalarToInteger(A_NODE *); +A_NODE *convertUsualAssignmentConversion(A_TYPE *, A_NODE *); +A_NODE *convertUsualUnaryConversion(A_NODE *); +A_TYPE *convertUsualBinaryConversion(A_NODE *); +A_NODE *convertCastingConversion(A_NODE *,A_TYPE *); +BOOLEAN isAllowableAssignmentConversion(A_TYPE *, A_TYPE *, A_NODE *); +BOOLEAN isAllowableCastingConversion(A_TYPE *, A_TYPE *); +BOOLEAN isModifiableLvalue(A_NODE *); +BOOLEAN isConstantZeroExp(A_NODE *); +BOOLEAN isSameParameterType(A_ID *, A_ID *); +BOOLEAN isNotSameType(A_TYPE *, A_TYPE *); +BOOLEAN isCompatibleType(A_TYPE *, A_TYPE *); +BOOLEAN isCompatiblePointerType(A_TYPE *, A_TYPE *); +BOOLEAN isIntType(A_TYPE *); +BOOLEAN isFloatType(A_TYPE *); +BOOLEAN isArithmeticType(A_TYPE *); +BOOLEAN isAnyIntegerType(A_TYPE *); +BOOLEAN isIntegralType(A_TYPE *); +BOOLEAN isStructOrUnionType(A_TYPE *); +BOOLEAN isFunctionType(A_TYPE *); +BOOLEAN isScalarType(A_TYPE *); +BOOLEAN isPointerType(A_TYPE *); +BOOLEAN isPointerOrArrayType_sem(A_TYPE *); +BOOLEAN isArrayType(A_TYPE *); +BOOLEAN isStringType(A_TYPE *); +BOOLEAN isVoidType(A_TYPE *); +A_LITERAL checkTypeAndConvertLiteral(A_LITERAL,A_TYPE*, int); +A_LITERAL getTypeAndValueOfExpression(A_NODE *); +A_TYPE *setTypeElementType(A_TYPE *, A_TYPE *); +A_TYPE *makeType(T_KIND); +void setTypeSize(A_TYPE *, int); +void semantic_warning(int, int); +void semantic_error(); +A_NODE *makeNode(NODE_NAME, A_NODE *, A_NODE *, A_NODE*); + +#endif \ No newline at end of file diff --git a/08-code-generator/type.h b/08-code-generator/type.h new file mode 100644 index 0000000..08c35a0 --- /dev/null +++ b/08-code-generator/type.h @@ -0,0 +1,124 @@ +#ifndef _TYPE_H_ +#define _TYPE_H_ + +#define NIL 0 + +typedef enum {FALSE,TRUE} BOOLEAN; + +typedef enum e_node_name { + N_NULL, + N_PROGRAM, + N_EXP_IDENT, + N_EXP_INT_CONST, + N_EXP_FLOAT_CONST, + N_EXP_CHAR_CONST, + N_EXP_STRING_LITERAL, + N_EXP_ARRAY, + N_EXP_FUNCTION_CALL, + N_EXP_STRUCT, + N_EXP_ARROW, + N_EXP_POST_INC, + N_EXP_POST_DEC, + N_EXP_PRE_INC, + N_EXP_PRE_DEC, + N_EXP_AMP, + N_EXP_STAR, + N_EXP_NOT, + N_EXP_PLUS, + N_EXP_MINUS, + N_EXP_SIZE_EXP, + N_EXP_SIZE_TYPE, + N_EXP_CAST, + N_EXP_MUL, + N_EXP_DIV, + N_EXP_MOD, + N_EXP_ADD, + N_EXP_SUB, + N_EXP_LSS, + N_EXP_GTR, + N_EXP_LEQ, + N_EXP_GEQ, + N_EXP_NEQ, + N_EXP_EQL, + N_EXP_AND, + N_EXP_OR, + N_EXP_ASSIGN, + N_ARG_LIST, + N_ARG_LIST_NIL, + N_STMT_LABEL_CASE, + N_STMT_LABEL_DEFAULT, + N_STMT_COMPOUND, + N_STMT_EMPTY, + N_STMT_EXPRESSION, + N_STMT_IF, + N_STMT_IF_ELSE, + N_STMT_SWITCH, + N_STMT_WHILE, + N_STMT_DO, + N_STMT_FOR, + N_STMT_RETURN, + N_STMT_CONTINUE, + N_STMT_BREAK, + N_FOR_EXP, + N_STMT_LIST, + N_STMT_LIST_NIL, + N_INIT_LIST, + N_INIT_LIST_ONE, + N_INIT_LIST_NIL +} NODE_NAME; + +typedef enum {T_NULL,T_ENUM,T_ARRAY,T_STRUCT,T_UNION,T_FUNC,T_POINTER,T_VOID} T_KIND; + +typedef enum {Q_NULL,Q_CONST,Q_VOLATILE} Q_KIND; + +typedef enum {S_NULL,S_AUTO,S_STATIC,S_TYPEDEF,S_EXTERN,S_REGISTER} S_KIND; + +typedef enum {ID_NULL,ID_VAR,ID_FUNC,ID_PARM,ID_FIELD,ID_TYPE,ID_ENUM,ID_STRUCT,ID_ENUM_LITERAL} ID_KIND; + +typedef struct s_node { // 신택스 트리의 노드 + NODE_NAME name; + int line; + int value; + struct s_type *type; + struct s_node *llink; + struct s_node *clink; + struct s_node *rlink; +} A_NODE; + +typedef struct s_type { // 타입 테이블 + T_KIND kind; + int size; + int local_var_size; + struct s_type *element_type; + struct s_id *field; + struct s_node *expr; + int line; + BOOLEAN check; + BOOLEAN prt; +} A_TYPE; + +typedef struct s_id { // 심볼 테이블 + char *name; + ID_KIND kind; + S_KIND specifier; + int level; + int address; + int value; + A_NODE *init; + A_TYPE *type; + int line; + struct s_id *prev; + struct s_id *link; +} A_ID; + +typedef union {int i; double f; char c; char *s;} LIT_VALUE; + +typedef struct lit {int addr; A_TYPE *type; LIT_VALUE value;} A_LITERAL; + +typedef struct { + A_TYPE *type; + S_KIND stor; + int line; +} A_SPECIFIER; + +#endif \ No newline at end of file diff --git a/08-code-generator/y.tab.c b/08-code-generator/y.tab.c new file mode 100644 index 0000000..8cddb00 --- /dev/null +++ b/08-code-generator/y.tab.c @@ -0,0 +1,2885 @@ +/* A Bison parser, made by GNU Bison 3.8.2. */ + +/* Bison implementation for Yacc-like parsers in C + + Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 Free Software Foundation, + Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* As a special exception, you may create a larger work that contains + part or all of the Bison parser skeleton and distribute that work + under terms of your choice, so long as that work isn't itself a + parser generator using the skeleton or a modified version thereof + as a parser skeleton. Alternatively, if you modify or redistribute + the parser skeleton itself, you may (at your option) remove this + special exception, which will cause the skeleton and the resulting + Bison output files to be licensed under the GNU General Public + License without this special exception. + + This special exception was added by the Free Software Foundation in + version 2.2 of Bison. */ + +/* C LALR(1) parser skeleton written by Richard Stallman, by + simplifying the original so-called "semantic" parser. */ + +/* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual, + especially those whose name start with YY_ or yy_. They are + private implementation details that can be changed or removed. */ + +/* All symbols defined below should begin with yy or YY, to avoid + infringing on user name space. This should be done even for local + variables, as they might otherwise be expanded by user macros. + There are some unavoidable exceptions within include files to + define necessary library symbols; they are noted "INFRINGES ON + USER NAME SPACE" below. */ + +/* Identify Bison output, and Bison version. */ +#define YYBISON 30802 + +/* Bison version string. */ +#define YYBISON_VERSION "3.8.2" + +/* Skeleton name. */ +#define YYSKELETON_NAME "yacc.c" + +/* Pure parsers. */ +#define YYPURE 0 + +/* Push parsers. */ +#define YYPUSH 0 + +/* Pull parsers. */ +#define YYPULL 1 + + + + +/* First part of user prologue. */ +#line 1 "yacc.y" + +#define YYSTYPE_IS_DECLARED 1 +typedef long YYSTYPE; + +#include "type.h" +#include "func.h" + +extern int line_no, syntax_err; +extern A_NODE *root; +extern A_ID *current_id; +extern int current_level; +extern A_TYPE *int_type; + +#line 85 "y.tab.c" + +# ifndef YY_CAST +# ifdef __cplusplus +# define YY_CAST(Type, Val) static_cast (Val) +# define YY_REINTERPRET_CAST(Type, Val) reinterpret_cast (Val) +# else +# define YY_CAST(Type, Val) ((Type) (Val)) +# define YY_REINTERPRET_CAST(Type, Val) ((Type) (Val)) +# endif +# endif +# ifndef YY_NULLPTR +# if defined __cplusplus +# if 201103L <= __cplusplus +# define YY_NULLPTR nullptr +# else +# define YY_NULLPTR 0 +# endif +# else +# define YY_NULLPTR ((void*)0) +# endif +# endif + +/* Use api.header.include to #include this header + instead of duplicating it here. */ +#ifndef YY_YY_Y_TAB_H_INCLUDED +# define YY_YY_Y_TAB_H_INCLUDED +/* Debug traces. */ +#ifndef YYDEBUG +# define YYDEBUG 0 +#endif +#if YYDEBUG +extern int yydebug; +#endif + +/* Token kinds. */ +#ifndef YYTOKENTYPE +# define YYTOKENTYPE + enum yytokentype + { + YYEMPTY = -2, + YYEOF = 0, /* "end of file" */ + YYerror = 256, /* error */ + YYUNDEF = 257, /* "invalid token" */ + IDENTIFIER = 258, /* IDENTIFIER */ + TYPE_IDENTIFIER = 259, /* TYPE_IDENTIFIER */ + INTEGER_CONSTANT = 260, /* INTEGER_CONSTANT */ + FLOAT_CONSTANT = 261, /* FLOAT_CONSTANT */ + CHARACTER_CONSTANT = 262, /* CHARACTER_CONSTANT */ + STRING_LITERAL = 263, /* STRING_LITERAL */ + AUTO_SYM = 264, /* AUTO_SYM */ + STATIC_SYM = 265, /* STATIC_SYM */ + CONST_SYM = 266, /* CONST_SYM */ + TYPEDEF_SYM = 267, /* TYPEDEF_SYM */ + STRUCT_SYM = 268, /* STRUCT_SYM */ + UNION_SYM = 269, /* UNION_SYM */ + ENUM_SYM = 270, /* ENUM_SYM */ + CASE_SYM = 271, /* CASE_SYM */ + DEFAULT_SYM = 272, /* DEFAULT_SYM */ + IF_SYM = 273, /* IF_SYM */ + ELSE_SYM = 274, /* ELSE_SYM */ + SWITCH_SYM = 275, /* SWITCH_SYM */ + WHILE_SYM = 276, /* WHILE_SYM */ + DO_SYM = 277, /* DO_SYM */ + FOR_SYM = 278, /* FOR_SYM */ + RETURN_SYM = 279, /* RETURN_SYM */ + CONTINUE_SYM = 280, /* CONTINUE_SYM */ + BREAK_SYM = 281, /* BREAK_SYM */ + GOTO_SYM = 282, /* GOTO_SYM */ + COMMA = 283, /* COMMA */ + ASSIGN = 284, /* ASSIGN */ + STAR = 285, /* STAR */ + ARROW = 286, /* ARROW */ + PLUSPLUS = 287, /* PLUSPLUS */ + MINUSMINUS = 288, /* MINUSMINUS */ + AMP = 289, /* AMP */ + EXCL = 290, /* EXCL */ + MINUS = 291, /* MINUS */ + PLUS = 292, /* PLUS */ + SIZEOF_SYM = 293, /* SIZEOF_SYM */ + SLASH = 294, /* SLASH */ + PERCENT = 295, /* PERCENT */ + LSS = 296, /* LSS */ + GTR = 297, /* GTR */ + LEQ = 298, /* LEQ */ + GEQ = 299, /* GEQ */ + EQL = 300, /* EQL */ + NEQ = 301, /* NEQ */ + AMPAMP = 302, /* AMPAMP */ + BARBAR = 303, /* BARBAR */ + LR = 304, /* LR */ + RR = 305, /* RR */ + LP = 306, /* LP */ + RP = 307, /* RP */ + LB = 308, /* LB */ + RB = 309, /* RB */ + SEMICOLON = 310, /* SEMICOLON */ + COLON = 311, /* COLON */ + DOTDOTDOT = 312, /* DOTDOTDOT */ + PERIOD = 313 /* PERIOD */ + }; + typedef enum yytokentype yytoken_kind_t; +#endif +/* Token kinds. */ +#define YYEMPTY -2 +#define YYEOF 0 +#define YYerror 256 +#define YYUNDEF 257 +#define IDENTIFIER 258 +#define TYPE_IDENTIFIER 259 +#define INTEGER_CONSTANT 260 +#define FLOAT_CONSTANT 261 +#define CHARACTER_CONSTANT 262 +#define STRING_LITERAL 263 +#define AUTO_SYM 264 +#define STATIC_SYM 265 +#define CONST_SYM 266 +#define TYPEDEF_SYM 267 +#define STRUCT_SYM 268 +#define UNION_SYM 269 +#define ENUM_SYM 270 +#define CASE_SYM 271 +#define DEFAULT_SYM 272 +#define IF_SYM 273 +#define ELSE_SYM 274 +#define SWITCH_SYM 275 +#define WHILE_SYM 276 +#define DO_SYM 277 +#define FOR_SYM 278 +#define RETURN_SYM 279 +#define CONTINUE_SYM 280 +#define BREAK_SYM 281 +#define GOTO_SYM 282 +#define COMMA 283 +#define ASSIGN 284 +#define STAR 285 +#define ARROW 286 +#define PLUSPLUS 287 +#define MINUSMINUS 288 +#define AMP 289 +#define EXCL 290 +#define MINUS 291 +#define PLUS 292 +#define SIZEOF_SYM 293 +#define SLASH 294 +#define PERCENT 295 +#define LSS 296 +#define GTR 297 +#define LEQ 298 +#define GEQ 299 +#define EQL 300 +#define NEQ 301 +#define AMPAMP 302 +#define BARBAR 303 +#define LR 304 +#define RR 305 +#define LP 306 +#define RP 307 +#define LB 308 +#define RB 309 +#define SEMICOLON 310 +#define COLON 311 +#define DOTDOTDOT 312 +#define PERIOD 313 + +/* Value type. */ +#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED +typedef int YYSTYPE; +# define YYSTYPE_IS_TRIVIAL 1 +# define YYSTYPE_IS_DECLARED 1 +#endif + + +extern YYSTYPE yylval; + + +int yyparse (void); + + +#endif /* !YY_YY_Y_TAB_H_INCLUDED */ +/* Symbol kind. */ +enum yysymbol_kind_t +{ + YYSYMBOL_YYEMPTY = -2, + YYSYMBOL_YYEOF = 0, /* "end of file" */ + YYSYMBOL_YYerror = 1, /* error */ + YYSYMBOL_YYUNDEF = 2, /* "invalid token" */ + YYSYMBOL_IDENTIFIER = 3, /* IDENTIFIER */ + YYSYMBOL_TYPE_IDENTIFIER = 4, /* TYPE_IDENTIFIER */ + YYSYMBOL_INTEGER_CONSTANT = 5, /* INTEGER_CONSTANT */ + YYSYMBOL_FLOAT_CONSTANT = 6, /* FLOAT_CONSTANT */ + YYSYMBOL_CHARACTER_CONSTANT = 7, /* CHARACTER_CONSTANT */ + YYSYMBOL_STRING_LITERAL = 8, /* STRING_LITERAL */ + YYSYMBOL_AUTO_SYM = 9, /* AUTO_SYM */ + YYSYMBOL_STATIC_SYM = 10, /* STATIC_SYM */ + YYSYMBOL_CONST_SYM = 11, /* CONST_SYM */ + YYSYMBOL_TYPEDEF_SYM = 12, /* TYPEDEF_SYM */ + YYSYMBOL_STRUCT_SYM = 13, /* STRUCT_SYM */ + YYSYMBOL_UNION_SYM = 14, /* UNION_SYM */ + YYSYMBOL_ENUM_SYM = 15, /* ENUM_SYM */ + YYSYMBOL_CASE_SYM = 16, /* CASE_SYM */ + YYSYMBOL_DEFAULT_SYM = 17, /* DEFAULT_SYM */ + YYSYMBOL_IF_SYM = 18, /* IF_SYM */ + YYSYMBOL_ELSE_SYM = 19, /* ELSE_SYM */ + YYSYMBOL_SWITCH_SYM = 20, /* SWITCH_SYM */ + YYSYMBOL_WHILE_SYM = 21, /* WHILE_SYM */ + YYSYMBOL_DO_SYM = 22, /* DO_SYM */ + YYSYMBOL_FOR_SYM = 23, /* FOR_SYM */ + YYSYMBOL_RETURN_SYM = 24, /* RETURN_SYM */ + YYSYMBOL_CONTINUE_SYM = 25, /* CONTINUE_SYM */ + YYSYMBOL_BREAK_SYM = 26, /* BREAK_SYM */ + YYSYMBOL_GOTO_SYM = 27, /* GOTO_SYM */ + YYSYMBOL_COMMA = 28, /* COMMA */ + YYSYMBOL_ASSIGN = 29, /* ASSIGN */ + YYSYMBOL_STAR = 30, /* STAR */ + YYSYMBOL_ARROW = 31, /* ARROW */ + YYSYMBOL_PLUSPLUS = 32, /* PLUSPLUS */ + YYSYMBOL_MINUSMINUS = 33, /* MINUSMINUS */ + YYSYMBOL_AMP = 34, /* AMP */ + YYSYMBOL_EXCL = 35, /* EXCL */ + YYSYMBOL_MINUS = 36, /* MINUS */ + YYSYMBOL_PLUS = 37, /* PLUS */ + YYSYMBOL_SIZEOF_SYM = 38, /* SIZEOF_SYM */ + YYSYMBOL_SLASH = 39, /* SLASH */ + YYSYMBOL_PERCENT = 40, /* PERCENT */ + YYSYMBOL_LSS = 41, /* LSS */ + YYSYMBOL_GTR = 42, /* GTR */ + YYSYMBOL_LEQ = 43, /* LEQ */ + YYSYMBOL_GEQ = 44, /* GEQ */ + YYSYMBOL_EQL = 45, /* EQL */ + YYSYMBOL_NEQ = 46, /* NEQ */ + YYSYMBOL_AMPAMP = 47, /* AMPAMP */ + YYSYMBOL_BARBAR = 48, /* BARBAR */ + YYSYMBOL_LR = 49, /* LR */ + YYSYMBOL_RR = 50, /* RR */ + YYSYMBOL_LP = 51, /* LP */ + YYSYMBOL_RP = 52, /* RP */ + YYSYMBOL_LB = 53, /* LB */ + YYSYMBOL_RB = 54, /* RB */ + YYSYMBOL_SEMICOLON = 55, /* SEMICOLON */ + YYSYMBOL_COLON = 56, /* COLON */ + YYSYMBOL_DOTDOTDOT = 57, /* DOTDOTDOT */ + YYSYMBOL_PERIOD = 58, /* PERIOD */ + YYSYMBOL_YYACCEPT = 59, /* $accept */ + YYSYMBOL_program = 60, /* program */ + YYSYMBOL_translation_unit = 61, /* translation_unit */ + YYSYMBOL_external_declaration = 62, /* external_declaration */ + YYSYMBOL_function_definition = 63, /* function_definition */ + YYSYMBOL_64_1 = 64, /* @1 */ + YYSYMBOL_65_2 = 65, /* @2 */ + YYSYMBOL_declaration_list_opt = 66, /* declaration_list_opt */ + YYSYMBOL_declaration_list = 67, /* declaration_list */ + YYSYMBOL_declaration = 68, /* declaration */ + YYSYMBOL_declaration_specifiers = 69, /* declaration_specifiers */ + YYSYMBOL_storage_class_specifier = 70, /* storage_class_specifier */ + YYSYMBOL_init_declarator_list_opt = 71, /* init_declarator_list_opt */ + YYSYMBOL_init_declarator_list = 72, /* init_declarator_list */ + YYSYMBOL_init_declarator = 73, /* init_declarator */ + YYSYMBOL_initializer = 74, /* initializer */ + YYSYMBOL_initializer_list = 75, /* initializer_list */ + YYSYMBOL_type_specifier = 76, /* type_specifier */ + YYSYMBOL_struct_type_specifier = 77, /* struct_type_specifier */ + YYSYMBOL_78_3 = 78, /* @3 */ + YYSYMBOL_79_4 = 79, /* @4 */ + YYSYMBOL_80_5 = 80, /* @5 */ + YYSYMBOL_81_6 = 81, /* @6 */ + YYSYMBOL_struct_or_union = 82, /* struct_or_union */ + YYSYMBOL_struct_declaration_list = 83, /* struct_declaration_list */ + YYSYMBOL_struct_declaration = 84, /* struct_declaration */ + YYSYMBOL_struct_declarator_list = 85, /* struct_declarator_list */ + YYSYMBOL_struct_declarator = 86, /* struct_declarator */ + YYSYMBOL_enum_type_specifier = 87, /* enum_type_specifier */ + YYSYMBOL_88_7 = 88, /* @7 */ + YYSYMBOL_89_8 = 89, /* @8 */ + YYSYMBOL_enumerator_list = 90, /* enumerator_list */ + YYSYMBOL_enumerator = 91, /* enumerator */ + YYSYMBOL_92_9 = 92, /* @9 */ + YYSYMBOL_declarator = 93, /* declarator */ + YYSYMBOL_pointer = 94, /* pointer */ + YYSYMBOL_direct_declarator = 95, /* direct_declarator */ + YYSYMBOL_96_10 = 96, /* @10 */ + YYSYMBOL_parameter_type_list_opt = 97, /* parameter_type_list_opt */ + YYSYMBOL_parameter_type_list = 98, /* parameter_type_list */ + YYSYMBOL_parameter_list = 99, /* parameter_list */ + YYSYMBOL_parameter_declaration = 100, /* parameter_declaration */ + YYSYMBOL_abstract_declarator_opt = 101, /* abstract_declarator_opt */ + YYSYMBOL_abstract_declarator = 102, /* abstract_declarator */ + YYSYMBOL_direct_abstract_declarator = 103, /* direct_abstract_declarator */ + YYSYMBOL_statement_list_opt = 104, /* statement_list_opt */ + YYSYMBOL_statement_list = 105, /* statement_list */ + YYSYMBOL_statement = 106, /* statement */ + YYSYMBOL_labeled_statement = 107, /* labeled_statement */ + YYSYMBOL_compound_statement = 108, /* compound_statement */ + YYSYMBOL_109_11 = 109, /* @11 */ + YYSYMBOL_expression_statement = 110, /* expression_statement */ + YYSYMBOL_selection_statement = 111, /* selection_statement */ + YYSYMBOL_iteration_statement = 112, /* iteration_statement */ + YYSYMBOL_for_expression = 113, /* for_expression */ + YYSYMBOL_expression_opt = 114, /* expression_opt */ + YYSYMBOL_jump_statement = 115, /* jump_statement */ + YYSYMBOL_arg_expression_list_opt = 116, /* arg_expression_list_opt */ + YYSYMBOL_arg_expression_list = 117, /* arg_expression_list */ + YYSYMBOL_constant_expression_opt = 118, /* constant_expression_opt */ + YYSYMBOL_constant_expression = 119, /* constant_expression */ + YYSYMBOL_expression = 120, /* expression */ + YYSYMBOL_comma_expression = 121, /* comma_expression */ + YYSYMBOL_assignment_expression = 122, /* assignment_expression */ + YYSYMBOL_conditional_expression = 123, /* conditional_expression */ + YYSYMBOL_logical_OR_expression = 124, /* logical_OR_expression */ + YYSYMBOL_logical_AND_expression = 125, /* logical_AND_expression */ + YYSYMBOL_bitwise_or_expression = 126, /* bitwise_or_expression */ + YYSYMBOL_bitwise_xor_expression = 127, /* bitwise_xor_expression */ + YYSYMBOL_bitwise_and_expression = 128, /* bitwise_and_expression */ + YYSYMBOL_equality_expression = 129, /* equality_expression */ + YYSYMBOL_relational_expression = 130, /* relational_expression */ + YYSYMBOL_shift_expression = 131, /* shift_expression */ + YYSYMBOL_additive_expression = 132, /* additive_expression */ + YYSYMBOL_multiplicative_expression = 133, /* multiplicative_expression */ + YYSYMBOL_cast_expression = 134, /* cast_expression */ + YYSYMBOL_unary_expression = 135, /* unary_expression */ + YYSYMBOL_postfix_expression = 136, /* postfix_expression */ + YYSYMBOL_primary_expression = 137, /* primary_expression */ + YYSYMBOL_type_name = 138 /* type_name */ +}; +typedef enum yysymbol_kind_t yysymbol_kind_t; + + + + +#ifdef short +# undef short +#endif + +/* On compilers that do not define __PTRDIFF_MAX__ etc., make sure + and (if available) are included + so that the code can choose integer types of a good width. */ + +#ifndef __PTRDIFF_MAX__ +# include /* INFRINGES ON USER NAME SPACE */ +# if defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__ +# include /* INFRINGES ON USER NAME SPACE */ +# define YY_STDINT_H +# endif +#endif + +/* Narrow types that promote to a signed type and that can represent a + signed or unsigned integer of at least N bits. In tables they can + save space and decrease cache pressure. Promoting to a signed type + helps avoid bugs in integer arithmetic. */ + +#ifdef __INT_LEAST8_MAX__ +typedef __INT_LEAST8_TYPE__ yytype_int8; +#elif defined YY_STDINT_H +typedef int_least8_t yytype_int8; +#else +typedef signed char yytype_int8; +#endif + +#ifdef __INT_LEAST16_MAX__ +typedef __INT_LEAST16_TYPE__ yytype_int16; +#elif defined YY_STDINT_H +typedef int_least16_t yytype_int16; +#else +typedef short yytype_int16; +#endif + +/* Work around bug in HP-UX 11.23, which defines these macros + incorrectly for preprocessor constants. This workaround can likely + be removed in 2023, as HPE has promised support for HP-UX 11.23 + (aka HP-UX 11i v2) only through the end of 2022; see Table 2 of + . */ +#ifdef __hpux +# undef UINT_LEAST8_MAX +# undef UINT_LEAST16_MAX +# define UINT_LEAST8_MAX 255 +# define UINT_LEAST16_MAX 65535 +#endif + +#if defined __UINT_LEAST8_MAX__ && __UINT_LEAST8_MAX__ <= __INT_MAX__ +typedef __UINT_LEAST8_TYPE__ yytype_uint8; +#elif (!defined __UINT_LEAST8_MAX__ && defined YY_STDINT_H \ + && UINT_LEAST8_MAX <= INT_MAX) +typedef uint_least8_t yytype_uint8; +#elif !defined __UINT_LEAST8_MAX__ && UCHAR_MAX <= INT_MAX +typedef unsigned char yytype_uint8; +#else +typedef short yytype_uint8; +#endif + +#if defined __UINT_LEAST16_MAX__ && __UINT_LEAST16_MAX__ <= __INT_MAX__ +typedef __UINT_LEAST16_TYPE__ yytype_uint16; +#elif (!defined __UINT_LEAST16_MAX__ && defined YY_STDINT_H \ + && UINT_LEAST16_MAX <= INT_MAX) +typedef uint_least16_t yytype_uint16; +#elif !defined __UINT_LEAST16_MAX__ && USHRT_MAX <= INT_MAX +typedef unsigned short yytype_uint16; +#else +typedef int yytype_uint16; +#endif + +#ifndef YYPTRDIFF_T +# if defined __PTRDIFF_TYPE__ && defined __PTRDIFF_MAX__ +# define YYPTRDIFF_T __PTRDIFF_TYPE__ +# define YYPTRDIFF_MAXIMUM __PTRDIFF_MAX__ +# elif defined PTRDIFF_MAX +# ifndef ptrdiff_t +# include /* INFRINGES ON USER NAME SPACE */ +# endif +# define YYPTRDIFF_T ptrdiff_t +# define YYPTRDIFF_MAXIMUM PTRDIFF_MAX +# else +# define YYPTRDIFF_T long +# define YYPTRDIFF_MAXIMUM LONG_MAX +# endif +#endif + +#ifndef YYSIZE_T +# ifdef __SIZE_TYPE__ +# define YYSIZE_T __SIZE_TYPE__ +# elif defined size_t +# define YYSIZE_T size_t +# elif defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__ +# include /* INFRINGES ON USER NAME SPACE */ +# define YYSIZE_T size_t +# else +# define YYSIZE_T unsigned +# endif +#endif + +#define YYSIZE_MAXIMUM \ + YY_CAST (YYPTRDIFF_T, \ + (YYPTRDIFF_MAXIMUM < YY_CAST (YYSIZE_T, -1) \ + ? YYPTRDIFF_MAXIMUM \ + : YY_CAST (YYSIZE_T, -1))) + +#define YYSIZEOF(X) YY_CAST (YYPTRDIFF_T, sizeof (X)) + + +/* Stored state numbers (used for stacks). */ +typedef yytype_int16 yy_state_t; + +/* State numbers in computations. */ +typedef int yy_state_fast_t; + +#ifndef YY_ +# if defined YYENABLE_NLS && YYENABLE_NLS +# if ENABLE_NLS +# include /* INFRINGES ON USER NAME SPACE */ +# define YY_(Msgid) dgettext ("bison-runtime", Msgid) +# endif +# endif +# ifndef YY_ +# define YY_(Msgid) Msgid +# endif +#endif + + +#ifndef YY_ATTRIBUTE_PURE +# if defined __GNUC__ && 2 < __GNUC__ + (96 <= __GNUC_MINOR__) +# define YY_ATTRIBUTE_PURE __attribute__ ((__pure__)) +# else +# define YY_ATTRIBUTE_PURE +# endif +#endif + +#ifndef YY_ATTRIBUTE_UNUSED +# if defined __GNUC__ && 2 < __GNUC__ + (7 <= __GNUC_MINOR__) +# define YY_ATTRIBUTE_UNUSED __attribute__ ((__unused__)) +# else +# define YY_ATTRIBUTE_UNUSED +# endif +#endif + +/* Suppress unused-variable warnings by "using" E. */ +#if ! defined lint || defined __GNUC__ +# define YY_USE(E) ((void) (E)) +#else +# define YY_USE(E) /* empty */ +#endif + +/* Suppress an incorrect diagnostic about yylval being uninitialized. */ +#if defined __GNUC__ && ! defined __ICC && 406 <= __GNUC__ * 100 + __GNUC_MINOR__ +# if __GNUC__ * 100 + __GNUC_MINOR__ < 407 +# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ + _Pragma ("GCC diagnostic push") \ + _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") +# else +# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ + _Pragma ("GCC diagnostic push") \ + _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") \ + _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") +# endif +# define YY_IGNORE_MAYBE_UNINITIALIZED_END \ + _Pragma ("GCC diagnostic pop") +#else +# define YY_INITIAL_VALUE(Value) Value +#endif +#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN +# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN +# define YY_IGNORE_MAYBE_UNINITIALIZED_END +#endif +#ifndef YY_INITIAL_VALUE +# define YY_INITIAL_VALUE(Value) /* Nothing. */ +#endif + +#if defined __cplusplus && defined __GNUC__ && ! defined __ICC && 6 <= __GNUC__ +# define YY_IGNORE_USELESS_CAST_BEGIN \ + _Pragma ("GCC diagnostic push") \ + _Pragma ("GCC diagnostic ignored \"-Wuseless-cast\"") +# define YY_IGNORE_USELESS_CAST_END \ + _Pragma ("GCC diagnostic pop") +#endif +#ifndef YY_IGNORE_USELESS_CAST_BEGIN +# define YY_IGNORE_USELESS_CAST_BEGIN +# define YY_IGNORE_USELESS_CAST_END +#endif + + +#define YY_ASSERT(E) ((void) (0 && (E))) + +#if !defined yyoverflow + +/* The parser invokes alloca or malloc; define the necessary symbols. */ + +# ifdef YYSTACK_USE_ALLOCA +# if YYSTACK_USE_ALLOCA +# ifdef __GNUC__ +# define YYSTACK_ALLOC __builtin_alloca +# elif defined __BUILTIN_VA_ARG_INCR +# include /* INFRINGES ON USER NAME SPACE */ +# elif defined _AIX +# define YYSTACK_ALLOC __alloca +# elif defined _MSC_VER +# include /* INFRINGES ON USER NAME SPACE */ +# define alloca _alloca +# else +# define YYSTACK_ALLOC alloca +# if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS +# include /* INFRINGES ON USER NAME SPACE */ + /* Use EXIT_SUCCESS as a witness for stdlib.h. */ +# ifndef EXIT_SUCCESS +# define EXIT_SUCCESS 0 +# endif +# endif +# endif +# endif +# endif + +# ifdef YYSTACK_ALLOC + /* Pacify GCC's 'empty if-body' warning. */ +# define YYSTACK_FREE(Ptr) do { /* empty */; } while (0) +# ifndef YYSTACK_ALLOC_MAXIMUM + /* The OS might guarantee only one guard page at the bottom of the stack, + and a page size can be as small as 4096 bytes. So we cannot safely + invoke alloca (N) if N exceeds 4096. Use a slightly smaller number + to allow for a few compiler-allocated temporary stack slots. */ +# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */ +# endif +# else +# define YYSTACK_ALLOC YYMALLOC +# define YYSTACK_FREE YYFREE +# ifndef YYSTACK_ALLOC_MAXIMUM +# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM +# endif +# if (defined __cplusplus && ! defined EXIT_SUCCESS \ + && ! ((defined YYMALLOC || defined malloc) \ + && (defined YYFREE || defined free))) +# include /* INFRINGES ON USER NAME SPACE */ +# ifndef EXIT_SUCCESS +# define EXIT_SUCCESS 0 +# endif +# endif +# ifndef YYMALLOC +# define YYMALLOC malloc +# if ! defined malloc && ! defined EXIT_SUCCESS +void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ +# endif +# endif +# ifndef YYFREE +# define YYFREE free +# if ! defined free && ! defined EXIT_SUCCESS +void free (void *); /* INFRINGES ON USER NAME SPACE */ +# endif +# endif +# endif +#endif /* !defined yyoverflow */ + +#if (! defined yyoverflow \ + && (! defined __cplusplus \ + || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) + +/* A type that is properly aligned for any stack member. */ +union yyalloc +{ + yy_state_t yyss_alloc; + YYSTYPE yyvs_alloc; +}; + +/* The size of the maximum gap between one aligned stack and the next. */ +# define YYSTACK_GAP_MAXIMUM (YYSIZEOF (union yyalloc) - 1) + +/* The size of an array large to enough to hold all stacks, each with + N elements. */ +# define YYSTACK_BYTES(N) \ + ((N) * (YYSIZEOF (yy_state_t) + YYSIZEOF (YYSTYPE)) \ + + YYSTACK_GAP_MAXIMUM) + +# define YYCOPY_NEEDED 1 + +/* Relocate STACK from its old location to the new one. The + local variables YYSIZE and YYSTACKSIZE give the old and new number of + elements in the stack, and YYPTR gives the new location of the + stack. Advance YYPTR to a properly aligned location for the next + stack. */ +# define YYSTACK_RELOCATE(Stack_alloc, Stack) \ + do \ + { \ + YYPTRDIFF_T yynewbytes; \ + YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \ + Stack = &yyptr->Stack_alloc; \ + yynewbytes = yystacksize * YYSIZEOF (*Stack) + YYSTACK_GAP_MAXIMUM; \ + yyptr += yynewbytes / YYSIZEOF (*yyptr); \ + } \ + while (0) + +#endif + +#if defined YYCOPY_NEEDED && YYCOPY_NEEDED +/* Copy COUNT objects from SRC to DST. The source and destination do + not overlap. */ +# ifndef YYCOPY +# if defined __GNUC__ && 1 < __GNUC__ +# define YYCOPY(Dst, Src, Count) \ + __builtin_memcpy (Dst, Src, YY_CAST (YYSIZE_T, (Count)) * sizeof (*(Src))) +# else +# define YYCOPY(Dst, Src, Count) \ + do \ + { \ + YYPTRDIFF_T yyi; \ + for (yyi = 0; yyi < (Count); yyi++) \ + (Dst)[yyi] = (Src)[yyi]; \ + } \ + while (0) +# endif +# endif +#endif /* !YYCOPY_NEEDED */ + +/* YYFINAL -- State number of the termination state. */ +#define YYFINAL 29 +/* YYLAST -- Last index in YYTABLE. */ +#define YYLAST 455 + +/* YYNTOKENS -- Number of terminals. */ +#define YYNTOKENS 59 +/* YYNNTS -- Number of nonterminals. */ +#define YYNNTS 80 +/* YYNRULES -- Number of rules. */ +#define YYNRULES 176 +/* YYNSTATES -- Number of states. */ +#define YYNSTATES 293 + +/* YYMAXUTOK -- Last valid token kind. */ +#define YYMAXUTOK 313 + + +/* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM + as returned by yylex, with out-of-bounds checking. */ +#define YYTRANSLATE(YYX) \ + (0 <= (YYX) && (YYX) <= YYMAXUTOK \ + ? YY_CAST (yysymbol_kind_t, yytranslate[YYX]) \ + : YYSYMBOL_YYUNDEF) + +/* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM + as returned by yylex. */ +static const yytype_int8 yytranslate[] = +{ + 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, + 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, + 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, + 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, + 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, + 55, 56, 57, 58 +}; + +#if YYDEBUG +/* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ +static const yytype_int16 yyrline[] = +{ + 0, 29, 29, 33, 34, 37, 38, 41, 41, 43, + 43, 47, 48, 51, 52, 55, 58, 59, 60, 61, + 64, 65, 66, 69, 70, 73, 74, 77, 78, 81, + 82, 85, 86, 89, 90, 91, 94, 95, 94, 97, + 98, 97, 100, 103, 104, 107, 108, 111, 114, 115, + 118, 121, 121, 123, 123, 125, 128, 129, 132, 133, + 133, 137, 138, 141, 142, 145, 146, 147, 149, 149, + 155, 156, 159, 160, 163, 164, 167, 168, 171, 172, + 175, 176, 177, 180, 181, 182, 183, 184, 187, 188, + 191, 192, 195, 196, 197, 198, 199, 200, 203, 204, + 207, 207, 211, 212, 215, 216, 217, 220, 221, 222, + 225, 228, 229, 232, 233, 234, 237, 238, 241, 243, + 247, 248, 251, 254, 257, 260, 261, 264, 267, 268, + 272, 273, 277, 280, 283, 286, 287, 288, 291, 292, + 293, 294, 295, 298, 301, 302, 303, 306, 307, 308, + 309, 312, 313, 316, 317, 318, 319, 320, 321, 322, + 323, 324, 325, 328, 329, 330, 332, 333, 334, 335, + 338, 339, 340, 341, 342, 343, 346 +}; +#endif + +/** Accessing symbol of state STATE. */ +#define YY_ACCESSING_SYMBOL(State) YY_CAST (yysymbol_kind_t, yystos[State]) + +#if YYDEBUG || 0 +/* The user-facing name of the symbol whose (internal) number is + YYSYMBOL. No bounds checking. */ +static const char *yysymbol_name (yysymbol_kind_t yysymbol) YY_ATTRIBUTE_UNUSED; + +/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. + First, the terminals, then, starting at YYNTOKENS, nonterminals. */ +static const char *const yytname[] = +{ + "\"end of file\"", "error", "\"invalid token\"", "IDENTIFIER", + "TYPE_IDENTIFIER", "INTEGER_CONSTANT", "FLOAT_CONSTANT", + "CHARACTER_CONSTANT", "STRING_LITERAL", "AUTO_SYM", "STATIC_SYM", + "CONST_SYM", "TYPEDEF_SYM", "STRUCT_SYM", "UNION_SYM", "ENUM_SYM", + "CASE_SYM", "DEFAULT_SYM", "IF_SYM", "ELSE_SYM", "SWITCH_SYM", + "WHILE_SYM", "DO_SYM", "FOR_SYM", "RETURN_SYM", "CONTINUE_SYM", + "BREAK_SYM", "GOTO_SYM", "COMMA", "ASSIGN", "STAR", "ARROW", "PLUSPLUS", + "MINUSMINUS", "AMP", "EXCL", "MINUS", "PLUS", "SIZEOF_SYM", "SLASH", + "PERCENT", "LSS", "GTR", "LEQ", "GEQ", "EQL", "NEQ", "AMPAMP", "BARBAR", + "LR", "RR", "LP", "RP", "LB", "RB", "SEMICOLON", "COLON", "DOTDOTDOT", + "PERIOD", "$accept", "program", "translation_unit", + "external_declaration", "function_definition", "@1", "@2", + "declaration_list_opt", "declaration_list", "declaration", + "declaration_specifiers", "storage_class_specifier", + "init_declarator_list_opt", "init_declarator_list", "init_declarator", + "initializer", "initializer_list", "type_specifier", + "struct_type_specifier", "@3", "@4", "@5", "@6", "struct_or_union", + "struct_declaration_list", "struct_declaration", + "struct_declarator_list", "struct_declarator", "enum_type_specifier", + "@7", "@8", "enumerator_list", "enumerator", "@9", "declarator", + "pointer", "direct_declarator", "@10", "parameter_type_list_opt", + "parameter_type_list", "parameter_list", "parameter_declaration", + "abstract_declarator_opt", "abstract_declarator", + "direct_abstract_declarator", "statement_list_opt", "statement_list", + "statement", "labeled_statement", "compound_statement", "@11", + "expression_statement", "selection_statement", "iteration_statement", + "for_expression", "expression_opt", "jump_statement", + "arg_expression_list_opt", "arg_expression_list", + "constant_expression_opt", "constant_expression", "expression", + "comma_expression", "assignment_expression", "conditional_expression", + "logical_OR_expression", "logical_AND_expression", + "bitwise_or_expression", "bitwise_xor_expression", + "bitwise_and_expression", "equality_expression", "relational_expression", + "shift_expression", "additive_expression", "multiplicative_expression", + "cast_expression", "unary_expression", "postfix_expression", + "primary_expression", "type_name", YY_NULLPTR +}; + +static const char * +yysymbol_name (yysymbol_kind_t yysymbol) +{ + return yytname[yysymbol]; +} +#endif + +#define YYPACT_NINF (-194) + +#define yypact_value_is_default(Yyn) \ + ((Yyn) == YYPACT_NINF) + +#define YYTABLE_NINF (-60) + +#define yytable_value_is_error(Yyn) \ + 0 + +/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing + STATE-NUM. */ +static const yytype_int16 yypact[] = +{ + 404, -194, -194, -194, -194, -194, -194, -194, 61, 40, + 28, 99, 404, -194, -194, -194, 28, 292, 292, -194, + 111, -194, -194, 18, 25, 104, 110, -194, 86, -194, + -194, 68, 120, -194, 11, -194, -194, 117, 128, 130, + 25, -194, 344, 139, 213, -194, -194, 28, 175, 130, + 168, -194, -194, -194, 292, -194, -194, -194, -194, -194, + 344, 355, 355, 344, 344, 344, 344, 364, 308, 164, + -194, -194, -194, -194, -194, 172, 176, -194, -194, -194, + 6, 121, -194, 74, 26, -194, 190, 197, -194, 213, + 193, 75, -194, -194, 196, 175, -194, -194, -194, -194, + 141, 292, 41, 180, -194, 199, -194, -194, -194, 344, + -194, -194, -194, -194, -194, -194, 308, -194, 24, 181, + 182, -194, 344, 344, 344, 344, 344, 344, 344, 344, + 344, 344, 344, 344, 344, 344, 232, -194, -194, 344, + 344, 237, 89, 216, 213, -194, -194, 92, 141, 28, + 122, -194, 236, 292, -194, 28, 33, 344, -194, 38, + -194, -194, 71, -194, 15, 194, 280, 90, -194, -194, + 344, 176, -194, 121, 121, -194, -194, -194, -194, 26, + 26, -194, -194, -194, -194, -194, 211, 221, -194, 210, + -194, -194, 344, -194, 175, -194, 171, 7, -194, -194, + -194, -194, 344, 195, 214, 224, 225, 236, 226, 344, + 212, 223, -194, 229, 236, -194, -194, -194, -194, -194, + -194, -194, 227, -194, 228, 231, 234, 71, 292, 344, + -194, -194, -194, -194, -194, 344, -194, -194, -194, -194, + 28, -194, 230, 236, 344, 344, 344, 260, 344, 242, + -194, -194, -194, -194, -194, -194, -194, -194, -194, 246, + 245, -194, -194, 236, -194, 248, 251, 256, 258, 267, + 269, -194, -194, -194, -194, 236, 236, 236, 344, 236, + 344, 306, -194, -194, 274, -194, 272, 236, 273, 344, + -194, -194, -194 +}; + +/* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM. + Performed when YYTABLE does not specify something else to do. Zero + means the default is an error. */ +static const yytype_uint8 yydefact[] = +{ + 0, 65, 35, 20, 21, 22, 43, 44, 53, 63, + 0, 0, 2, 3, 5, 6, 23, 17, 16, 33, + 39, 34, 9, 0, 62, 55, 0, 64, 0, 1, + 4, 0, 24, 25, 27, 19, 18, 42, 0, 0, + 61, 68, 120, 0, 0, 66, 15, 0, 0, 0, + 0, 40, 100, 10, 70, 170, 171, 172, 173, 174, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 121, 122, 123, 124, 125, 127, 128, 130, 132, 133, + 134, 135, 138, 143, 144, 147, 151, 153, 163, 0, + 58, 0, 56, 26, 27, 0, 28, 29, 8, 37, + 0, 11, 78, 0, 71, 72, 74, 157, 151, 0, + 154, 155, 156, 158, 159, 160, 0, 161, 78, 0, + 0, 67, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 168, 169, 116, + 0, 0, 0, 0, 0, 54, 31, 0, 0, 0, + 0, 45, 88, 12, 13, 23, 70, 120, 76, 81, + 77, 79, 80, 69, 0, 0, 70, 81, 176, 175, + 0, 129, 131, 136, 137, 139, 140, 141, 142, 146, + 145, 148, 149, 150, 126, 167, 0, 117, 118, 0, + 166, 52, 0, 57, 0, 30, 0, 0, 48, 50, + 41, 46, 0, 0, 0, 0, 0, 0, 0, 111, + 0, 0, 102, 0, 89, 90, 92, 93, 94, 95, + 96, 97, 0, 14, 0, 0, 0, 82, 70, 120, + 73, 75, 162, 152, 165, 0, 164, 60, 32, 38, + 0, 47, 0, 0, 0, 0, 0, 0, 111, 0, + 112, 114, 115, 101, 91, 103, 85, 83, 84, 0, + 0, 119, 49, 0, 99, 0, 0, 0, 0, 0, + 0, 113, 87, 86, 98, 0, 0, 0, 0, 0, + 111, 104, 106, 107, 0, 109, 0, 0, 0, 111, + 105, 108, 110 +}; + +/* YYPGOTO[NTERM-NUM]. */ +static const yytype_int16 yypgoto[] = +{ + -194, -194, -194, 317, -194, -194, -194, -194, -194, -68, + 5, -194, -194, -194, 283, -85, -194, -89, -194, -194, + -194, -194, -194, -194, 184, -116, -194, 94, -194, -194, + -194, 247, 191, -194, -9, -5, -15, -194, -52, -194, + -194, 173, 235, -61, -110, -194, -194, -175, -194, 69, + -194, -194, -194, -194, -194, -193, -194, -194, -194, -139, + -45, -42, -194, -119, -194, -194, 217, 233, -194, -194, + -194, 49, 42, -194, 84, -51, 67, -194, -194, 238 +}; + +/* YYDEFGOTO[NTERM-NUM]. */ +static const yytype_int16 yydefgoto[] = +{ + 0, 11, 12, 13, 14, 49, 39, 152, 153, 15, + 102, 17, 31, 32, 33, 96, 147, 18, 19, 50, + 148, 38, 100, 20, 150, 151, 197, 198, 21, 43, + 26, 91, 92, 143, 22, 23, 24, 54, 224, 104, + 105, 106, 160, 161, 162, 213, 214, 215, 216, 217, + 101, 218, 219, 220, 269, 249, 221, 186, 187, 69, + 70, 222, 72, 73, 74, 75, 76, 77, 78, 79, + 80, 81, 82, 83, 84, 85, 86, 87, 88, 120 +}; + +/* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If + positive, shift that token. If negative, reduce the rule whose + number is the opposite. If YYTABLE_NINF, syntax error. */ +static const yytype_int16 yytable[] = +{ + 71, 28, 103, 97, 27, 16, 71, 34, 40, 107, + 146, 149, 112, 113, 114, 115, 184, 16, 226, 2, + 188, 1, 35, 36, 3, 4, 119, 5, 6, 7, + 8, 1, 247, 154, 201, 240, 1, 2, 94, 254, + 48, 1, 3, 4, 1, 5, 6, 7, 8, 227, + 97, 124, 125, 71, 9, 270, 132, 227, 9, 149, + -7, 149, 241, 9, 25, 133, 134, 119, 264, 10, + 9, 9, 230, 118, 119, 166, 41, 157, 42, 10, + 201, 181, 182, 183, 156, 223, 157, 286, 274, 156, + 260, 157, 156, 158, 157, 225, 292, 159, 189, 29, + 281, 282, 283, 144, 285, 225, 155, 149, 53, 238, + 130, 131, 290, 167, 37, 71, 261, 144, 98, 233, + 194, 118, 228, 46, 229, 145, 2, 108, 110, 111, + 108, 108, 108, 108, 117, 6, 7, 8, 45, 191, + 199, 166, 195, 157, 40, 2, 94, 28, 47, 97, + 237, 159, 71, -51, 6, 7, 8, 242, 155, 44, + 71, 167, 126, 127, 128, 129, -36, 250, 175, 176, + 177, 178, 200, 173, 174, 2, 259, 51, 55, 52, + 56, 57, 58, 59, 6, 7, 8, 71, 89, 108, + 108, 108, 108, 108, 108, 108, 108, 108, 108, 108, + 108, 108, 265, 266, 267, 60, 250, 61, 62, 63, + 64, 65, 66, 67, 179, 180, 90, 99, 121, 135, + 122, 239, -59, 123, 95, 48, 68, 164, 136, 137, + 138, 199, 163, 169, 170, 185, 284, 108, 250, 55, + 190, 56, 57, 58, 59, 192, 232, 250, 139, 235, + 140, 243, 202, 203, 204, 141, 205, 206, 207, 208, + 209, 210, 211, 234, 236, 244, 60, 251, 61, 62, + 63, 64, 65, 66, 67, 245, 246, 248, 252, 253, + 256, 268, 255, 257, 2, 52, 263, 68, 258, 3, + 4, 212, 5, 6, 7, 8, 2, 271, 272, 273, + 275, 3, 4, 276, 5, 6, 7, 8, 277, 278, + 9, 55, 2, 56, 57, 58, 59, 3, 4, 279, + 5, 6, 7, 8, 280, 287, 288, 289, 291, 30, + 93, 166, 196, 157, 262, 193, 142, 231, 60, 171, + 61, 62, 63, 64, 65, 66, 67, 55, 0, 56, + 57, 58, 59, 168, 165, 0, 172, 0, 55, 68, + 56, 57, 58, 59, 0, 0, 0, 55, 0, 56, + 57, 58, 59, 0, 60, 0, 61, 62, 63, 64, + 65, 66, 67, 0, 0, 60, 0, 61, 62, 63, + 64, 65, 66, 67, 60, 68, 61, 62, 63, 64, + 65, 66, 67, 0, 0, 0, 109, 1, 2, 0, + 0, 0, 0, 3, 4, 116, 5, 6, 7, 8, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 10 +}; + +static const yytype_int16 yycheck[] = +{ + 42, 10, 54, 48, 9, 0, 48, 16, 23, 60, + 95, 100, 63, 64, 65, 66, 135, 12, 157, 4, + 139, 3, 17, 18, 9, 10, 68, 12, 13, 14, + 15, 3, 207, 101, 150, 28, 3, 4, 47, 214, + 29, 3, 9, 10, 3, 12, 13, 14, 15, 159, + 95, 45, 46, 95, 30, 248, 30, 167, 30, 148, + 49, 150, 55, 30, 3, 39, 40, 109, 243, 51, + 30, 30, 57, 68, 116, 51, 51, 53, 53, 51, + 196, 132, 133, 134, 51, 153, 53, 280, 263, 51, + 229, 53, 51, 102, 53, 156, 289, 102, 140, 0, + 275, 276, 277, 28, 279, 166, 101, 196, 39, 194, + 36, 37, 287, 118, 3, 157, 235, 28, 49, 170, + 28, 116, 51, 55, 53, 50, 4, 60, 61, 62, + 63, 64, 65, 66, 67, 13, 14, 15, 52, 50, + 149, 51, 50, 53, 159, 4, 155, 156, 28, 194, + 192, 156, 194, 49, 13, 14, 15, 202, 153, 49, + 202, 166, 41, 42, 43, 44, 49, 209, 126, 127, + 128, 129, 50, 124, 125, 4, 228, 49, 3, 49, + 5, 6, 7, 8, 13, 14, 15, 229, 49, 122, + 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, + 133, 134, 244, 245, 246, 30, 248, 32, 33, 34, + 35, 36, 37, 38, 130, 131, 3, 49, 54, 29, + 48, 50, 29, 47, 49, 29, 51, 28, 31, 32, + 33, 240, 52, 52, 52, 3, 278, 170, 280, 3, + 3, 5, 6, 7, 8, 29, 52, 289, 51, 28, + 53, 56, 16, 17, 18, 58, 20, 21, 22, 23, + 24, 25, 26, 52, 54, 51, 30, 55, 32, 33, + 34, 35, 36, 37, 38, 51, 51, 51, 55, 50, + 52, 21, 55, 52, 4, 49, 56, 51, 54, 9, + 10, 55, 12, 13, 14, 15, 4, 55, 52, 54, + 52, 9, 10, 52, 12, 13, 14, 15, 52, 51, + 30, 3, 4, 5, 6, 7, 8, 9, 10, 52, + 12, 13, 14, 15, 55, 19, 52, 55, 55, 12, + 47, 51, 148, 53, 240, 144, 89, 164, 30, 122, + 32, 33, 34, 35, 36, 37, 38, 3, -1, 5, + 6, 7, 8, 118, 116, -1, 123, -1, 3, 51, + 5, 6, 7, 8, -1, -1, -1, 3, -1, 5, + 6, 7, 8, -1, 30, -1, 32, 33, 34, 35, + 36, 37, 38, -1, -1, 30, -1, 32, 33, 34, + 35, 36, 37, 38, 30, 51, 32, 33, 34, 35, + 36, 37, 38, -1, -1, -1, 51, 3, 4, -1, + -1, -1, -1, 9, 10, 51, 12, 13, 14, 15, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, 30, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, 51 +}; + +/* YYSTOS[STATE-NUM] -- The symbol kind of the accessing symbol of + state STATE-NUM. */ +static const yytype_uint8 yystos[] = +{ + 0, 3, 4, 9, 10, 12, 13, 14, 15, 30, + 51, 60, 61, 62, 63, 68, 69, 70, 76, 77, + 82, 87, 93, 94, 95, 3, 89, 94, 93, 0, + 62, 71, 72, 73, 93, 69, 69, 3, 80, 65, + 95, 51, 53, 88, 49, 52, 55, 28, 29, 64, + 78, 49, 49, 108, 96, 3, 5, 6, 7, 8, + 30, 32, 33, 34, 35, 36, 37, 38, 51, 118, + 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, + 129, 130, 131, 132, 133, 134, 135, 136, 137, 49, + 3, 90, 91, 73, 93, 49, 74, 119, 108, 49, + 81, 109, 69, 97, 98, 99, 100, 134, 135, 51, + 135, 135, 134, 134, 134, 134, 51, 135, 69, 120, + 138, 54, 48, 47, 45, 46, 41, 42, 43, 44, + 36, 37, 30, 39, 40, 29, 31, 32, 33, 51, + 53, 58, 90, 92, 28, 50, 74, 75, 79, 76, + 83, 84, 66, 67, 68, 69, 51, 53, 93, 94, + 101, 102, 103, 52, 28, 138, 51, 94, 101, 52, + 52, 125, 126, 130, 130, 131, 131, 131, 131, 133, + 133, 134, 134, 134, 122, 3, 116, 117, 122, 120, + 3, 50, 29, 91, 28, 50, 83, 85, 86, 93, + 50, 84, 16, 17, 18, 20, 21, 22, 23, 24, + 25, 26, 55, 104, 105, 106, 107, 108, 110, 111, + 112, 115, 120, 68, 97, 102, 118, 103, 51, 53, + 57, 100, 52, 134, 52, 28, 54, 120, 74, 50, + 28, 55, 119, 56, 51, 51, 51, 106, 51, 114, + 120, 55, 55, 50, 106, 55, 52, 52, 54, 97, + 118, 122, 86, 56, 106, 120, 120, 120, 21, 113, + 114, 55, 52, 54, 106, 52, 52, 52, 51, 52, + 55, 106, 106, 106, 120, 106, 114, 19, 52, 55, + 106, 55, 114 +}; + +/* YYR1[RULE-NUM] -- Symbol kind of the left-hand side of rule RULE-NUM. */ +static const yytype_uint8 yyr1[] = +{ + 0, 59, 60, 61, 61, 62, 62, 64, 63, 65, + 63, 66, 66, 67, 67, 68, 69, 69, 69, 69, + 70, 70, 70, 71, 71, 72, 72, 73, 73, 74, + 74, 75, 75, 76, 76, 76, 78, 79, 77, 80, + 81, 77, 77, 82, 82, 83, 83, 84, 85, 85, + 86, 88, 87, 89, 87, 87, 90, 90, 91, 92, + 91, 93, 93, 94, 94, 95, 95, 95, 96, 95, + 97, 97, 98, 98, 99, 99, 100, 100, 101, 101, + 102, 102, 102, 103, 103, 103, 103, 103, 104, 104, + 105, 105, 106, 106, 106, 106, 106, 106, 107, 107, + 109, 108, 110, 110, 111, 111, 111, 112, 112, 112, + 113, 114, 114, 115, 115, 115, 116, 116, 117, 117, + 118, 118, 119, 120, 121, 122, 122, 123, 124, 124, + 125, 125, 126, 127, 128, 129, 129, 129, 130, 130, + 130, 130, 130, 131, 132, 132, 132, 133, 133, 133, + 133, 134, 134, 135, 135, 135, 135, 135, 135, 135, + 135, 135, 135, 136, 136, 136, 136, 136, 136, 136, + 137, 137, 137, 137, 137, 137, 138 +}; + +/* YYR2[RULE-NUM] -- Number of symbols on the right-hand side of rule RULE-NUM. */ +static const yytype_int8 yyr2[] = +{ + 0, 2, 1, 1, 2, 1, 1, 0, 4, 0, + 3, 0, 1, 1, 2, 3, 1, 1, 2, 2, + 1, 1, 1, 0, 1, 1, 3, 1, 3, 1, + 3, 1, 3, 1, 1, 1, 0, 0, 7, 0, + 0, 6, 2, 1, 1, 1, 2, 3, 1, 3, + 1, 0, 6, 0, 5, 2, 1, 3, 1, 0, + 4, 2, 1, 1, 2, 1, 3, 4, 0, 5, + 0, 1, 1, 3, 1, 3, 2, 2, 0, 1, + 1, 1, 2, 3, 3, 3, 4, 4, 0, 1, + 1, 2, 1, 1, 1, 1, 1, 1, 4, 3, + 0, 5, 1, 2, 5, 7, 5, 5, 7, 5, + 5, 0, 1, 3, 2, 2, 0, 1, 1, 3, + 0, 1, 1, 1, 1, 1, 3, 1, 1, 3, + 1, 3, 1, 1, 1, 1, 3, 3, 1, 3, + 3, 3, 3, 1, 1, 3, 3, 1, 3, 3, + 3, 1, 4, 1, 2, 2, 2, 2, 2, 2, + 2, 2, 4, 1, 4, 4, 3, 3, 2, 2, + 1, 1, 1, 1, 1, 3, 2 +}; + + +enum { YYENOMEM = -2 }; + +#define yyerrok (yyerrstatus = 0) +#define yyclearin (yychar = YYEMPTY) + +#define YYACCEPT goto yyacceptlab +#define YYABORT goto yyabortlab +#define YYERROR goto yyerrorlab +#define YYNOMEM goto yyexhaustedlab + + +#define YYRECOVERING() (!!yyerrstatus) + +#define YYBACKUP(Token, Value) \ + do \ + if (yychar == YYEMPTY) \ + { \ + yychar = (Token); \ + yylval = (Value); \ + YYPOPSTACK (yylen); \ + yystate = *yyssp; \ + goto yybackup; \ + } \ + else \ + { \ + yyerror (YY_("syntax error: cannot back up")); \ + YYERROR; \ + } \ + while (0) + +/* Backward compatibility with an undocumented macro. + Use YYerror or YYUNDEF. */ +#define YYERRCODE YYUNDEF + + +/* Enable debugging if requested. */ +#if YYDEBUG + +# ifndef YYFPRINTF +# include /* INFRINGES ON USER NAME SPACE */ +# define YYFPRINTF fprintf +# endif + +# define YYDPRINTF(Args) \ +do { \ + if (yydebug) \ + YYFPRINTF Args; \ +} while (0) + + + + +# define YY_SYMBOL_PRINT(Title, Kind, Value, Location) \ +do { \ + if (yydebug) \ + { \ + YYFPRINTF (stderr, "%s ", Title); \ + yy_symbol_print (stderr, \ + Kind, Value); \ + YYFPRINTF (stderr, "\n"); \ + } \ +} while (0) + + +/*-----------------------------------. +| Print this symbol's value on YYO. | +`-----------------------------------*/ + +static void +yy_symbol_value_print (FILE *yyo, + yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep) +{ + FILE *yyoutput = yyo; + YY_USE (yyoutput); + if (!yyvaluep) + return; + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN + YY_USE (yykind); + YY_IGNORE_MAYBE_UNINITIALIZED_END +} + + +/*---------------------------. +| Print this symbol on YYO. | +`---------------------------*/ + +static void +yy_symbol_print (FILE *yyo, + yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep) +{ + YYFPRINTF (yyo, "%s %s (", + yykind < YYNTOKENS ? "token" : "nterm", yysymbol_name (yykind)); + + yy_symbol_value_print (yyo, yykind, yyvaluep); + YYFPRINTF (yyo, ")"); +} + +/*------------------------------------------------------------------. +| yy_stack_print -- Print the state stack from its BOTTOM up to its | +| TOP (included). | +`------------------------------------------------------------------*/ + +static void +yy_stack_print (yy_state_t *yybottom, yy_state_t *yytop) +{ + YYFPRINTF (stderr, "Stack now"); + for (; yybottom <= yytop; yybottom++) + { + int yybot = *yybottom; + YYFPRINTF (stderr, " %d", yybot); + } + YYFPRINTF (stderr, "\n"); +} + +# define YY_STACK_PRINT(Bottom, Top) \ +do { \ + if (yydebug) \ + yy_stack_print ((Bottom), (Top)); \ +} while (0) + + +/*------------------------------------------------. +| Report that the YYRULE is going to be reduced. | +`------------------------------------------------*/ + +static void +yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp, + int yyrule) +{ + int yylno = yyrline[yyrule]; + int yynrhs = yyr2[yyrule]; + int yyi; + YYFPRINTF (stderr, "Reducing stack by rule %d (line %d):\n", + yyrule - 1, yylno); + /* The symbols being reduced. */ + for (yyi = 0; yyi < yynrhs; yyi++) + { + YYFPRINTF (stderr, " $%d = ", yyi + 1); + yy_symbol_print (stderr, + YY_ACCESSING_SYMBOL (+yyssp[yyi + 1 - yynrhs]), + &yyvsp[(yyi + 1) - (yynrhs)]); + YYFPRINTF (stderr, "\n"); + } +} + +# define YY_REDUCE_PRINT(Rule) \ +do { \ + if (yydebug) \ + yy_reduce_print (yyssp, yyvsp, Rule); \ +} while (0) + +/* Nonzero means print parse trace. It is left uninitialized so that + multiple parsers can coexist. */ +int yydebug; +#else /* !YYDEBUG */ +# define YYDPRINTF(Args) ((void) 0) +# define YY_SYMBOL_PRINT(Title, Kind, Value, Location) +# define YY_STACK_PRINT(Bottom, Top) +# define YY_REDUCE_PRINT(Rule) +#endif /* !YYDEBUG */ + + +/* YYINITDEPTH -- initial size of the parser's stacks. */ +#ifndef YYINITDEPTH +# define YYINITDEPTH 200 +#endif + +/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only + if the built-in stack extension method is used). + + Do not make this value too large; the results are undefined if + YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH) + evaluated with infinite-precision integer arithmetic. */ + +#ifndef YYMAXDEPTH +# define YYMAXDEPTH 10000 +#endif + + + + + + +/*-----------------------------------------------. +| Release the memory associated to this symbol. | +`-----------------------------------------------*/ + +static void +yydestruct (const char *yymsg, + yysymbol_kind_t yykind, YYSTYPE *yyvaluep) +{ + YY_USE (yyvaluep); + if (!yymsg) + yymsg = "Deleting"; + YY_SYMBOL_PRINT (yymsg, yykind, yyvaluep, yylocationp); + + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN + YY_USE (yykind); + YY_IGNORE_MAYBE_UNINITIALIZED_END +} + + +/* Lookahead token kind. */ +int yychar; + +/* The semantic value of the lookahead symbol. */ +YYSTYPE yylval; +/* Number of syntax errors so far. */ +int yynerrs; + + + + +/*----------. +| yyparse. | +`----------*/ + +int +yyparse (void) +{ + yy_state_fast_t yystate = 0; + /* Number of tokens to shift before error messages enabled. */ + int yyerrstatus = 0; + + /* Refer to the stacks through separate pointers, to allow yyoverflow + to reallocate them elsewhere. */ + + /* Their size. */ + YYPTRDIFF_T yystacksize = YYINITDEPTH; + + /* The state stack: array, bottom, top. */ + yy_state_t yyssa[YYINITDEPTH]; + yy_state_t *yyss = yyssa; + yy_state_t *yyssp = yyss; + + /* The semantic value stack: array, bottom, top. */ + YYSTYPE yyvsa[YYINITDEPTH]; + YYSTYPE *yyvs = yyvsa; + YYSTYPE *yyvsp = yyvs; + + int yyn; + /* The return value of yyparse. */ + int yyresult; + /* Lookahead symbol kind. */ + yysymbol_kind_t yytoken = YYSYMBOL_YYEMPTY; + /* The variables used to return semantic value and location from the + action routines. */ + YYSTYPE yyval; + + + +#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)) + + /* The number of symbols on the RHS of the reduced rule. + Keep to zero when no symbol should be popped. */ + int yylen = 0; + + YYDPRINTF ((stderr, "Starting parse\n")); + + yychar = YYEMPTY; /* Cause a token to be read. */ + + goto yysetstate; + + +/*------------------------------------------------------------. +| yynewstate -- push a new state, which is found in yystate. | +`------------------------------------------------------------*/ +yynewstate: + /* In all cases, when you get here, the value and location stacks + have just been pushed. So pushing a state here evens the stacks. */ + yyssp++; + + +/*--------------------------------------------------------------------. +| yysetstate -- set current state (the top of the stack) to yystate. | +`--------------------------------------------------------------------*/ +yysetstate: + YYDPRINTF ((stderr, "Entering state %d\n", yystate)); + YY_ASSERT (0 <= yystate && yystate < YYNSTATES); + YY_IGNORE_USELESS_CAST_BEGIN + *yyssp = YY_CAST (yy_state_t, yystate); + YY_IGNORE_USELESS_CAST_END + YY_STACK_PRINT (yyss, yyssp); + + if (yyss + yystacksize - 1 <= yyssp) +#if !defined yyoverflow && !defined YYSTACK_RELOCATE + YYNOMEM; +#else + { + /* Get the current used size of the three stacks, in elements. */ + YYPTRDIFF_T yysize = yyssp - yyss + 1; + +# if defined yyoverflow + { + /* Give user a chance to reallocate the stack. Use copies of + these so that the &'s don't force the real ones into + memory. */ + yy_state_t *yyss1 = yyss; + YYSTYPE *yyvs1 = yyvs; + + /* Each stack pointer address is followed by the size of the + data in use in that stack, in bytes. This used to be a + conditional around just the two extra args, but that might + be undefined if yyoverflow is a macro. */ + yyoverflow (YY_("memory exhausted"), + &yyss1, yysize * YYSIZEOF (*yyssp), + &yyvs1, yysize * YYSIZEOF (*yyvsp), + &yystacksize); + yyss = yyss1; + yyvs = yyvs1; + } +# else /* defined YYSTACK_RELOCATE */ + /* Extend the stack our own way. */ + if (YYMAXDEPTH <= yystacksize) + YYNOMEM; + yystacksize *= 2; + if (YYMAXDEPTH < yystacksize) + yystacksize = YYMAXDEPTH; + + { + yy_state_t *yyss1 = yyss; + union yyalloc *yyptr = + YY_CAST (union yyalloc *, + YYSTACK_ALLOC (YY_CAST (YYSIZE_T, YYSTACK_BYTES (yystacksize)))); + if (! yyptr) + YYNOMEM; + YYSTACK_RELOCATE (yyss_alloc, yyss); + YYSTACK_RELOCATE (yyvs_alloc, yyvs); +# undef YYSTACK_RELOCATE + if (yyss1 != yyssa) + YYSTACK_FREE (yyss1); + } +# endif + + yyssp = yyss + yysize - 1; + yyvsp = yyvs + yysize - 1; + + YY_IGNORE_USELESS_CAST_BEGIN + YYDPRINTF ((stderr, "Stack size increased to %ld\n", + YY_CAST (long, yystacksize))); + YY_IGNORE_USELESS_CAST_END + + if (yyss + yystacksize - 1 <= yyssp) + YYABORT; + } +#endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */ + + + if (yystate == YYFINAL) + YYACCEPT; + + goto yybackup; + + +/*-----------. +| yybackup. | +`-----------*/ +yybackup: + /* Do appropriate processing given the current state. Read a + lookahead token if we need one and don't already have one. */ + + /* First try to decide what to do without reference to lookahead token. */ + yyn = yypact[yystate]; + if (yypact_value_is_default (yyn)) + goto yydefault; + + /* Not known => get a lookahead token if don't already have one. */ + + /* YYCHAR is either empty, or end-of-input, or a valid lookahead. */ + if (yychar == YYEMPTY) + { + YYDPRINTF ((stderr, "Reading a token\n")); + yychar = yylex (); + } + + if (yychar <= YYEOF) + { + yychar = YYEOF; + yytoken = YYSYMBOL_YYEOF; + YYDPRINTF ((stderr, "Now at end of input.\n")); + } + else if (yychar == YYerror) + { + /* The scanner already issued an error message, process directly + to error recovery. But do not keep the error token as + lookahead, it is too special and may lead us to an endless + loop in error recovery. */ + yychar = YYUNDEF; + yytoken = YYSYMBOL_YYerror; + goto yyerrlab1; + } + else + { + yytoken = YYTRANSLATE (yychar); + YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); + } + + /* If the proper action on seeing token YYTOKEN is to reduce or to + detect an error, take that action. */ + yyn += yytoken; + if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken) + goto yydefault; + yyn = yytable[yyn]; + if (yyn <= 0) + { + if (yytable_value_is_error (yyn)) + goto yyerrlab; + yyn = -yyn; + goto yyreduce; + } + + /* Count tokens shifted since error; after three, turn off error + status. */ + if (yyerrstatus) + yyerrstatus--; + + /* Shift the lookahead token. */ + YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); + yystate = yyn; + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN + *++yyvsp = yylval; + YY_IGNORE_MAYBE_UNINITIALIZED_END + + /* Discard the shifted token. */ + yychar = YYEMPTY; + goto yynewstate; + + +/*-----------------------------------------------------------. +| yydefault -- do the default action for the current state. | +`-----------------------------------------------------------*/ +yydefault: + yyn = yydefact[yystate]; + if (yyn == 0) + goto yyerrlab; + goto yyreduce; + + +/*-----------------------------. +| yyreduce -- do a reduction. | +`-----------------------------*/ +yyreduce: + /* yyn is the number of a rule to reduce with. */ + yylen = yyr2[yyn]; + + /* If YYLEN is nonzero, implement the default value of the action: + '$$ = $1'. + + Otherwise, the following line sets YYVAL to garbage. + This behavior is undocumented and Bison + users should not rely upon it. Assigning to YYVAL + unconditionally makes the parser a bit smaller, and it avoids a + GCC warning that YYVAL may be used uninitialized. */ + yyval = yyvsp[1-yylen]; + + + YY_REDUCE_PRINT (yyn); + switch (yyn) + { + case 2: /* program: translation_unit */ +#line 30 "yacc.y" + {root = makeNode(N_PROGRAM, NIL, yyvsp[0], NIL); checkForwardReference();} +#line 1634 "y.tab.c" + break; + + case 3: /* translation_unit: external_declaration */ +#line 33 "yacc.y" + {yyval = yyvsp[0];} +#line 1640 "y.tab.c" + break; + + case 4: /* translation_unit: translation_unit external_declaration */ +#line 34 "yacc.y" + {yyval = linkDeclaratorList(yyvsp[-1], yyvsp[0]);} +#line 1646 "y.tab.c" + break; + + case 5: /* external_declaration: function_definition */ +#line 37 "yacc.y" + {yyval = yyvsp[0];} +#line 1652 "y.tab.c" + break; + + case 6: /* external_declaration: declaration */ +#line 38 "yacc.y" + {yyval = yyvsp[0];} +#line 1658 "y.tab.c" + break; + + case 7: /* @1: %empty */ +#line 41 "yacc.y" + {yyval = setFunctionDeclaratorSpecifier(yyvsp[0], yyvsp[-1]);} +#line 1664 "y.tab.c" + break; + + case 8: /* function_definition: declaration_specifiers declarator @1 compound_statement */ +#line 42 "yacc.y" + {yyval = setFunctionDeclaratorBody(yyvsp[-1], yyvsp[0]);} +#line 1670 "y.tab.c" + break; + + case 9: /* @2: %empty */ +#line 43 "yacc.y" + {yyval = setFunctionDeclaratorSpecifier(yyvsp[0], makeSpecifier(int_type, 0));} +#line 1676 "y.tab.c" + break; + + case 10: /* function_definition: declarator @2 compound_statement */ +#line 44 "yacc.y" + {yyval = setFunctionDeclaratorBody(yyvsp[-1], yyvsp[0]);} +#line 1682 "y.tab.c" + break; + + case 11: /* declaration_list_opt: %empty */ +#line 47 "yacc.y" + {yyval = NIL;} +#line 1688 "y.tab.c" + break; + + case 12: /* declaration_list_opt: declaration_list */ +#line 48 "yacc.y" + {yyval = yyvsp[0];} +#line 1694 "y.tab.c" + break; + + case 13: /* declaration_list: declaration */ +#line 51 "yacc.y" + {yyval = yyvsp[0];} +#line 1700 "y.tab.c" + break; + + case 14: /* declaration_list: declaration_list declaration */ +#line 52 "yacc.y" + {yyval = linkDeclaratorList(yyvsp[-1], yyvsp[0]);} +#line 1706 "y.tab.c" + break; + + case 15: /* declaration: declaration_specifiers init_declarator_list_opt SEMICOLON */ +#line 55 "yacc.y" + {yyval = setDeclaratorListSpecifier(yyvsp[-1], yyvsp[-2]);} +#line 1712 "y.tab.c" + break; + + case 16: /* declaration_specifiers: type_specifier */ +#line 58 "yacc.y" + {yyval = makeSpecifier(yyvsp[0], 0);} +#line 1718 "y.tab.c" + break; + + case 17: /* declaration_specifiers: storage_class_specifier */ +#line 59 "yacc.y" + {yyval = makeSpecifier(0, yyvsp[0]);} +#line 1724 "y.tab.c" + break; + + case 18: /* declaration_specifiers: type_specifier declaration_specifiers */ +#line 60 "yacc.y" + {yyval = updateSpecifier(yyvsp[0], yyvsp[-1], 0);} +#line 1730 "y.tab.c" + break; + + case 19: /* declaration_specifiers: storage_class_specifier declaration_specifiers */ +#line 61 "yacc.y" + {yyval = updateSpecifier(yyvsp[0], 0, yyvsp[-1]);} +#line 1736 "y.tab.c" + break; + + case 20: /* storage_class_specifier: AUTO_SYM */ +#line 64 "yacc.y" + {yyval = S_AUTO;} +#line 1742 "y.tab.c" + break; + + case 21: /* storage_class_specifier: STATIC_SYM */ +#line 65 "yacc.y" + {yyval = S_STATIC;} +#line 1748 "y.tab.c" + break; + + case 22: /* storage_class_specifier: TYPEDEF_SYM */ +#line 66 "yacc.y" + {yyval = S_TYPEDEF;} +#line 1754 "y.tab.c" + break; + + case 23: /* init_declarator_list_opt: %empty */ +#line 69 "yacc.y" + {yyval = makeDummyIdentifier();} +#line 1760 "y.tab.c" + break; + + case 24: /* init_declarator_list_opt: init_declarator_list */ +#line 70 "yacc.y" + {yyval = yyvsp[0];} +#line 1766 "y.tab.c" + break; + + case 25: /* init_declarator_list: init_declarator */ +#line 73 "yacc.y" + {yyval = yyvsp[0];} +#line 1772 "y.tab.c" + break; + + case 26: /* init_declarator_list: init_declarator_list COMMA init_declarator */ +#line 74 "yacc.y" + {yyval = linkDeclaratorList(yyvsp[-2], yyvsp[0]);} +#line 1778 "y.tab.c" + break; + + case 27: /* init_declarator: declarator */ +#line 77 "yacc.y" + {yyval = yyvsp[0];} +#line 1784 "y.tab.c" + break; + + case 28: /* init_declarator: declarator ASSIGN initializer */ +#line 78 "yacc.y" + {yyval = setDeclaratorInit(yyvsp[-2], yyvsp[0]);} +#line 1790 "y.tab.c" + break; + + case 29: /* initializer: constant_expression */ +#line 81 "yacc.y" + {yyval = makeNode(N_INIT_LIST_ONE, NIL, yyvsp[0], NIL);} +#line 1796 "y.tab.c" + break; + + case 30: /* initializer: LR initializer_list RR */ +#line 82 "yacc.y" + {yyval = yyvsp[-1];} +#line 1802 "y.tab.c" + break; + + case 31: /* initializer_list: initializer */ +#line 85 "yacc.y" + {yyval = makeNode(N_INIT_LIST, yyvsp[0], NIL, makeNode(N_INIT_LIST_NIL, NIL, NIL, NIL));} +#line 1808 "y.tab.c" + break; + + case 32: /* initializer_list: initializer_list COMMA initializer */ +#line 86 "yacc.y" + {yyval = makeNodeList(N_INIT_LIST, yyvsp[-2], yyvsp[0]);} +#line 1814 "y.tab.c" + break; + + case 33: /* type_specifier: struct_type_specifier */ +#line 89 "yacc.y" + {yyval = yyvsp[0];} +#line 1820 "y.tab.c" + break; + + case 34: /* type_specifier: enum_type_specifier */ +#line 90 "yacc.y" + {yyval = yyvsp[0];} +#line 1826 "y.tab.c" + break; + + case 35: /* type_specifier: TYPE_IDENTIFIER */ +#line 91 "yacc.y" + {yyval = yyvsp[0];} +#line 1832 "y.tab.c" + break; + + case 36: /* @3: %empty */ +#line 94 "yacc.y" + {yyval = setTypeStructOrEnumIdentifier(yyvsp[-1], yyvsp[0], ID_STRUCT);} +#line 1838 "y.tab.c" + break; + + case 37: /* @4: %empty */ +#line 95 "yacc.y" + {yyval = current_id; current_level++;} +#line 1844 "y.tab.c" + break; + + case 38: /* struct_type_specifier: struct_or_union IDENTIFIER @3 LR @4 struct_declaration_list RR */ +#line 96 "yacc.y" + {checkForwardReference(); yyval = setTypeField(yyvsp[-4], yyvsp[-1]); current_level--; current_id = yyvsp[-2];} +#line 1850 "y.tab.c" + break; + + case 39: /* @5: %empty */ +#line 97 "yacc.y" + {yyval = makeType(yyvsp[0]);} +#line 1856 "y.tab.c" + break; + + case 40: /* @6: %empty */ +#line 98 "yacc.y" + {yyval = current_id; current_level++;} +#line 1862 "y.tab.c" + break; + + case 41: /* struct_type_specifier: struct_or_union @5 LR @6 struct_declaration_list RR */ +#line 99 "yacc.y" + {checkForwardReference(); yyval = setTypeField(yyvsp[-4], yyvsp[-1]); current_level--; current_id = yyvsp[-2];} +#line 1868 "y.tab.c" + break; + + case 42: /* struct_type_specifier: struct_or_union IDENTIFIER */ +#line 100 "yacc.y" + {yyval = getTypeOfStructOrEnumRefIdentifier(yyvsp[-1], yyvsp[0], ID_STRUCT);} +#line 1874 "y.tab.c" + break; + + case 43: /* struct_or_union: STRUCT_SYM */ +#line 103 "yacc.y" + {yyval = T_STRUCT;} +#line 1880 "y.tab.c" + break; + + case 44: /* struct_or_union: UNION_SYM */ +#line 104 "yacc.y" + {yyval = T_UNION;} +#line 1886 "y.tab.c" + break; + + case 45: /* struct_declaration_list: struct_declaration */ +#line 107 "yacc.y" + {yyval = yyvsp[0];} +#line 1892 "y.tab.c" + break; + + case 46: /* struct_declaration_list: struct_declaration_list struct_declaration */ +#line 108 "yacc.y" + {yyval = linkDeclaratorList(yyvsp[-1], yyvsp[0]);} +#line 1898 "y.tab.c" + break; + + case 47: /* struct_declaration: type_specifier struct_declarator_list SEMICOLON */ +#line 111 "yacc.y" + {yyval = setStructDeclaratorListSpecifier(yyvsp[-1], yyvsp[-2]);} +#line 1904 "y.tab.c" + break; + + case 48: /* struct_declarator_list: struct_declarator */ +#line 114 "yacc.y" + {yyval = yyvsp[0];} +#line 1910 "y.tab.c" + break; + + case 49: /* struct_declarator_list: struct_declarator_list COMMA struct_declarator */ +#line 115 "yacc.y" + {yyval = linkDeclaratorList(yyvsp[-2], yyvsp[0]);} +#line 1916 "y.tab.c" + break; + + case 50: /* struct_declarator: declarator */ +#line 118 "yacc.y" + {yyval = yyvsp[0];} +#line 1922 "y.tab.c" + break; + + case 51: /* @7: %empty */ +#line 121 "yacc.y" + {yyval = setTypeStructOrEnumIdentifier(T_ENUM, yyvsp[0], ID_ENUM);} +#line 1928 "y.tab.c" + break; + + case 52: /* enum_type_specifier: ENUM_SYM IDENTIFIER @7 LR enumerator_list RR */ +#line 122 "yacc.y" + {yyval = setTypeField(yyvsp[-3], yyvsp[-1]);} +#line 1934 "y.tab.c" + break; + + case 53: /* @8: %empty */ +#line 123 "yacc.y" + {yyval = makeType(T_ENUM);} +#line 1940 "y.tab.c" + break; + + case 54: /* enum_type_specifier: ENUM_SYM @8 LR enumerator_list RR */ +#line 124 "yacc.y" + {yyval = setTypeField(yyvsp[-3], yyvsp[-1]);} +#line 1946 "y.tab.c" + break; + + case 55: /* enum_type_specifier: ENUM_SYM IDENTIFIER */ +#line 125 "yacc.y" + {yyval = getTypeOfStructOrEnumRefIdentifier(T_ENUM, yyvsp[0], ID_ENUM);} +#line 1952 "y.tab.c" + break; + + case 56: /* enumerator_list: enumerator */ +#line 128 "yacc.y" + {yyval = yyvsp[0];} +#line 1958 "y.tab.c" + break; + + case 57: /* enumerator_list: enumerator_list COMMA enumerator */ +#line 129 "yacc.y" + {yyval = linkDeclaratorList(yyvsp[-2], yyvsp[0]);} +#line 1964 "y.tab.c" + break; + + case 58: /* enumerator: IDENTIFIER */ +#line 132 "yacc.y" + {yyval = setDeclaratorKind(makeIdentifier(yyvsp[0]), ID_ENUM_LITERAL);} +#line 1970 "y.tab.c" + break; + + case 59: /* @9: %empty */ +#line 133 "yacc.y" + {yyval = setDeclaratorKind(makeIdentifier(yyvsp[0]), ID_ENUM_LITERAL);} +#line 1976 "y.tab.c" + break; + + case 60: /* enumerator: IDENTIFIER @9 ASSIGN expression */ +#line 134 "yacc.y" + {yyval = setDeclaratorInit(yyvsp[-2], yyvsp[0]);} +#line 1982 "y.tab.c" + break; + + case 61: /* declarator: pointer direct_declarator */ +#line 137 "yacc.y" + {yyval = setDeclaratorElementType(yyvsp[0], yyvsp[-1]);} +#line 1988 "y.tab.c" + break; + + case 62: /* declarator: direct_declarator */ +#line 138 "yacc.y" + {yyval = yyvsp[0];} +#line 1994 "y.tab.c" + break; + + case 63: /* pointer: STAR */ +#line 141 "yacc.y" + {yyval = makeType(T_POINTER);} +#line 2000 "y.tab.c" + break; + + case 64: /* pointer: STAR pointer */ +#line 142 "yacc.y" + {yyval = setTypeElementType(yyvsp[0], makeType(T_POINTER));} +#line 2006 "y.tab.c" + break; + + case 65: /* direct_declarator: IDENTIFIER */ +#line 145 "yacc.y" + {yyval = makeIdentifier(yyvsp[0]);} +#line 2012 "y.tab.c" + break; + + case 66: /* direct_declarator: LP declarator RP */ +#line 146 "yacc.y" + {yyval = yyvsp[-1];} +#line 2018 "y.tab.c" + break; + + case 67: /* direct_declarator: direct_declarator LB constant_expression_opt RB */ +#line 148 "yacc.y" + {yyval = setDeclaratorElementType(yyvsp[-3], setTypeExpr(makeType(T_ARRAY), yyvsp[-1]));} +#line 2024 "y.tab.c" + break; + + case 68: /* @10: %empty */ +#line 149 "yacc.y" + {yyval = current_id; current_level++;} +#line 2030 "y.tab.c" + break; + + case 69: /* direct_declarator: direct_declarator LP @10 parameter_type_list_opt RP */ +#line 151 "yacc.y" + {checkForwardReference(); current_id = yyvsp[-2]; current_level--; + yyval = setDeclaratorElementType(yyvsp[-4], setTypeField(makeType(T_FUNC), yyvsp[-1]));} +#line 2037 "y.tab.c" + break; + + case 70: /* parameter_type_list_opt: %empty */ +#line 155 "yacc.y" + {yyval = NIL;} +#line 2043 "y.tab.c" + break; + + case 71: /* parameter_type_list_opt: parameter_type_list */ +#line 156 "yacc.y" + {yyval = yyvsp[0];} +#line 2049 "y.tab.c" + break; + + case 72: /* parameter_type_list: parameter_list */ +#line 159 "yacc.y" + {yyval = yyvsp[0];} +#line 2055 "y.tab.c" + break; + + case 73: /* parameter_type_list: parameter_list COMMA DOTDOTDOT */ +#line 160 "yacc.y" + {yyval = linkDeclaratorList(yyvsp[-2], setDeclaratorKind(makeDummyIdentifier(), ID_PARM));} +#line 2061 "y.tab.c" + break; + + case 74: /* parameter_list: parameter_declaration */ +#line 163 "yacc.y" + {yyval = yyvsp[0];} +#line 2067 "y.tab.c" + break; + + case 75: /* parameter_list: parameter_list COMMA parameter_declaration */ +#line 164 "yacc.y" + {yyval = linkDeclaratorList(yyvsp[-2], yyvsp[0]);} +#line 2073 "y.tab.c" + break; + + case 76: /* parameter_declaration: declaration_specifiers declarator */ +#line 167 "yacc.y" + {yyval = setParameterDeclaratorSpecifier(yyvsp[0], yyvsp[-1]);} +#line 2079 "y.tab.c" + break; + + case 77: /* parameter_declaration: declaration_specifiers abstract_declarator_opt */ +#line 168 "yacc.y" + {yyval = setParameterDeclaratorSpecifier(setDeclaratorType(makeDummyIdentifier(), yyvsp[0]), yyvsp[-1]);} +#line 2085 "y.tab.c" + break; + + case 78: /* abstract_declarator_opt: %empty */ +#line 171 "yacc.y" + {yyval = NIL;} +#line 2091 "y.tab.c" + break; + + case 79: /* abstract_declarator_opt: abstract_declarator */ +#line 172 "yacc.y" + {yyval = yyvsp[0];} +#line 2097 "y.tab.c" + break; + + case 80: /* abstract_declarator: direct_abstract_declarator */ +#line 175 "yacc.y" + {yyval = yyvsp[0];} +#line 2103 "y.tab.c" + break; + + case 81: /* abstract_declarator: pointer */ +#line 176 "yacc.y" + {yyval = makeType(T_POINTER);} +#line 2109 "y.tab.c" + break; + + case 82: /* abstract_declarator: pointer direct_abstract_declarator */ +#line 177 "yacc.y" + {yyval = setTypeElementType(yyvsp[0], makeType(T_POINTER));} +#line 2115 "y.tab.c" + break; + + case 83: /* direct_abstract_declarator: LP abstract_declarator RP */ +#line 180 "yacc.y" + {yyval = yyvsp[-1];} +#line 2121 "y.tab.c" + break; + + case 84: /* direct_abstract_declarator: LB constant_expression_opt RB */ +#line 181 "yacc.y" + {yyval = setTypeExpr(makeType(T_ARRAY), yyvsp[-1]);} +#line 2127 "y.tab.c" + break; + + case 85: /* direct_abstract_declarator: LP parameter_type_list_opt RP */ +#line 182 "yacc.y" + {yyval = setTypeExpr(makeType(T_FUNC), yyvsp[-1]);} +#line 2133 "y.tab.c" + break; + + case 86: /* direct_abstract_declarator: direct_abstract_declarator LB constant_expression_opt RB */ +#line 183 "yacc.y" + {yyval = setTypeElementType(yyvsp[-3], setTypeExpr(makeType(T_ARRAY), yyvsp[-1]));} +#line 2139 "y.tab.c" + break; + + case 87: /* direct_abstract_declarator: direct_abstract_declarator LP parameter_type_list_opt RP */ +#line 184 "yacc.y" + {yyval = setTypeElementType(yyvsp[-3], setTypeExpr(makeType(T_FUNC), yyvsp[-1]));} +#line 2145 "y.tab.c" + break; + + case 88: /* statement_list_opt: %empty */ +#line 187 "yacc.y" + {yyval = makeNode(N_STMT_LIST_NIL, NIL, NIL, NIL);} +#line 2151 "y.tab.c" + break; + + case 89: /* statement_list_opt: statement_list */ +#line 188 "yacc.y" + {yyval = yyvsp[0];} +#line 2157 "y.tab.c" + break; + + case 90: /* statement_list: statement */ +#line 191 "yacc.y" + {yyval = makeNode(N_STMT_LIST, yyvsp[0], NIL, makeNode(N_STMT_LIST_NIL, NIL, NIL, NIL));} +#line 2163 "y.tab.c" + break; + + case 91: /* statement_list: statement_list statement */ +#line 192 "yacc.y" + {yyval = makeNodeList(N_STMT_LIST, yyvsp[-1], yyvsp[0]);} +#line 2169 "y.tab.c" + break; + + case 92: /* statement: labeled_statement */ +#line 195 "yacc.y" + {yyval = yyvsp[0];} +#line 2175 "y.tab.c" + break; + + case 93: /* statement: compound_statement */ +#line 196 "yacc.y" + {yyval = yyvsp[0];} +#line 2181 "y.tab.c" + break; + + case 94: /* statement: expression_statement */ +#line 197 "yacc.y" + {yyval = yyvsp[0];} +#line 2187 "y.tab.c" + break; + + case 95: /* statement: selection_statement */ +#line 198 "yacc.y" + {yyval = yyvsp[0];} +#line 2193 "y.tab.c" + break; + + case 96: /* statement: iteration_statement */ +#line 199 "yacc.y" + {yyval = yyvsp[0];} +#line 2199 "y.tab.c" + break; + + case 97: /* statement: jump_statement */ +#line 200 "yacc.y" + {yyval = yyvsp[0];} +#line 2205 "y.tab.c" + break; + + case 98: /* labeled_statement: CASE_SYM constant_expression COLON statement */ +#line 203 "yacc.y" + {yyval = makeNode(N_STMT_LABEL_CASE, yyvsp[-2], NIL, yyvsp[0]);} +#line 2211 "y.tab.c" + break; + + case 99: /* labeled_statement: DEFAULT_SYM COLON statement */ +#line 204 "yacc.y" + {yyval = makeNode(N_STMT_LABEL_DEFAULT, NIL, yyvsp[0], NIL);} +#line 2217 "y.tab.c" + break; + + case 100: /* @11: %empty */ +#line 207 "yacc.y" + {yyval = current_id; current_level++;} +#line 2223 "y.tab.c" + break; + + case 101: /* compound_statement: LR @11 declaration_list_opt statement_list_opt RR */ +#line 208 "yacc.y" + {checkForwardReference(); yyval = makeNode(N_STMT_COMPOUND, yyvsp[-2], NIL, yyvsp[-1]); current_id = yyvsp[-3]; current_level--;} +#line 2229 "y.tab.c" + break; + + case 102: /* expression_statement: SEMICOLON */ +#line 211 "yacc.y" + {yyval = makeNode(N_STMT_EMPTY, NIL, NIL, NIL);} +#line 2235 "y.tab.c" + break; + + case 103: /* expression_statement: expression SEMICOLON */ +#line 212 "yacc.y" + {yyval = makeNode(N_STMT_EXPRESSION, NIL, yyvsp[-1], NIL);} +#line 2241 "y.tab.c" + break; + + case 104: /* selection_statement: IF_SYM LP expression RP statement */ +#line 215 "yacc.y" + {yyval = makeNode(N_STMT_IF, yyvsp[-2], NIL, yyvsp[0]);} +#line 2247 "y.tab.c" + break; + + case 105: /* selection_statement: IF_SYM LP expression RP statement ELSE_SYM statement */ +#line 216 "yacc.y" + {yyval = makeNode(N_STMT_IF_ELSE, yyvsp[-4], yyvsp[-2], yyvsp[0]);} +#line 2253 "y.tab.c" + break; + + case 106: /* selection_statement: SWITCH_SYM LP expression RP statement */ +#line 217 "yacc.y" + {yyval = makeNode(N_STMT_SWITCH, yyvsp[-2], NIL, yyvsp[0]);} +#line 2259 "y.tab.c" + break; + + case 107: /* iteration_statement: WHILE_SYM LP expression RP statement */ +#line 220 "yacc.y" + {yyval = makeNode(N_STMT_WHILE, yyvsp[-2], NIL, yyvsp[0]);} +#line 2265 "y.tab.c" + break; + + case 108: /* iteration_statement: DO_SYM statement WHILE_SYM LP expression RP SEMICOLON */ +#line 221 "yacc.y" + {yyval = makeNode(N_STMT_DO, yyvsp[-5], NIL, yyvsp[-2]);} +#line 2271 "y.tab.c" + break; + + case 109: /* iteration_statement: FOR_SYM LP for_expression RP statement */ +#line 222 "yacc.y" + {yyval = makeNode(N_STMT_FOR, yyvsp[-2], NIL, yyvsp[0]);} +#line 2277 "y.tab.c" + break; + + case 110: /* for_expression: expression_opt SEMICOLON expression_opt SEMICOLON expression_opt */ +#line 225 "yacc.y" + {yyval = makeNode(N_FOR_EXP, yyvsp[-4], yyvsp[-2], yyvsp[0]);} +#line 2283 "y.tab.c" + break; + + case 111: /* expression_opt: %empty */ +#line 228 "yacc.y" + {yyval = NIL;} +#line 2289 "y.tab.c" + break; + + case 112: /* expression_opt: expression */ +#line 229 "yacc.y" + {yyval = yyvsp[0];} +#line 2295 "y.tab.c" + break; + + case 113: /* jump_statement: RETURN_SYM expression_opt SEMICOLON */ +#line 232 "yacc.y" + {yyval = makeNode(N_STMT_RETURN, NIL, yyvsp[-1], NIL);} +#line 2301 "y.tab.c" + break; + + case 114: /* jump_statement: CONTINUE_SYM SEMICOLON */ +#line 233 "yacc.y" + {yyval = makeNode(N_STMT_CONTINUE, NIL, NIL, NIL);} +#line 2307 "y.tab.c" + break; + + case 115: /* jump_statement: BREAK_SYM SEMICOLON */ +#line 234 "yacc.y" + {yyval = makeNode(N_STMT_BREAK, NIL, NIL, NIL);} +#line 2313 "y.tab.c" + break; + + case 116: /* arg_expression_list_opt: %empty */ +#line 237 "yacc.y" + {yyval = makeNode(N_ARG_LIST_NIL, NIL, NIL, NIL);} +#line 2319 "y.tab.c" + break; + + case 117: /* arg_expression_list_opt: arg_expression_list */ +#line 238 "yacc.y" + {yyval = yyvsp[0];} +#line 2325 "y.tab.c" + break; + + case 118: /* arg_expression_list: assignment_expression */ +#line 242 "yacc.y" + {yyval = makeNode(N_ARG_LIST, yyvsp[0], NIL, makeNode(N_ARG_LIST_NIL, NIL, NIL, NIL));} +#line 2331 "y.tab.c" + break; + + case 119: /* arg_expression_list: arg_expression_list COMMA assignment_expression */ +#line 244 "yacc.y" + {yyval = makeNodeList(N_ARG_LIST, yyvsp[-2], yyvsp[0]);} +#line 2337 "y.tab.c" + break; + + case 120: /* constant_expression_opt: %empty */ +#line 247 "yacc.y" + {yyval = NIL;} +#line 2343 "y.tab.c" + break; + + case 121: /* constant_expression_opt: constant_expression */ +#line 248 "yacc.y" + {yyval = yyvsp[0];} +#line 2349 "y.tab.c" + break; + + case 122: /* constant_expression: expression */ +#line 251 "yacc.y" + {yyval = yyvsp[0];} +#line 2355 "y.tab.c" + break; + + case 123: /* expression: comma_expression */ +#line 254 "yacc.y" + {yyval = yyvsp[0];} +#line 2361 "y.tab.c" + break; + + case 124: /* comma_expression: assignment_expression */ +#line 257 "yacc.y" + {yyval = yyvsp[0];} +#line 2367 "y.tab.c" + break; + + case 125: /* assignment_expression: conditional_expression */ +#line 260 "yacc.y" + {yyval = yyvsp[0];} +#line 2373 "y.tab.c" + break; + + case 126: /* assignment_expression: unary_expression ASSIGN assignment_expression */ +#line 261 "yacc.y" + {yyval = makeNode(N_EXP_ASSIGN, yyvsp[-2], NIL, yyvsp[0]);} +#line 2379 "y.tab.c" + break; + + case 127: /* conditional_expression: logical_OR_expression */ +#line 264 "yacc.y" + {yyval = yyvsp[0];} +#line 2385 "y.tab.c" + break; + + case 128: /* logical_OR_expression: logical_AND_expression */ +#line 267 "yacc.y" + {yyval = yyvsp[0];} +#line 2391 "y.tab.c" + break; + + case 129: /* logical_OR_expression: logical_OR_expression BARBAR logical_AND_expression */ +#line 269 "yacc.y" + {yyval = makeNode(N_EXP_OR, yyvsp[-2], NIL, yyvsp[0]);} +#line 2397 "y.tab.c" + break; + + case 130: /* logical_AND_expression: bitwise_or_expression */ +#line 272 "yacc.y" + {yyval = yyvsp[0];} +#line 2403 "y.tab.c" + break; + + case 131: /* logical_AND_expression: logical_AND_expression AMPAMP bitwise_or_expression */ +#line 274 "yacc.y" + {yyval = makeNode(N_EXP_AND, yyvsp[-2], NIL, yyvsp[0]);} +#line 2409 "y.tab.c" + break; + + case 132: /* bitwise_or_expression: bitwise_xor_expression */ +#line 277 "yacc.y" + {yyval = yyvsp[0];} +#line 2415 "y.tab.c" + break; + + case 133: /* bitwise_xor_expression: bitwise_and_expression */ +#line 280 "yacc.y" + {yyval = yyvsp[0];} +#line 2421 "y.tab.c" + break; + + case 134: /* bitwise_and_expression: equality_expression */ +#line 283 "yacc.y" + {yyval = yyvsp[0];} +#line 2427 "y.tab.c" + break; + + case 135: /* equality_expression: relational_expression */ +#line 286 "yacc.y" + {yyval = yyvsp[0];} +#line 2433 "y.tab.c" + break; + + case 136: /* equality_expression: equality_expression EQL relational_expression */ +#line 287 "yacc.y" + {yyval = makeNode(N_EXP_EQL, yyvsp[-2], NIL, yyvsp[0]);} +#line 2439 "y.tab.c" + break; + + case 137: /* equality_expression: equality_expression NEQ relational_expression */ +#line 288 "yacc.y" + {yyval = makeNode(N_EXP_NEQ, yyvsp[-2], NIL, yyvsp[0]);} +#line 2445 "y.tab.c" + break; + + case 138: /* relational_expression: shift_expression */ +#line 291 "yacc.y" + {yyval = yyvsp[0];} +#line 2451 "y.tab.c" + break; + + case 139: /* relational_expression: relational_expression LSS shift_expression */ +#line 292 "yacc.y" + {yyval = makeNode(N_EXP_LSS, yyvsp[-2], NIL, yyvsp[0]);} +#line 2457 "y.tab.c" + break; + + case 140: /* relational_expression: relational_expression GTR shift_expression */ +#line 293 "yacc.y" + {yyval = makeNode(N_EXP_GTR, yyvsp[-2], NIL, yyvsp[0]);} +#line 2463 "y.tab.c" + break; + + case 141: /* relational_expression: relational_expression LEQ shift_expression */ +#line 294 "yacc.y" + {yyval = makeNode(N_EXP_LEQ, yyvsp[-2], NIL, yyvsp[0]);} +#line 2469 "y.tab.c" + break; + + case 142: /* relational_expression: relational_expression GEQ shift_expression */ +#line 295 "yacc.y" + {yyval = makeNode(N_EXP_GEQ, yyvsp[-2], NIL, yyvsp[0]);} +#line 2475 "y.tab.c" + break; + + case 143: /* shift_expression: additive_expression */ +#line 298 "yacc.y" + {yyval = yyvsp[0];} +#line 2481 "y.tab.c" + break; + + case 144: /* additive_expression: multiplicative_expression */ +#line 301 "yacc.y" + {yyval = yyvsp[0];} +#line 2487 "y.tab.c" + break; + + case 145: /* additive_expression: additive_expression PLUS multiplicative_expression */ +#line 302 "yacc.y" + {yyval = makeNode(N_EXP_ADD, yyvsp[-2], NIL, yyvsp[0]);} +#line 2493 "y.tab.c" + break; + + case 146: /* additive_expression: additive_expression MINUS multiplicative_expression */ +#line 303 "yacc.y" + {yyval = makeNode(N_EXP_SUB, yyvsp[-2], NIL, yyvsp[0]);} +#line 2499 "y.tab.c" + break; + + case 147: /* multiplicative_expression: cast_expression */ +#line 306 "yacc.y" + {yyval = yyvsp[0];} +#line 2505 "y.tab.c" + break; + + case 148: /* multiplicative_expression: multiplicative_expression STAR cast_expression */ +#line 307 "yacc.y" + {yyval = makeNode(N_EXP_MUL, yyvsp[-2], NIL, yyvsp[0]);} +#line 2511 "y.tab.c" + break; + + case 149: /* multiplicative_expression: multiplicative_expression SLASH cast_expression */ +#line 308 "yacc.y" + {yyval = makeNode(N_EXP_DIV, yyvsp[-2], NIL, yyvsp[0]);} +#line 2517 "y.tab.c" + break; + + case 150: /* multiplicative_expression: multiplicative_expression PERCENT cast_expression */ +#line 309 "yacc.y" + {yyval = makeNode(N_EXP_MOD, yyvsp[-2], NIL, yyvsp[0]);} +#line 2523 "y.tab.c" + break; + + case 151: /* cast_expression: unary_expression */ +#line 312 "yacc.y" + {yyval = yyvsp[0];} +#line 2529 "y.tab.c" + break; + + case 152: /* cast_expression: LP type_name RP cast_expression */ +#line 313 "yacc.y" + {yyval = makeNode(N_EXP_CAST, yyvsp[-2], NIL, yyvsp[0]);} +#line 2535 "y.tab.c" + break; + + case 153: /* unary_expression: postfix_expression */ +#line 316 "yacc.y" + {yyval = yyvsp[0];} +#line 2541 "y.tab.c" + break; + + case 154: /* unary_expression: PLUSPLUS unary_expression */ +#line 317 "yacc.y" + {yyval = makeNode(N_EXP_PRE_INC, NIL, yyvsp[0], NIL);} +#line 2547 "y.tab.c" + break; + + case 155: /* unary_expression: MINUSMINUS unary_expression */ +#line 318 "yacc.y" + {yyval = makeNode(N_EXP_PRE_DEC, NIL, yyvsp[0], NIL);} +#line 2553 "y.tab.c" + break; + + case 156: /* unary_expression: AMP cast_expression */ +#line 319 "yacc.y" + {yyval = makeNode(N_EXP_AMP, NIL, yyvsp[0], NIL);} +#line 2559 "y.tab.c" + break; + + case 157: /* unary_expression: STAR cast_expression */ +#line 320 "yacc.y" + {yyval = makeNode(N_EXP_STAR, NIL, yyvsp[0], NIL);} +#line 2565 "y.tab.c" + break; + + case 158: /* unary_expression: EXCL cast_expression */ +#line 321 "yacc.y" + {yyval = makeNode(N_EXP_NOT, NIL, yyvsp[0], NIL);} +#line 2571 "y.tab.c" + break; + + case 159: /* unary_expression: MINUS cast_expression */ +#line 322 "yacc.y" + {yyval = makeNode(N_EXP_MINUS, NIL, yyvsp[0], NIL);} +#line 2577 "y.tab.c" + break; + + case 160: /* unary_expression: PLUS cast_expression */ +#line 323 "yacc.y" + {yyval = makeNode(N_EXP_PLUS, NIL, yyvsp[0], NIL);} +#line 2583 "y.tab.c" + break; + + case 161: /* unary_expression: SIZEOF_SYM unary_expression */ +#line 324 "yacc.y" + {yyval = makeNode(N_EXP_SIZE_EXP, NIL, yyvsp[0], NIL);} +#line 2589 "y.tab.c" + break; + + case 162: /* unary_expression: SIZEOF_SYM LP type_name RP */ +#line 325 "yacc.y" + {yyval = makeNode(N_EXP_SIZE_TYPE, NIL, yyvsp[-1], NIL);} +#line 2595 "y.tab.c" + break; + + case 163: /* postfix_expression: primary_expression */ +#line 328 "yacc.y" + {yyval = yyvsp[0];} +#line 2601 "y.tab.c" + break; + + case 164: /* postfix_expression: postfix_expression LB expression RB */ +#line 329 "yacc.y" + {yyval = makeNode(N_EXP_ARRAY, yyvsp[-3], NIL, yyvsp[-1]);} +#line 2607 "y.tab.c" + break; + + case 165: /* postfix_expression: postfix_expression LP arg_expression_list_opt RP */ +#line 331 "yacc.y" + {yyval = makeNode(N_EXP_FUNCTION_CALL, yyvsp[-3], NIL, yyvsp[-1]);} +#line 2613 "y.tab.c" + break; + + case 166: /* postfix_expression: postfix_expression PERIOD IDENTIFIER */ +#line 332 "yacc.y" + {yyval = makeNode(N_EXP_STRUCT, yyvsp[-2], NIL, yyvsp[0]);} +#line 2619 "y.tab.c" + break; + + case 167: /* postfix_expression: postfix_expression ARROW IDENTIFIER */ +#line 333 "yacc.y" + {yyval = makeNode(N_EXP_ARROW, yyvsp[-2], NIL, yyvsp[0]);} +#line 2625 "y.tab.c" + break; + + case 168: /* postfix_expression: postfix_expression PLUSPLUS */ +#line 334 "yacc.y" + {yyval = makeNode(N_EXP_POST_INC, NIL, yyvsp[-1], NIL);} +#line 2631 "y.tab.c" + break; + + case 169: /* postfix_expression: postfix_expression MINUSMINUS */ +#line 335 "yacc.y" + {yyval = makeNode(N_EXP_POST_DEC, NIL, yyvsp[-1], NIL);} +#line 2637 "y.tab.c" + break; + + case 170: /* primary_expression: IDENTIFIER */ +#line 338 "yacc.y" + {yyval = makeNode(N_EXP_IDENT, NIL, getIdentifierDeclared(yyvsp[0]), NIL);} +#line 2643 "y.tab.c" + break; + + case 171: /* primary_expression: INTEGER_CONSTANT */ +#line 339 "yacc.y" + {yyval = makeNode(N_EXP_INT_CONST, NIL, yyvsp[0], NIL);} +#line 2649 "y.tab.c" + break; + + case 172: /* primary_expression: FLOAT_CONSTANT */ +#line 340 "yacc.y" + {yyval = makeNode(N_EXP_FLOAT_CONST, NIL, yyvsp[0], NIL);} +#line 2655 "y.tab.c" + break; + + case 173: /* primary_expression: CHARACTER_CONSTANT */ +#line 341 "yacc.y" + {yyval = makeNode(N_EXP_CHAR_CONST, NIL, yyvsp[0], NIL);} +#line 2661 "y.tab.c" + break; + + case 174: /* primary_expression: STRING_LITERAL */ +#line 342 "yacc.y" + {yyval = makeNode(N_EXP_STRING_LITERAL, NIL, yyvsp[0], NIL);} +#line 2667 "y.tab.c" + break; + + case 175: /* primary_expression: LP expression RP */ +#line 343 "yacc.y" + {yyval = yyvsp[-1];} +#line 2673 "y.tab.c" + break; + + case 176: /* type_name: declaration_specifiers abstract_declarator_opt */ +#line 347 "yacc.y" + {yyval = setTypeNameSpecifier(yyvsp[0], yyvsp[-1]);} +#line 2679 "y.tab.c" + break; + + +#line 2683 "y.tab.c" + + default: break; + } + /* User semantic actions sometimes alter yychar, and that requires + that yytoken be updated with the new translation. We take the + approach of translating immediately before every use of yytoken. + One alternative is translating here after every semantic action, + but that translation would be missed if the semantic action invokes + YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or + if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an + incorrect destructor might then be invoked immediately. In the + case of YYERROR or YYBACKUP, subsequent parser actions might lead + to an incorrect destructor call or verbose syntax error message + before the lookahead is translated. */ + YY_SYMBOL_PRINT ("-> $$ =", YY_CAST (yysymbol_kind_t, yyr1[yyn]), &yyval, &yyloc); + + YYPOPSTACK (yylen); + yylen = 0; + + *++yyvsp = yyval; + + /* Now 'shift' the result of the reduction. Determine what state + that goes to, based on the state we popped back to and the rule + number reduced by. */ + { + const int yylhs = yyr1[yyn] - YYNTOKENS; + const int yyi = yypgoto[yylhs] + *yyssp; + yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyssp + ? yytable[yyi] + : yydefgoto[yylhs]); + } + + goto yynewstate; + + +/*--------------------------------------. +| yyerrlab -- here on detecting error. | +`--------------------------------------*/ +yyerrlab: + /* Make sure we have latest lookahead translation. See comments at + user semantic actions for why this is necessary. */ + yytoken = yychar == YYEMPTY ? YYSYMBOL_YYEMPTY : YYTRANSLATE (yychar); + /* If not already recovering from an error, report this error. */ + if (!yyerrstatus) + { + ++yynerrs; + yyerror (YY_("syntax error")); + } + + if (yyerrstatus == 3) + { + /* If just tried and failed to reuse lookahead token after an + error, discard it. */ + + if (yychar <= YYEOF) + { + /* Return failure if at end of input. */ + if (yychar == YYEOF) + YYABORT; + } + else + { + yydestruct ("Error: discarding", + yytoken, &yylval); + yychar = YYEMPTY; + } + } + + /* Else will try to reuse lookahead token after shifting the error + token. */ + goto yyerrlab1; + + +/*---------------------------------------------------. +| yyerrorlab -- error raised explicitly by YYERROR. | +`---------------------------------------------------*/ +yyerrorlab: + /* Pacify compilers when the user code never invokes YYERROR and the + label yyerrorlab therefore never appears in user code. */ + if (0) + YYERROR; + ++yynerrs; + + /* Do not reclaim the symbols of the rule whose action triggered + this YYERROR. */ + YYPOPSTACK (yylen); + yylen = 0; + YY_STACK_PRINT (yyss, yyssp); + yystate = *yyssp; + goto yyerrlab1; + + +/*-------------------------------------------------------------. +| yyerrlab1 -- common code for both syntax error and YYERROR. | +`-------------------------------------------------------------*/ +yyerrlab1: + yyerrstatus = 3; /* Each real token shifted decrements this. */ + + /* Pop stack until we find a state that shifts the error token. */ + for (;;) + { + yyn = yypact[yystate]; + if (!yypact_value_is_default (yyn)) + { + yyn += YYSYMBOL_YYerror; + if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYSYMBOL_YYerror) + { + yyn = yytable[yyn]; + if (0 < yyn) + break; + } + } + + /* Pop the current state because it cannot handle the error token. */ + if (yyssp == yyss) + YYABORT; + + + yydestruct ("Error: popping", + YY_ACCESSING_SYMBOL (yystate), yyvsp); + YYPOPSTACK (1); + yystate = *yyssp; + YY_STACK_PRINT (yyss, yyssp); + } + + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN + *++yyvsp = yylval; + YY_IGNORE_MAYBE_UNINITIALIZED_END + + + /* Shift the error token. */ + YY_SYMBOL_PRINT ("Shifting", YY_ACCESSING_SYMBOL (yyn), yyvsp, yylsp); + + yystate = yyn; + goto yynewstate; + + +/*-------------------------------------. +| yyacceptlab -- YYACCEPT comes here. | +`-------------------------------------*/ +yyacceptlab: + yyresult = 0; + goto yyreturnlab; + + +/*-----------------------------------. +| yyabortlab -- YYABORT comes here. | +`-----------------------------------*/ +yyabortlab: + yyresult = 1; + goto yyreturnlab; + + +/*-----------------------------------------------------------. +| yyexhaustedlab -- YYNOMEM (memory exhaustion) comes here. | +`-----------------------------------------------------------*/ +yyexhaustedlab: + yyerror (YY_("memory exhausted")); + yyresult = 2; + goto yyreturnlab; + + +/*----------------------------------------------------------. +| yyreturnlab -- parsing is finished, clean up and return. | +`----------------------------------------------------------*/ +yyreturnlab: + if (yychar != YYEMPTY) + { + /* Make sure we have latest lookahead translation. See comments at + user semantic actions for why this is necessary. */ + yytoken = YYTRANSLATE (yychar); + yydestruct ("Cleanup: discarding lookahead", + yytoken, &yylval); + } + /* Do not reclaim the symbols of the rule whose action triggered + this YYABORT or YYACCEPT. */ + YYPOPSTACK (yylen); + YY_STACK_PRINT (yyss, yyssp); + while (yyssp != yyss) + { + yydestruct ("Cleanup: popping", + YY_ACCESSING_SYMBOL (+*yyssp), yyvsp); + YYPOPSTACK (1); + } +#ifndef yyoverflow + if (yyss != yyssa) + YYSTACK_FREE (yyss); +#endif + + return yyresult; +} + +#line 349 "yacc.y" + +extern char *yytext; +yyerror(char *s) +{ + syntax_err++; + printf("line %d: %s near %s\n", line_no, s, yytext); +} +int yywrap() { + return (1); +} diff --git a/08-code-generator/y.tab.h b/08-code-generator/y.tab.h new file mode 100644 index 0000000..3b94f21 --- /dev/null +++ b/08-code-generator/y.tab.h @@ -0,0 +1,192 @@ +/* A Bison parser, made by GNU Bison 3.8.2. */ + +/* Bison interface for Yacc-like parsers in C + + Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 Free Software Foundation, + Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* As a special exception, you may create a larger work that contains + part or all of the Bison parser skeleton and distribute that work + under terms of your choice, so long as that work isn't itself a + parser generator using the skeleton or a modified version thereof + as a parser skeleton. Alternatively, if you modify or redistribute + the parser skeleton itself, you may (at your option) remove this + special exception, which will cause the skeleton and the resulting + Bison output files to be licensed under the GNU General Public + License without this special exception. + + This special exception was added by the Free Software Foundation in + version 2.2 of Bison. */ + +/* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual, + especially those whose name start with YY_ or yy_. They are + private implementation details that can be changed or removed. */ + +#ifndef YY_YY_Y_TAB_H_INCLUDED +# define YY_YY_Y_TAB_H_INCLUDED +/* Debug traces. */ +#ifndef YYDEBUG +# define YYDEBUG 0 +#endif +#if YYDEBUG +extern int yydebug; +#endif + +/* Token kinds. */ +#ifndef YYTOKENTYPE +# define YYTOKENTYPE + enum yytokentype + { + YYEMPTY = -2, + YYEOF = 0, /* "end of file" */ + YYerror = 256, /* error */ + YYUNDEF = 257, /* "invalid token" */ + IDENTIFIER = 258, /* IDENTIFIER */ + TYPE_IDENTIFIER = 259, /* TYPE_IDENTIFIER */ + INTEGER_CONSTANT = 260, /* INTEGER_CONSTANT */ + FLOAT_CONSTANT = 261, /* FLOAT_CONSTANT */ + CHARACTER_CONSTANT = 262, /* CHARACTER_CONSTANT */ + STRING_LITERAL = 263, /* STRING_LITERAL */ + AUTO_SYM = 264, /* AUTO_SYM */ + STATIC_SYM = 265, /* STATIC_SYM */ + CONST_SYM = 266, /* CONST_SYM */ + TYPEDEF_SYM = 267, /* TYPEDEF_SYM */ + STRUCT_SYM = 268, /* STRUCT_SYM */ + UNION_SYM = 269, /* UNION_SYM */ + ENUM_SYM = 270, /* ENUM_SYM */ + CASE_SYM = 271, /* CASE_SYM */ + DEFAULT_SYM = 272, /* DEFAULT_SYM */ + IF_SYM = 273, /* IF_SYM */ + ELSE_SYM = 274, /* ELSE_SYM */ + SWITCH_SYM = 275, /* SWITCH_SYM */ + WHILE_SYM = 276, /* WHILE_SYM */ + DO_SYM = 277, /* DO_SYM */ + FOR_SYM = 278, /* FOR_SYM */ + RETURN_SYM = 279, /* RETURN_SYM */ + CONTINUE_SYM = 280, /* CONTINUE_SYM */ + BREAK_SYM = 281, /* BREAK_SYM */ + GOTO_SYM = 282, /* GOTO_SYM */ + COMMA = 283, /* COMMA */ + ASSIGN = 284, /* ASSIGN */ + STAR = 285, /* STAR */ + ARROW = 286, /* ARROW */ + PLUSPLUS = 287, /* PLUSPLUS */ + MINUSMINUS = 288, /* MINUSMINUS */ + AMP = 289, /* AMP */ + EXCL = 290, /* EXCL */ + MINUS = 291, /* MINUS */ + PLUS = 292, /* PLUS */ + SIZEOF_SYM = 293, /* SIZEOF_SYM */ + SLASH = 294, /* SLASH */ + PERCENT = 295, /* PERCENT */ + LSS = 296, /* LSS */ + GTR = 297, /* GTR */ + LEQ = 298, /* LEQ */ + GEQ = 299, /* GEQ */ + EQL = 300, /* EQL */ + NEQ = 301, /* NEQ */ + AMPAMP = 302, /* AMPAMP */ + BARBAR = 303, /* BARBAR */ + LR = 304, /* LR */ + RR = 305, /* RR */ + LP = 306, /* LP */ + RP = 307, /* RP */ + LB = 308, /* LB */ + RB = 309, /* RB */ + SEMICOLON = 310, /* SEMICOLON */ + COLON = 311, /* COLON */ + DOTDOTDOT = 312, /* DOTDOTDOT */ + PERIOD = 313 /* PERIOD */ + }; + typedef enum yytokentype yytoken_kind_t; +#endif +/* Token kinds. */ +#define YYEMPTY -2 +#define YYEOF 0 +#define YYerror 256 +#define YYUNDEF 257 +#define IDENTIFIER 258 +#define TYPE_IDENTIFIER 259 +#define INTEGER_CONSTANT 260 +#define FLOAT_CONSTANT 261 +#define CHARACTER_CONSTANT 262 +#define STRING_LITERAL 263 +#define AUTO_SYM 264 +#define STATIC_SYM 265 +#define CONST_SYM 266 +#define TYPEDEF_SYM 267 +#define STRUCT_SYM 268 +#define UNION_SYM 269 +#define ENUM_SYM 270 +#define CASE_SYM 271 +#define DEFAULT_SYM 272 +#define IF_SYM 273 +#define ELSE_SYM 274 +#define SWITCH_SYM 275 +#define WHILE_SYM 276 +#define DO_SYM 277 +#define FOR_SYM 278 +#define RETURN_SYM 279 +#define CONTINUE_SYM 280 +#define BREAK_SYM 281 +#define GOTO_SYM 282 +#define COMMA 283 +#define ASSIGN 284 +#define STAR 285 +#define ARROW 286 +#define PLUSPLUS 287 +#define MINUSMINUS 288 +#define AMP 289 +#define EXCL 290 +#define MINUS 291 +#define PLUS 292 +#define SIZEOF_SYM 293 +#define SLASH 294 +#define PERCENT 295 +#define LSS 296 +#define GTR 297 +#define LEQ 298 +#define GEQ 299 +#define EQL 300 +#define NEQ 301 +#define AMPAMP 302 +#define BARBAR 303 +#define LR 304 +#define RR 305 +#define LP 306 +#define RP 307 +#define LB 308 +#define RB 309 +#define SEMICOLON 310 +#define COLON 311 +#define DOTDOTDOT 312 +#define PERIOD 313 + +/* Value type. */ +#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED +typedef int YYSTYPE; +# define YYSTYPE_IS_TRIVIAL 1 +# define YYSTYPE_IS_DECLARED 1 +#endif + + +extern YYSTYPE yylval; + + +int yyparse (void); + + +#endif /* !YY_YY_Y_TAB_H_INCLUDED */ diff --git a/08-code-generator/yacc.y b/08-code-generator/yacc.y new file mode 100644 index 0000000..a47384b --- /dev/null +++ b/08-code-generator/yacc.y @@ -0,0 +1,358 @@ +%{ +#define YYSTYPE_IS_DECLARED 1 +typedef long YYSTYPE; + +#include "type.h" +#include "func.h" + +extern int line_no, syntax_err; +extern A_NODE *root; +extern A_ID *current_id; +extern int current_level; +extern A_TYPE *int_type; +%} + +%start program +%token IDENTIFIER TYPE_IDENTIFIER INTEGER_CONSTANT FLOAT_CONSTANT CHARACTER_CONSTANT STRING_LITERAL + AUTO_SYM STATIC_SYM CONST_SYM TYPEDEF_SYM + STRUCT_SYM UNION_SYM ENUM_SYM + CASE_SYM DEFAULT_SYM IF_SYM ELSE_SYM SWITCH_SYM + WHILE_SYM DO_SYM FOR_SYM + RETURN_SYM CONTINUE_SYM BREAK_SYM GOTO_SYM + COMMA ASSIGN STAR ARROW PLUSPLUS MINUSMINUS + AMP EXCL MINUS PLUS SIZEOF_SYM SLASH PERCENT + LSS GTR LEQ GEQ EQL NEQ AMPAMP BARBAR + LR RR LP RP LB RB SEMICOLON COLON DOTDOTDOT PERIOD + +%% +program + : translation_unit + {root = makeNode(N_PROGRAM, NIL, $1, NIL); checkForwardReference();} + ; +translation_unit + : external_declaration {$$ = $1;} + | translation_unit external_declaration {$$ = linkDeclaratorList($1, $2);} + ; +external_declaration + : function_definition {$$ = $1;} + | declaration {$$ = $1;} + ; +function_definition + : declaration_specifiers declarator {$$ = setFunctionDeclaratorSpecifier($2, $1);} + compound_statement {$$ = setFunctionDeclaratorBody($3, $4);} + | declarator {$$ = setFunctionDeclaratorSpecifier($1, makeSpecifier(int_type, 0));} + compound_statement {$$ = setFunctionDeclaratorBody($2, $3);} + ; +declaration_list_opt + : {$$ = NIL;} + | declaration_list {$$ = $1;} + ; +declaration_list + : declaration {$$ = $1;} + | declaration_list declaration {$$ = linkDeclaratorList($1, $2);} + ; +declaration + : declaration_specifiers init_declarator_list_opt SEMICOLON {$$ = setDeclaratorListSpecifier($2, $1);} + ; +declaration_specifiers + : type_specifier {$$ = makeSpecifier($1, 0);} + | storage_class_specifier {$$ = makeSpecifier(0, $1);} + | type_specifier declaration_specifiers {$$ = updateSpecifier($2, $1, 0);} + | storage_class_specifier declaration_specifiers {$$ = updateSpecifier($2, 0, $1);} + ; +storage_class_specifier + : AUTO_SYM {$$ = S_AUTO;} + | STATIC_SYM {$$ = S_STATIC;} + | TYPEDEF_SYM {$$ = S_TYPEDEF;} + ; +init_declarator_list_opt + : {$$ = makeDummyIdentifier();} + | init_declarator_list {$$ = $1;} + ; +init_declarator_list + : init_declarator {$$ = $1;} + | init_declarator_list COMMA init_declarator {$$ = linkDeclaratorList($1, $3);} + ; +init_declarator + : declarator {$$ = $1;} + | declarator ASSIGN initializer {$$ = setDeclaratorInit($1, $3);} + ; +initializer + : constant_expression {$$ = makeNode(N_INIT_LIST_ONE, NIL, $1, NIL);} + | LR initializer_list RR {$$ = $2;} + ; +initializer_list + : initializer {$$ = makeNode(N_INIT_LIST, $1, NIL, makeNode(N_INIT_LIST_NIL, NIL, NIL, NIL));} + | initializer_list COMMA initializer {$$ = makeNodeList(N_INIT_LIST, $1, $3);} + ; +type_specifier + : struct_type_specifier {$$ = $1;} + | enum_type_specifier {$$ = $1;} + | TYPE_IDENTIFIER {$$ = $1;} + ; +struct_type_specifier + : struct_or_union IDENTIFIER {$$ = setTypeStructOrEnumIdentifier($1, $2, ID_STRUCT);} + LR {$$ = current_id; current_level++;} + struct_declaration_list RR {checkForwardReference(); $$ = setTypeField($3, $6); current_level--; current_id = $5;} + | struct_or_union {$$ = makeType($1);} + LR {$$ = current_id; current_level++;} + struct_declaration_list RR {checkForwardReference(); $$ = setTypeField($2, $5); current_level--; current_id = $4;} + | struct_or_union IDENTIFIER {$$ = getTypeOfStructOrEnumRefIdentifier($1, $2, ID_STRUCT);} + ; +struct_or_union + : STRUCT_SYM {$$ = T_STRUCT;} + | UNION_SYM {$$ = T_UNION;} + ; +struct_declaration_list + : struct_declaration {$$ = $1;} + | struct_declaration_list struct_declaration {$$ = linkDeclaratorList($1, $2);} + ; +struct_declaration + : type_specifier struct_declarator_list SEMICOLON {$$ = setStructDeclaratorListSpecifier($2, $1);} + ; +struct_declarator_list + : struct_declarator {$$ = $1;} + | struct_declarator_list COMMA struct_declarator {$$ = linkDeclaratorList($1, $3);} + ; +struct_declarator + : declarator {$$ = $1;} + ; +enum_type_specifier + : ENUM_SYM IDENTIFIER {$$ = setTypeStructOrEnumIdentifier(T_ENUM, $2, ID_ENUM);} + LR enumerator_list RR {$$ = setTypeField($3, $5);} + | ENUM_SYM {$$ = makeType(T_ENUM);} + LR enumerator_list RR {$$ = setTypeField($2, $4);} + | ENUM_SYM IDENTIFIER {$$ = getTypeOfStructOrEnumRefIdentifier(T_ENUM, $2, ID_ENUM);} + ; +enumerator_list + : enumerator {$$ = $1;} + | enumerator_list COMMA enumerator {$$ = linkDeclaratorList($1, $3);} + ; +enumerator + : IDENTIFIER {$$ = setDeclaratorKind(makeIdentifier($1), ID_ENUM_LITERAL);} + | IDENTIFIER {$$ = setDeclaratorKind(makeIdentifier($1), ID_ENUM_LITERAL);} + ASSIGN expression {$$ = setDeclaratorInit($2, $4);} + ; +declarator + : pointer direct_declarator {$$ = setDeclaratorElementType($2, $1);} + | direct_declarator {$$ = $1;} + ; +pointer + : STAR {$$ = makeType(T_POINTER);} + | STAR pointer {$$ = setTypeElementType($2, makeType(T_POINTER));} + ; +direct_declarator + : IDENTIFIER {$$ = makeIdentifier($1);} + | LP declarator RP {$$ = $2;} + | direct_declarator LB constant_expression_opt RB + {$$ = setDeclaratorElementType($1, setTypeExpr(makeType(T_ARRAY), $3));} + | direct_declarator LP {$$ = current_id; current_level++;} + parameter_type_list_opt RP + {checkForwardReference(); current_id = $3; current_level--; + $$ = setDeclaratorElementType($1, setTypeField(makeType(T_FUNC), $4));} + ; +parameter_type_list_opt + : {$$ = NIL;} + | parameter_type_list {$$ = $1;} + ; +parameter_type_list + : parameter_list {$$ = $1;} + | parameter_list COMMA DOTDOTDOT {$$ = linkDeclaratorList($1, setDeclaratorKind(makeDummyIdentifier(), ID_PARM));} + ; +parameter_list + : parameter_declaration {$$ = $1;} + | parameter_list COMMA parameter_declaration {$$ = linkDeclaratorList($1, $3);} + ; +parameter_declaration + : declaration_specifiers declarator {$$ = setParameterDeclaratorSpecifier($2, $1);} + | declaration_specifiers abstract_declarator_opt {$$ = setParameterDeclaratorSpecifier(setDeclaratorType(makeDummyIdentifier(), $2), $1);} + ; +abstract_declarator_opt + : {$$ = NIL;} + | abstract_declarator {$$ = $1;} + ; +abstract_declarator + : direct_abstract_declarator {$$ = $1;} + | pointer {$$ = makeType(T_POINTER);} + | pointer direct_abstract_declarator {$$ = setTypeElementType($2, makeType(T_POINTER));} + ; +direct_abstract_declarator + : LP abstract_declarator RP {$$ = $2;} + | LB constant_expression_opt RB {$$ = setTypeExpr(makeType(T_ARRAY), $2);} + | LP parameter_type_list_opt RP {$$ = setTypeExpr(makeType(T_FUNC), $2);} + | direct_abstract_declarator LB constant_expression_opt RB {$$ = setTypeElementType($1, setTypeExpr(makeType(T_ARRAY), $3));} + | direct_abstract_declarator LP parameter_type_list_opt RP {$$ = setTypeElementType($1, setTypeExpr(makeType(T_FUNC), $3));} + ; +statement_list_opt + : {$$ = makeNode(N_STMT_LIST_NIL, NIL, NIL, NIL);} + | statement_list {$$ = $1;} + ; +statement_list + : statement {$$ = makeNode(N_STMT_LIST, $1, NIL, makeNode(N_STMT_LIST_NIL, NIL, NIL, NIL));} + | statement_list statement {$$ = makeNodeList(N_STMT_LIST, $1, $2);} + ; +statement + : labeled_statement {$$ = $1;} + | compound_statement {$$ = $1;} + | expression_statement {$$ = $1;} + | selection_statement {$$ = $1;} + | iteration_statement {$$ = $1;} + | jump_statement {$$ = $1;} + ; +labeled_statement + : CASE_SYM constant_expression COLON statement {$$ = makeNode(N_STMT_LABEL_CASE, $2, NIL, $4);} + | DEFAULT_SYM COLON statement {$$ = makeNode(N_STMT_LABEL_DEFAULT, NIL, $3, NIL);} + ; +compound_statement + : LR {$$ = current_id; current_level++;} declaration_list_opt + statement_list_opt RR {checkForwardReference(); $$ = makeNode(N_STMT_COMPOUND, $3, NIL, $4); current_id = $2; current_level--;} + ; +expression_statement + : SEMICOLON {$$ = makeNode(N_STMT_EMPTY, NIL, NIL, NIL);} + | expression SEMICOLON {$$ = makeNode(N_STMT_EXPRESSION, NIL, $1, NIL);} + ; +selection_statement + : IF_SYM LP expression RP statement {$$ = makeNode(N_STMT_IF, $3, NIL, $5);} + | IF_SYM LP expression RP statement ELSE_SYM statement {$$ = makeNode(N_STMT_IF_ELSE, $3, $5, $7);} + | SWITCH_SYM LP expression RP statement {$$ = makeNode(N_STMT_SWITCH, $3, NIL, $5);} + ; +iteration_statement + : WHILE_SYM LP expression RP statement {$$ = makeNode(N_STMT_WHILE, $3, NIL, $5);} + | DO_SYM statement WHILE_SYM LP expression RP SEMICOLON {$$ = makeNode(N_STMT_DO, $2, NIL, $5);} + | FOR_SYM LP for_expression RP statement {$$ = makeNode(N_STMT_FOR, $3, NIL, $5);} + ; +for_expression + :expression_opt SEMICOLON expression_opt SEMICOLON expression_opt {$$ = makeNode(N_FOR_EXP, $1, $3, $5);} + ; +expression_opt + : {$$ = NIL;} + | expression {$$ = $1;} + ; +jump_statement + : RETURN_SYM expression_opt SEMICOLON {$$ = makeNode(N_STMT_RETURN, NIL, $2, NIL);} + | CONTINUE_SYM SEMICOLON {$$ = makeNode(N_STMT_CONTINUE, NIL, NIL, NIL);} + | BREAK_SYM SEMICOLON {$$ = makeNode(N_STMT_BREAK, NIL, NIL, NIL);} + ; +arg_expression_list_opt + : {$$ = makeNode(N_ARG_LIST_NIL, NIL, NIL, NIL);} + | arg_expression_list {$$ = $1;} + ; +arg_expression_list + : assignment_expression + {$$ = makeNode(N_ARG_LIST, $1, NIL, makeNode(N_ARG_LIST_NIL, NIL, NIL, NIL));} + | arg_expression_list COMMA assignment_expression + {$$ = makeNodeList(N_ARG_LIST, $1, $3);} + ; +constant_expression_opt + : {$$ = NIL;} + | constant_expression {$$ = $1;} + ; +constant_expression + : expression {$$ = $1;} + ; +expression + : comma_expression {$$ = $1;} + ; +comma_expression + : assignment_expression {$$ = $1;} + ; +assignment_expression + : conditional_expression {$$ = $1;} + | unary_expression ASSIGN assignment_expression {$$ = makeNode(N_EXP_ASSIGN, $1, NIL, $3);} + ; +conditional_expression + : logical_OR_expression {$$ = $1;} + ; +logical_OR_expression + : logical_AND_expression {$$ = $1;} + | logical_OR_expression BARBAR logical_AND_expression + {$$ = makeNode(N_EXP_OR, $1, NIL, $3);} + ; +logical_AND_expression + : bitwise_or_expression {$$ = $1;} + | logical_AND_expression AMPAMP bitwise_or_expression + {$$ = makeNode(N_EXP_AND, $1, NIL, $3);} + ; +bitwise_or_expression + : bitwise_xor_expression {$$ = $1;} + ; +bitwise_xor_expression + : bitwise_and_expression {$$ = $1;} + ; +bitwise_and_expression + : equality_expression {$$ = $1;} + ; +equality_expression + : relational_expression {$$ = $1;} + | equality_expression EQL relational_expression {$$ = makeNode(N_EXP_EQL, $1, NIL, $3);} + | equality_expression NEQ relational_expression {$$ = makeNode(N_EXP_NEQ, $1, NIL, $3);} + ; +relational_expression + : shift_expression {$$ = $1;} + | relational_expression LSS shift_expression {$$ = makeNode(N_EXP_LSS, $1, NIL, $3);} + | relational_expression GTR shift_expression {$$ = makeNode(N_EXP_GTR, $1, NIL, $3);} + | relational_expression LEQ shift_expression {$$ = makeNode(N_EXP_LEQ, $1, NIL, $3);} + | relational_expression GEQ shift_expression {$$ = makeNode(N_EXP_GEQ, $1, NIL, $3);} + ; +shift_expression + : additive_expression {$$ = $1;} + ; +additive_expression + : multiplicative_expression {$$ = $1;} + | additive_expression PLUS multiplicative_expression {$$ = makeNode(N_EXP_ADD, $1, NIL, $3);} + | additive_expression MINUS multiplicative_expression {$$ = makeNode(N_EXP_SUB, $1, NIL, $3);} + ; +multiplicative_expression + : cast_expression {$$ = $1;} + | multiplicative_expression STAR cast_expression {$$ = makeNode(N_EXP_MUL, $1, NIL, $3);} + | multiplicative_expression SLASH cast_expression {$$ = makeNode(N_EXP_DIV, $1, NIL, $3);} + | multiplicative_expression PERCENT cast_expression {$$ = makeNode(N_EXP_MOD, $1, NIL, $3);} + ; +cast_expression + : unary_expression {$$ = $1;} + | LP type_name RP cast_expression {$$ = makeNode(N_EXP_CAST, $2, NIL, $4);} + ; +unary_expression + : postfix_expression {$$ = $1;} + | PLUSPLUS unary_expression {$$ = makeNode(N_EXP_PRE_INC, NIL, $2, NIL);} + | MINUSMINUS unary_expression {$$ = makeNode(N_EXP_PRE_DEC, NIL, $2, NIL);} + | AMP cast_expression {$$ = makeNode(N_EXP_AMP, NIL, $2, NIL);} + | STAR cast_expression {$$ = makeNode(N_EXP_STAR, NIL, $2, NIL);} + | EXCL cast_expression {$$ = makeNode(N_EXP_NOT, NIL, $2, NIL);} + | MINUS cast_expression {$$ = makeNode(N_EXP_MINUS, NIL, $2, NIL);} + | PLUS cast_expression {$$ = makeNode(N_EXP_PLUS, NIL, $2, NIL);} + | SIZEOF_SYM unary_expression {$$ = makeNode(N_EXP_SIZE_EXP, NIL, $2, NIL);} + | SIZEOF_SYM LP type_name RP {$$ = makeNode(N_EXP_SIZE_TYPE, NIL, $3, NIL);} + ; +postfix_expression + : primary_expression {$$ = $1;} + | postfix_expression LB expression RB {$$ = makeNode(N_EXP_ARRAY, $1, NIL, $3);} + | postfix_expression LP arg_expression_list_opt RP + {$$ = makeNode(N_EXP_FUNCTION_CALL, $1, NIL, $3);} + | postfix_expression PERIOD IDENTIFIER {$$ = makeNode(N_EXP_STRUCT, $1, NIL, $3);} + | postfix_expression ARROW IDENTIFIER {$$ = makeNode(N_EXP_ARROW, $1, NIL, $3);} + | postfix_expression PLUSPLUS {$$ = makeNode(N_EXP_POST_INC, NIL, $1, NIL);} + | postfix_expression MINUSMINUS {$$ = makeNode(N_EXP_POST_DEC, NIL, $1, NIL);} + ; +primary_expression + : IDENTIFIER {$$ = makeNode(N_EXP_IDENT, NIL, getIdentifierDeclared($1), NIL);} + | INTEGER_CONSTANT {$$ = makeNode(N_EXP_INT_CONST, NIL, $1, NIL);} + | FLOAT_CONSTANT {$$ = makeNode(N_EXP_FLOAT_CONST, NIL, $1, NIL);} + | CHARACTER_CONSTANT {$$ = makeNode(N_EXP_CHAR_CONST, NIL, $1, NIL);} + | STRING_LITERAL {$$ = makeNode(N_EXP_STRING_LITERAL, NIL, $1, NIL);} + | LP expression RP {$$ = $2;} + ; +type_name + : declaration_specifiers abstract_declarator_opt + {$$ = setTypeNameSpecifier($2, $1);} + ; +%% +extern char *yytext; +yyerror(char *s) +{ + syntax_err++; + printf("line %d: %s near %s\n", line_no, s, yytext); +} +int yywrap() { + return (1); +} \ No newline at end of file From e5b0ed718073cfcf353749a70f95676144201910 Mon Sep 17 00:00:00 2001 From: daeun Date: Thu, 18 Dec 2025 17:22:28 +0900 Subject: [PATCH 2/9] feat(gen): add code generation functions --- 08-code-generator/gen_func.c | 800 +++++++++++++++++++++++++++++++++++ 08-code-generator/gen_func.h | 52 +++ 2 files changed, 852 insertions(+) diff --git a/08-code-generator/gen_func.c b/08-code-generator/gen_func.c index e69de29..73999d1 100644 --- a/08-code-generator/gen_func.c +++ b/08-code-generator/gen_func.c @@ -0,0 +1,800 @@ +#include "gen_func.h" +#include "type.h" + +void code_generation(A_NODE *node){ + gen_program(node); + gen_literal_table(); +} + +void gen_literal_table(){ // literal들을 어셈블리 파일의 데이터 섹션에 기록 + int i; + // literal_table에 등록된 모든 리터럴 순회 + for (i = 1; i <= literal_no; i++){ + // .literal: 리터럴 선언 명령어 + // 명령어와 함께 해당 literal이 위치할 addr 출력 + fprintf(fout, ".literal %5d ", literal_table[i].addr); + // literal의 type에 따라 실제 값 출력 + if (literal_table[i].type == int_type) + fprintf(fout, "%d\n", literal_table[i].value.i); + else if (literal_table[i].type == float_type) + fprintf(fout, "%f\n", literal_table[i].value.f); + else if (literal_table[i].type == char_type) // char 타입은 ASCII 코드로 출력 + fprintf(fout, "%d\n", literal_table[i].value.c); + else if (literal_table[i].type == string_type) + fprintf(fout, "%s\n", literal_table[i].value.s); + } +} +void gen_program(A_NODE *node){ + switch (node->name){ + case N_PROGRAM: + // 전역 변수 공간 확보(INT) + // node->value는 전역 변수들의 총 크기, 스택 포인터를 node->value만큼 증가 + gen_code_i(INT, 0, node->value); + // main 함수의 label로 점프하여 실행 시작 + gen_code_s(SUP, 0, "main"); + // main 함수 종료되면 return -> 프로그램 종료 + gen_code_i(RET, 0, 0); + + // 프로그램에 정의된 모든 함수와 전역 변수 초기화 코드 생성 + gen_declaration_list(node->clink); + break; + + default: // root가 N_PROGRAM이 아닌 경우 + gen_error(100, node->line); + break; + } +} +void gen_expression(A_NODE *node){ // expression을 평가하여 r-value를 stack top에 남김 + A_ID *id; + A_TYPE *t; + int i, ll; + + switch (node->name){ + case N_EXP_IDENT: // Identifier: 변수나 상수의 값을 로드 + id = node->clink; + t = id->type; + switch (id->kind){ + case ID_VAR: + case ID_PARM: // variable이나 parameter인 경우 + switch (t->kind) { + case T_ENUM: + case T_POINTER: // 일반 변수나 포인터 변수는 값을 stack에 로드 + gen_code_i(LOD, id->level, id->address); // level과 offset 사용 + break; + case T_ARRAY: + // 배열의 이름은 시작 주소로 취급 -> 주소 로드(LDA) + if (id->kind == ID_VAR) + gen_code_i(LDA, id->level, id->address); + else // ID_PARM인 경우 포인트이므로 값을 로드(LOD) + gen_code_i(LOD, id->level, id->address); + break; + case T_STRUCT: // 구현하지 않음. + gen_error(24, node->line, "T_STRUCT"); // not implemented + break; + case T_UNION: + // 주소를 로드한 뒤 LDI를 통해 값을 로드 + gen_code_i(LDA, id->level, id->address); + i = id->type->size; + // LDI: load indirect + gen_code_i(LDI, 0, i%4 ? i/4+1 : i/4); + break; + default: + gen_error(11, id->line); // error11: illegal identifier in expression + break; + } + break; + case ID_ENUM_LITERAL: + // 정수 literal로 취급하여 값 로드 + gen_code_i(LITI, 0, id->init); + break; + default: + gen_error(11, node->line); + break; + } + break; + case N_EXP_INT_CONST: + // LITI로 직접 로드 + gen_code_i(LITI, 0, node->clink); + break; + case N_EXP_FLOAT_CONST: + // float const는 literal_table에 저장된 값을 로드(LOD) + i = node->clink; + gen_code_i(LOD, 0, literal_table[i].addr); + break; + case N_EXP_CHAR_CONST: + // ASCII로 취급하여 로드(LITI) + gen_code_i(LITI, 0, node->clink); + break; + case N_EXP_STRING_LITERAL: + // string 주소 로드(LDA) + i = node->clink; + gen_code_i(LDA, 0, literal_table[i].addr); + break; + case N_EXP_ARRAY: // 주소 계산 -> 값 로드 + gen_expression(node->llink); // array base 주소 연산 + gen_expression(node->rlink); // index 평가(array 크기) + + if (node->type->size > 1){ + gen_code_i(LITI, 0, node->type->size); // element 타입의 크기 로드 + gen_code_i(MULI, 0, 0); // offset 계산: element 개수 * 타입 크기 + } + // base + offset + gen_code_i(OFFSET, 0, 0); + + if (!isArrayType(node->type)) { // 타입이 원소이면 + i = node->type->size; + if (i == 1) + gen_code_i(LDIB, 0, 0); + else + gen_code_i(LDI, 0, i%4 ? i/4+1 : i/4); // word alignment + } + break; + case N_EXP_FUNCTION_CALL: + t = node->llink->type; + // return type 크기 계산 + i = t->element_type->element_type->size; + // word alignment + if (i%4) + i = i/4 * 4 + 4; + if (node->rlink){ + // header + return 사이즈 만큼 공간 확보 + gen_code_i(INT, 0, 12 + i); + // argument 계산 + gen_arg_expression(node->rlink); + // argument 개수 만큼 stack pointer 조정 + gen_code_i(POP, 0, node->rlink->value / 4 + 3); + } else { + gen_code_i(INT, 0, i); // 인자 없는 경우 + } + // 호출 함수의 주소 로드 + gen_expression(node->llink); + // 함수 호출 + gen_code_i(CAL, 0, 0); + break; + case N_EXP_STRUCT: // struct 멤버 참조는 구현하지 않음. + gen_error(24, node->line, "N_EXP_STRUCT"); + break; + case N_EXP_ARROW: // 포인터의 멤버 참조는 구현하지 않음. + gen_error(24, node->line, "N_EXP_ARROW"); + break; + case N_EXP_POST_INC: // 후위 증가 연산자 + gen_expression(node->clink); // 증가 전 값 로드 + gen_expression_left(node->clink); // 주소 로드 + t = node->type; + // 주소로부터 값 로드(증가 전) + if (node->type->size == 1) + gen_code_i(LDXB, 0, 0); + else + gen_code_i(LDX, 0, 1); + // 값 증가 + if (isPointerOrArrayType(node->type)){ + // 포인터 타입이면 타입 크기만큼 증가 + gen_code_i(LITI, 0, node->type->element_type->size); // 타입 크기 (정수값) 로드 + gen_code_i(ADDI, 0, 0); // 타입 크기만큼 증가 + } else if (isFloatType(node->type)){ + gen_code_i(INCF, 0, 0); + } else { + // 포인터가 아니면 1만큼 증가 + gen_code_i(INCI, 0, 0); + } + // 증가된 값 메모리에 저장 (STO) + if (node->type->size == 1) + gen_code_i(STOB, 0, 0); + else + gen_code_i(STO, 0, 1); + break; + case N_EXP_POST_DEC: // 후위 감소 연산자 + gen_expression(node->clink); // 감소 전 값 로드 + gen_expression_left(node->clink); // 변수의 주소 로드 + t = node->type; + // 주소로부터 값 로드(감소 전) + if (node->type->size == 1) + gen_code_i(LDXB, 0, 0); + else + gen_code_i(LDX, 0, 1); + // 값 감소 + if (isPointerOrArrayType(node->type)){ + // 포인터 타입이면 타입 크기만큼 감소 + gen_code_i(LITI, 0, node->type->element_type->size); // 타입 크기 로드 + gen_code_i(SUBI, 0, 0); // 타입 크기만큼 감소 + } else if (isFloatType(node->type)){ + gen_code_i(DECF, 0, 0); + } else { + // 포인터 타입이 아니면 1만큼 감소 + gen_code_i(DECI, 0, 0); + } + // 감소한 값 메모리에 저장(STO) + if (node->type->size == 1) + gen_code_i(STOB, 0, 0); + else + gen_code_i(STO, 0, 1); + break; + case N_EXP_PRE_INC: // 전위 증가 연산자 + gen_expression_left(node->clink); // 후위 연산자와 달리 변수의 주소부터 로드 + t = node->type; + // 주소로부터 값 로드 (증가 전) + if (node->type->size == 1) + gen_code_i(LDXB, 0, 0); + else + gen_code_i(LDX, 0, 1); + // 값 증가 + if (isPointerOrArrayType(node->type)){ + // 포인터 타입이면 타입 크기만큼 증가 + gen_code_i(LITI, 0, node->type->element_type->size); + gen_code_i(ADDI, 0, 0); + } else if (isFloatType(node->type)){ + gen_code_i(INCF, 0, 0); + } else { + // 포인터 타입이 아니면 1만큼 증가 + gen_code_i(INCI, 0, 0); + } + // 증가한 값 저장 + if (node->type->size == 1){ + gen_code_i(STXB, 0, 0); + } else { + gen_code_i(STX, 0, 1); + } + break; + case N_EXP_PRE_DEC: // 전위 감소 연산자 + gen_expression_left(node->clink); // 변수의 주소 로드 + t = node->type; + // 주소로부터 값 로드 (감소 전) + if (node->type->size == 1) + gen_code_i(LDXB, 0, 0); + else + gen_code_i(LDX, 0, 1); + // 값 감소 + if (isPointerOrArrayType(node->type)){ + // 포인터 타입이면 타입 크기만큼 증가 + gen_code_i(LITI, 0, node->type->element_type->size); + gen_code_i(SUBI, 0, 0); + } else if (isFloatType(node->type)){ + gen_code_i(DECF, 0, 0); + } else { + // 포인터 타입이 아니면 1만큼 감소 + gen_code_i(DECI, 0, 0); + } + break; + case N_EXP_NOT: // ! 연산자 + gen_expression(node->clink); + gen_code_i(NOT, 0, 0); + break; + case N_EXP_PLUS: + gen_expression(node->clink); + break; + case N_EXP_MINUS: + gen_expression(node->clink); + if (isFloatType(node->type)) + gen_code_i(MINUSF, 0, 0); + else + gen_code_i(MINUSI, 0, 0); + break; + case N_EXP_AMP: // 주소 연산자 + gen_expression_left(node->clink); // lvalue를 구해야 함 + break; + case N_EXP_STAR: // 역참조 + gen_expression(node->clink); // 포인터 값 로드 -> 주소 + i = node->type->size; + // 주소에 있는 값 로드 + if (i == 1) + gen_code_i(LDIB, 0, 0); + else + gen_code_i(LDI, 0, i%4 ? i/4+1 : i/4); + break; + case N_EXP_SIZE_EXP: + gen_code_i(LITI, 0, node->clink); + break; + case N_EXP_SIZE_TYPE: + gen_code_i(LITI, 0, node->clink); + break; + case N_EXP_CAST: // type casting + gen_expression(node->rlink); // RHS expression 계산 + if (node->type != node->rlink->type){ // 양쪽 타입이 다르면 캐스팅 + if (isFloatType(node->type)) // LHS: float이면 int->float으로 변환 + gen_code_i(CVTF, 0, 0); + else if (isFloatType(node->rlink->type)) // LHS가 float이 아니면서 RHS가 float이면 float->int로 변환 + gen_code_i(CVTI, 0, 0); + } + break; + case N_EXP_MUL: // 곱셈 연산 + gen_expression(node->llink); // 좌측 계산 + gen_expression(node->rlink); // 우측 계산 + if (isFloatType(node->type)) // 타입에 따라 연산 코드 생성 + gen_code_i(MULF, 0, 0); + else + gen_code_i(MULI, 0, 0); + break; + case N_EXP_DIV: // 나눗셈 + gen_expression(node->llink); // 좌측 계산 + gen_expression(node->rlink); // 우측 계산 + if (isFloatType(node->type)) // 타입에 따라 연산 코드 생성 + gen_code_i(DIVF, 0, 0); + else + gen_code_i(DIVI, 0, 0); + break; + case N_EXP_MOD: // 모듈러 연산 + gen_expression(node->llink); + gen_expression(node->rlink); + gen_code_i(MOD, 0, 0); + break; + case N_EXP_ADD: // 덧셈 + gen_expression(node->llink); + if (isPointerOrArrayType(node->rlink->type)){ + // 포인터 연산일 경우(포인터 + 정수) 정수*타입 크기 계산 + gen_code_i(LITI, 0, node->rlink->type->element_type->size); + gen_code_i(MULI, 0, 0); + } + gen_expression(node->rlink); + if (isPointerOrArrayType(node->llink->type->element_type->size)){ + gen_code_i(LITI, 0, node->llink->type->element_type->size); + gen_code_i(MULI, 0, 0); + } + // 타입에 따라 연산 코드 생성 + if (isFloatType(node->type)) + gen_code_i(ADDF, 0, 0); + else + gen_code_i(ADDI, 0, 0); + break; + case N_EXP_SUB: // 뺄셈 + gen_expression(node->llink); + gen_expression(node->rlink); + if (isPointerOrArrayType(node->llink->type) && !isPointerOrArrayType(node->rlink->type)){ + // 좌측은 포인터, 우측은 포인터 타입이 아닌 경우 정수 * 타입 크기 계산 + gen_code_i(LITI, 0, node->llink->type->element_type->size); + gen_code_i(MULI, 0, 0); + } // 포인터 - 정수 + if (isFloatType(node->type)) + gen_code_i(SUBF, 0, 0); + else + gen_code_i(SUBI, 0, 0); + break; + case N_EXP_LSS: // < (논리 연산) + gen_expression(node->llink); // 좌측 계산 + gen_expression(node->rlink); // 우측 계산 + if (isFloatType(node->llink->type)) // 타입에 따라 연산 코드 생성 + gen_code_i(LSSF, 0, 0); + else + gen_code_i(LSSI, 0, 0); + break; + case N_EXP_GTR: // > + gen_expression(node->llink); + gen_expression(node->rlink); + if (isFloatType(node->llink->type)) // 타입에 따라 연산 코드 생성 + gen_code_i(GTRF, 0, 0); + else + gen_code_i(GTRI, 0, 0); + break; + case N_EXP_LEQ: // <= + gen_expression(node->llink); + gen_expression(node->rlink); + if (isFloatType(node->llink->type)) + gen_code_i(LEQF, 0, 0); + else + gen_code_i(LEQI, 0, 0); + break; + case N_EXP_GEQ: // >= + gen_expression(node->llink); + gen_expression(node->rlink); + if (isFloatType(node->llink->type)) + gen_code_i(GEQF, 0, 0); + else + gen_code_i(GEQI, 0, 0); + break; + case N_EXP_NEQ: // != + gen_expression(node->llink); + gen_expression(node->rlink); + if (isFloatType(node->llink->type)) + gen_code_i(NEQF, 0, 0); + else + gen_code_i(NEQI, 0, 0); + break; + case N_EXP_EQL: // == + gen_expression(node->llink); + gen_expression(node->rlink); + if (isFloatType(node->llink->type)) + gen_code_i(EQLF, 0, 0); + else + gen_code_i(EQLI, 0, 0); + break; + case N_EXP_AND: // && + gen_expresison(node->llink); + // short-circuit evaluation + gen_code_l(JPCR, 0, i=get_label()); // llink expression이 거짓이면 평가하지 않고 점프 + gen_expression(node->rlink); + gen_label_number(i); + break; + case N_EXP_OR: + gen_expression(node->llink); + // short-circuit evaluation + // llink 평가가 true이면 더 이상 평가하지 않고 점프 + gen_code_l(JPTR, 0, i=get_label()); + gen_expression(node->rlink); + gen_label_number(i); + break; + case N_EXP_ASSIGN: + gen_expression_left(node->llink); // 좌측 피연산자의 주소 계산 + gen_expression(node->rlink); // 우측 피연산자의 값 계산 + i = node->type->size; + // store(STX) + // STX: 값을 저장하고, 스택 탑에 남겨둠 + if (i == 1) + gen_code_i(STXB, 0, 0); + else + gen_code_i(STX, 0, i%4 ? i/4+1 : i/4); + break; + default: + gen_error(100, node->line); + break; + } +} +void gen_expression_left(A_NODE *node){ + A_ID *id; + A_TYPE *t; + int result; + switch (node->name) { + case N_EXP_IDENT: // 식별자의 주소를 구함 + id = node->clink; + t = id->type; + switch (id->kind){ + case ID_VAR: + case ID_PARM: + switch (t->kind){ + case T_ENUM: + case T_POINTER: + case T_STRUCT: + case T_UNION: + // 일반 변수, 포인터, 구조체 등은 주소 로드하는 코드 생성 + gen_code_i(LDA, id->level, id->address); + break; + case T_ARRAY: + if (id->kind == ID_VAR){ + // 일반적인 배열 선언의 경우 + gen_code_i(LDA, id->level, id->address); + // 배열의 이름이 곧 시작 주소 + } else { + // 파라미터와 같은 경웽는 포인터 변수에 주소값이 담겨서 넘어오기 때문에 + // LDA가 아니라 LOD로 주소값을 로드 + gen_code_i(LOD, id->level, id->address); + } + break; + } + break; + case ID_FUNC: + // 함수 이름 -> 함수 시작 주소 + gen_code_s(ADDR, 0, id->name); + break; + default: + gen_error(13, node->line, id->name); + break; + } + break; + case N_EXP_ARRAY: // 배열의 원소 접근: a[i] + gen_expression(node->llink); // 배열의 시작 주소 계산 + gen_expression(node->rlink); // 배열의 인덱스 계산 + if (node->type->size > 1){ // 인덱스 * 원소의 타입 크기 + gen_code_i(LITI, 0, node->type->size); + gen_code_i(MULI, 0, 0); + } + // 주소 연산: base + offset + gen_code_i(OFFSET, 0, 0); + break; + case N_EXP_STRUCT: // 구현하지 않음 + gen_error(24, node->line, "N_EXP_STRUCT"); + break; + case N_EXP_ARROW: // 구현하지 않음 + gen_error(24, node->line, "N_EXP_ARROW"); + break; + case N_EXP_STAR: // 역참조 + gen_expression(node->clink); // 변수가 가지고 있는 값 + break; + case N_EXP_INT_CONST: + case N_EXP_FLOAT_CONST: + case N_EXP_CHAR_CONST: + case N_EXP_STRING_LITERAL: + case N_EXP_FUNCTION_CALL: + case N_EXP_POST_INC: + case N_EXP_POST_DEC: + case N_EXP_PRE_INC: + case N_EXP_PRE_DEC: + case N_EXP_NOT: + case N_EXP_MINUS: + case N_EXP_SIZE_EXP: + case N_EXP_SIZE_TYPE: + case N_EXP_CAST: + case N_EXP_MUL: + case N_EXP_DIV: + case N_EXP_MOD: + case N_EXP_ADD: + case N_EXP_SUB: + case N_EXP_LSS: + case N_EXP_GTR: + case N_EXP_LEQ: + case N_EXP_GEQ: + case N_EXP_NEQ: + case N_EXP_EQL: + case N_EXP_AMP: + case N_EXP_AND: + case N_EXP_OR: + case N_EXP_ASSIGN: + gen_error(12, node->line); // 위와 같은 case는 lvalue가 될 수 없음 + break; + default: + gen_error(100, node->line); + break; + } +} +void gen_arg_expression(A_NODE *node){ + A_NODE *n; + switch (node->name) { + // argument list 분석 + case N_ARG_LIST: + gen_expression(node->llink); // llink 수식 평가 + // 결과값 stack top에 push + gen_arg_expression(node->rlink); // 재귀 호출 + // 첫 번째 ~ 마지막 argument가 순서대로 + break; + case N_ARG_LIST_NIL: + break; + default: + gen_error(100, node->line); + break; + } +} +int get_label() { + label_no++; + return (label_no); +} +void gen_statement(A_NODE *node, int cont_label, int break_label, A_SWITCH sw[], int *sn){ + A_SWITCH switch_table[100]; + int switch_no = 0; + A_NODE *n; + int i, l1, l2, l3; + switch (node->name) { + case N_STMT_LABEL_CASE: // switch문 구현하지 않음. + gen_error(24, node->line, "N_STMT_LABEL_CASE"); + break; + case N_STMT_LABEL_DEFAULT: // 구현하지 않음 + gen_error(24, node->line, "N_STMT_LABEL_DEFAULT"); + break; + case N_STMT_COMPOUND: + // 복합문 처리 + if (node->llink) // 선언문이 있다면 + gen_declaration_list(node->llink); // 지역 변수 선언 처리 + gen_statement_list(node->rlink, cont_label, break_label, sw, sn); // 내부 statement 처리 + // 전달받은 cont, break 문맥 그대로 유지 + break; + case N_STMT_EMPTY: + break; + case N_STMT_EXPRESSION: + n = node->clink; + gen_expression(n); // expression 평가 + // 평가 결과값은 스택에서 제거 + i = n->type->size; + if (i) + gen_code_i(POP, 0, i%4 ? i/4+1 : i/4); + break; + case N_STMT_IF: + gen_expression(node->llink); // 조건식 평가 + gen_code_l(JPC, 0, l1 = get_label()); // 조건이 거짓이라면 l1으로 점프 (JPC 코드 생성하며 l1 label도 생성) + gen_statement(node->clink, cont_label, break_label, 0, 0); // if statement 코드 생성 + gen_label_number(l1); // l1: if문 종료 + break; + case N_STMT_IF_ELSE: + gen_expression(node->llink); // 조건식 평가 + gen_code_l(JPC, 0, l1 = get_label()); // 조건이 거짓이라면 l1으로 점프 + gen_statement(node->clink, cont_label, break_label, 0, 0); // cont, break 문맥 그대로 유지 + gen_code_l(JMP, 0, l2 = get_label()); // if statement 실행 후 else 문을 건너뛰고 l2로 점프(if문 종료) + gen_label_number(l1); + gen_statement(node->rlink, cont_label, break_label, 0, 0); // else statement 실행 코드 생성 + gen_label_number(l2); + break; + case N_STMT_SWITCH: // 구현하지 않음. + gen_error(24, node->line, "N_STMT_SWITCH"); + break; + case N_STMT_WHILE: + l3 = gel_label(); // loop 시작 + gen_label_number(l1 = get_label()); // 조건 검사 (루프 시작) + gen_expression(node->llink); // 조건식 평가 + gen_code_l(JPC, 0, l2 = get_label()); // 조건이 거짓이면 루프 종료 l2로 점프 + // 루프 body 실행 코드 생성 + gen_statement(node->rlink, l3, l2, 0, 0); // l3 시작 ~ l2 종료 + gen_label_number(l3); + gen_code_l(JMP, 0, l1); // 조건 검사로 점프 + gen_label_number(l2); + break; + case N_STMT_DO: + l3 = get_label(); // continue + l2 = get_label(); // break + gen_label_number(l1 = get_label()); + gen_statement(node->llink, l2, l3, 0, 0); + gen_label_number(l2); + gen_expression(node->rlink); + // 조건이 참이면 l1으로 점프 + gen_code_l(JPT, 0, l1); + gen_label_number(l3); // 루프 종료 + break; + case N_STMT_FOR: + n = node->llink; + l3 = get_label(); + // 초기화 식 + if (n->llink) { + gen_expression(n->llink); + i = n->llink->type->size; + if (i) + gen_code_i(POP, 0, i%4 ? i/4+1 : i/4); // 식의 결과값 버림 + } + gen_label_number(l1 = get_label()); + l2 = get_label(); + // 조건 식 평가 + if (n->clink){ + gen_expression(n->clink); + // 조건이 거짓이면 l2로 점프 + gen_code_l(JPC, 0, l2); + } + gen_statement(node->rlink, l3, l2, 0, 0); + gen_label_number(l3); + if (n->rlink) { + gen_expression(n->rlink); + i = n->rlink->type->size; + if (i) + gen_code_i(POP, 0, i%4 ? i/4+1 : i/4); + } + gen_code_l(JMP, 0, l1); + gen_label_number(l2); + break; + case N_STMT_CONTINUE: + if (cont_label) + gen_code_l(JMP, 0, cont_label); // 가장 가까운 루프의 레이블로 점프 + else + gen_error(22, node->line); + break; + case N_STMT_BREAK: + if (break_label) + gen_code_l(JMP, 0, break_label); // 가장 가까운 루프의 종료 레이블로 점프 + else + gen_error(23, node->line); + break; + case N_STMT_RETURN: + n = node->clink; + if (n) { + // 리턴값이 있는 경우 + i = n->type->size; + if (i%4) + i = i/4 * 4 + 4; + gen_code_i(LDA, 1, -i); + gen_expression(n); + // 결과값 리턴 주소에 저장 + gen_code_i(STO, 0, i/4); + } + // 함수 종료 및 복귀 + gen_code_i(RET, 0, 0); + break; + default: + gen_error(100, node->line); + break; + } +} +void gen_statement_list(A_NODE *node, int cont_label, int break_label, A_SWITCH sw[], int *sn) +{ + switch(node->name) { + case N_STMT_LIST: + gen_statement(node->llink, cont_label, break_label, sw, sn); // 전달받은 context 그대로 전달 + gen_statement_list(node->rlink, cont_label, break_label, sw, sn); // 재귀 호출 + break; + case N_STMT_LIST_NIL: + break; + default : + gen_error(100,node->line); + break; + } +} +void gen_initializer_global(A_NODE *node, A_TYPE *t, int addr) { + +} +void gen_initializer_local(A_NODE *node, A_TYPE *t, int addr) { + +} +void gen_declaration_list(A_ID *id) +{ + while (id) { + gen_declaration(id); // 현재 id 선언 처리 + id=id->link; // 다음 id로 + } +} +void gen_declaration(A_ID *id){ + int i; + A_NODE *node; + switch (id->kind){ + case ID_VAR: // 변수 선언 + // 초기화 식의 존재 여부 확인 + if (id->init){ + // 전역 변수 + if (id->level == 0) + gen_initializer_global(id->init, id->type, id->address); + else // 지역 변수 + gen_initializer_local(id->init, id->type, id->address); + } + break; + case ID_FUNC: + if (id->type->expr) { + gen_label_name(id->name); // 함수 레이블 생성 + gen_code_i(INT, 0, id->type->local_var_size); // 지역 변수 공간 확보 + gen_statement(id->type->expr, 0, 0, 0, 0); + gen_code_i(RET, 0, 0); // 리턴 명령어 생성 + } + break; + case ID_PARM: + case ID_TYPE: + case ID_ENUM: + case ID_STRUCT: + case ID_FIELD: + case ID_ENUM_LITERAL: + case ID_NULL: + break; // 위 경우 선언 시점에 별도 실행 코드를 생성하지 않음. + default: + gen_error(100, id->line); + break; + } +} +void gen_error(int i, int ll, char *s ) +{ + gen_err++; + printf("*** error at line %d: ",ll); + + switch (i) { + case 11: + printf("illegal identifier in expression \n"); + break; + case 12: + printf("illegal l-value expression \n"); + break; + case 13: + printf("identifier %s not l-value expression \n",s); + break; + case 20: + printf("illegal default label in switch statement \n"); + break; + case 21: + printf("illegal case label in switch statement \n"); + break; + case 22: + printf("no destination for continue statement \n"); + break; + case 23: + printf("no destination for break statement \n"); + break; + case 24: + printf("not implemented %s for code generation\n",s); + break; + case 100: + printf("fatal compiler error during code generation\n"); + break; + default: + printf("unknown \n"); + break; + } +} +void gen_code_i(OPCODE op, int l, int a) +{ + fprintf(fout,"\t%9s %d, %d\n",opcode_name[op],l,a); +} +void gen_code_f(OPCODE op, int l, float a) +{ + fprintf(fout,"\t%9s %d, %f\n",opcode_name[op],l,a); +} +void gen_code_s(OPCODE op, int l, char *a) +{ + fprintf(fout,"\t%9s %d, %s\n",opcode_name[op],l,a); +} +void gen_code_l(OPCODE op, int l, int a) +{ + fprintf(fout,"\t%9s %d, L%d\n",opcode_name[op],l,a); +} +void gen_label_number(int i) +{ + fprintf(fout,"L%d:\n",i); +} +void gen_label_name(char *s) +{ + fprintf(fout,"%s:\n",s); +} \ No newline at end of file diff --git a/08-code-generator/gen_func.h b/08-code-generator/gen_func.h index e69de29..88d0aa0 100644 --- a/08-code-generator/gen_func.h +++ b/08-code-generator/gen_func.h @@ -0,0 +1,52 @@ +#ifndef _GEN_FUNC_H_ +#define _GEN_FUNC_H_ + +typedef enum op {OP_NULL, LOD,LDX,LDXB, LDA, LITI, + STO,STOB,STX,STXB, + SUBI,SUBF,DIVI,DIVF,ADDI,ADDF,OFFSET,MULI,MULF, MOD, + LSSI,LSSF,GTRI,GTRF, LEQI,LEQF,GEQI,GEQF,NEQI,NEQF,EQLI,EQLF, + NOT, OR, AND, CVTI,CVTF, + JPC,JPCR,JMP,JPT,JPTR,INT,INCI,INCF,DECI,DECF,SUP, CAL,ADDR, + RET, MINUSI, MINUSF, CHK,LDI,LDIB,SWITCH,SWVALUE,SWDEFAULT, + SWLABEL, SWEND,POP, POPB } OPCODE; +char *opcode_name[]={ "OP_NULL", "LOD","LDX","LDXB", "LDA", "LITI", + "STO","STOB","STX","STXB","SUBI","SUBF","DIVI","DIVF","ADDI","ADDF", + "OFFSET","MULI","MULF", "MOD", "LSSI","LSSF","GTRI","GTRF", "LEQI","LEQF", + "GEQI", "GEQF","NEQI","NEQF","EQLI","EQLF", "NOT", "OR", "AND", + "CVTI","CVTF", "JPC","JPCR","JMP","JPT","JPTR", + "INT","INCI","INCF","DECI","DECF","SUP","CAL","ADDR", + "RET","MINUSI","MINUSF","CHK","LDI","LDIB","SWITCH","SWVALUE", + "SWDEFAULT", "SWLABEL", "SWEND","POP","POPB"} ; + +typedef enum {SW_VALUE,SW_DEFAULT} SW_KIND; +typedef struct sw {SW_KIND kind; int val; int label;} A_SWITCH; + +void code_generation(A_NODE *); + +void gen_literal_table(); +void gen_program(A_NODE *); +void gen_expression(A_NODE *); +void gen_expression_left(A_NODE *); +void gen_arg_expression(A_NODE *); +void gen_statement(A_NODE *,int, int, A_SWITCH [], int *); +void gen_statement_list(A_NODE *,int, int, A_SWITCH [], int *); +void gen_initializer_global(A_NODE *, A_TYPE *, int); +void gen_initializer_local(A_NODE *, A_TYPE *, int); +void gen_declaration_list(A_ID *); void gen_declaration(A_ID *); +void gen_code_i(OPCODE,int,int); void gen_code_f(OPCODE,int,float); +void gen_code_s(OPCODE,int,char *); void gen_code_l(OPCODE,int,int); +void gen_label_number(int); +void gen_label_name(char *); +void gen_error(); + +int get_label(); + +extern FILE *fout; +extern A_TYPE *int_type, *float_type, *char_type, *void_type, *string_type; +extern A_LITERAL literal_table[]; +extern int literal_no; + +int label_no=0; +int gen_err=0; + +#endif \ No newline at end of file From faf50ea68ef415bac261993ef8966b7a0b07290d Mon Sep 17 00:00:00 2001 From: daeun Date: Thu, 18 Dec 2025 17:40:30 +0900 Subject: [PATCH 3/9] fix: fix typo --- 08-code-generator/gen_func.c | 4 ++-- 08-code-generator/gen_func.h | 3 +++ 08-code-generator/main.c | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/08-code-generator/gen_func.c b/08-code-generator/gen_func.c index 73999d1..7d8a318 100644 --- a/08-code-generator/gen_func.c +++ b/08-code-generator/gen_func.c @@ -397,7 +397,7 @@ void gen_expression(A_NODE *node){ // expression을 평가하여 r-value를 stac gen_code_i(EQLI, 0, 0); break; case N_EXP_AND: // && - gen_expresison(node->llink); + gen_expression(node->llink); // short-circuit evaluation gen_code_l(JPCR, 0, i=get_label()); // llink expression이 거짓이면 평가하지 않고 점프 gen_expression(node->rlink); @@ -592,7 +592,7 @@ void gen_statement(A_NODE *node, int cont_label, int break_label, A_SWITCH sw[], gen_error(24, node->line, "N_STMT_SWITCH"); break; case N_STMT_WHILE: - l3 = gel_label(); // loop 시작 + l3 = get_label(); // loop 시작 gen_label_number(l1 = get_label()); // 조건 검사 (루프 시작) gen_expression(node->llink); // 조건식 평가 gen_code_l(JPC, 0, l2 = get_label()); // 조건이 거짓이면 루프 종료 l2로 점프 diff --git a/08-code-generator/gen_func.h b/08-code-generator/gen_func.h index 88d0aa0..673cb6f 100644 --- a/08-code-generator/gen_func.h +++ b/08-code-generator/gen_func.h @@ -1,3 +1,6 @@ +#include "type.h" +#include + #ifndef _GEN_FUNC_H_ #define _GEN_FUNC_H_ diff --git a/08-code-generator/main.c b/08-code-generator/main.c index 7a48930..0e99d87 100644 --- a/08-code-generator/main.c +++ b/08-code-generator/main.c @@ -47,7 +47,7 @@ void main(int argc, char *argv[]){ if (semantic_err) exit(1); printf("\nStart Code Generation\n"); - code_genaration(root); + code_generation(root); exit(0); } \ No newline at end of file From df8c1637aaf686b71c80aedbdee0590b2a10cbf1 Mon Sep 17 00:00:00 2001 From: daeun Date: Thu, 18 Dec 2025 18:29:33 +0900 Subject: [PATCH 4/9] fix(gen): resolve seg fault and runtime error --- 08-code-generator/gen_func.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/08-code-generator/gen_func.c b/08-code-generator/gen_func.c index 7d8a318..9e0da31 100644 --- a/08-code-generator/gen_func.c +++ b/08-code-generator/gen_func.c @@ -181,7 +181,7 @@ void gen_expression(A_NODE *node){ // expression을 평가하여 r-value를 stac if (node->type->size == 1) gen_code_i(STOB, 0, 0); else - gen_code_i(STO, 0, 1); + gen_code_i(STO, 0, 0); break; case N_EXP_POST_DEC: // 후위 감소 연산자 gen_expression(node->clink); // 감소 전 값 로드 @@ -207,7 +207,7 @@ void gen_expression(A_NODE *node){ // expression을 평가하여 r-value를 stac if (node->type->size == 1) gen_code_i(STOB, 0, 0); else - gen_code_i(STO, 0, 1); + gen_code_i(STO, 0, 0); break; case N_EXP_PRE_INC: // 전위 증가 연산자 gen_expression_left(node->clink); // 후위 연산자와 달리 변수의 주소부터 로드 @@ -325,7 +325,7 @@ void gen_expression(A_NODE *node){ // expression을 평가하여 r-value를 stac gen_code_i(MULI, 0, 0); } gen_expression(node->rlink); - if (isPointerOrArrayType(node->llink->type->element_type->size)){ + if (isPointerOrArrayType(node->llink->type)){ gen_code_i(LITI, 0, node->llink->type->element_type->size); gen_code_i(MULI, 0, 0); } @@ -664,7 +664,7 @@ void gen_statement(A_NODE *node, int cont_label, int break_label, A_SWITCH sw[], gen_code_i(LDA, 1, -i); gen_expression(n); // 결과값 리턴 주소에 저장 - gen_code_i(STO, 0, i/4); + gen_code_i(STO, 0, 0); } // 함수 종료 및 복귀 gen_code_i(RET, 0, 0); From 07b42fad1546fe9b021baad3cf7cdb5aff2082a4 Mon Sep 17 00:00:00 2001 From: daeun Date: Thu, 18 Dec 2025 18:44:28 +0900 Subject: [PATCH 5/9] fix(gen): modify STX operand to 0 --- 08-code-generator/gen_func.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/08-code-generator/gen_func.c b/08-code-generator/gen_func.c index 9e0da31..ac68c0e 100644 --- a/08-code-generator/gen_func.c +++ b/08-code-generator/gen_func.c @@ -232,7 +232,7 @@ void gen_expression(A_NODE *node){ // expression을 평가하여 r-value를 stac if (node->type->size == 1){ gen_code_i(STXB, 0, 0); } else { - gen_code_i(STX, 0, 1); + gen_code_i(STX, 0, 0); } break; case N_EXP_PRE_DEC: // 전위 감소 연산자 @@ -420,7 +420,7 @@ void gen_expression(A_NODE *node){ // expression을 평가하여 r-value를 stac if (i == 1) gen_code_i(STXB, 0, 0); else - gen_code_i(STX, 0, i%4 ? i/4+1 : i/4); + gen_code_i(STX, 0, 0); break; default: gen_error(100, node->line); From f3ddf1924420b6d2e1d48f2062464c4370c1fb26 Mon Sep 17 00:00:00 2001 From: daeun Date: Thu, 18 Dec 2025 19:19:23 +0900 Subject: [PATCH 6/9] fix(gen): modify operand to 0 --- 08-code-generator/gen_func.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/08-code-generator/gen_func.c b/08-code-generator/gen_func.c index ac68c0e..bc6c533 100644 --- a/08-code-generator/gen_func.c +++ b/08-code-generator/gen_func.c @@ -76,7 +76,7 @@ void gen_expression(A_NODE *node){ // expression을 평가하여 r-value를 stac gen_code_i(LDA, id->level, id->address); i = id->type->size; // LDI: load indirect - gen_code_i(LDI, 0, i%4 ? i/4+1 : i/4); + gen_code_i(LDI, 0, 0); break; default: gen_error(11, id->line); // error11: illegal identifier in expression @@ -126,7 +126,7 @@ void gen_expression(A_NODE *node){ // expression을 평가하여 r-value를 stac if (i == 1) gen_code_i(LDIB, 0, 0); else - gen_code_i(LDI, 0, i%4 ? i/4+1 : i/4); // word alignment + gen_code_i(LDI, 0, 0); // word alignment } break; case N_EXP_FUNCTION_CALL: @@ -165,7 +165,7 @@ void gen_expression(A_NODE *node){ // expression을 평가하여 r-value를 stac if (node->type->size == 1) gen_code_i(LDXB, 0, 0); else - gen_code_i(LDX, 0, 1); + gen_code_i(LDX, 0, 0); // 값 증가 if (isPointerOrArrayType(node->type)){ // 포인터 타입이면 타입 크기만큼 증가 @@ -191,7 +191,7 @@ void gen_expression(A_NODE *node){ // expression을 평가하여 r-value를 stac if (node->type->size == 1) gen_code_i(LDXB, 0, 0); else - gen_code_i(LDX, 0, 1); + gen_code_i(LDX, 0, 0); // 값 감소 if (isPointerOrArrayType(node->type)){ // 포인터 타입이면 타입 크기만큼 감소 @@ -216,7 +216,7 @@ void gen_expression(A_NODE *node){ // expression을 평가하여 r-value를 stac if (node->type->size == 1) gen_code_i(LDXB, 0, 0); else - gen_code_i(LDX, 0, 1); + gen_code_i(LDX, 0, 0); // 값 증가 if (isPointerOrArrayType(node->type)){ // 포인터 타입이면 타입 크기만큼 증가 @@ -242,7 +242,7 @@ void gen_expression(A_NODE *node){ // expression을 평가하여 r-value를 stac if (node->type->size == 1) gen_code_i(LDXB, 0, 0); else - gen_code_i(LDX, 0, 1); + gen_code_i(LDX, 0, 0); // 값 감소 if (isPointerOrArrayType(node->type)){ // 포인터 타입이면 타입 크기만큼 증가 @@ -279,7 +279,7 @@ void gen_expression(A_NODE *node){ // expression을 평가하여 r-value를 stac if (i == 1) gen_code_i(LDIB, 0, 0); else - gen_code_i(LDI, 0, i%4 ? i/4+1 : i/4); + gen_code_i(LDI, 0, 0); break; case N_EXP_SIZE_EXP: gen_code_i(LITI, 0, node->clink); @@ -576,7 +576,7 @@ void gen_statement(A_NODE *node, int cont_label, int break_label, A_SWITCH sw[], case N_STMT_IF: gen_expression(node->llink); // 조건식 평가 gen_code_l(JPC, 0, l1 = get_label()); // 조건이 거짓이라면 l1으로 점프 (JPC 코드 생성하며 l1 label도 생성) - gen_statement(node->clink, cont_label, break_label, 0, 0); // if statement 코드 생성 + gen_statement(node->rlink, cont_label, break_label, 0, 0); // if statement 코드 생성 gen_label_number(l1); // l1: if문 종료 break; case N_STMT_IF_ELSE: From 062fea5dc782f2655163a103fedcf63ee29eca0c Mon Sep 17 00:00:00 2001 From: daeun Date: Thu, 18 Dec 2025 21:02:07 +0900 Subject: [PATCH 7/9] fix(sem): fix typo --- 08-code-generator/sem_func.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/08-code-generator/sem_func.c b/08-code-generator/sem_func.c index 8baa88f..60a3b87 100644 --- a/08-code-generator/sem_func.c +++ b/08-code-generator/sem_func.c @@ -311,12 +311,12 @@ A_TYPE *sem_expression(A_NODE *node) { case N_EXP_AND : case N_EXP_OR : t=sem_expression(node->llink); - if(!isScalarType(t)) + if(isScalarType(t)) node->llink = convertUsualUnaryConversion(node->llink); else semantic_error(27, node->line); t = sem_expression(node->rlink); - if(!isScalarType(t)) + if(isScalarType(t)) node->rlink = convertUsualUnaryConversion(node->rlink); else semantic_error(27, node->line); From aff1ddf8513bf918ff00209a0886b022528513ce Mon Sep 17 00:00:00 2001 From: daeun Date: Thu, 18 Dec 2025 21:02:22 +0900 Subject: [PATCH 8/9] test(gen): add test files --- 08-code-generator/test/test01.c | 6 ++++++ 08-code-generator/test/test02.c | 4 ++++ 08-code-generator/test/test03.c | 9 +++++++++ 08-code-generator/test/test04.c | 7 +++++++ 08-code-generator/test/test05.c | 7 +++++++ 08-code-generator/test/test06.c | 7 +++++++ 08-code-generator/test/test07.c | 7 +++++++ 08-code-generator/test/test08.c | 8 ++++++++ 08-code-generator/test/test09.c | 6 ++++++ 08-code-generator/test/test10.c | 6 ++++++ 10 files changed, 67 insertions(+) create mode 100644 08-code-generator/test/test01.c create mode 100644 08-code-generator/test/test02.c create mode 100644 08-code-generator/test/test03.c create mode 100644 08-code-generator/test/test04.c create mode 100644 08-code-generator/test/test05.c create mode 100644 08-code-generator/test/test06.c create mode 100644 08-code-generator/test/test07.c create mode 100644 08-code-generator/test/test08.c create mode 100644 08-code-generator/test/test09.c create mode 100644 08-code-generator/test/test10.c diff --git a/08-code-generator/test/test01.c b/08-code-generator/test/test01.c new file mode 100644 index 0000000..fcbd73f --- /dev/null +++ b/08-code-generator/test/test01.c @@ -0,0 +1,6 @@ +int g = 10; +void main() { + int a = 5; + int b; + b = g + a; +} \ No newline at end of file diff --git a/08-code-generator/test/test02.c b/08-code-generator/test/test02.c new file mode 100644 index 0000000..570c0c2 --- /dev/null +++ b/08-code-generator/test/test02.c @@ -0,0 +1,4 @@ +void main() { + int a; + a = 10 + 20 * 3; +} \ No newline at end of file diff --git a/08-code-generator/test/test03.c b/08-code-generator/test/test03.c new file mode 100644 index 0000000..3bc99aa --- /dev/null +++ b/08-code-generator/test/test03.c @@ -0,0 +1,9 @@ +void main() { + int i = 0; + while(i < 5) { + if (i == 3) { + break; + } + i++; + } +} \ No newline at end of file diff --git a/08-code-generator/test/test04.c b/08-code-generator/test/test04.c new file mode 100644 index 0000000..9b79eb9 --- /dev/null +++ b/08-code-generator/test/test04.c @@ -0,0 +1,7 @@ +int add(int a, int b) { + return a + b; +} +void main() { + int res; + res = add(10, 20); +} \ No newline at end of file diff --git a/08-code-generator/test/test05.c b/08-code-generator/test/test05.c new file mode 100644 index 0000000..5fc295e --- /dev/null +++ b/08-code-generator/test/test05.c @@ -0,0 +1,7 @@ +int arr[5]; +void main() { + int *p; + arr[2] = 10; + p = &arr[1]; + *(p + 1) = 20; +} \ No newline at end of file diff --git a/08-code-generator/test/test06.c b/08-code-generator/test/test06.c new file mode 100644 index 0000000..e9c2fa9 --- /dev/null +++ b/08-code-generator/test/test06.c @@ -0,0 +1,7 @@ +void set(int p[]) { + p[1] = 99; +} +void main() { + int arr[3]; + set(arr); +} \ No newline at end of file diff --git a/08-code-generator/test/test07.c b/08-code-generator/test/test07.c new file mode 100644 index 0000000..eb1c7e9 --- /dev/null +++ b/08-code-generator/test/test07.c @@ -0,0 +1,7 @@ +void main() { + int a = 0; + int b = 10; + if (a > 5 && b++ > 5) { + a = 1; + } +} \ No newline at end of file diff --git a/08-code-generator/test/test08.c b/08-code-generator/test/test08.c new file mode 100644 index 0000000..fc65c28 --- /dev/null +++ b/08-code-generator/test/test08.c @@ -0,0 +1,8 @@ +int fact(int n) { + if (n == 1) return 1; + return n * fact(n - 1); +} +void main() { + int res; + res = fact(5); +} \ No newline at end of file diff --git a/08-code-generator/test/test09.c b/08-code-generator/test/test09.c new file mode 100644 index 0000000..db37bad --- /dev/null +++ b/08-code-generator/test/test09.c @@ -0,0 +1,6 @@ +void main() { + int a = 10; + int b; + b = a++; + b = ++a; +} \ No newline at end of file diff --git a/08-code-generator/test/test10.c b/08-code-generator/test/test10.c new file mode 100644 index 0000000..f37f27f --- /dev/null +++ b/08-code-generator/test/test10.c @@ -0,0 +1,6 @@ +void main() { + int a = 10; + float f; + f = a + 3.14; + a = f + 10; +} \ No newline at end of file From 512e1cb504baa0c05816725d94da9aed5d1f290b Mon Sep 17 00:00:00 2001 From: daeun Date: Thu, 18 Dec 2025 23:25:58 +0900 Subject: [PATCH 9/9] feat(gen): add test files --- 08-code-generator/test/test11.c | 7 +++++++ 08-code-generator/test/test12.c | 7 +++++++ 08-code-generator/test/test13.c | 4 ++++ 3 files changed, 18 insertions(+) create mode 100644 08-code-generator/test/test11.c create mode 100644 08-code-generator/test/test12.c create mode 100644 08-code-generator/test/test13.c diff --git a/08-code-generator/test/test11.c b/08-code-generator/test/test11.c new file mode 100644 index 0000000..40dc839 --- /dev/null +++ b/08-code-generator/test/test11.c @@ -0,0 +1,7 @@ +void main() { + int i; + int sum = 0; + for (i = 1; i <= 3; i++) { + sum = sum + i; + } +} \ No newline at end of file diff --git a/08-code-generator/test/test12.c b/08-code-generator/test/test12.c new file mode 100644 index 0000000..1edb174 --- /dev/null +++ b/08-code-generator/test/test12.c @@ -0,0 +1,7 @@ +void main() { + int i = 0; + do { + i++; + if (i == 2) continue; + } while (i < 5); +} \ No newline at end of file diff --git a/08-code-generator/test/test13.c b/08-code-generator/test/test13.c new file mode 100644 index 0000000..5a0e9d0 --- /dev/null +++ b/08-code-generator/test/test13.c @@ -0,0 +1,4 @@ +void main() { + char *s; + s = "Hello"; +} \ No newline at end of file