Skip to content

Latest commit

 

History

History
112 lines (77 loc) · 5.67 KB

File metadata and controls

112 lines (77 loc) · 5.67 KB

< Language Specification

Chapter 7 – Execution

Contents

  • 7.1 – General
  • 7.2 – Parsing
  • 7.3 – Semantic analysis
  • 7.4 – Runtime execution
  • 7.5 – Errors
    • 7.5.1 – Syntax errors
    • 7.5.2 – Semantic errors
    • 7.5.3 – Runtime errors

This chapter describes the proper loading, pre-processing, and execution of DeltaScript files by a language implementation like an interpreter or compiler.

7.1 – General

The particulars of the execution of DeltaScript code are highly dependent on the language implementation. This chapter outlines general steps and guidelines for correct and expected behaviour.

Note:

DeltaScript execution threads are limited to a single source code file. This is a limitation of the base language; if necessary, it can be worked around by defining a new type§8.3.1 to represent scripts in an extension§8.2 to the language. That way, scripts will be able to call other scripts.

Execution can generally be sorted into three stages:

  1. Parsing (syntax§1 analysis)
  2. Semantic analysis
  3. Runtime

Errors§7.5 can occur at any stage and are categorized accordingly.

7.2 – Parsing

Parsing or syntax analysis is the process of analyzing DeltaScript code to ensure it conforms to the grammar rules §1.2 defined in this specification.

If the grammars are unable to match the contents of the file to <head_rule>[a], a syntax error is triggered and execution does not proceed to semantic analysis.

Note:

The degree of descriptiveness syntax error messages are capable of providing will depend on the parsing algorithm of the language implementation.

In the event that the contents of the file are a match for <head_rule>, the parser will generate an abstract syntax tree (AST) that represents the hierarchical structure of the program.

7.3 – Semantic analysis

Semantic analysis involves validating the AST to ensure that the script adheres to the language's semantic rules. This includes type§2 checking, ensuring variables§3.1 are in scope§3.4 wherever they are references, and ensuring that operations§4.5 are performed on compatible types.

If a semantic error is during the analysis, execution is halted and does not proceed to runtime execution.

7.4 – Runtime execution

Runtime execution is the final stage, where the validated script is executed. The interpreter or compiler processes the AST, performing the operations specified in the script. This stage involves managing the program's state (e.g. updating the values of variables§3.1), executing statements§5.2, and evaluating expressions§4.

7.5 – Errors

Errors in DeltaScript are categorized based on the stage at which they occur. An error encountered at any stage of the execution process must be resolved in order to progress to the next stage.

7.5.1 – Syntax errors

Syntax errors occur during the parsing§7.2 (syntax analysis) stage when the script does not conform to the grammar rules.

Example:

() {
  print("Hello, world!");

This script is missing a curly bracket } to close its header function§6.3.1.

7.5.2 – Semantic errors

Semantic errors are detected during the semantic analysis§7.3. These errors occur when the script violates the language's semantic rules, such as type§2 mismatches or attempting to evaluate an undefined variable§3.1.

Examples of semantic errors:

int some_var = "This is not an int";
int some_var = 10 - false;
() {
  if (flip_coin()) {
    string v = "Vendetta";
  }

  print(v);   // semantic error - v is out of scope
}

These code snippets are all syntacticall correct but fail semantic analysis.

7.5.3 – Runtime errors

Runtime errors occur during the runtime execution§7.4 stage. These errors arise from invalid operations performed while the script is running, such as division by zero or accessing out-of-bounds array elements.

As of this language version, DeltaScript has no runtime error suppression mechanisms. Any runtime error triggered during execution§7.4 will cause the script to terminate abruptly.


Footnotes

  • a - Only entire scripts must be a match for <head_rule>. Code snippets in isolation may match different rules from the syntax grammar§1.2.