From e7f3b538254ea98e5b65bb45c41d7f574c772c8f Mon Sep 17 00:00:00 2001 From: Alex Smith Date: Sat, 21 Jun 2008 18:40:40 -0400 Subject: [PATCH] Parsing for jic compilation of expressions --- src/dekludge.c | 5 +++-- src/feh2.c | 28 +++++++++++++++++++++++++++- src/lexer.l | 4 ++++ src/parser.y | 17 ++++++++++++++--- 4 files changed, 48 insertions(+), 6 deletions(-) diff --git a/src/dekludge.c b/src/dekludge.c index 7395541..92401d4 100644 --- a/src/dekludge.c +++ b/src/dekludge.c @@ -524,12 +524,12 @@ void checknodeactbits(node *np) case C_NOT: np->optdata = np->width == 16 ? 0xffffLU : 0xffffffffLU; - break; + break; case C_A: np->optdata = 0xffffffffLU; break; - + case C_NOTEQUAL: case C_ISEQUAL: case C_LOGICALNOT: @@ -617,6 +617,7 @@ void checknodeactbits(node *np) /*@=nullderef@*/ /*@fallthrough@*/ + case UNKNOWNOP: default: /*@-nullderef@*/ if(np->opcode == BY && !np->lval->optdata) optuple->warn239 = 1; diff --git a/src/feh2.c b/src/feh2.c index 46c0a9f..8344d53 100644 --- a/src/feh2.c +++ b/src/feh2.c @@ -304,6 +304,10 @@ void typecast(node *np) np->width = np->rval->width; else if (np->opcode == SELECT) np->width = np->rval->width; /* n-bit select has an n-bit result */ + else if (np->opcode == UNKNOWNOP || np->opcode == INTERSECTION) /* AIS */ + np->width = (np->rval->width == 16 ? np->lval->width : 32); + else if (np->opcode == BADCHAR) /* AIS */ + np->width = 16; else if (np->opcode == SUB) np->width = np->lval->width; /* type of the array */ else if (np->opcode == SLAT || np->opcode == BACKSLAT) @@ -621,6 +625,19 @@ void explexpr(node* np, FILE* fp) (void) fprintf(fp, ")"); break; + case UNKNOWNOP: + (void) fprintf(fp, "("); + explexpr(np->rval->lval, fp); + if(np->lval->constant < 256) + (void) fprintf(fp, " %c ", (char)np->lval->constant); + else + (void) fprintf(fp, " %c^H%c ", + (char)(np->lval->constant / 256), + (char)(np->lval->constant % 256)); + explexpr(np->rval->rval, fp); + (void) fprintf(fp, ")"); + break; + case SLAT: (void) fprintf(fp, "("); explexpr(np->lval, fp); @@ -1035,6 +1052,11 @@ static void revprexpr(node *np, FILE *fp, node *target) free(temp); break; + case UNKNOWNOP: /* don't be silly */ + fprintf(fp, " ick_lose(IE277, ick_lineno, (char*) NULL);\n"); + ick_lwarn(W278, emitlineno, (char*) NULL); + break; + case BACKSLAT: /* Unimplemented. This isn't even in the parser yet, so it's a ick_mystery how we got here. */ @@ -1129,7 +1151,7 @@ static void revprexpr(node *np, FILE *fp, node *target) else if(!pickcompile) { node* sp; - + if (np->opcode != SUB) { sp = np; (void) fprintf(fp," (void) ick_assign((char*)&"); @@ -1217,6 +1239,10 @@ void prexpr(node *np, FILE *fp, int freenode) (void) fprintf(fp, ")"); break; + case UNKNOWNOP: /* AIS //tk */ + (void) fprintf(fp, "0"); + break; + case BACKSLAT: /* AIS */ /* Unimplemented. This isn't even in the parser yet, so it's a ick_mystery how we got here. */ diff --git a/src/lexer.l b/src/lexer.l index 52b4688..9bd5538 100644 --- a/src/lexer.l +++ b/src/lexer.l @@ -436,6 +436,10 @@ CONFICENDUM {yylval.numval = CREATE; return(GERUND);} {W} ; {I} {/* AIS */ yylval.numval = *yytext; return(UNKNOWNID);} +.\^H. {/* AIS */ yylval.numval = yytext[0]*256 + yytext[3]; + if(yytext[0] > yytext[3]) + yylval.numval = yytext[0] + yytext[3]*256; + return(BADCHAR);} . {yylval.numval = yytext[0]; /* AIS: The line below for debug */ if(yydebug) fprintf(stdout, "yylex: bad char %#x\n",(unsigned char)yytext[0]); return(BADCHAR);} diff --git a/src/parser.y b/src/parser.y index 0962d95..482632e 100644 --- a/src/parser.y +++ b/src/parser.y @@ -116,11 +116,11 @@ static tuple *prevtuple = NULL; /* AIS: ONCE and AGAIN added, for multithread support; also, NOSPOT added, so that I can reserve _ for future use (it's nowhere in the grammar yet) */ %token MAYBE DO PLEASE NOT ONCE AGAIN MESH NOSPOT ick_ONESPOT ick_TWOSPOT ick_TAIL ick_HYBRID -%token MINGLE SELECT /* AIS: SPARK EARS */ SUB BY BADCHAR +%token MINGLE SELECT UNKNOWNOP /* AIS: SPARK EARS */ SUB BY /* AIS: For operand overloading */ %token SLAT BACKSLAT -%token NUMBER UNARY OHOHSEVEN GERUND LABEL +%token NUMBER UNARY OHOHSEVEN GERUND LABEL BADCHAR %token INTERSECTION /* @@ -150,7 +150,7 @@ static tuple *prevtuple = NULL; %type subscr byexpr scalar scalar2s ick_array initem outitem sublist %type unambig limunambig subscr1 sublist1 oparray osubscr osubscr1 %type notanlvalue nlunambig lunambig unknownstatement unknownatom -%type unknownsin unknownsif unknownaid +%type unknownsin unknownsif unknownaid unop %type preproc perform mtperform %type please preftype @@ -501,12 +501,19 @@ osubscr1: oparray SUB sublist1 {$$ = $1; $$->rval = cons(SUB, $$->rval, $3);} ; +/* AIS: Unknown operators */ +unop : BADCHAR {$$ = newnode(); $$->opcode = BADCHAR; + $$->constant = $1;} + ; + /* here goes the general expression syntax */ expr : unambig {$$ = $1;} /* AIS: CLC-INTERCAL allows right-association of SELECT and MINGLE. (Strangely, that simplifies this section somewhat.) */ | unambig SELECT expr {$$ = cons(SELECT, $1, $3);} | unambig MINGLE expr {$$ = cons(MINGLE, $1, $3);} + | unambig unop expr {$$ = cons(UNKNOWNOP, $2, + cons(INTERSECTION, $1, $3));} /* AIS: Operand overloading */ | scalar SLAT expr {NEWFANGLED{$$ = cons(SLAT, $1, $3); opoverused=1; if(!firstslat) @@ -522,6 +529,8 @@ notanlvalue:nlunambig {$$ = $1;} | osubscr {$$ = $1;} | unambig SELECT expr {$$ = cons(SELECT, $1, $3);} | unambig MINGLE expr {$$ = cons(MINGLE, $1, $3);} + | unambig unop expr {$$ = cons(UNKNOWNOP, $2, + cons(INTERSECTION, $1, $3));} | scalar SLAT expr {NEWFANGLED{$$ = cons(SLAT, $1, $3); opoverused=1; if(!firstslat) firstslat=$$; else @@ -533,6 +542,8 @@ notanlvalue:nlunambig {$$ = $1;} limexpr : limunambig {$$ = $1;} | limunambig SELECT expr {$$ = cons(SELECT, $1, $3);} | limunambig MINGLE expr {$$ = cons(MINGLE, $1, $3);} + | limunambig unop expr {$$ = cons(UNKNOWNOP, $2, + cons(INTERSECTION, $1, $3));} | scalar SLAT expr {NEWFANGLED{$$ = cons(SLAT, $1, $3); opoverused=1; if(!firstslat) firstslat=$$; else -- 2.43.0