]> thyrsus.com Git - intercal.git/commitdiff
Parsing for jic compilation of expressions
authorAlex Smith <ais523@bham.ac.uk>
Sat, 21 Jun 2008 22:40:40 +0000 (18:40 -0400)
committerEric S. Raymond <esr@thyrsus.com>
Thu, 26 Aug 2010 00:34:58 +0000 (20:34 -0400)
src/dekludge.c
src/feh2.c
src/lexer.l
src/parser.y

index 739554118e206ebe39dc02ddc8b6e0e4cb757ae4..92401d492a0f8c82e7084ea25091d37f2ab8c951 100644 (file)
@@ -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;
index 46c0a9f19393034eeb2e620841ca5d527b92ab97..8344d53fd0cbc739d6ef23d38ee7fc82fe3102eb 100644 (file)
@@ -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. */
index 52b46883a1781bcd5e30f63b847560c718ec3cc9..9bd5538645b479a9d170e20f69b5b87b923c1901 100644 (file)
@@ -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);}
index 0962d9534fcf27f64867e4842db671d2f8241cd7..482632ee64f11eabad0326c07023af335c34e701 100644 (file)
@@ -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 <numval> NUMBER UNARY OHOHSEVEN GERUND LABEL
+%token <numval> NUMBER UNARY OHOHSEVEN GERUND LABEL BADCHAR
 %token <node> INTERSECTION
 
 /*
@@ -150,7 +150,7 @@ static tuple *prevtuple = NULL;
 %type <node> subscr byexpr scalar scalar2s ick_array initem outitem sublist
 %type <node> unambig limunambig subscr1 sublist1 oparray osubscr osubscr1
 %type <node> notanlvalue nlunambig lunambig unknownstatement unknownatom
-%type <node> unknownsin unknownsif unknownaid
+%type <node> unknownsin unknownsif unknownaid unop
 %type <tuple> preproc perform mtperform
 %type <numval> 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