Pagini
Workshops
Parteneri
References:
Recommended reading:
AST Examples:
To get a better understanding of what an AST looks like, we can dump the ASTs produced by Clang for some simple files. You can start with the ones below. You should try to modify them and check out other language constructs to see how they are expressed in the AST.
int inc(int a) { return a + 1; }
int sum_sq(int a, int b) { return a * a + b * b; }
int max(int a, int b, int c) { if (a > b) { if (c > a) { return c; } else { return a; } } if (b > c) { return b; } return c; }
int sum(int *a, int n) { int s = 0; for (int i = 0; i < n; i++) { s += a[i]; } return s; }
struct point { int x, y; }; int max(int a, int b) { return a < b ? b : a; } // Chebyshev int distance(struct point A, struct point B) { return max(A.x - B.x, A.y - B.y); }