Skip to content

Instantly share code, notes, and snippets.

@RealNeGate
Last active February 8, 2023 00:18
Show Gist options
  • Select an option

  • Save RealNeGate/95948bc83b55115f8334df90d613f578 to your computer and use it in GitHub Desktop.

Select an option

Save RealNeGate/95948bc83b55115f8334df90d613f578 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <assert.h>
#include <ctype.h>
int s[1024],i=0,a,b,m[4096];
char *d[256],e;
#define X(x) (i>0?(x)=s[--i]:E("SU"))
#define Y (X(b),X(a))
#define Z(x) (i<1024?s[i++]=(x):E("SO"))
#define W(o) (Y,Z(a o b))
#define V(o) C(o)?W(o):
#define E(x) (fprintf(stderr,x"\n"),abort(),0)
#define P printf
#define S strcmp
#define K strlen
#define A atoi
#define L assert
#define B abort
#define D(x) isdigit(*x)
#define U(x) strdup(x)
#define C(x) !S(w,#x)
#define T(x) strtok_s(x," \t\n",&c)
char *q(char *n) {
for(char **j=d;*j;j+=2) if(!S(n,*j)) return j[1];
return 0;
}
void r(char* n, const char *t) {
char *c,z=1,y=1,*o,l[256],*w=(strncpy(l,t,256),l[255]=0,T(l));
do V(+)V(-)V(*)V(/)
C(;)?z=0:
C(@)?z=1:
C(nz)?X(a),z=!!a:
C(drop)?X(a):
C(.)?X(a),P("%c",a):
C(read)?X(a),a=m[a],Z(b):
C(write)?Y,m[a]=b:
C(swap)?Y,Z(a),Z(b):
C(dup)?X(a),Z(a),Z(a):
C(:)?w=T(NULL),d[e*2]=U(w),d[e*2+1]=U(c),e+=1,w=T(strchr(c,';')),0:
D(w)?Z(A(w)):
(o=q(w),(o?0:E("?")),(S(n,w)?(r(w,o),0):(strncpy(l,t,256),l[255]=0,w=T(l),y=0)),0);
while (z&&(y?w=T(NULL):(y=1,w)));
}
int main(int argc, char **argv) {
char *l;
do l=fgets(malloc(80), 80, stdin), l?(r("", l), P("ok.\n")):0; while (l);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment