Tree Sitter to CAST translation - ml4ai/skema GitHub Wiki

Comment Extraction

Fortran

Fortran Idioms

MATLAB

The following MATLAB idioms either have or will have CAST support

Assignment

x = 6;        % literal integer
x = 3.141;    % literal real
x = 'Bob';    % literal string
x = true;     % literal boolean
y = x;        % identifier
z = x / y;    % operator
m = [2 3 11]; % matrix

Completed: PR #527, 641

Operators

MATLAB does not have augmented assignment operators such as +=, %=, ++ etc.

x = y * 2;    % Binary operator. 
x = -y;       % Unary operator.
x = y < 5;    % Comparison operator.
z = x && y;   % Boolean operator.
x = ~y;       % Not operator, logical matrix inversion.
x(:,1) = y;   % Spread operator.
x = y';       % Postfix operator

Completed: PR #532, #641, #671

Conditionals

if elseif else

if x == 'one'
    n = 1;
elseif x == 'two'
    n = 2;
else
    n = 0;
end

Completed: PR #613

Switch

CAST has no switch statement so these are translated into conditionals

switch x
    case 'one'   % if
        n = 1;
    case 'two'   % elseif
        n = 2;
    otherwise    % else
        n = 0;
end

Completed, PR #634

For Loops

MATLAB for loops reach their ending values

% Implicit step increment of 1, will iterate values (1, 2, 3, 4, 5)
for i=1:5  
    disp(i);
end

% Explicit step increment of 2, will iterate values (0, 2, 4, 8)
for j=0:2:8 
    disp(j);
end

% Range of matrix literal values, will iterate values (10, 3, 5 6)
for k = [10 3 5 6]
    disp(k);
end

In progress: Issue #639

TODO

Functions

Definition

function addition_demo = both(x, y)  
    both = x + y;
end

Completed: PR #671

Call

y = addition_demo(1, 3);

Completed: PR #641

Commands

clear all;
reset;

Completed: PR #641

Execution Control

  • Continue statement: TODO

Python

Main issue that tracks Python tree-sitter to CAST port: #489

Python Idioms

Foundational Idioms

Assignment

Status: Complete

PR: #513

Notes:

Arithmetic Operations

Status: Complete

PR: #545

Notes:

Functions

Status: PR Created

PR: #584

Notes:

Conditionals

Status: PR Created

PR: #711

Loops

Status: TBD

Advanced Idioms/Idioms Specific to Python

Comprehensions (List/Dict/Lambdas)

Classes

Calls to super()

Inheritance

Advanced Function Definitions

Nested function definitions

Star and Double-Star operators

Default Arguments

Keyword Args

Imports

Slicing

List/Array Slicing

Decorators/Descriptors

Generators

Exception Handling

With Clauses

Variable introduction/declaration within conditionals

Initializing a variable within the bodies of a conditional, and then using it beyond the conditional. Currently only shows up in one instance in the Bucky model (nonvaccs variable). This requires more thought as to how to handle.