thomas-siozos / Ocean-Compiler

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Ocean Compiler 🌊

Στόχος του project είναι η μεταγλώττιση μιας αυτοσχέδιας αντικειμενοοστραφής προγραμματιστικής γλώσσας που ονομάστηκε Ocean. Χρησιμοποιήθηκαν τα εργαλεία lex και bison. Το αρχείο εξόδου θα είναι μεταφρασμένο σε γλώσσα C με μικρές διαφορές.

Ocean's Features

  • int, int[], char, double.
  • Classes.
  • Objects.
  • Constructors.
  • Inheritance.
  • Constructor overloading.
  • Method overriding.
  • Polymorphism.
  • Abstract methods.
  • Interfaces.

Ocean's Grammar

<program> ::= <class_type>


<main> ::= main ( ) { <method_block> }
<class_type> ::= ε | ()* | ()
<class> ::= class id { } | class id extends id { }
<interface> ::= interface id { (<interface_block>)
}
<block> ::= ()* ()
<interface_block> ::= ε | id ( ) ;
<declarations> ::= ε | public (<values_list>)
endpublic
<values_list> ::= ε | <int_values> | <double_values> | <char_values> | <object_values>
<int_values> ::= int <array_or_not>
<array_or_not> ::= id <init_int_rule> | [digit] id <int_array_rule>
<int_array_rule> ::= ; | = { <many_digits> } ;
<many_digits> ::= digit | (digit)
<init_int_rule> ::= ε | ; | = ( )
;
<double_values> ::= double id ; | double id = ()* ;
<char_values> ::= char id ; | char id = char ;
<object_values> ::= object id id ;
<constructors> ::= ε | id ( ) { <constructor_block> }
<methods> ::= ε | void id ( ) { (<method_block>)* }
| int id ( ) { (<method_block>)* }
| double id ( ) { (<method_block>)* }
| char id ( ) { (<method_block>)* }
| abstract id ( ) ;
<parlist> ::= ε | <parlist_types> | (, <parlist_types> )
<par_int> ::= ε | id | [ digit ] id
<constructor_block> ::= (<method_block>)

<method_block> ::= ε | <assignment>
| <ifstat>
| <whilestat>
| <switchstat>
| <forstat>
| <callstat>
| <returnstat>
| <inputstat>
| <printstat>
| <super>
<assignment> ::= int <local_array_or_not>
| id = ()* ;
| double id = ();
| double id ;
| char id = ()
;
| char id ;
| object id id <init_object>
<local_array_or_not> ::= id <local_int> | [ digit ] id <init_array_rule>
<local_int> ::= ; | = ()* ;
<init_object> ::= = id ( <actualpars_constructor> ) ; | ;
<actualspars_constructor>::= ε | id | char | digit | double | (, id)* | (, char)
| (, digit)
| (, double)
<ifstat> ::= if ( ) { (<method_block)
}
| elif ( ) { (<method_block)* }
| else { (<method_block)* }
<whilestat> ::= while ( ) { (<method_block)* }
<forstat> ::= for ( <int_values_for> id
<number_or_id>; <for_step> ) { (<method_block>)* }
<int_values_for> ::= int id = ()* ; | id = ()* ;
<number_of_id> ::= digit | id
<forstep> ::= id = ()* | id = ++ | id = –
<returnstat> ::= return ()* ;
<switchstat> ::= switch ( id ) { ()}
<caserule> ::= ε | case <id_char_digit>: (<method_block>)
break;
| default: break;
| default: (<method_block>)* break;
<id_char_digit> ::= id | char | digit
<printstat> ::= print ( (<inside_print>)* );
<inside_print> ::= ε | (‘ <inside_apostrophe> ‘)* | (, )
<aftercomma> ::= <inside_apostrophe> | <outside_apostrophe>
<inside_apostrophe> ::= ε | id | %d | %f | %c
<outside_apostrophe> ::= id | digit | double | char
<id_print> ::= id | digit | double | char
<inputstat> ::= input ( id );
<callstat> ::= call id
<callcase> ::= . id ( ); | = id . id ( );
<actualpars> ::= ε | id | char | digit | double | (, id)
| (, digit)
| (, double)
| (, char)
<super> ::= super ( <actualpars_constructor> );
<condition> ::= | (|| )

<boolterm> ::= | (&& <boolfactor)
<boolfactor> ::= ε | not | != ( ) |
()
()
| | true | false
<expression> ::= ε | digit digit | double double
| char | <array_expr> <array_expr>
| <array_expr> | id id
| id digit | id double
| double id | digit id
| ( ()
) | ( ()* )
| digit | id
| ()* digit
| ()* <array_expr>
| ()* id | double
<array_expr> ::= id [digit]
<operations> ::= + | - | * | / | ^ | – | ++
<relationaloper> ::= == | < | > | <= | >= | !=

Running the project

  1. make
  2. ./a.out <input_file.txt> <output_file.txt>

Testing

Αρχείο εισόδο: "example1.txt"
Alt Text
Αρχείο εξόδου: "example1out.txt"
Alt Text
Περισσότερα tests στον φάκελο "testing".

Copyright

MIT © 2020 Thomas Siozos

About

License:MIT License


Languages

Language:C 75.9%Language:Yacc 22.7%Language:Lex 1.4%Language:Makefile 0.0%