Master Thesis Compiler
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
headers
loki-0.1.7
tests
.gitignore
LICENSE
Makefile
README.md
application.cpp
assignment_expression.cpp
bison_parser.cpp
bison_parser.y
code_generating_visitor.cpp
code_generator.cpp
compound_instruction.cpp
declaration.cpp
dereference.cpp
do_while_instruction.cpp
equal_types_multimethod.cpp
equal_types_nothrowable_dispatcher.cpp
errors_detector.cpp
expression.cpp
factor.cpp
for_instruction.cpp
function.cpp
function_call.cpp
function_data.cpp
get_address.cpp
if_instruction.cpp
keywords_table.cpp
label_generator.cpp
loki
main.cpp
makefile.dep
mtc-Makefile.mk
mtc.sh
number.cpp
operators.cpp
parameter.cpp
parenthesis.cpp
parser.cpp
program.cpp
return_instruction.cpp
scanner.cpp
scanner.l
scope.cpp
semantic_analysis_exceptions.cpp
semantic_analysis_visitor.cpp
simple_expression.cpp
start_tests.sh
string.cpp
string_data.cpp
strings_controller.cpp
symbol_data.cpp
symbols_controller_factory.cpp
tests.sh
type.cpp
type_data.cpp
types_mapping.cpp
unary_factor.cpp
variable.cpp
variable_data.cpp
variables_controller.cpp
while_instruction.cpp

README.md

Copyright (C) 2007 Łukasz Czerwiński

Master Thesis Compiler

This project it a practical part of my master thesis `Syntax, semantics analysis methods and assembly code generating for Intel x86 architecture' describes lexical analysis, parsing theory, semantic analysis focused on types and classes and computer's architecture basics. It contains a source code of a compiler for a simplified version of C language.

Website

https://github.com/wo3kie/mtc

Requirements

  • C++03
  • flex++ >=2.5.35, optional, only if you change scanner.l
  • bison++ >= 1.21.9-1, optional, only if you change bison_parser.y
  • loki library, included as part of my code in version 0.1.7 link

How to build code?

make

How to run it?

./mtc.sh tests/expression_1.mtc

How to write your own program

Please follow examples in 'tests' directory. Shortly speaking mtc has C like syntax with no struct support.

tests/factorial.mtc

int factorial_recursive( int value ){
    if( value == 0 ) return 1;
    else return value * factorial_recursive( value - 1 );
}

int factorial_for( int value ){
    int result = 1;

    for( int start = 1 ; start < value + 1; start = start + 1 ){
        result = result * start;
    }

    return result;
}

int main(){
    return factorial_recursive( 4 ) - factorial_for( 4 );
}
// tests/function_arguments_2.mtc

int * Pint_F_Pint( int * p ){
    return p;
}

int int_F_Pint( int * p ){
    return * p;
}

int int_F_int_Pint( int i, int * p ){
    return i + * p;
}

int main(){
    int i1 = 3;
    int * p1 = & i1;

    if( Pint_F_Pint( & i1 ) != & i1 ) return 1;
    if( Pint_F_Pint( p1 ) != p1 ) return 2;

    if( int_F_Pint( & i1 ) != i1 ) return 3;
    if( int_F_Pint( p1 ) != i1 ) return 4;
    if( int_F_Pint( Pint_F_Pint( & i1 ) ) != i1 ) return 5;
    if( int_F_Pint( Pint_F_Pint( p1 ) ) != i1 ) return 6;

    if( int_F_int_Pint( 3, p1 ) != 6 ) return 7;
    if( int_F_int_Pint( int_F_Pint( p1 ), & i1 ) != 6 ) return 8;

    return 0;
}