Skip to content

Commit 5442b03

Browse files
updated binary file, fixed bugs with classes
1 parent 9d482d0 commit 5442b03

File tree

8 files changed

+87
-70
lines changed

8 files changed

+87
-70
lines changed

compiler.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -109,31 +109,32 @@ def extract_additional_files(file_path):
109109
includes.append(i)
110110

111111

112+
print_log("Class analysis")
113+
classes_list, updated_tokens = find_classes(tokens)
114+
for i in classes_list:
115+
classes.append(i)
116+
117+
for i in includes:
118+
tempclasses, temptokens = find_classes(remove_comments(lexical_analyzer(open(f"{absp}lib/{i.strip()}/{i.strip()}.h", "r").read())))
119+
for j in tempclasses:
120+
classes.append(j)
121+
112122

113123
print_log("Variable analysis")
114-
for i in find_variables(tokens):
115-
variables[i] = find_variables(tokens)[i]
124+
for i in find_variables(tokens, classes):
125+
variables[i] = find_variables(tokens, classes)[i]
116126
print(variables)
117127

118128

119129
for i in includes:
120130
temptokens = lexical_analyzer(open(f"{absp}lib/{i.strip()}/{i.strip()}.h", "r").read())
121131
temptokens = remove_comments(temptokens)
122-
tempvariables = find_variables(temptokens)
132+
tempvariables = find_variables(temptokens, classes)
123133
for j in tempvariables:
124134
variables[j] = tempvariables[j]
125135

126136

127137

128-
print_log("Class analysis")
129-
classes_list, updated_tokens = find_classes(tokens)
130-
for i in classes_list:
131-
classes.append(i)
132-
133-
for i in includes:
134-
tempclasses, temptokens = find_classes(remove_comments(lexical_analyzer(open(f"{absp}lib/{i.strip()}/{i.strip()}.h", "r").read())))
135-
for j in tempclasses:
136-
classes.append(j)
137138

138139
print_log("Namespace analysys")
139140
for i in find_namespaces(tokens):
@@ -260,9 +261,9 @@ def extract_additional_files(file_path):
260261
print(f"{absp}ucrt64\\bin\\g++.exe -o {bin_dir}/{settings['filename']} {objectfiles} -L{absp}lib -I{absp}lib -lponylib -finput-charset=UTF-8 -lstdc++ ")
261262
compiler = subprocess.run(f"{absp}ucrt64\\bin\\g++.exe -o {bin_dir}/{settings['filename']} {objectfiles} -I{absp}lib -I{bin_dir}/lib -L{absp}lib -lponylib -finput-charset=UTF-8 -lstdc++ ", capture_output=True)
262263

263-
# for i in os.listdir(bin_dir):
264-
# if i.split('.')[-1] == 'o':
265-
# os.remove(bin_dir + "/" + i)
264+
for i in os.listdir(bin_dir):
265+
if i.split('.')[-1] == 'o':
266+
os.remove(bin_dir + "/" + i)
266267

267268
if compiler.returncode == 0:
268269
print_log("Compilation successful!")

