+#include <stddef.h>
#include <stdio.h>
#include <assert.h>
+#include <errno.h>
+#include <string.h>
#include "parser.h"
#include "parser_proc.h"
{
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;
}
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) {
#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); \
} \
'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);}
'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);}