setting VS 2015 with Win-Flex

0

How do you adjust correctly the settings in VS 2015 to compile and run programs using in Win-Flex?

I wrote a program implementing compiler given a certain grammar. Given 2 text files (for tests), the purpose is to get eventually 6 output files: lexical analysis, syntactic analysis and semantic analysis for each text file.

Here is my Main.c:

#define _CRT_SECURE_NO_DEPRECATE
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "LEXYY.h"
#include "PARSER.h"
#include "semantic.h"

char *yytext;
FILE *yyin;
int yylex();

void printToken() {
    const char *TokenNames[11] = {
        "PROGRAM", "END",
        "INTEGER", "REAL", "INT_NUMBER", "REAL_NUMBER",
        "ID", "VOID", "RETURN",
        "COMMA", "SEMICOLON",
    };
    char buffer[] = { (char)token->kind, '\0' };
    const char *token_name = token->kind >= PROGRAM ? TokenNames[token->kind - PROGRAM] : buffer;
    token->count = strlen(token->lexeme);

    fprintf(yyout, "Token of kind '%s' was found at line: %d, lexeme: '%s'\n", token_name, token->line, token->lexeme);
}

int main(int argc, char *argv[]) {
    int current_token;

    for (int i = 1; i < 3; i++) {
        if (i == 1) {
            yyin = fopen("C:\\temp\\test1.txt", "r");
            yyout = fopen("C:\\temp\\test1_lex.txt", "w");
        }
        else {
            yyin = fopen("C:\\temp\\test2.txt", "r");
            yyout = fopen("C:\\temp\\test2_lex.txt", "w");
        }
        if (yyin == NULL) {
            printf("Cannot find file.\nPlease use standard input.\n");
            yyin = stdin;
        }
        if (yyout == NULL) {
            printf("Cannot open output file.\n");
            yyout = stdout;
        }
        initLexer();
        while ((current_token = yylex()) != 0) {
            create_and_store_token(current_token, (char *)yytext, line_number);
            printToken();
        }

        if (i == 1) {
            yyout = fopen("C:\\temp\\test1_syntatic.txt", "w");
        }
        else {
            yyout = fopen("C:\\temp\\test2_syntatic.txt", "w");
        }
        if (yyout == NULL) {
            printf("Cannot open output file.\n");
            yyout = stdout;
        }
        if (lexer_errors) {
            fprintf(yyout, "Detected Errors by lexical analysis.\nPlease first fix lexical error.\n");
            continue;
        }
        parser();

        if (i == 1) {
            yyout = fopen("C:\\temp\\test1_semantic.txt", "w");
        }
        else {
            yyout = fopen("C:\\temp\\test2_semantic.txt", "w");
        }
        if (yyout == NULL) {
            printf("Cannot open output file.\n");
            yyout = stdout;
        }
        if (parser_errors) {
            fprintf(yyout, "Detected Errors by syntatic analysis.\nPlease first fix syntax error.\n");
            continue;
        }
        semantic();
    }
    return 0;
}

However, it seems that there is a failure to read input files , since I get the following when I run it:

enter image description here

Debugging gives me the following:

'task3.exe' (Win32): Loaded 'C:\Users\itzha\Desktop\TASK3\task3\Debug\task3.exe'. Symbols loaded.
'task3.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ntdll.dll'. Symbols loaded.
'task3.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel32.dll'. Symbols loaded.
'task3.exe' (Win32): Loaded 'C:\Windows\SysWOW64\KernelBase.dll'. Symbols loaded.
'task3.exe' (Win32): Loaded 'C:\Windows\SysWOW64\vcruntime140d.dll'. Symbols loaded.
'task3.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ucrtbased.dll'. Symbols loaded.
'task3.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ucrtbased.dll'. Symbols loaded.
'task3.exe' (Win32): Unloaded 'C:\Windows\SysWOW64\ucrtbased.dll'
The thread 0x300c has exited with code -1073741510 (0xc000013a).
The thread 0x2d2c has exited with code -1073741510 (0xc000013a).
The thread 0x1dac has exited with code -1073741510 (0xc000013a).
The thread 0x2374 has exited with code -1073741749 (0xc000004b).
The program '[9524] task3.exe' has exited with code -1073741510 (0xc000013a).
visual-studio-2015
compilation
flex-lexer
lexer
asked on Stack Overflow May 15, 2020 by DonaldT • edited May 15, 2020 by DonaldT

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0