-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdoc.txt
157 lines (86 loc) · 3.75 KB
/
doc.txt
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
string s = "strignText";
print(s);
print("String");
int x=10;
print(x);
float f=83.33;
print (f);
char c ='a';
print(c);
if(3>1)then{
print("if");
}
compiler project
(lex and yacc)
# how to run lex and yacc in visual studio code
1- download and install flex and bison from https://sourceforge.net/projects/winflexbison/
or Program/Program.zip
2- add the path of flex and bison to the environment variable
"open the start menu and search for environment variable"
"click on environment variable"
"click on path"
"click on new"
"add the path of flex and bison/bin"
"add the path of gcc "
3- create a new folder and add the lex file and yacc file to it
"create a new file and name it LexFile.l"
"create a new file and name it YaccFile.y"
4- add the vs-code extension "flex" and "bison"
https://marketplace.visualstudio.com/items?itemName=daohong-emilio.yash
https://marketplace.visualstudio.com/items?itemName=luniclynx.lex
https://marketplace.visualstudio.com/items?itemName=luniclynx.bison
5- to run lex only
flex LexFile.l; gcc lex.yy.c -o Lex; ./Lex.exe
6- to run lex and yacc
flex LexFile.l; yacc -d YaccFile.y; gcc lex.yy.c -o lexer; gcc YaccFile.tab.c lex.yy.c -o program
7- to run lex and yacc in visual studio code
"open the terminal"
"run the command flex LexFile.l; yacc -d YaccFile.y; gcc lex.yy.c -o lexer; gcc YaccFile.tab.c lex.yy.c -o program"
"run the command ./program.exe"
# how to use GUI in lex and yacc
(using the GUI pyhton library custom tkinter)
1- install pyhton (https://www.python.org/downloads/)
2- install custom tkinter ( pip install customtkinter ) or you can use tkinter
3- create a new file and name it "GUI.py"
4- import library
"
import tkinter as tk
import customtkinter as ctk
import subprocess
import os
"
5- create a new function to run the lex and yacc
"
def use_GUI():
user_input = text_input.get("1.0", tk.END).strip()
process = subprocess.Popen(["program.exe"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = process.communicate(input=user_input.encode())
result_output.delete("1.0", tk.END)
result_output.insert(tk.END, stdout.decode())
"
- ensure that the path of the program.exe is correct
- this function will take the input from the user and run the program.exe and display the output in the result_output
- the text_input is the input from the user and the result_output is the output of the program.exe
6- create the GUI
"
root = ctk.CTk()
root.title("Compiler")
root.geometry("1400x800")
root.grid_rowconfigure(0, weight=1, minsize=5)
root.grid_rowconfigure(1, weight=0, minsize=5)
root.grid_columnconfigure(0, weight=1, minsize=5)
root.grid_columnconfigure(1, weight=0, minsize=5)
root.grid_columnconfigure(2, weight=1, minsize=5)
text_input = ctk.CTkTextbox(root, height=10, width=30, font=("Consolas", 19, "bold"), wrap=tk.WORD, corner_radius=8)
text_input.grid(row=0, column=0, padx=20, pady=10, sticky="nsew")
result_output = ctk.CTkTextbox(root, height=10, width=30, font=("Consolas", 19, "bold"), wrap=tk.WORD, corner_radius=8)
result_output.grid(row=0, column=1, columnspan=3, padx=10, pady=10, sticky="nsew")
run_button = ctk.CTkButton(root, text="Run Code", command=use_GUI, width=200, height=40, font=("Consolas", 15, "bold"))
run_button.grid(row=2, column=0, padx=20, pady=10)
root.mainloop()
"
7- run the GUI
@ note:
- you should have the program.exe in the same folder as the GUI.py file
after each update in the lex or yacc file, you should run the command "flex LexFile.l; yacc -d YaccFile.y; gcc lex.yy.c -o lexer; gcc YaccFile.tab.c lex.yy.c -o program" to update the program.exe file
- you can use the GUI to run the program.exe and display the output in the GUI