Fix the syntactic analyzer for real.
[TP_AL_C.git] / lexer / print_helper.c
index d5ca8f0da8705e4865663718ce215a9fd3ea5bcd..40d05232bb7004cc6e43f5624627440be7ebf6bd 100644 (file)
@@ -1,13 +1,17 @@
-#include <stdarg.h>
 #include <stdio.h>
 #include <wchar.h>
+#include <stdarg.h>
 
-void pr_warning(const char *format, ...) {
+#include "print_helper.h"
+#include "global_vars.h"
+
+void pr_warning(const char* format, ...) {
     va_list args;
 
     va_start(args, format);
     fprintf(stdout, format, args);
     va_end(args);
+    fflush(stdout);
 }
 
 void pr_error(const char *format, ...) {
@@ -16,7 +20,21 @@ void pr_error(const char *format, ...) {
     va_start(args, format);
     fprintf(stderr, format, args);
     va_end(args);
+    fflush(stderr);
+}
+
+#if DEBUG
+void pr_debug(const char *format, ...) {
+    va_list args;
+
+    va_start(args, format);
+    fprintf(stderr, format, args);
+    va_end(args);
+    fflush(stderr);
 }
+#else
+void pr_debug(const char *format, ...);
+#endif /* DEBUG */
 
 void wpr_warning(const wchar_t *format, ...) {
     va_list args;
@@ -24,6 +42,7 @@ void wpr_warning(const wchar_t *format, ...) {
     va_start(args, format);
     fwprintf(stdout, format, args);
     va_end(args);
+    fflush(stdout);
 }
 
 void wpr_error(const wchar_t *format, ...) {
@@ -32,4 +51,23 @@ void wpr_error(const wchar_t *format, ...) {
     va_start(args, format);
     fwprintf(stderr, format, args);
     va_end(args);
+    fflush(stderr);
+}
+
+void wprint_token(FILE* out_file) {
+    if (tokenType == MOT || tokenType == MOTCLE) {
+        fwprintf(out_file, L"%20s: %ls\n", tokenTypestr[tokenType], token[tokenFound].value);
+    } else {
+        fwprintf(out_file, L"%20s\n", tokenTypestr[tokenType]);
+    }
+    fflush(out_file);
+}
+
+void wprint_ctoken(FILE* out_file) {
+    if (tokenType == MOT || tokenType == MOTCLE) {
+        fwprintf(out_file, L"%20s: %ls\n", tokenTypestr[tokenType], tokenValue);
+    } else {
+        fwprintf(out_file, L"%20s\n", tokenTypestr[tokenType]);
+    }
+    fflush(out_file);
 }