Introduction

  • C/C++ Build Tools: Preprocessor, Compiler, Assembler, Linker
  • General Compiler Structure: Front-end, Back-end, Optimizations
  • Front-end: Lexical Analysis, Syntax Analysis, Semantic Analysis

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.

1-basic.c
int inc(int a) {
	return a + 1;
}
2-expr.c
int sum_sq(int a, int b) {
	return a * a + b * b;
}
3-if.c
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;
}
4-for.c
int sum(int *a, int n) {
	int s = 0;
	for (int i = 0; i < n; i++) {
		s += a[i];
	}
	return s;
}
5-call.c
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);
}
sesiuni/compiler/intro.txt · Last modified: 2014/07/14 20:34 by freescale