lastest.log

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
[23:28:55] Compiler started
2-
[23:28:55] Bin directory already exists
3-
[23:28:55] Reading files in floader
4-
[23:28:55] Compiling file prog.psc
5-
[23:28:55] Lexical analysis
6-
[23:28:55] Variable analysis
7-
[23:28:55] Class analysis
8-
[23:28:55] Namespace analysys
9-
[23:28:55] Translation
10-
[23:28:55] Assembling code
11-
[23:28:55] Writing code to file
12-
[23:28:55] Finished compiling file prog.psc
13-
[23:28:55] Reading configuration file
14-
[23:28:55] Copying built in libriaries
15-
[23:28:55] Copying additional files
16-
[23:28:55] Copying additional built-in libriaries
17-
[23:28:55] Building executable
18-
[23:28:55] Writing run.h
19-
[23:28:55] Writing run.cpp
20-
[23:28:55] Starting gcc compyler
21-
[23:28:55] Compiling c:/pony/bin/prog.cpp
22-
[23:28:56] Compiling c:/pony/bin/lib/run.cpp
23-
[23:28:57] Compiling c:/pony/bin/lib/testlib.cpp
24-
[23:28:57] Compiling c:/pony/bin/lib/math.cpp
25-
[23:28:57] Compiling c:/pony/bin/lib/datetime.cpp
26-
[23:28:58] Compilation successful!
1+
[18:02:45] Compiler started
2+
[18:02:45] Bin directory already exists
3+
[18:02:45] Reading files in floader
4+
[18:02:45] Compiling file prog.psc
5+
[18:02:45] Lexical analysis
6+
[18:02:45] Class analysis
7+
[18:02:45] Variable analysis
8+
[18:02:45] Namespace analysys
9+
[18:02:45] Translation
10+
[18:02:45] Assembling code
11+
[18:02:45] Writing code to file
12+
[18:02:45] Finished compiling file prog.psc
13+
[18:02:45] Reading configuration file
14+
[18:02:45] Copying built in libriaries
15+
[18:02:45] Copying additional files
16+
[18:02:45] Copying additional built-in libriaries
17+
[18:02:45] Building executable
18+
[18:02:45] Writing run.h
19+
[18:02:45] Writing run.cpp
20+
[18:02:45] Starting gcc compyler
21+
[18:02:45] Compiling c:/pony/bin/prog.cpp
22+
[18:02:47] Compiling c:/pony/bin/lib/run.cpp
23+
[18:02:48] Compiling c:/pony/bin/lib/testlib.cpp
24+
[18:02:48] Compiling c:/pony/bin/lib/math.cpp
25+
[18:02:49] Compiling c:/pony/bin/lib/datetime.cpp
26+
[18:02:50] Compilation successful!

launcher/programm.cpp

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,24 @@
22
#include <filesystem>
33
#include <format>
44
#include <fstream>
5-
5+
#include <string>
6+
#include <cctype>
67

78
using namespace std;
89
using std::filesystem::current_path;
910

