*ALICE: Assembly Logical Instruction for C+- Engine

An innovative assembly engine optimized for C+- code, turning complex logic into optimized instructions for scalable processors.

GitHub Go to Documentation

Compilation Flow

Input: test.cmm

Your source C+- code file, the starting point of the compilation process.

Tokenization: lexer.l

Breaks down the input file into tokens (keywords, identifiers, etc.).

Parsing: parser.y

Analyzes token sequences based on grammar rules to create the syntax tree.

AST Construction: ast.c

Generates the Abstract Syntax Tree (AST) representing the program structure.

Generated Lexical Analysis: lex.yy.c

The output from the lexical analyzer based on the tokens.

Generated Parsing: parser.tab.c

Generated parsing logic, derived from the grammar rules.

Include Handling: handle_include.c

Handles all file includes specified within the source code.

Output:test.asm

Final assembly code, ready to run on the processor.


The compilation transforms test.cmm into test.asm through these sequential steps.

test.cmm

This is the input file.

int a = 5;
int b = 10;
int c = a + b;
return c;
    
manufacturing Which goes directly to myccompiler.exe

scan lexer.l

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

Bison Icon parser.y

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($$); }

AST Icon ast.c

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)

test.asm

This is the output file.

LOAD 5
SET a
LOAD 10
SET b
LOAD a
ADD b
SET c
PLD c
RETURN
ROOT

Example Video

Compilation Flow Diagram

Compilation Flow Diagram

Features

bolt

Fast Compilation

*ALICE compiles C+- code quickly and efficiently for optimized performance.

folder_open

Multi-file Support

Compile multiple files at once with precise error tracking by line.

manufacturing

Custom Stack Size

Adjustable stack size for faster processing and hardware optimization.

balance

Processor Choice

Select between fixed-point or floating-point processor types.

code_blocks

Directive Management

Supports a wide range of directives with customizable parameters.

Future Features

lightbulb

Enhanced Error Reporting

More detailed error and warning reports.

speed

Performance Optimization

Faster compilation and built-in code optimization tips.

extension

Plugin System

Support for add-ons and community-built tools.

trending_up

Statistical Insights

Data-driven suggestions for code improvements.

security

Security Enhancements

Improved reliability and security features.

ALICE Documentation

Find detailed information and guides about the ALICE Assembly Logical Instruction for C Engine.

Read Documentation