enums
[m6w6/ext-psi] / src / parser.re
index 69e76c8f124244f9c7920844569dfa5da11c3a80..50d15aadd86d0b9ae7dfb35a1b445277afdbf554 100644 (file)
@@ -1,5 +1,8 @@
+#include <stddef.h>
 #include <stdio.h>
 #include <assert.h>
+#include <errno.h>
+#include <string.h>
 
 #include "parser.h"
 #include "parser_proc.h"
@@ -13,15 +16,11 @@ PSI_Parser *PSI_ParserInit(PSI_Parser *P, const char *filename, psi_error_cb err
 {
        FILE *fp;
 
-       if (!P) {
-               P = malloc(sizeof(*P));
-       }
-       memset(P, 0, sizeof(*P));
-
        fp = fopen(filename, "r");
 
        if (!fp) {
-               perror(filename);
+               error(NULL, PSI_WARNING, "Could not open '%s' for reading: %s",
+                               filename, strerror(errno));
                return NULL;
        }
 
@@ -47,20 +46,6 @@ PSI_Parser *PSI_ParserInit(PSI_Parser *P, const char *filename, psi_error_cb err
        return P;
 }
 
-void PSI_ParserSyntaxError(PSI_Parser *P, const char *fn, size_t ln, const char *msg, ...) {
-       char buf[0x1000] = {0};
-       va_list argv;
-
-       va_start(argv, msg);
-       vsnprintf(buf, 0x1000-1, msg, argv);
-       va_end(argv);
-
-       P->error(PSI_WARNING, "PSI syntax error on line %zu in '%s'%s%s",
-                       ln, fn, msg ? ": ": "", buf);
-
-       ++P->errors;
-}
-
 size_t PSI_ParserFill(PSI_Parser *P, size_t n)
 {
        if (P->flags & PSI_PARSER_DEBUG) {
@@ -214,7 +199,7 @@ void PSI_ParserFree(PSI_Parser **P)
 #define RETURN(t) do { \
        P->num = t; \
        if (P->flags & PSI_PARSER_DEBUG) { \
-               fprintf(stderr, "PSI> TOKEN: %d %.*s (EOF=%d %s:%zu:%zu)\n", \
+               fprintf(stderr, "PSI> TOKEN: %d %.*s (EOF=%d %s:%u:%u)\n", \
                                P->num, (int) (P->cur-P->tok), P->tok, P->num == PSI_T_EOF, \
                                P->psi.file.fn, P->line, P->col); \
        } \
@@ -277,7 +262,10 @@ token_t PSI_ParserScan(PSI_Parser *P)
                'MIXED' {RETURN(PSI_T_MIXED);}
                'VOID' {RETURN(PSI_T_VOID);}
                'BOOL' {RETURN(PSI_T_BOOL);}
+               'CHAR' {RETURN(PSI_T_CHAR);}
+               'SHORT' {RETURN(PSI_T_SHORT);}
                'INT' {RETURN(PSI_T_INT);}
+               'LONG' {RETURN(PSI_T_LONG);}
                'FLOAT' {RETURN(PSI_T_FLOAT);}
                'DOUBLE' {RETURN(PSI_T_DOUBLE);}
                'INT8_T' {RETURN(PSI_T_INT8);}
@@ -289,12 +277,14 @@ token_t PSI_ParserScan(PSI_Parser *P)
                'INT64_T' {RETURN(PSI_T_INT64);}
                'UINT64_T' {RETURN(PSI_T_UINT64);}
                'UNSIGNED' {RETURN(PSI_T_UNSIGNED);}
+               'SIGNED' {RETURN(PSI_T_SIGNED);}
                'STRING' {RETURN(PSI_T_STRING);}
                'ARRAY' {RETURN(PSI_T_ARRAY);}
                'OBJECT' {RETURN(PSI_T_OBJECT);}
                'FUNCTION' {RETURN(PSI_T_FUNCTION);}
                'TYPEDEF' {RETURN(PSI_T_TYPEDEF);}
                'STRUCT' {RETURN(PSI_T_STRUCT);}
+               'ENUM' {RETURN(PSI_T_ENUM);}
                'CONST' {RETURN(PSI_T_CONST);}
                'LIB' {RETURN(PSI_T_LIB);}
                'LET' {RETURN(PSI_T_LET);}