Initial Commit
This commit is contained in:
parent
8855b219eb
commit
f014088199
3
compile
Executable file
3
compile
Executable file
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/bash
|
||||
|
||||
g++ parser.cpp lexer.cpp main.cpp -o main
|
||||
30
lexer.cpp
Normal file
30
lexer.cpp
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include "lexer.h"
|
||||
|
||||
char c;
|
||||
FILE* input_file;
|
||||
|
||||
Lexer::Lexer(std::string &file_name) {
|
||||
input_file = fopen(file_name.c_str(),"r");
|
||||
if(input_file == nullptr) {
|
||||
std::cout << "[Error] Script " << input_file << " could not be read\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
c = getc(input_file);
|
||||
if (c == EOF) {
|
||||
//do something related to eof here?
|
||||
fclose(input_file);
|
||||
}
|
||||
}
|
||||
|
||||
char nextChar() {
|
||||
if (c != EOF) {
|
||||
c = getc(input_file);
|
||||
} else {
|
||||
c = EOF;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
14
lexer.h
Normal file
14
lexer.h
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
#include <iostream>
|
||||
|
||||
#ifndef LEXER_H
|
||||
#define LEXER_H
|
||||
|
||||
class Lexer
|
||||
{
|
||||
private:
|
||||
std::string extension = ".prog";
|
||||
public:
|
||||
Lexer(std::string &file_name);
|
||||
};
|
||||
|
||||
#endif
|
||||
15
main.cpp
Normal file
15
main.cpp
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include "lexer.h"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
if (argc > 1) {
|
||||
std::string file_name(argv[1]);
|
||||
Lexer lex(file_name);
|
||||
} else {
|
||||
std::cout << "[Error] No input file provided\n";
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
8
parser.cpp
Normal file
8
parser.cpp
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
|
||||
#include "parser.h"
|
||||
|
||||
Parser::Parser(std::string input_file) {
|
||||
|
||||
}
|
||||
14
parser.h
Normal file
14
parser.h
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
#include <iostream>
|
||||
|
||||
#ifndef PARSER_H
|
||||
#define PARSER_H
|
||||
|
||||
class Parser
|
||||
{
|
||||
private:
|
||||
|
||||
public:
|
||||
Parser(std::string input_file);
|
||||
};
|
||||
|
||||
#endif
|
||||
3
script.prog
Normal file
3
script.prog
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
hello world, this is a lexer test
|
||||
hello world
|
||||
Kanye's new name is Ye
|
||||
Loading…
Reference in New Issue
Block a user