-
Notifications
You must be signed in to change notification settings - Fork 0
/
listing.cc
74 lines (63 loc) · 1.84 KB
/
listing.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*******************************************************************************
File: listing.cc
Author: Dylan Bryan
Date: 8/9/21, 8:33 PM
Project: project-four
Purpose: This file contains the bodies of the functions that produces
the compilation listing
******************************************************************************/
#include <cstdio>
#include <string>
using namespace std;
#include "listing.h"
static int lineNumber;
static string error = "";
static int totalErrors = 0;
static int lexicalErrors = 0;
static int syntaxErrors = 0;
static int semanticErrors = 0;
static void displayErrors();
void firstLine()
{
lineNumber = 1;
printf("\n%4d ",lineNumber);
}
void nextLine()
{
displayErrors();
lineNumber++;
printf("%4d ",lineNumber);
}
int lastLine()
{
printf("\r");
displayErrors();
printf(" \n");
printf("Total Number of Errors: %i \n", totalErrors);
if (totalErrors == 0)
printf("Compiled Successfully\n");
printf("Lexical Errors: %i \n", lexicalErrors);
printf("Syntax Errors: %i \n", syntaxErrors );
printf("Semantic Errors: %i \n", semanticErrors);
return totalErrors;
}
void appendError(ErrorCategories errorCategory, string message)
{
string messages[] = { "Lexical Error, Invalid Character ", "",
"Semantic Error, ", "Semantic Error, Duplicate Identifier: ",
"Semantic Error, Undeclared " };
if(errorCategory == LEXICAL)
lexicalErrors++;
if(errorCategory == SYNTAX)
syntaxErrors++;
if(errorCategory == GENERAL_SEMANTIC)
semanticErrors++;
error += messages[errorCategory] + message;
totalErrors++;
}
void displayErrors()
{
if (error != "")
printf("%s\n", error.c_str());
error = "";
}