AARCHMRS Schema 2.9.6

↚ Home

AST.ForLoop object

A model representing an ASL for statement. Models the following structures:

  • An ascending For loop
for i = 0 to 15 do
    x = x + i;
end;
  • A descending For loop
for i = 15 downto 0 do
    x = x + i;
end;

object

Properties Type Description
_meta Meta
See Meta for more information.
_type
Enum
AST.ForLoop
ascending◊
  • boolean

If the for loop is iterating upwards or downwards.

end◊ AST.BinaryOp

The value to stop iterating at (inclusive).

See definitions.expression in AST.BinaryOp for more information.
start◊ AST.BinaryOp

The value to begin iterating from.

See definitions.expression in AST.BinaryOp for more information.
statements◊ StatementBlock

The statements to execute each loop iteration.

See StatementBlock for more information.
variable◊ Identifier

The variable holding the value of the current iteration.

See Identifier for more information.
Additional Properties
Not Allowed
◊ Required
Properties marked with ◊ are required properties.
Examples
{
    "_type": "AST.ForLoop", 
    "variable": {
        "_type": "AST.Identifier", 
        "value": "i"
    }, 
    "start": {
        "_type": "AST.Integer", 
        "value": 0
    }, 
    "ascending": true, 
    "end": {
        "_type": "AST.Integer", 
        "value": 15
    }, 
    "statements": {
        "_type": "AST.StatementBlock", 
        "statements": [
            {
                "_type": "AST.Assignment", 
                "var": {
                    "_type": "AST.Identifier", 
                    "value": "x"
                }, 
                "val": {
                    "_type": "AST.BinaryOp", 
                    "left": {
                        "_type": "AST.Identifier", 
                        "value": "x"
                    }, 
                    "op": "+", 
                    "right": {
                        "_type": "AST.Identifier", 
                        "value": "i"
                    }
                }
            }
        ]
    }
}
{
    "_type": "AST.ForLoop", 
    "variable": {
        "_type": "AST.Identifier", 
        "value": "i"
    }, 
    "start": {
        "_type": "AST.Integer", 
        "value": 15
    }, 
    "ascending": false, 
    "end": {
        "_type": "AST.Integer", 
        "value": 0
    }, 
    "statements": {
        "_type": "AST.StatementBlock", 
        "statements": [
            {
                "_type": "AST.Assignment", 
                "var": {
                    "_type": "AST.Identifier", 
                    "value": "x"
                }, 
                "val": {
                    "_type": "AST.BinaryOp", 
                    "left": {
                        "_type": "AST.Identifier", 
                        "value": "x"
                    }, 
                    "op": "+", 
                    "right": {
                        "_type": "AST.Identifier", 
                        "value": "i"
                    }
                }
            }
        ]
    }
}

Schema http://json-schema.org/draft-04/schema#

{
  "title": "For Loop",
  "info": [
    "A model representing an ASL for statement. Models the following structures:",
    [
      "* An ascending For loop",
      "```",
      "for i = 0 to 15 do",
      "    x = x + i;",
      "end;",
      "```",
      "* A descending For loop",
      "```",
      "for i = 15 downto 0 do",
      "    x = x + i;",
      "end;",
      "```"
    ]
  ],
  "examples": [
    {
      "_type": "AST.ForLoop",
      "variable": {
        "_type": "AST.Identifier",
        "value": "i"
      },
      "start": {
        "_type": "AST.Integer",
        "value": 0
      },
      "ascending": true,
      "end": {
        "_type": "AST.Integer",
        "value": 15
      },
      "statements": {
        "_type": "AST.StatementBlock",
        "statements": [
          {
            "_type": "AST.Assignment",
            "var": {
              "_type": "AST.Identifier",
              "value": "x"
            },
            "val": {
              "_type": "AST.BinaryOp",
              "left": {
                "_type": "AST.Identifier",
                "value": "x"
              },
              "op": "+",
              "right": {
                "_type": "AST.Identifier",
                "value": "i"
              }
            }
          }
        ]
      }
    },
    {
      "_type": "AST.ForLoop",
      "variable": {
        "_type": "AST.Identifier",
        "value": "i"
      },
      "start": {
        "_type": "AST.Integer",
        "value": 15
      },
      "ascending": false,
      "end": {
        "_type": "AST.Integer",
        "value": 0
      },
      "statements": {
        "_type": "AST.StatementBlock",
        "statements": [
          {
            "_type": "AST.Assignment",
            "var": {
              "_type": "AST.Identifier",
              "value": "x"
            },
            "val": {
              "_type": "AST.BinaryOp",
              "left": {
                "_type": "AST.Identifier",
                "value": "x"
              },
              "op": "+",
              "right": {
                "_type": "AST.Identifier",
                "value": "i"
              }
            }
          }
        ]
      }
    }
  ],
  "properties": {
    "_meta": {
      "$ref": "../Meta.json"
    },
    "_type": {
      "enum": [
        "AST.ForLoop"
      ]
    },
    "variable": {
      "info": [
        "The variable holding the value of the current iteration."
      ],
      "$ref": "Identifier.json"
    },
    "start": {
      "info": [
        "The value to begin iterating from."
      ],
      "$ref": "../AST/BinaryOp.json#/definitions/expression"
    },
    "ascending": {
      "info": [
        "If the for loop is iterating upwards or downwards."
      ],
      "type": "boolean"
    },
    "end": {
      "info": [
        "The value to stop iterating at (inclusive)."
      ],
      "$ref": "../AST/BinaryOp.json#/definitions/expression"
    },
    "statements": {
      "info": [
        "The statements to execute each loop iteration."
      ],
      "$ref": "StatementBlock.json"
    }
  },
  "required": [
    "variable",
    "start",
    "ascending",
    "end",
    "statements"
  ],
  "type": "object",
  "additionalProperties": false,
  "$schema": "http://json-schema.org/draft-04/schema#"
}