11+
std::string strip(const std::string &inpt)
12+
{
13+
auto start_it = inpt.begin();
14+
auto end_it = inpt.rbegin();
15+
while (std::isspace(*start_it))
16+
++start_it;
17+
while (std::isspace(*end_it))
18+
++end_it;
19+
return std::string(start_it, end_it.base());
20+
}
21+
22+
1023
int main(int argc, char *argv[]){
1124

1225
std::filesystem::path exePath = std::filesystem::absolute(std::filesystem::path(argv[0]));
@@ -16,18 +29,17 @@ int main(int argc, char *argv[]){
1629
filesystem::path directoryPath = exeDir;
1730
string stringpath = directoryPath.generic_string();
1831

19-
if (argv[0] == "version")
32+
if (strip(argv[1]) == "version")
2033
{
2134

22-
cout << "Version: 0.0.1 alpha" << endl;
35+
cout << "Version: 0.0.2 alpha" << endl;
2336
return 0;
2437
}
2538

26-
27-
if (argv[0] == "libinfo")
39+
if (strip(argv[1]) == "libinfo")
2840
{
2941
std::ifstream file;
30-
file.open(stringpath + "/lib/" + argv[1] + "/libinfo");
42+
file.open(stringpath + "/lib/" + strip(argv[2]) + "/libinfo");
3143
if (file.is_open())
3244
{
3345
string line;
@@ -41,7 +53,6 @@ int main(int argc, char *argv[]){
4153

4254
}
4355

44-
4556
std::string path = argv[0];
4657

4758
string command = stringpath + "/python/python.exe" + " " + stringpath + "/compiler.py" + " " + argv[1];

lexer.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
libs, psclibs = parcse_libs()
1212

13-
def find_variables(tokens):
13+
def find_variables(tokens, classes):
1414
variables = {}
1515
for i in range(0, len(tokens)):
1616
if tokens[i] in variable_types:
@@ -29,6 +29,12 @@ def find_variables(tokens):
2929
j += 1
3030
variables[tokens[i+j]] = tokens[i]
3131

32+
elif tokens[i] in classes:
33+
j = 1
34+
while tokens[i + j] == '*':
35+
j += 1
36+
variables[tokens[i+j]] = tokens[i]
37+
3238
return variables
3339

3440
def get_libs(tokens):
@@ -78,13 +84,13 @@ def find_classes(tokens:list):
7884
if tokens[i+j] == '{':
7985
insert_indexes.append(i+j+1)
8086

81-
# updated_tokens = tokens
82-
# for i in insert_indexes:
83-
# tokens.insert(i, '\n')
84-
# tokens.insert(i+1, 'public:')
87+
updated_tokens = tokens
88+
for i in insert_indexes:
89+
tokens.insert(i, '\n')
90+
tokens.insert(i+1, 'public:')
8591

8692

87-
return classes, tokens
93+
return classes, updated_tokens
8894

8995

9096
def find_namespaces(tokens:list):

lextree.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,16 @@ def assemble_tokens(treelist, indent=0):
8282

8383
from lexer import *
8484
tokens = (lexical_analyzer(open("C:\pony\prog.psc", "r").read()))
85-
variables = find_variables(tokens)
8685
classes, tokens = find_classes(tokens)
87-
88-
translated = translate_tokens(tokens=tokens, variables=variables, classes=classes)
86+
variables = find_variables(tokens, classes)
87+
includes = get_libs(tokens)
88+
namespaces = find_namespaces(tokens)
89+
tokens = format_strings(tokens)
90+
translated = translate_tokens(tokens=tokens, variables=variables, classes=classes, includes=includes, namespaces=namespaces)
8991
tree = build_tree(translated)
9092
tree_list = tree_to_list(tree)
9193

92-
print(assemble_tokens(nested_lists(tree_list)))
94+
print(nested_lists(tree_list))
9395
# assemble_tokens(tree_list)
9496

9597
# print(nested_lists(translated))

libbuilder.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def get_libs(tokens):
2828

2929
return includes
3030

31-
def find_variables(tokens):
31+
def find_variables(tokens, classes):
3232
variables = {}
3333
for i in range(0, len(tokens)):
3434
if tokens[i] in variable_types:
@@ -46,6 +46,12 @@ def find_variables(tokens):
4646
while tokens[i + j] == '*':
4747
j += 1
4848
variables[tokens[i+j]] = tokens[i]
49+
50+
elif tokens[i] in classes:
51+
j = 1
52+
while tokens[i + j] == '*':
53+
j += 1
54+
variables[tokens[i+j]] = tokens[i]
4955

5056
return variables
5157

@@ -158,8 +164,8 @@ def assemble_code(tokens):
158164
def build_lib(libname):
159165
i = libname
160166
lib_tokens = lexical_analyzer(open(f"{absp}lib/{i.strip()}/{i.strip()}.psc", "r").read())
161-
lib_variables = find_variables(lib_tokens)
162167
lib_classes = find_classes(lib_tokens)[0]
168+
lib_variables = find_variables(lib_tokens, lib_classes)
163169
lib_namespaces = find_namespaces(lib_tokens)
164170
tokens = translate_tokens(lib_tokens, lib_variables, lib_classes, lib_namespaces)
165171
tokens = format_strings(tokens)
@@ -168,8 +174,8 @@ def build_lib(libname):
168174
file.write(assembled_code)
169175

170176
lib_tokens = lexical_analyzer(open(f"{absp}lib/{i.strip()}/{i.strip()}.psh", "r").read())
171-
lib_variables = find_variables(lib_tokens)
172177
lib_classes = find_classes(lib_tokens)[0]
178+
lib_variables = find_variables(lib_tokens, lib_classes)
173179
lib_namespaces = find_namespaces(lib_tokens)
174180
tokens = translate_tokens(lib_tokens, lib_variables, lib_classes, lib_namespaces)
175181
tokens = format_strings(tokens)

pony.exe

14.3 KB
Binary file not shown.

test2.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +0,0 @@
1-
from lexer import *
2-
3-
tokens = lexical_analyzer(open('C:/pony/prog.psc', 'r').read())
4-
5-
variables = find_variables(tokens)
6-
classes, tokens = find_classes(tokens)
7-
8-
print(assemble_code(translate_tokens(tokens, variables, classes)))
9-

0 commit comments

Comments
 (0)