Skip to content

Commit 027b112

Browse files
Merge pull request #5 from Pip-Install-Party/officialblake-develop
add tokenizer files
2 parents 1c9da12 + 2ca6be6 commit 027b112

File tree

5 files changed

+31
-14
lines changed

5 files changed

+31
-14
lines changed

commentDFA.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include "commentDFA.h"
1010

1111
// State 0: Normal state, reading and printing code character by character
12-
void commentDFA::state0(std::ifstream& file, int& lineCount, std::ostringstream& buffer) {
12+
void CommentDFA::state0(std::ifstream& file, int& lineCount, std::ostringstream& buffer) {
1313
char ch;
1414
file.get(ch); // Read a character from the file
1515
if (file.eof()) { // Check if the end of file is reached
@@ -41,7 +41,7 @@ void commentDFA::state0(std::ifstream& file, int& lineCount, std::ostringstream&
4141
}
4242

4343
// State 1: After hitting a '/', figure out if it's a comment or a division operator
44-
void commentDFA::state1(std::ifstream& file, int& lineCount, std::ostringstream& buffer) {
44+
void CommentDFA::state1(std::ifstream& file, int& lineCount, std::ostringstream& buffer) {
4545
char ch;
4646
file.get(ch); // Read the next character
4747
if (file.eof()) { // Check for end of file
@@ -68,7 +68,7 @@ void commentDFA::state1(std::ifstream& file, int& lineCount, std::ostringstream&
6868
}
6969

7070
// State 2: Inside a C++-style line comment, skip characters until newline is reached
71-
void commentDFA::state2(std::ifstream& file, int& lineCount, std::ostringstream& buffer) {
71+
void CommentDFA::state2(std::ifstream& file, int& lineCount, std::ostringstream& buffer) {
7272
char ch;
7373
file.get(ch); // Read the next character
7474
if (ch == '\n') { // If it's a newline, return to state0 to process the next line
@@ -82,7 +82,7 @@ void commentDFA::state2(std::ifstream& file, int& lineCount, std::ostringstream&
8282
}
8383

8484
// State 3: Inside a C-style block comment, look for the closing '*/'
85-
bool commentDFA::state3(std::ifstream& file, int& lineCount, int& commentLineCount, std::ostringstream& buffer) {
85+
bool CommentDFA::state3(std::ifstream& file, int& lineCount, int& commentLineCount, std::ostringstream& buffer) {
8686
char ch;
8787
file.get(ch); // Read the next character
8888
if (ch == '*') { // If it's a '*', check if it's the start of '*/' (end of comment)
@@ -99,7 +99,7 @@ bool commentDFA::state3(std::ifstream& file, int& lineCount, int& commentLineCou
9999
}
100100

101101
// State 4: Looking for '/' to close the C-style block comment
102-
bool commentDFA::state4(std::ifstream& file, int& lineCount, int& commentLineCount, std::ostringstream& buffer) {
102+
bool CommentDFA::state4(std::ifstream& file, int& lineCount, int& commentLineCount, std::ostringstream& buffer) {
103103
char ch;
104104
file.get(ch); // Read the next character
105105
if (ch == '/') { // If it's '/', the block comment is closed, return to state0
@@ -121,7 +121,7 @@ bool commentDFA::state4(std::ifstream& file, int& lineCount, int& commentLineCou
121121

122122
// State 5: Inside a quoted string (either single or double quotes),
123123
// ignore characters inside until the closing quote is found
124-
bool commentDFA::state5(std::ifstream& file, int& lineCount, int& quoteLineCount, std::ostringstream& buffer) {
124+
bool CommentDFA::state5(std::ifstream& file, int& lineCount, int& quoteLineCount, std::ostringstream& buffer) {
125125
char ch;
126126
file.get(ch);
127127
if (file.eof()) { // If end of file is reached, return false
@@ -139,7 +139,7 @@ bool commentDFA::state5(std::ifstream& file, int& lineCount, int& quoteLineCount
139139

140140
// State 6: Detected an asterisk ('*'),
141141
// check if it's an unterminated C-style block comment
142-
bool commentDFA::state6(std::ifstream& file, int& lineCount, std::ostringstream& buffer) {
142+
bool CommentDFA::state6(std::ifstream& file, int& lineCount, std::ostringstream& buffer) {
143143
char ch;
144144
file.get(ch);
145145
if (ch == '/') { // If a slash is found, return false

commentDFA.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
// commentDFA.h
2-
#ifndef commentDFA_H // include guard
3-
#define commentDFA_H
2+
#ifndef COMMENTDFA_H // include guard
3+
#define COMMENTDFA_H
44

55
#include <iostream>
66
#include <fstream>
77
#include <string>
88
#include <filesystem>
99
#include <sstream>
1010

11-
class commentDFA
11+
class CommentDFA
1212
{
1313
private:
1414
int lineCount = 1;
@@ -21,9 +21,9 @@ class commentDFA
2121
bool state5(std::ifstream& file, int& lineCount, int& quoteLinecount, std::ostringstream& buffer); // Inside a quoted string, skip over characters until end of quote
2222
bool state6(std::ifstream& file, int& lineCount, std::ostringstream& buffer); // Detected Asterisk, check if unterminated comment
2323
public:
24-
commentDFA() {}
25-
~commentDFA() { delete this; };
24+
CommentDFA() {}
25+
~CommentDFA() { delete this; };
2626
void begin(std::ifstream& file, std::ostringstream& buffer) { state0(file, lineCount, buffer); }
2727
};
2828

29-
#endif /* commentDFA_H */
29+
#endif /* COMMENTDFA_H */

main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <sstream>
66

77
#include "commentDFA.h"
8+
#include "tokenizer.h"
89

910
// Vectors holding the file paths for test files
1011
const std::filesystem::path a1Tests[] = {
@@ -65,7 +66,7 @@ int main() {
6566
std::cerr << "Error: Could not open the file " << a1Tests[filenum] << std::endl;
6667
return 1; // Exit with an error code
6768
}
68-
commentDFA *removeComments = new commentDFA();
69+
CommentDFA *removeComments = new CommentDFA();
6970
// Start in state0 to process the file
7071
removeComments->begin(file, buffer);
7172
file.close(); // Close the file after processing

tokenizer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// tokenize.cpp

tokenizer.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// tokenizer.h
2+
#ifndef TOKENIZER_H // include guard
3+
#define TOKENIZER_H
4+
5+
#include <iostream>
6+
7+
class Tokenizer
8+
{
9+
private:
10+
public:
11+
Tokenizer() {}
12+
~Tokenizer() { delete this; };
13+
};
14+
15+
#endif /* TOKENIZER */

0 commit comments

Comments
 (0)