An innovative assembly engine optimized for C+- code, turning complex logic into optimized instructions for scalable processors.
test.cmm
Your source C+- code file, the starting point of the compilation process.
lexer.l
Breaks down the input file into tokens (keywords, identifiers, etc.).
parser.y
Analyzes token sequences based on grammar rules to create the syntax tree.
ast.c
Generates the Abstract Syntax Tree (AST) representing the program structure.
lex.yy.c
The output from the lexical analyzer based on the tokens.
parser.tab.c
Generated parsing logic, derived from the grammar rules.
handle_include.c
Handles all file includes specified within the source code.
test.asm
Final assembly code, ready to run on the processor.
The compilation transforms test.cmm
into test.asm
through these sequential steps.
This is the input file.
int a = 5; int b = 10; int c = a + b; return c;manufacturing Which goes directly to myccompiler.exe
Here, the compiler starts tokenizing the text stream from test.cmm.
...
digit [0-9]
letter [a-zA-Z]
identifier {letter}({letter}|{digit})*
number -?{digit}+
float_number [0-9]*\.[0-9]+([eE][+-]?[0-9]+)?
scientific_number [0-9]+(\.[0-9]*)?[eE][+-]?[0-9]+
...
"int" { return INT; }
"=" { return ASSIGN; }
";" { return SEMICOLON; }
...
{identifier} {
yylval.sval = strdup(yytext);
return IDENTIFIER;
}
{number} {
yylval.ival = atoi(yytext);
return NUMBER;
}
...
Tokens:
INT IDENTIFIER ASSIGN NUMBER SEMICOLON INT IDENTIFIER ASSIGN NUMBER SEMICOLON INT IDENTIFIER ASSIGN IDENTIFIER PLUS IDENTIFIER SEMICOLON
Next, the *ALICE compiler checks if the input stream of tokens is valid according to the grammar.
%token INT
%token PLUS ASSIGN SEMICOLON
%token sval IDENTIFIER
%token ival NUMBER
...
stmt:
IDENTIFIER ASSIGN expr SEMICOLON { $$ = create_node('=', NULL, $3, NULL, NULL, 0, 0.0, 0.0, $1); }
| RETURN expr SEMICOLON { $$ = create_node('R', $2, NULL, NULL, NULL, 0, 0.0, 0.0, NULL); }
expr:
expr PLUS expr { $$ = create_node('+', $1, $3, NULL, NULL, 0, 0.0, 0.0, NULL); }
...
Several nodes are created by the 'create_node' function. In this example, five productions/reductions are made:
decl: INT IDENTIFIER ASSIGN expr SEMICOLON { $$ = create_node('=', NULL, $4, NULL, NULL, 0, 0.0, 0.0, $2); } (3 times);
expr: expr PLUS expr { $$ = create_node('+', $1, $3, NULL, NULL, 0, 0.0, 0.0, NULL); }
stmt: RETURN expr SEMICOLON { $$ = create_node('R', $2, NULL, NULL, NULL, 0, 0.0, 0.0, NULL); }
decls: decls decl { $$ = create_node(';', $1, $2, NULL, NULL, 0, 0.0, 0.0, NULL); }
program: decls { $$ = create_node('RTN', $1, NULL, NULL, NULL, 0, 0.0, 0.0, NULL); generate_code_from_ast($$); }
Finally, the *ALICE compiler generates the ASM output code based on the nodes created by the create_node function in the previous step.
ASTNode *create_node(int type, ASTNode *left, ASTNode *right, ASTNode *back, ASTNode *forth, int ival, float fval, double dval, char *sval)
{
ASTNode *node = (ASTNode *)malloc(sizeof(ASTNode));
node->type = type;
node->left = left;
node->right = right;
node->back = back;
node->forth = forth;
if (sval)
{
node->value.sval = strdup(sval);
}
else if (type == 'FL')
{
node->value.fval = fval;
}
else if (type == 'DB')
{
node->value.dval = dval;
}
else
{
node->value.ival = ival;
}
return node;
}
Nodes:
'N' (2x)
'=' (3x)
'I' (5x)
'+' (1x)
'R' (1x)
'RTN' (1x)
This is the output file.
LOAD 5
SET a
LOAD 10
SET b
LOAD a
ADD b
SET c
PLD c
RETURN
ROOT
*ALICE compiles C+- code quickly and efficiently for optimized performance.
Compile multiple files at once with precise error tracking by line.
Adjustable stack size for faster processing and hardware optimization.
Select between fixed-point or floating-point processor types.
Supports a wide range of directives with customizable parameters.
More detailed error and warning reports.
Faster compilation and built-in code optimization tips.
Support for add-ons and community-built tools.
Data-driven suggestions for code improvements.
Improved reliability and security features.
Find detailed information and guides about the ALICE Assembly Logical Instruction for C Engine.