frame_transpiler icon indicating copy to clipboard operation
frame_transpiler copied to clipboard

Semantic stages needed in compiler for lang specific parsing decisions and processing.

Open frame-lang opened this issue 2 years ago • 0 comments

Currently autoinc tokens ++/-- are parsed but permitted/forbidden per language. This is being done in the code generators. Need to add an additional stage to analyze AST for correctness for a target language and generate proper error messages or possibly adjust the tree, if desired by the user.

For instance, fully supporting autoinc for Python would require handling situations like this in C++:

#include <stdio.h>
#include <iostream>
using namespace std;

int boo(int a,int b) {
    return a + b;
}

int foo(int a) {
    cout << a;
    return a;
}

int main()
{
    int a = 0;
    
    cout << boo(foo(++a),foo(++a));
  
    return 0;
}

This would involve exploding the boo(foo(++a),foo(++a)) expression into a number of intermediate steps which is probably best done by rewriting the AST.

However, this may create really ugly code which might be offputting to some users (as well as hard to reason about if there is a bug) so don't necessarily want to do this by default.

frame-lang avatar Sep 16 '23 14:09 frame-lang