Esempio n. 1
0
 /// <summary>
 /// This method prints the elseifStatementNode and make an indentation
 /// It accepts the Val and Expressions if there exist any
 /// Then it accepts all the statements and then lastly outdent
 /// </summary>
 /// <param name="elseifStatementNode">The node to print.</param>
 /// <returns>Returns null</returns>
 public override object Visit(ElseifStatementNode elseifStatementNode)
 {
     Print("ElseifStatementNode");
     Indent++;
     elseifStatementNode.Val?.Accept(this);
     elseifStatementNode.Expression?.Accept(this);
     if (elseifStatementNode.Statements.Any())
     {
         elseifStatementNode.Statements.ForEach(node => node.Accept(this));
     }
     Indent--;
     return(null);
 }
Esempio n. 2
0
 /// <summary>
 /// This method type checks the ElseIfStatementNode node in the AST.
 /// </summary>
 /// <param name="elseifStatementNode">The node to check.</param>
 /// <returns>Returns null</returns>
 public override object Visit(ElseifStatementNode elseifStatementNode)
 {
     CurrentScope = GlobalScope.FindChild($"{elseifStatementNode.Type}_{elseifStatementNode.Line}");
     if (((TypeContext)elseifStatementNode.Expression.Accept(this)).Type == BOOL)
     {
         elseifStatementNode.Statements.ForEach(stmnt => stmnt.Accept(this));
     }
     else
     {
         new InvalidTypeException($"Else if statement expected a boolean expression at {elseifStatementNode.Line}:{elseifStatementNode.Offset}");
     }
     CurrentScope = CurrentScope.Parent ?? GlobalScope;
     return(null);
 }
        /// <summary>
        /// This method visits an elseif statement node
        /// It checks if there is an expression to accepts
        /// Then it accepts any statement
        /// </summary>
        /// <param name="elseifStatementNode">The name of the node</param>
        /// <returns>It returns an else if</returns>
        public override object Visit(ElseifStatementNode elseifStatementNode)
        {
            string elseif = "else if (";

            elseif += elseifStatementNode.Expression?.Accept(this);
            elseif += "){";
            if (elseifStatementNode.Statements.Any())
            {
                elseifStatementNode.Statements.ForEach(node => node.Parent = elseifStatementNode);
                elseifStatementNode.Statements.ForEach(node => elseif     += node.Accept(this));
            }
            elseif += ("}");

            return(elseif);
        }
Esempio n. 4
0
 /// <summary>
 /// This visits an ElseIf statement
 /// </summary>
 /// <param name="elseifStatementNode">The visited node</param>
 /// <returns></returns>
 public abstract object Visit(ElseifStatementNode elseifStatementNode);