CAST

The C/AL Abstract Syntax Tree (CAST) is a new hobby project I’m working on to parse and define the C/AL programming language (object file format) using the haXe type system to express the C/AL syntax tree. I’ll post in my blog on the progress. So far there are a couple of preliminary definitions (partial and work in progress, naturally)

The Cell type defines a typed linked list.

enum Cell<T>
{
none;
some (x: T, xs: Cell<T>);
}

The Identifier type defines a C/AL identifier with a name and an integer key

enum Identifier
{
id (name: String, id: Int);
}

The TypeDefinition type defines C/AL type

enum TypeDefinition
{
variant_t;
boolean_t;
char_t;
integer_t;
decimal_t (length: Int);
text_t (length: Int);
code_t (length: Int);
record_t (name: Identifier);
recref_t;
file_t;
instream_t;
outstream_t;
automation_t (name: String);
ocx_t;
array_t (type: TypeDefinition, size: Cell<Int>);
}

The FunctionDefinition type defines function signatures

enum FunctionDefinition
{
fun (a: Cell<Parameterdefinition>, b: TypeDefinition);
}

The ParameterDefinition type defines function parameter type declarations, including whether they are pass-by-reference or pass-by-value (or in vs inout/ref)

enum ParameterDefinition
{
val (key: Identifier, type: TypeDefinition);
ref (key: Identifier, type: TypeDefinition);
}

The VariableDefinition type defines variable declarations; that is: an identifier and a type definition

enum VariableDefinition
{
def (key: Identifier, type: TypeDefinition);
}

The Numeric type defines numeric or ordered primitive types

enum Numeric
{
bool (x: Bool);
char (x: Int);
int (x: Int);
dec (x: Float);
}

The Expression type defines all kinds of expressions. This is a critical type and needs more thought

enum Expression
{
const (x: Numeric);
apply (f: Identifier, x: Cell<Expression>);
assign (v: Identifier, x: Expression);
}

The Statement type defines all kinds of statements (very incomplete as of now)

enum Statement
{
exp (x: Expression);
block (x: Cell<Statement>);
iff (a: Expression, b: Statement);
repeat (s: Statement, until: Expression);

}

That’s it for now. I hope to get a full AST in the not too distant future. I’ve concentrated on the core C/AL language but there is also the object container format which also needs some syntactic constructs.

If/when the CAST project is done, I have a follow-up project: C/AL Code Coverage (CCC) which looks at C/AL code for patterns of bad code. Sort of like the FXcop for Navision.

Edit: Fixed some formatting errors due to the “<”-sign being interpreted as an HTML start tag and therefore obscuring generic type parameters.


About this entry