added Random Int Generator
This commit is contained in:
@@ -37,7 +37,6 @@ void processSource(const std::string& src, CompilerState& state) {
|
||||
// --- 1. DEFINICJA FUNKCJI ---
|
||||
// Warunki: zaczyna się od typu, ma '(', ma '{' i NIE ma '=' (żeby nie mylić ze zmienną)
|
||||
bool startsWithType = (line.rfind("int ", 0) == 0 || line.rfind("void ", 0) == 0 || line.rfind("bool ", 0) == 0);
|
||||
|
||||
if (startsWithType && line.find("(") != std::string::npos && line.find("{") != std::string::npos && line.find("=") == std::string::npos) {
|
||||
|
||||
size_t openParen = line.find('(');
|
||||
@@ -56,7 +55,6 @@ void processSource(const std::string& src, CompilerState& state) {
|
||||
std::cout << "[PARSER] New Function: " << funcName << "\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
// --- 2. ZAMYKANIE BLOKU '}' ---
|
||||
if (line == "}") {
|
||||
// Najpierw sprawdzamy, czy zamykamy IF-a (czy jest coś na stosie bloków)
|
||||
@@ -75,7 +73,6 @@ void processSource(const std::string& src, CompilerState& state) {
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// --- JESTEŚMY W ŚRODKU FUNKCJI ---
|
||||
if (state.currentFunction) {
|
||||
Function& f = *state.currentFunction;
|
||||
@@ -188,6 +185,19 @@ void processSource(const std::string& src, CompilerState& state) {
|
||||
std::string b = trim(rightSide.substr(opPos + 1));
|
||||
f.instructions.push_back({ OpType::MUL, varName, a, b }); // <--- Używamy MUL
|
||||
}
|
||||
else if (rightSide.find("/") != std::string::npos) {
|
||||
size_t opPos = rightSide.find("/");
|
||||
std::string a = trim(rightSide.substr(0, opPos));
|
||||
std::string b = trim(rightSide.substr(opPos + 1));
|
||||
f.instructions.push_back({ OpType::DIV, varName, a, b });
|
||||
}
|
||||
// MODULO: a % b
|
||||
else if (rightSide.find("%") != std::string::npos) {
|
||||
size_t opPos = rightSide.find("%");
|
||||
std::string a = trim(rightSide.substr(0, opPos));
|
||||
std::string b = trim(rightSide.substr(opPos + 1));
|
||||
f.instructions.push_back({ OpType::MOD, varName, a, b });
|
||||
}
|
||||
// 3. Czy to porównanie? a == b (Ważne: == może być w IFie, ale tu jesteśmy w linii z '=')
|
||||
// UWAGA: To rzadkie w C++ (bool x = a == b), ale obsłużmy proste przypisanie wartości logicznej
|
||||
else if (rightSide.find("==") != std::string::npos) {
|
||||
|
||||
Reference in New Issue
Block a user