Class ConditionalStatement

  • All Implemented Interfaces:
    Statement

    public final class ConditionalStatement
    extends java.lang.Object
    implements Statement
    The ConditionalStatement class is used to store information about conditional statements declared during compilation.
    Since:
    1.0
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  ConditionalStatement.ElseStatement
      The ElseStatement class is used to store information about else statements declared during compilation.
    • Constructor Summary

      Constructors 
      Constructor Description
      ConditionalStatement​(Token ifToken, Expression condition, Statement thenStatement)
      Constructs a ConditionalStatement object, initialised with the statements contents.
    • Constructor Detail

      • ConditionalStatement

        public ConditionalStatement​(Token ifToken,
                                    Expression condition,
                                    Statement thenStatement)
        Constructs a ConditionalStatement object, initialised with the statements contents.

        A SourceSpan containing the range of the statement is automatically generated, as well as a LinkedList of its children.

        Parameters:
        ifToken - The if Token
        condition - The condition Expression for the then Statement to run
        thenStatement - The Statement to be run if the condition is true
    • Method Detail

      • addElseStatement

        public void addElseStatement​(Token elseToken,
                                     Statement statement)
        Adds an ElseStatement to this ConditionalStatement, which will run if the condition is false.
        Parameters:
        elseToken - The else Token
        statement - The Statement to be run if the condition is false
      • includesElseStatement

        public boolean includesElseStatement()
        Returns a boolean to indicate if a ConditionalStatement contains an ElseStatement.
        Returns:
        A boolean indicating if an else is present