added int func(int x, int y), return int
This commit is contained in:
@@ -6,28 +6,51 @@
|
||||
#include <map>
|
||||
#include <stack>
|
||||
|
||||
struct Expression {
|
||||
std::string leftVar;
|
||||
std::string op;
|
||||
std::string rightVar;
|
||||
std::string resultVar;
|
||||
// Typy operacji, które nasz kompilator rozumie
|
||||
enum class OpType {
|
||||
ASSIGN, // a = 5
|
||||
ADD, // a = b + c
|
||||
SUB, // a = b - c
|
||||
MUL, // a = b * c
|
||||
EQ, // a == b
|
||||
PRINT, // print(a)
|
||||
JMP_FALSE, // if (false) skocz...
|
||||
JMP, // else / pêtla
|
||||
LABEL, // miejsce skoku
|
||||
CALL, // wywo³anie funkcji
|
||||
RETURN, // return x
|
||||
NOP // pusta instrukcja
|
||||
};
|
||||
|
||||
struct IfBlock {
|
||||
std::string conditionVar;
|
||||
std::vector<std::string> prints;
|
||||
// Pojedynczy rozkaz kompilatora (Intermediate Representation)
|
||||
struct Instruction {
|
||||
OpType type;
|
||||
std::string arg1;
|
||||
std::string arg2;
|
||||
std::string arg3;
|
||||
};
|
||||
|
||||
// Definicja funkcji
|
||||
struct Function {
|
||||
std::string name;
|
||||
std::string returnType; // "int", "void", "bool"
|
||||
std::vector<std::string> args; // Nazwy argumentów (np. "a", "b")
|
||||
std::vector<Instruction> instructions; // Lista rozkazów w funkcji
|
||||
};
|
||||
|
||||
struct CompilerState {
|
||||
std::vector<Expression> expressions;
|
||||
std::vector<IfBlock> ifBlocks;
|
||||
std::map<std::string, int> variables;
|
||||
std::vector<std::string> printCalls;
|
||||
std::vector<std::string> globalPrints;
|
||||
std::map<std::string, std::vector<std::string>> functions;
|
||||
bool inFunction = false;
|
||||
std::string currentFunction;
|
||||
std::stack<bool> braceStack;
|
||||
// Mapa wszystkich funkcji (klucz to nazwa)
|
||||
std::map<std::string, Function> functions;
|
||||
|
||||
// Zmienne globalne (tylko nazwa -> wartoœæ pocz¹tkowa)
|
||||
std::map<std::string, int> globals;
|
||||
|
||||
// Stan parsera
|
||||
Function* currentFunction = nullptr; // WskaŸnik na aktualnie parsuj¹c¹ siê funkcjê
|
||||
int labelCounter = 0; // Do generowania unikalnych nazw etykiet (L1, L2...)
|
||||
std::stack<std::string> loopStack; // Do break/continue (przysz³oœciowo)
|
||||
|
||||
std::stack<std::string> blockStack;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user