#ifndef PARSER_H #define PARSER_H #include #include #include #include #include namespace Solstice { // External variables referenced in parser logic extern int tmpIdIterator; extern int labelIterator; namespace Parser { enum class SolNodeType { Add, Subtract, Equal, Inequal, Greater, Lesser, EqGreater, EqLesser, Set, While, If, Value, Identifier, None, Root, CodeBlock, CodeBlockStart, CodeBlockEnd, FunctionCall, Expression, BracketStart, BracketEnd, Puts }; enum class SolDataType { Int, String, Double, Bool, Char, None }; class SolNode; class SolGroundCodeBlock { public: std::vector code; std::vector toBeDropped; SolGroundCodeBlock() = default; }; class SolData { typedef std::variant varData; varData data; public: SolDataType type = SolDataType::Int; SolData() = default; SolData(int64_t in); SolData(double in); SolData(std::string in); SolData(char in); SolData(bool in); std::optional getInt(); std::optional getDouble(); std::optional getString(); std::optional getChar(); std::optional getBool(); }; class SolNode { SolData data; public: SolNodeType nodeType = SolNodeType::None; std::vector children; std::string outputId; SolNode(SolNodeType nodeType); SolNode(SolNodeType nodeType, SolData data); SolNode() = default; void addNode(SolNode in); void setValue(SolData in); const std::vector generateCode(); }; class Parser { std::vector tokensToParse; size_t current; size_t size; std::optional peek(int ahead = 1); std::optional consume(); bool isInt(std::string in); bool isDouble(std::string in); bool isString(std::string in); bool isChar(std::string in); bool isBool(std::string in); SolDataType getDataType(std::string in); SolNodeType getNodeType(std::string in); public: Parser(std::vector in); SolNode parse(); }; GroundProgram assembleProgram(SolNode& rootNode); } // namespace Parser } #endif