Advertisement
StandingPad

Untitled

Apr 17th, 2022
1,422
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 28.40 KB | None | 0 0
  1. #include "RendorCompiler/Parser/Parser.hpp"
  2. #include <memory>
  3. #include <utility>
  4. /* -------------------------------------------------------------------------- */
  5. /*                               Parser function                              */
  6. /* -------------------------------------------------------------------------- */
  7. void Parser::ASTGeneration(const std::vector<std::pair<Lex::Token, std::string>>& Tokens)
  8. {
  9.     for (auto const& [token, value] : Tokens)
  10.     {        
  11.         Scope = ScopeList.back();
  12.         ParserTempID = ParserTempIDList.back();
  13.         // std::cout << "Token: " << static_cast<std::underlying_type<Lex::Token>::type>(token) << " " << value << std::endl;
  14.  
  15.         switch (token)
  16.         {
  17.             case lt::NEWLINE: // * Newlines
  18.             {
  19.                 if
  20.                 ((ParserTempID != TempID::FunctionScope) &&
  21.                 (ParserTempID != TempID::IfElseScope) &&
  22.                 (ParserTempID != TempID::NameSpace))
  23.                 {
  24.                     if (ParserTempIDList.size() == 2)
  25.                     {
  26.                         PopTempID();
  27.                     }
  28.                     else
  29.                     {
  30.                         AddTempID(TempID::None);
  31.                     }
  32.                 }
  33.  
  34.                 ++LineNumber;
  35.                 break;
  36.             }
  37.  
  38.             /* -------------------------------------------------------------------------- */
  39.             /*                           Functions and variables                          */
  40.             /* -------------------------------------------------------------------------- */
  41.             case lt::IDENTIFIER: // * user defined things
  42.             {
  43.                 /* ------------ if found during definition of another identifier ------------ */
  44.                 if (ParserTempID == TempID::IdentifierDefinition)
  45.                 {
  46.                     if (GetTypeOfNode() == NodeType::AssignVariable)
  47.                     {
  48.                         /* ------------------------ Create FunctionCall Node ------------------------ */
  49.                         auto& AssignVariableNode = static_cast<AssignVariable&>(*Scope->back());
  50.                         throw error::RendorException(fmt::format("Syntax Error: {} found during the definition of {}; Line {}", value, AssignVariableNode.VariableName, LineNumber));
  51.                     }
  52.                 }
  53.  
  54.                 else if (ParserTempID == TempID::NameSpace)
  55.                 {
  56.                     // Add namespace to body
  57.                     ParentNodes.back()->NameSpace = value;
  58.                 }
  59.  
  60.                 /* -------------------------- function definitions -------------------------- */
  61.                 else if (ParserTempID == TempID::FunctionDefiniton) // functions
  62.                 {
  63.                     if (value == "main")
  64.                     {
  65.                         IsScript = true; // This is a script and not a library or module
  66.                     }
  67.                     PushToScope(std::make_unique<Edef>(value, LineNumber));
  68.                 }
  69.  
  70.                 else if (ParserTempID == TempID::Extern)
  71.                 {
  72.                     PopTempID();
  73.                     std::unique_ptr<FowardEdef> ForwardEdefNode = std::make_unique<FowardEdef>(value, LineNumber);
  74.                     ForwardEdefNode->Extern = true;
  75.                     PushToScope(std::move(ForwardEdefNode));
  76.                     AddTempID(TempID::FowardDefinition);
  77.                 }
  78.  
  79.                 /* -------------------------- if it is an argument -------------------------- */
  80.                 else if (ParserTempID == TempID::FunctionCall) // function calls
  81.                 {
  82.                     PushToScope(std::make_unique<Reference>(value, LineNumber)); // Add argument to Node
  83.                 }
  84.  
  85.  
  86.                 /* ------------- if it's a scoped argument(like edef lol(world)) ------------ */
  87.                 else if (ParserTempID == TempID::FunctionArgumentsDefinition) // Function arguments
  88.                 {
  89.                     if (GetTypeOfNode() == NodeType::Edef)
  90.                     {
  91.                         auto& EdefNode = static_cast<Edef&>(*Scope->back());
  92.                         EdefNode.Args.emplace_back(value, NodeType::Any); // Add argument to Node
  93.                     }
  94.                 }
  95.  
  96.                 else if (ParserTempID == TempID::FowardDefinition)
  97.                 {
  98.                     PushToScope(std::make_unique<FowardEdef>(value, LineNumber)); // Add argument to Node
  99.                 }
  100.                
  101.                 else if (ParserTempID == TempID::FowardArgsDefinition)
  102.                 {
  103.                     if (GetTypeOfNode() == NodeType::FowardEdef)
  104.                     {
  105.                         auto& FowardNode = static_cast<FowardEdef&>(*Scope->back());
  106.  
  107.                         // Check if it's an extern statement
  108.                         if (FowardNode.Extern)
  109.                         {
  110.                             throw error::RendorException(fmt::format("{} is not a typehint; Line {}", value, LineNumber));
  111.                         }
  112.  
  113.                         if (!FowardNode.Args.empty())
  114.                         {
  115.                             // grab the identifier and type
  116.                             auto& [Identifier, Type] = FowardNode.Args.back();
  117.  
  118.                             // if the identifer is a placeholder
  119.                             if (Identifier == "@placeholder")
  120.                             {
  121.                                 Identifier = value;
  122.                                 break;
  123.                             }
  124.                         }
  125.                         FowardNode.Args.emplace_back(value, NodeType::Any); // Add argument to Node with type Any
  126.                     }
  127.                 }
  128.  
  129.                 /* ------------------------------ if statements ----------------------------- */
  130.                 else if (ParserTempID == TempID::ConditionDefinition)
  131.                 {
  132.                     /* -------------------------- Adding Condition Node ------------------------- */
  133.                     auto& IfElseNode = dynamic_cast<IfElse&>(*Scope->back());
  134.                     AddTokenToConditions<IfElse, Reference>(IfElseNode, value, LineNumber);
  135.                 }
  136.                
  137.                 /* ----------------------------- Add as variable ---------------------------- */
  138.                 else
  139.                 {
  140.                     PushToScope(std::make_unique<Reference>(value, LineNumber));
  141.                     AddTempID(TempID::IdentifierDefinition);
  142.                 }
  143.                 break;
  144.             }
  145.  
  146.             /* -------------------------------------------------------------------------- */
  147.             /*                                   Symbols                                  */
  148.             /* -------------------------------------------------------------------------- */
  149.  
  150.             /* ---------------------------------- Equal --------------------------------- */
  151.             case lt::EQUAL: // * = sign
  152.             {
  153.                 if (ParserTempID == TempID::IdentifierDefinition)
  154.                 {
  155.                     auto& ReferenceNode = static_cast<Reference&>(*Scope->back());
  156.                     ReplaceNode(std::make_unique<AssignVariable>(ReferenceNode.Value, LineNumber));
  157.                     AddTempID(TempID::VariableDefition);
  158.                 }
  159.                 else
  160.                 {
  161.                     throw error::RendorException(fmt::format("Syntax Error: = found on line {}, expected variable definition", LineNumber));
  162.                 }
  163.                 break;
  164.             }
  165.  
  166.             /* ---------------------------------- Comma --------------------------------- */
  167.             case lt::COMMA:
  168.             {
  169.                 break;
  170.             }
  171.  
  172.             /* --------------------------------- L paren -------------------------------- */
  173.             case lt::LPAREN: // * ( sign
  174.             {
  175.                 /* -------------------- function calls in function calls -------------------- */
  176.                 if (ParserTempID == TempID::FunctionCall)
  177.                 {
  178.                     if (!Scope->empty())
  179.                     {
  180.                         switch (GetTypeOfNode())
  181.                         {
  182.                             case NodeType::FunctionCall:
  183.                             {
  184.                                 auto& FunctionCallNode = static_cast<FunctionCall&>(*Scope->back());
  185.                                 if (*Scope != FunctionCallNode.Args)
  186.                                 {
  187.                                     AddScope(&FunctionCallNode.Args);
  188.                                 }
  189.                                 break;
  190.                             }
  191.  
  192.                             case NodeType::AssignVariable:
  193.                             {
  194.                                 auto& AssignmentNode = static_cast<AssignVariable&>(*Scope->back());
  195.                                 auto& FunctionCallNode = static_cast<FunctionCall&>(*AssignmentNode.Value);
  196.                                 if (*Scope != FunctionCallNode.Args)
  197.                                 {
  198.                                     AddScope(&FunctionCallNode.Args);
  199.                                 }
  200.                                 break;
  201.                             }
  202.  
  203.                             default:
  204.                             {
  205.                                 break;
  206.                             }
  207.                         }
  208.                     }
  209.                 }
  210.  
  211.                 /* --------------------------- Defining functions --------------------------- */
  212.                 else if (ParserTempID == TempID::FunctionDefiniton) // Defining a funcion
  213.                 {
  214.                     PopTempID();
  215.                     AddTempID(TempID::FunctionArgumentsDefinition);
  216.                 }
  217.  
  218.                 else if (ParserTempID == TempID::FowardDefinition)
  219.                 {
  220.                     PopTempID();
  221.                     AddTempID(TempID::FowardArgsDefinition);
  222.                 }
  223.                
  224.                 /* -------------------- Function Calls in the main scope -------------------- */
  225.                 else if (ParserTempID == TempID::IdentifierDefinition)
  226.                 {
  227.                     /* ---------------- Check if the last node is an assign node ---------------- */
  228.                     if (GetTypeOfNode() == NodeType::Reference)
  229.                     {
  230.                         /* ------------------------ Create FunctionCall Node ------------------------ */
  231.                         auto& AssignVariableNode = static_cast<Reference&>(*Scope->back());
  232.                         std::unique_ptr<FunctionCall> FunctionCallNode = std::make_unique<FunctionCall>(AssignVariableNode.Value, LineNumber);
  233.                         AddScope(&FunctionCallNode->Args);
  234.                        
  235.                         /* ------------------------------ Replace Node ------------------------------ */
  236.                         ReplaceNode(std::move(FunctionCallNode));
  237.                         PopTempID();
  238.                         AddTempID(TempID::FunctionCall);
  239.  
  240.                     }
  241.                 }
  242.  
  243.                 /* ------------------------- Defining if statements ------------------------- */
  244.                 else if (ParserTempID == TempID::IfStatementDefinition)
  245.                 {
  246.                     PopTempID();
  247.                     AddTempID(TempID::ConditionDefinition);
  248.                 }
  249.  
  250.                 /* ------------------------------- Arithmethic ------------------------------ */
  251.                 else if (ParserTempID == TempID::VariableDefition)
  252.                 {
  253.                     if (GetTypeOfNode() == NodeType::AssignVariable)
  254.                     {
  255.                         auto& AssignVariableNode = static_cast<AssignVariable&>(*Scope->back());
  256.                         AddToArithmethicNode(AssignVariableNode, value, LineNumber);
  257.                     }
  258.                 }
  259.                 break;
  260.             }
  261.  
  262.             /* --------------------------------- R paren -------------------------------- */
  263.             case lt::RPAREN: // * ) sign
  264.             {
  265.                 if (ParserTempID == TempID::FunctionArgumentsDefinition)
  266.                 {
  267.                     PopTempID();
  268.                     AddTempID(TempID::FunctionScope);
  269.                 }
  270.  
  271.                 else if (ParserTempID == TempID::FowardArgsDefinition)
  272.                 {
  273.                     PopTempID();
  274.                 }
  275.  
  276.                 else if (ParserTempID == TempID::ConditionDefinition)
  277.                 {
  278.                     PopTempID();
  279.                     AddTempID(TempID::IfElseScope);
  280.                 }
  281.  
  282.                 else if (ParserTempID == TempID::FunctionCall)
  283.                 {
  284.                     PopTempID();
  285.                     PopScope();
  286.                 }
  287.  
  288.                 /* ------------------------------- Arithmethic ------------------------------ */
  289.                 else if (ParserTempID == TempID::VariableDefition)
  290.                 {
  291.                     if (GetTypeOfNode() == NodeType::AssignVariable)
  292.                     {
  293.                         auto& AssignVariableNode = static_cast<AssignVariable&>(*Scope->back());
  294.                         AddToArithmethicNode(AssignVariableNode, value, LineNumber);
  295.                     }
  296.                 }
  297.                 break;
  298.             }
  299.  
  300.             /* --------------------------------- L brace -------------------------------- */
  301.             case lt::LBRACE: // * { sign
  302.             {
  303.                 /* --------------------------- Defining functions --------------------------- */
  304.                 if (ParserTempID == TempID::FunctionScope)
  305.                 {
  306.                     PopTempID();
  307.  
  308.                     // Add it as a scope
  309.                     auto& EdefNode = dynamic_cast<Edef&>(*Scope->back());
  310.                     AddScope(&EdefNode.FunctionBody.ConnectedNodes);
  311.                 }
  312.  
  313.                 /* ------------------------------ If Statements ----------------------------- */
  314.                 else if (ParserTempID == TempID::IfElseScope)
  315.                 {
  316.                     PopTempID();
  317.  
  318.                     // Add it as a scope
  319.                     auto& IfElseNode = dynamic_cast<IfElse&>(*Scope->back());
  320.                     AddScope(&IfElseNode.IfElseBody.ConnectedNodes);
  321.                 }
  322.  
  323.                 /* ----------------------------- Else Statements ---------------------------- */
  324.                 else if (ParserTempID == TempID::ElseDefinition)
  325.                 {
  326.                     PopTempID();
  327.  
  328.                     // Add it as a scope
  329.                     auto& IfNode = dynamic_cast<IfElse&>(*Scope->back());
  330.                     auto& ElseNode = dynamic_cast<IfElse&>(*IfNode.ElseStatement);
  331.                     AddScope(&ElseNode.IfElseBody.ConnectedNodes);
  332.                 }
  333.  
  334.                 else if (ParserTempID == TempID::NameSpace)
  335.                 {
  336.                     PopTempID();
  337.                 }
  338.  
  339.                 else
  340.                 {
  341.                     throw error::RendorException(fmt::format("Syntax Error: {{ found outside of function/if/else scope; Line {}", LineNumber));
  342.                 }
  343.                 break;
  344.             }
  345.  
  346.             /* --------------------------------- R brace -------------------------------- */
  347.             case lt::RBRACE: // * } sign
  348.             {
  349.                 PopScope();
  350.                 if (GetTypeOfNode() == NodeType::Body)
  351.                 {
  352.                     PopScope();
  353.                 }
  354.                 break;
  355.             }
  356.  
  357.             /* -------------------------------------------------------------------------- */
  358.             /*                                    Types                                   */
  359.             /* -------------------------------------------------------------------------- */
  360.  
  361.             /* ----------------------------------- int ---------------------------------- */
  362.             case lt::INT:
  363.             {
  364.                 if (ParserTempID == TempID::VariableDefition) // variables
  365.                 {
  366.                     if (GetTypeOfNode() == NodeType::AssignVariable)
  367.                     {
  368.                         auto& AssignVariableNode = static_cast<AssignVariable&>(*Scope->back());
  369.                         if (AssignVariableNode.Value)
  370.                         {
  371.                             if (AssignVariableNode.Value->Type == NodeType::Arithmethic)
  372.                             {
  373.                                 auto& ArithNode = static_cast<Arithmethic&>(*AssignVariableNode.Value);
  374.                                 ArithNode.Value += value;
  375.                             }
  376.                         }
  377.                         else
  378.                         {
  379.                             AssignVariableNode.Value = std::make_unique<Int>(value, LineNumber);
  380.                         }
  381.                     }
  382.                 }
  383.                
  384.                 else if (ParserTempID == TempID::FunctionCall) // function calls
  385.                 {
  386.                     PushToScope(std::make_unique<Int>(value, LineNumber));
  387.                 }
  388.  
  389.                 else if (ParserTempID == TempID::ConditionDefinition)
  390.                 {
  391.                     /* -------------------------- Adding Condition Node ------------------------- */
  392.                     auto& IfElseNode = dynamic_cast<IfElse&>(*Scope->back());
  393.                     AddTokenToConditions<IfElse, Int>(IfElseNode, value, LineNumber);
  394.                 }
  395.                 break;
  396.             }
  397.  
  398.             /* ---------------------------------- float --------------------------------- */
  399.             case lt::FLOAT:
  400.             {
  401.                 if (ParserTempID == TempID::VariableDefition) // variables
  402.                 {
  403.                     if (GetTypeOfNode() == NodeType::AssignVariable)
  404.                     {
  405.                         auto& AssignVariableNode = static_cast<AssignVariable&>(*Scope->back());
  406.                         if (AssignVariableNode.Value)
  407.                         {
  408.                             if (AssignVariableNode.Value->Type == NodeType::Arithmethic)
  409.                             {
  410.                                 auto& ArithNode = static_cast<Arithmethic&>(*AssignVariableNode.Value);
  411.                                 ArithNode.Value += value;
  412.                             }
  413.                         }
  414.                         else
  415.                         {
  416.                             AssignVariableNode.Value = std::make_unique<Double>(value, LineNumber);
  417.                         }
  418.                     }
  419.                 }
  420.  
  421.                 else if (ParserTempID == TempID::FunctionCall) // function calls
  422.                 {
  423.                     PushToScope(std::make_unique<Double>(value, LineNumber));
  424.                 }
  425.  
  426.                 else if (ParserTempID == TempID::ConditionDefinition)
  427.                 {
  428.                     /* -------------------------- Adding Condition Node ------------------------- */
  429.                     auto& IfElseNode = dynamic_cast<IfElse&>(*Scope->back());
  430.                     AddTokenToConditions<IfElse, Double>(IfElseNode, value, LineNumber);
  431.                 }
  432.                 break;
  433.             }
  434.  
  435.             /* --------------------------------- string --------------------------------- */
  436.             case lt::STRING:
  437.             {
  438.                 if (ParserTempID == TempID::VariableDefition) // variables
  439.                 {
  440.                     if (GetTypeOfNode() == NodeType::AssignVariable)
  441.                     {
  442.                         auto& AssignVariableNode = static_cast<AssignVariable&>(*Scope->back());
  443.                         AssignVariableNode.Value = std::make_unique<String>(value, LineNumber);
  444.                     }
  445.                 }
  446.  
  447.                 else if (ParserTempID == TempID::FunctionCall) // function calls
  448.                 {
  449.                     PushToScope(std::make_unique<String>(value, LineNumber));
  450.                 }
  451.  
  452.                 else if (ParserTempID == TempID::ConditionDefinition)
  453.                 {
  454.                     /* -------------------------- Adding Condition Node ------------------------- */
  455.                     auto& IfElseNode = dynamic_cast<IfElse&>(*Scope->back());
  456.                     AddTokenToConditions<IfElse, String>(IfElseNode, value, LineNumber);
  457.                 }
  458.  
  459.                 else if (ParserTempID == TempID::Import)
  460.                 {
  461.                     if (GetTypeOfNode() == NodeType::Import)
  462.                     {
  463.                         auto& ImportNode = static_cast<Import&>(*Scope->back());
  464.                         ImportNode.Name = value;
  465.                     }
  466.                     PopTempID();
  467.                 }
  468.  
  469.                 else if (ParserTempID == TempID::NameSpace)
  470.                 {
  471.                     if (GetTypeOfNode() == NodeType::Body)
  472.                     {
  473.                         auto& BodyNode = static_cast<Body&>(*Scope->back());
  474.                         BodyNode.NameSpace = value;
  475.                     }
  476.                 }
  477.                 break;
  478.             }
  479.            
  480.             /* ---------------------------------- bool ---------------------------------- */
  481.             case lt::BOOL:
  482.             {
  483.                 if (ParserTempID == TempID::VariableDefition) // variables
  484.                 {
  485.                     if (GetTypeOfNode() == NodeType::AssignVariable)
  486.                     {
  487.                         auto& AssignVariableNode = static_cast<AssignVariable&>(*Scope->back());
  488.                         AssignVariableNode.Value = std::make_unique<Bool>(std::string{value}, LineNumber);
  489.                     }
  490.                 }
  491.  
  492.                 else if (ParserTempID == TempID::FunctionCall) // function calls
  493.                 {
  494.                     PushToScope(std::make_unique<Bool>(std::string{value}, LineNumber));
  495.                 }
  496.  
  497.                 else if (ParserTempID == TempID::ConditionDefinition)
  498.                 {
  499.                     /* -------------------------- Adding Condition Node ------------------------- */
  500.                     auto& IfElseNode = dynamic_cast<IfElse&>(*Scope->back());
  501.                     AddTokenToConditions<IfElse, Bool>(IfElseNode, value, LineNumber);
  502.                 }
  503.                 break;
  504.             }
  505.            
  506.             case lt::TYPE_HINT:
  507.             {
  508.                 if (GetTypeOfNode() == NodeType::FowardEdef)
  509.                 {
  510.                     auto& FowardEdefNode = dynamic_cast<FowardEdef&>(*Scope->back());
  511.  
  512.                     // @ is not a valid characther to use in an argument, thus it's safe to use
  513.                     FowardEdefNode.Args.emplace_back("@placeholder", TypeTable.at(value));
  514.                 }
  515.                 break;
  516.             }
  517.  
  518.             case lt::ATTRIBUTE:
  519.             {
  520.                 PushToScope(std::make_unique<Attribute>(LineNumber));
  521.                 break;
  522.             }
  523.  
  524.             /* -------------------------------------------------------------------------- */
  525.             /*                                  Keywords                                  */
  526.             /* -------------------------------------------------------------------------- */
  527.             case lt::KEYWORD: // * keywords
  528.             {
  529.                 if (value == "edef")
  530.                 {
  531.                     PopTempID();
  532.                     AddTempID(TempID::FunctionDefiniton);
  533.                     if (*ScopeList.back() != Script.Global)
  534.                     {
  535.                         throw error::RendorException("Compiler Error!");
  536.                     }
  537.                 }
  538.  
  539.                 else if
  540.                 ((value == "if") ||
  541.                 (value == "else"))
  542.                 {
  543.                     if (GetTypeOfNode() == NodeType::IfElse)
  544.                     {
  545.                         if (value == "else")
  546.                         {
  547.                             // ! Else statements are not supported
  548.                             break;
  549.                         }
  550.                     }
  551.                     std::unique_ptr<IfElse> IfElseNode = std::make_unique<IfElse>(LineNumber);
  552.                     IfElseNode->Conditions = std::make_unique<Condition>(LineNumber);
  553.                    
  554.                     ReplaceNode(std::move(IfElseNode));
  555.                     PopTempID();
  556.                     AddTempID(TempID::IfStatementDefinition);
  557.                 }
  558.  
  559.                 else if (value == "~forward")
  560.                 {
  561.                     PopTempID();
  562.                     AddTempID(TempID::FowardDefinition);
  563.                     if (*ScopeList.back() != Script.Global)
  564.                     {
  565.                         throw error::RendorException("Compiler Error!");
  566.                     }
  567.                 }
  568.  
  569.                 /* --------------------------------- Imports -------------------------------- */
  570.                 else if (value == "cimport")
  571.                 {
  572.                     PopTempID();
  573.                     AddTempID(TempID::Import);
  574.                     std::unique_ptr<Import> ImportNode = std::make_unique<Import>(LineNumber);
  575.                     ImportNode->CImport = true;
  576.                     PushToScope(std::move(ImportNode));
  577.                 }
  578.                
  579.                 /* --------------------------------- Exports -------------------------------- */
  580.                 else if (value == "export")
  581.                 {
  582.                     PopTempID();
  583.                     std::unique_ptr<Export> ExportNode = std::make_unique<Export>(LineNumber);
  584.                     AddScope(&ExportNode->ExportBody.ConnectedNodes);
  585.                     PushToScope(std::move(ExportNode));
  586.                 }
  587.  
  588.                 /* ------------------------------- Namespaces ------------------------------- */
  589.                 else if (value == "namespace")
  590.                 {
  591.                     PopTempID();
  592.                     std::unique_ptr<Body> BodyNode = std::make_unique<Body>();
  593.                     AddParentNode(BodyNode.get()); // Add it to parent nodes
  594.                     AddScope(&BodyNode->ConnectedNodes); // Add the body to scopes
  595.                     PushToScope(std::move(BodyNode)); // Add the node to the current scope
  596.                     AddTempID(TempID::NameSpace);
  597.                 }
  598.  
  599.                 else if (value == "extern")
  600.                 {
  601.                     PopTempID();
  602.                     AddTempID(TempID::Extern);
  603.                 }
  604.  
  605.                 else
  606.                 {
  607.                     throw error::RendorException("Not supported yet");
  608.                 }
  609.                 break;
  610.             }
  611.  
  612.             /* -------------------------------------------------------------------------- */
  613.             /*                              Binary Operators                              */
  614.             /* -------------------------------------------------------------------------- */
  615.             case lt::BIOP:
  616.             {
  617.                 if (ParserTempID == TempID::ConditionDefinition)
  618.                 {
  619.                     /* -------------------------- Adding Condition Node ------------------------- */
  620.                     auto& IfElseNode = dynamic_cast<IfElse&>(*Scope->back());
  621.                     if (IfElseNode.Conditions->Operator)
  622.                     {
  623.                         /*
  624.                         TODO: Implement nested condition nodes for operators "or", "and", etc.
  625.                         */
  626.  
  627.                         // ! Temporary, not permanent
  628.                         throw error::RendorException(fmt::format("Syntax Error: extra Binary Operator found in if statement; Line {}", LineNumber));
  629.                     }
  630.                     IfElseNode.Conditions->Operator = std::make_unique<BiOp>(value, LineNumber);
  631.                 }
  632.                
  633.                 else if (ParserTempID == TempID::VariableDefition)
  634.                 {
  635.                     if (GetTypeOfNode() == NodeType::AssignVariable)
  636.                     {
  637.                         auto& AssignVariableNode = static_cast<AssignVariable&>(*Scope->back());
  638.                         AddToArithmethicNode(AssignVariableNode, value, LineNumber);
  639.                     }
  640.                 }
  641.                 break;
  642.             }
  643.  
  644.             /* -------------------------------------------------------------------------- */
  645.             /*                           Anything not supported                           */
  646.             /* -------------------------------------------------------------------------- */
  647.             default:
  648.             {
  649.                 throw error::RendorException("Not supported yet");
  650.             }
  651.         }
  652.     }
  653. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement