flex-output file can't be generated

1

Using VS 2015 and Win Flex , I developed a program which implements lexical, syntactic and semantic analysis according to some grammar written in LEXYY.l file. Win Flex is installed correctly.

Here is my main.c file:

#define _CRT_SECURE_NO_DEPRECATE
#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;
}

Well, my program compiles with no errors, and when I run it , 6 output files are expected to get, representing the 3*2 analysis steps accordingly, since I created a 2 text file for testing).

However, I get only 1 empty output file named test1_lex, and the cmd.exe screen shows the following:

Cannot find file.
Please use standard input.

I have to note that the lex.yy.c file is generated.

Debugging gives the following output:

'task3.exe' (Win32): Loaded 'C:\Users\itzha\Desktop\task3\Debug\task3.exe'. Symbols loaded.
'task3.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ntdll.dll'. Cannot find or open the PDB file.
'task3.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel32.dll'. Cannot find or open the PDB file.
'task3.exe' (Win32): Loaded 'C:\Windows\SysWOW64\KernelBase.dll'. Cannot find or open the PDB file.
'task3.exe' (Win32): Loaded 'C:\Windows\SysWOW64\vcruntime140d.dll'. Cannot find or open the PDB file.
'task3.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ucrtbased.dll'. Cannot find or open the PDB file.
The thread 0x2db4 has exited with code -1073741510 (0xc000013a).
The thread 0x3ef0 has exited with code -1073741510 (0xc000013a).
The thread 0x4868 has exited with code -1073741510 (0xc000013a).
The thread 0x4ab8 has exited with code -1073741749 (0xc000004b).
The program '[16424] task3.exe' has exited with code -1073741510 (0xc000013a).

enter image description here

c
flex-lexer
stdio
asked on Stack Overflow May 15, 2020 by TRUMP • edited May 16, 2020 by user207421

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0