--- /dev/null
+/*\r
+ * sint.c\r
+ *\r
+ * SOFTWARE RIGHTS\r
+ *\r
+ * We reserve no LEGAL rights to SORCERER -- SORCERER is in the public\r
+ * domain. An individual or company may do whatever they wish with\r
+ * source code distributed with SORCERER or the code generated by\r
+ * SORCERER, including the incorporation of SORCERER, or its output, into\r
+ * commerical software.\r
+ *\r
+ * We encourage users to develop software with SORCERER. However, we do\r
+ * ask that credit is given to us for developing SORCERER. By "credit",\r
+ * we mean that if you incorporate our source code into one of your\r
+ * programs (commercial product, research project, or otherwise) that you\r
+ * acknowledge this fact somewhere in the documentation, research report,\r
+ * etc... If you like SORCERER and have developed a nice tool with the\r
+ * output, please mention that you developed it using SORCERER. In\r
+ * addition, we ask that this header remain intact in our source code.\r
+ * As long as these guidelines are kept, we expect to continue enhancing\r
+ * this system and expect to make other tools available as they are\r
+ * completed.\r
+ *\r
+ * SORCERER 1.00B\r
+ * Terence Parr\r
+ * AHPCRC, University of Minnesota\r
+ * 1992-1994\r
+ */\r
+#include <stdio.h>\r
+#include <setjmp.h>\r
+\r
+#ifdef PCCTS_USE_STDARG\r
+#include <stdarg.h>\r
+#else\r
+#include <varargs.h>\r
+#endif\r
+\r
+#include "CASTBase.h"\r
+#include "sintstack.h"\r
+\r
+SIntStack *\r
+#ifdef __USE_PROTOS\r
+sint_newstack(int size)\r
+#else\r
+sint_newstack(size)\r
+int size;\r
+#endif\r
+{\r
+ SIntStack *p = (SIntStack *) calloc(1, sizeof(SIntStack));\r
+ require(p!=NULL, "sint_newstack: out of memory");\r
+ p->data = (int *) calloc(size, sizeof(int));\r
+ require(p!=NULL, "sint_newstack: out of memory");\r
+ p->size = size;\r
+ p->sp = size;\r
+ return p;\r
+}\r
+\r
+void\r
+#ifdef __USE_PROTOS\r
+sint_freestack(SIntStack *st)\r
+#else\r
+sint_freestack(st)\r
+SIntStack *st;\r
+#endif\r
+{\r
+ if ( st==NULL ) return;\r
+ if ( st->data==NULL ) return;\r
+ free(st->data);\r
+ free(st);\r
+}\r
+\r
+void\r
+#ifdef __USE_PROTOS\r
+sint_push(SIntStack *st,int i)\r
+#else\r
+sint_push(st,i)\r
+SIntStack *st;\r
+int i;\r
+#endif\r
+{\r
+ require(st->sp>0, "sint_push: stack overflow");\r
+ st->data[--(st->sp)] = i;\r
+}\r
+\r
+int\r
+#ifdef __USE_PROTOS\r
+sint_pop(SIntStack *st)\r
+#else\r
+sint_pop(st)\r
+SIntStack *st;\r
+#endif\r
+{\r
+ require(st->sp<st->size, "sint_pop: stack underflow");\r
+ return st->data[st->sp++];\r
+}\r
+\r
+int\r
+#ifdef __USE_PROTOS\r
+sint_stacksize(SIntStack *st)\r
+#else\r
+sint_stacksize(st)\r
+SIntStack *st;\r
+#endif\r
+{\r
+ return st->size - st->sp;\r
+}\r
+\r
+void\r
+#ifdef __USE_PROTOS\r
+sint_stackreset(SIntStack *st)\r
+#else\r
+sint_stackreset(st)\r
+SIntStack *st;\r
+#endif\r
+{\r
+ st->sp = st->size;\r
+}\r
+\r
+int\r
+#ifdef __USE_PROTOS\r
+sint_stackempty(SIntStack *st)\r
+#else\r
+sint_stackempty(st)\r
+SIntStack *st;\r
+#endif\r
+{\r
+ return st->sp==st->size;\r
+}\r
+\r
+int\r
+#ifdef __USE_PROTOS\r
+sint_top(SIntStack *st)\r
+#else\r
+sint_top(st)\r
+SIntStack *st;\r
+#endif\r
+{\r
+ require(st->sp<st->size, "sint_top: stack underflow");\r
+ return st->data[st->sp];\r
+}\r