コード例 #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);
 }
コード例 #2
0
ファイル: TypeChecker.cs プロジェクト: smh87/PseudoIno-lang
 /// <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);
 }
コード例 #3
0
        /// <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);
        }
コード例 #4
0
ファイル: Visitor.cs プロジェクト: smh87/PseudoIno-lang
 /// <summary>
 /// This visits an ElseIf statement
 /// </summary>
 /// <param name="elseifStatementNode">The visited node</param>
 /// <returns></returns>
 public abstract object Visit(ElseifStatementNode elseifStatementNode);