Enum endbasic_core::ast::Statement[][src]

pub enum Statement {
    ArrayAssignment(VarRefVec<Expr>, Expr),
    Assignment(VarRefExpr),
    BuiltinCall(StringVec<(Option<Expr>, ArgSep)>),
    Dim(StringVarType),
    DimArray(StringVec<Expr>, VarType),
    If(Vec<(Expr, Vec<Statement>)>),
    For(VarRefExprExprExprVec<Statement>),
    While(ExprVec<Statement>),
}
Expand description

Represents a statement in the program along all data to execute it.

Variants

ArrayAssignment(VarRefVec<Expr>, Expr)

Represents an assignment to an element of an array.

The first parameter is the reference to the array to modify. The second parameter is the expressions to compute the subscripts to index the array. the third parameter is the expression to compute the value of the modified element.

Tuple Fields of ArrayAssignment

0: VarRef1: Vec<Expr>2: Expr
Assignment(VarRefExpr)

Represents a variable assignment.

The first parameter is the reference to the variable to set. The second parameter is the expression to compute the value for the variable.

Tuple Fields of Assignment

0: VarRef1: Expr
BuiltinCall(StringVec<(Option<Expr>, ArgSep)>)

Represents a call to a builtin command such as PRINT.

The first parameter is the name of the builtin. The second parameter is the sequence of arguments to pass to the builtin.

Each argument is represented as an optional expression to evaluate and the separator that was to separate it from the next argument. Because of this, the last argument always carries ArgSep::End as the separator. The reason the expression is optional is to support calls of the form PRINT a, , b.

Tuple Fields of BuiltinCall

0: String1: Vec<(Option<Expr>, ArgSep)>

Represents a variable declaration.

The first parameter is the name of the variable to set; type annotations are not allowed. The second parameter is the type of the variable to be defined.

Given that a declaration causes the variable to be initialized to a default value, it is tempting to model this statement as a simple assignment. However, we must be able to detect variable redeclarations at runtime, so we must treat this statement as a separate type from assignments.

Tuple Fields of Dim

0: String1: VarType
DimArray(StringVec<Expr>, VarType)

Represents an array declaration.

The first parameter is the name of the array to set; type annotations are not allowed. The second parameter is the expressions to compute the dimensions of the array. The third parameter is the type of the elements in the array.

Tuple Fields of DimArray

0: String1: Vec<Expr>2: VarType

Represents an IF statement.

The first and only parameter is a sequence containing all the branches of the statement. Each element is a pair of the conditional guard for the branch and the collection of statements in that branch. The final ELSE branch, if present, is also included here and its guard clause is always a true expression.

Tuple Fields of If

0: Vec<(Expr, Vec<Statement>)>

Represents a FOR statement.

The first parameter is the loop’s iterator name, which is expressed a variable reference that must be either automatic or an integer. The second parameter is the expression to compute the iterator’s initial value, which must evaluate to an integer. The third parameter is the condition to test after each body execution, which if false terminates the loop. The fourth parameter is the expression to compute the iterator’s next value. The fifth parameter is the collection of statements within the loop.

Note that we do not store the original end and step values, and instead use expressions to represent the loop condition and the computation of the next iterator value. We do this for run-time efficiency. The reason this is possible is because we force the step to be an integer literal at parse time and do not allow it to be an expression.

Tuple Fields of For

0: VarRef1: Expr2: Expr3: Expr4: Vec<Statement>
While(ExprVec<Statement>)

Represents a WHILE statement.

The first parameter is the loop’s condition. The second parameter is the collection of statements within the loop.

Tuple Fields of While

0: Expr1: Vec<Statement>

Trait Implementations

Formats the value using the given formatter. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.