Commit f6c2d656 authored by qanastek's avatar qanastek

update post backup de l'uapv

parent 58867e23
# CERIcompiler :computer: # CERIcompiler
*Author: Labrak Yanis*
*Degree: Licence 2 Informatique - Groupe 4*
*School: Université d'Avignon*
**Task List :**
- [x] Initialize the project
- [x] LL(1)
- [x] Modify Main
- [x] Create function OperatorComparaison()
- [x] Create function Comparaison()
- [x] Check result of the compilator
- [x] Numbers
- [ ] Mul / Div
- [ ] Program
- [x] DeclarationPart
- [ ] Statements
- [ ] if
- [ ] while
- [ ] do while
- [ ] for
- [ ] AssignementStatement - A = B
- [ ] LL(2)
- [x] Read next char
- [ ] MultiplicativeOperator
- [ ] RelationalOperator
- [ ] AdditiveOperator
**Errors to fix :**
- [ ] Cannot do (a+2)
**Compile, inject the arithmetic expression in the program and check functionement in DDD**
> g++ -ggdb compilateur.cpp -o compilateur && cat test.p | ./compilateur > test.s && gcc -ggdb test.s -o test && ddd ./test
**Program working diagram :** *(So big to be fully modelized)*
```mermaid
graph TD;
input_expression-->ReadChar;
ReadChar-->CheckSign;
CheckSign-->ReadChar;
CheckSign-->Error;
ReadChar-->Stop;
ReadChar-->Comparaison;
Comparaison-->ReadChar;
Comparaison-->ArithmeticExpression;
ArithmeticExpression-->Term;
Term-->IfParemthese;
Term-->IfNotParemthese;
IfParemthese-->ReadChar;
IfParemthese-->ArithmeticExpression;
```
>>>
A simple compiler.
From : `Pascal`-like imperative LL(k) langage
To : 64 bit 80x86 assembly langage (`AT&T`)
>>>
# Usage Informations A simple compiler.
From : Pascal-like imperative LL(k) langage
To : 64 bit 80x86 assembly langage (AT&T)
**Download the repository :** **Download the repository :**
> git clone https://framagit.org/qanastek/cericompiler > git clone git@framagit.org:jourlin/cericompiler.git
**Build the compiler with debug symbols :**
> g++ -ggdb compilateur.cpp -o compilateur **Build the compiler and test it :**
**Compile the test program :** > make test
> cat test.p | ./compilateur > test.s
**Have a look at the output :** **Have a look at the output :**
> gedit test.s > gedit test.s
**Produce the executable (with debug info) :**
> gcc -ggdb test.s -o test :
**Debug the executable :** **Debug the executable :**
> ddd ./test > ddd ./test
...@@ -103,3 +32,24 @@ To : 64 bit 80x86 assembly langage (`AT&T`) ...@@ -103,3 +32,24 @@ To : 64 bit 80x86 assembly langage (`AT&T`)
> git pull -u origin master > git pull -u origin master
**This version Can handle :**
// Program := [DeclarationPart] StatementPart
// DeclarationPart := "[" Identifier {"," Identifier} "]"
// StatementPart := Statement {";" Statement} "."
// Statement := AssignementStatement
// AssignementStatement := Identifier ":=" Expression
// Expression := SimpleExpression [RelationalOperator SimpleExpression]
// SimpleExpression := Term {AdditiveOperator Term}
// Term := Factor {MultiplicativeOperator Factor}
// Factor := Number | Letter | "(" Expression ")"| "!" Factor
// Number := Digit{Digit}
// Identifier := Letter {(Letter|Digit)}
// AdditiveOperator := "+" | "-" | "||"
// MultiplicativeOperator := "*" | "/" | "%" | "&&"
// RelationalOperator := "==" | "!=" | "<" | ">" | "<=" | ">="
// Digit := "0"|"1"|"2"|"3"|"4"|"5"|"6"|"7"|"8"|"9"
// Letter := "a"|...|"z"
No preview for this file type
This diff is collapsed.
all: test
clean:
rm *.o *.s
rm tokeniser.cpp
tokeniser.cpp: tokeniser.l
flex++ -d -otokeniser.cpp tokeniser.l
tokeniser.o: tokeniser.cpp
g++ -c tokeniser.cpp
compilateur: compilateur.cpp tokeniser.o
g++ -ggdb -o compilateur compilateur.cpp tokeniser.o
test.s: compilateur test.p
./compilateur <test.p >test.s
test: test.s
gcc -ggdb -no-pie -fno-pie test.s -o test
No preview for this file type
[a,b] [a,b]
(a+1)=(2+1) FOR
\ No newline at end of file a:=0
TO
10
DO
b:=1+1.
# This code was produced by the CERI Compiler # This code was produced by the CERI Compiler
# Author: Labrak Yanis .data
# School: University of Avignon FormatString1: .string "%llu\n" # used by printf to display 64-bit unsigned integers
.data
.align 8
a: .quad 0 a: .quad 0
b: .quad 0 b: .quad 0
.align 8
.text # The following lines contain the program .text # The following lines contain the program
.global main # The main function must be visible from outside .globl main # The main function must be visible from outside
faux:
push $0 # Return false
jmp fin
vrai:
push $1 # Return true
jmp fin
main: # The main function body : main: # The main function body :
movq %rsp, %rbp # Save the position of the stack's top movq %rsp, %rbp # Save the position of the stack's top
push a # Variable - a ForInit0:
push $1 push $0
pop %rbx pop a
push $10
pop %rax pop %rax
addq %rbx, %rax For0 :
push %rax cmpq %rax, a
push $2 jge SuiteFor0
push $1
push $1 push $1
pop %rbx pop %rbx
pop %rax pop %rax
addq %rbx, %rax addq %rbx, %rax # ADD
push %rax push %rax
pop %rax # Resultat de l'expression 1 pop b
pop %rbx # Resultat de l'expression 2 addq $1,a
cmpq %rbx,%rax jmp For0
je vrai SuiteFor0 :
jne faux
fin:
movq %rbp, %rsp # Restore the position of the stack's top movq %rbp, %rsp # Restore the position of the stack's top
ret # Return from main function ret # Return from main function
\ No newline at end of file
This diff is collapsed.
// tokeniser.h : shared definition for tokeniser.l and compilateur.cpp
enum TOKEN {FEOF, UNKNOWN, KEYWORD, NUMBER, ID, STRINGCONST, RBRACKET, LBRACKET, RPARENT, LPARENT, COMMA,
SEMICOLON, DOT, ADDOP, MULOP, RELOP, NOT, ASSIGN};
%{
// This is our Lexical tokeniser
// It should be compiled into cpp with :
// flex++ -d -otokeniser.cpp tokeniser.l
// And then compiled into object with
// g++ -c tokeniser.cpp
// tokens can be read using lexer->yylex()
// lexer->yylex() returns the type of the lexicon entry (see enum TOKEN in tokeniser.h)
// and lexer->YYText() returns the lexicon entry as a string
#include "tokeniser.h"
#include <iostream>
using namespace std;
%}
%option noyywrap
%option c++
%option yylineno
stringconst \"[^\n"]+\"
ws [ \t\n\r]+
alpha [A-Za-z]
digit [0-9]
number {digit}+
keyword (DISPLAY|IF|THEN|ELSE|BEGIN|END|FOR|TO|DOWNTO|WHILE|DO)
id {alpha}({alpha}|{digit})*
addop (\+|\-|\|\|)
mulop (\*|\/|%|\&\&)
relop (\<|\>|"=="|\<=|\>=|!=)
unknown [^\"A-Za-z0-9 \n\r\t\(\)\<\>\=\!\%\&\|\}\-\;\.]+
%%
{addop} return ADDOP;
{mulop} return MULOP;
{relop} return RELOP;
{number} return NUMBER;
{keyword} return KEYWORD;
{id} return ID;
{stringconst} return STRINGCONST;
"[" return RBRACKET;
"]" return LBRACKET;
"," return COMMA;
";" return SEMICOLON;
"." return DOT;
":=" return ASSIGN;
"(" return RPARENT;
")" return LPARENT;
"!" return NOT;
<<EOF>> return FEOF;
{ws} {/* skip blanks and tabs */};
"(*" { /* Skip comments between '(*' and '*)' */
int c;
while((c = yyinput()) != 0){
if(c == '*'){
if((c = yyinput()) == ')')
break;
else
unput(c);
}
}
};
{unknown} return UNKNOWN;
%%
File added
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment