|
97 | 97 | indentation_required = 0
|
98 | 98 |
|
99 | 99 | compiled_file = open(compiled_file_filename, "w", encoding="utf-8")
|
100 |
| -compiled_file.write("# Compiled from ACPL programming language\n# Download from github : https://www.github.com/megat69/ACPL\n\nfrom time import sleep\nfrom random import randrange\n\n") |
| 100 | +compiled_file.write("# Compiled from ACPL programming language\n# Download from github : https://www.github.com/megat69/ACPL\n\nfrom time import sleep\nfrom random import randrange\nfrom math import *\n\n") |
101 | 101 |
|
102 | 102 | while line_numbers < len(code_lines):
|
103 | 103 | line = code_lines[line_numbers]
|
|
135 | 135 |
|
136 | 136 | while "<" in line and ">" in line:
|
137 | 137 | equation = line[line.find("<") + 1:line.find(">")]
|
138 |
| - while "{" in line and "}" in equation: |
139 |
| - variable = equation[equation.find("{") + 1:equation.find("}")] |
140 |
| - debug("other", lineno(), f"Variable {variable} found in print.") |
141 |
| - try: |
142 |
| - line = line.replace("{" + variable + "}", variable) |
143 |
| - except KeyError: |
144 |
| - error(line_numbers, "ArgumentError", |
145 |
| - f"The variable \"{variable}\" is not existing or has been declared later in the code.") |
146 |
| - debug("other", lineno(), f"Equation {equation} found.") |
147 |
| - try: |
148 |
| - line = line.replace(f"<{str(equation)}>", "{"+equation+"}") |
149 |
| - except KeyError: |
150 |
| - error(line_numbers, "ArgumentError", |
151 |
| - f"The equation \"{equation}\" is not existing or has been declared later in the code.") |
| 138 | + new_equation = line[line.find("<") + 1:line.find(">")] |
| 139 | + while "{" in new_equation and "}" in new_equation: |
| 140 | + variable = new_equation[new_equation.find("{") + 1:new_equation.find("}")] |
| 141 | + new_equation = new_equation.replace("{"+variable+"}", variable) |
| 142 | + line = line.replace("<"+equation+">", "{"+new_equation+"}") |
152 | 143 |
|
153 | 144 | if line.startswith("for"):
|
154 | 145 | indentation_required += 1
|
|
230 | 221 | elif line.startswith("var"):
|
231 | 222 | line = line.replace("var", "", 1)
|
232 | 223 | var_type = None
|
| 224 | + var_action = None |
| 225 | + var_parameters = None |
233 | 226 |
|
234 | 227 | do_regroup = True
|
235 | 228 |
|
|
241 | 234 | else:
|
242 | 235 | var_type = 'str'
|
243 | 236 | line = line.replace(":"+var_type, "", 1)
|
244 |
| - line = line.replace(" ", "", 1) |
| 237 | + if line.startswith(" "): |
| 238 | + line = line.replace(" ", "", 1) |
| 239 | + |
| 240 | + if line.startswith("--"): |
| 241 | + if line.startswith("--lowercase"): |
| 242 | + var_action = "lowercase" |
| 243 | + elif line.startswith("--uppercase"): |
| 244 | + var_action = "uppercase" |
| 245 | + elif line.startswith("--round:"): |
| 246 | + var_action = "round" |
| 247 | + var_parameters = [re.search('\-\-round\:\d*', line).group(0)] |
| 248 | + elif line.startswith("--ceil"): |
| 249 | + var_action = "ceil" |
| 250 | + if var_parameters is None: |
| 251 | + line = line.replace("--"+var_action, "", 1) |
| 252 | + else: |
| 253 | + var_parameters_to_str = "" |
| 254 | + for param in var_parameters: |
| 255 | + var_parameters_to_str += param |
| 256 | + line = line.replace("--" + var_action + ":" + var_parameters_to_str, "", 1) |
| 257 | + if line.startswith(" "): |
| 258 | + line = line.replace(" ", "", 1) |
245 | 259 |
|
246 | 260 | line = line.split(" ") # Result : [name, "=", content]
|
247 | 261 |
|
| 262 | + if var_parameters is not None: |
| 263 | + line.pop(0) |
| 264 | + if line[2].endswith("\n"): |
| 265 | + line[2] = line[2][:-1] |
| 266 | + |
248 | 267 | if str(line[2]).startswith("input"):
|
249 | 268 | line[2] = line[2].replace("input", "", 1)
|
250 | 269 | for i in range(3, len(line)):
|
|
280 | 299 |
|
281 | 300 | else:
|
282 | 301 | try:
|
283 |
| - line[2] = eval(line[2]) |
284 |
| - except SyntaxError: |
285 |
| - print(line[2]) |
286 |
| - pass |
287 |
| - except NameError: |
288 |
| - print(line[2]) |
289 |
| - pass |
| 302 | + if "." not in str(line[2]): |
| 303 | + line[2] = int(line[2]) |
| 304 | + elif re.search("\d*", str(line[2]).replace(".", "")).group(0) == str(line[2]): |
| 305 | + line[2] = float(line[2]) |
| 306 | + except ValueError: |
| 307 | + try: |
| 308 | + line[2] = float(line[2]) |
| 309 | + except ValueError: |
| 310 | + line[2] = str(line[2]) |
290 | 311 |
|
291 | 312 | if do_regroup:
|
292 | 313 | for i in range(3, len(line)):
|
|
311 | 332 | elif str(line[2]).lower() == "f\"false\"":
|
312 | 333 | line[2] = False
|
313 | 334 |
|
| 335 | + if var_action == "lowercase": |
| 336 | + line[2] = str(line[2]) + ".lower()" |
| 337 | + elif var_action == "uppercase": |
| 338 | + line[2] = str(line[2]) + ".upper()" |
| 339 | + elif var_action == "round": |
| 340 | + line[2] = f"round(float({line[2]}), {int(var_parameters[0].replace('--round:', ''))})" |
| 341 | + elif var_action == "ceil": |
| 342 | + line[2] = f"ceil({line[2]})" |
| 343 | + |
314 | 344 | if var_type is not None:
|
315 | 345 | line = line[0] + " = " + var_type + "(" + str(line[2]) + ")"
|
316 | 346 | else:
|
|
0 commit comments