├── tests ├── abn_completexp ├── abn_tailleexp ├── arbrebinexp ├── fileexp ├── pileexp ├── emptyalgolist.algo ├── intvectexp ├── list.test ├── test-fail.c ├── globvalparam ├── arrayfail.c ├── hashtable.test ├── emptyalgolist.c ├── ptr.test ├── array.test ├── fibo.test ├── parser.test ├── allouer.test ├── product.test ├── struct.test ├── switch.test ├── algolist.test ├── multiply.test ├── const-decl.test ├── constarray.test ├── param.test ├── switchnodef.test ├── typerec.test ├── emptyalgolist.test ├── test-ifthen.test ├── arrayfail.test ├── globvalparam.test ├── parser-testfail.test ├── test-typedecl.test ├── intvect.test ├── globvalparam.algo ├── liberer.test ├── test-ifthen.algo ├── intvect.algo ├── multiply.c ├── test-ifthen.c ├── arbrebin.test ├── file.test ├── test.algo ├── constarray.algo ├── multiply.algo ├── test-fail.algo ├── abn_taille.test ├── array.algo ├── constarray.c ├── abn_complet.test ├── struct.algo ├── fibo.c ├── test.c ├── algolist.c ├── allouer.algo ├── pile.test ├── arrayfail.algo ├── ptr.c ├── test-param.c ├── array.c ├── liberer.algo ├── fibo.algo ├── all.test ├── switchnodef.algo ├── test-typerec.algo ├── const-decl.c ├── switch.algo ├── struct.c ├── switchnodef.c ├── ptr.algo ├── const-decl.algo ├── file.algo ├── test-typerec.c ├── allouer.c ├── pile.algo ├── test-param.algo ├── switch.c ├── algolist.algo ├── all_en.algo ├── all.c ├── all.algo ├── product.c ├── product.algo ├── test-typedecl.algo ├── abn_taille.algo ├── test-typedecl.c ├── arbrebin.algo ├── hashtable.c ├── list.c └── abn_complet.algo ├── bootstrap ├── ft-detect-algo.vim ├── src ├── standard_lib │ ├── t_vecteurEntiers.c │ ├── bin_tree.h │ ├── t_liste.c │ ├── t_arbre_dyn.c │ ├── t_arbre_bin.h │ ├── t_arbre_nuplets.c │ ├── t_graph_stat.c │ ├── t_graph_dyn.c │ ├── lifo.h │ ├── t_pile.h │ ├── t_file.h │ ├── fifo.h │ └── standard_lib.h ├── get_line.h ├── error.h ├── parser.h ├── a2c.h ├── get_line.c ├── type_table.h ├── error.c ├── var_table.h ├── codegen.h ├── funtable.h ├── stdlibalgo.h ├── typecheck.h ├── type_table.c ├── type.c ├── lexer.h ├── type.h ├── data_struct │ ├── hashtable │ │ ├── README │ │ └── hashtable.h │ └── list │ │ └── list.h ├── funtable.c ├── var_table.c ├── a2c.c ├── stdlibalgo.c ├── lexer.c └── parser.y ├── share ├── report1 │ └── cahier-des-charges │ │ ├── Makefile │ │ ├── website.png │ │ ├── logo-epita.png │ │ ├── website2.png │ │ └── website3.png ├── cdc │ ├── img │ │ └── max.jpg │ ├── lucien.png │ ├── logo-epita.png │ ├── Makefile │ ├── cout.tex │ ├── presLucien.tex │ ├── tech.tex │ ├── chrono.tex │ ├── pageGarde.tex │ ├── presMax.tex │ ├── semantique.tex │ └── algo.tex ├── slides1 │ ├── bison.jpg │ ├── screen-grammar.png │ ├── Makefile │ └── slides.tex ├── website │ ├── images │ │ ├── cdc.pdf │ │ ├── logo.png │ │ ├── preview.pdf │ │ ├── reports1.pdf │ │ └── OneClick.svg │ ├── src │ │ ├── guidelines.pdf │ │ ├── rapport1.pdf │ │ ├── rapport2.pdf │ │ ├── community │ │ │ ├── members │ │ │ │ └── members.html │ │ │ └── index.html │ │ ├── news │ │ │ ├── 2015 │ │ │ │ └── 20150215.html │ │ │ └── index.html │ │ ├── download.html │ │ └── docs │ │ │ └── index.html │ ├── css │ │ └── main.css │ └── index.html └── outline1 │ ├── Makefile │ └── outline.tex ├── configure.ac ├── .gitignore ├── TODO ├── algo.vim ├── Makefile.am ├── README.md └── grammar.txt /tests/abn_completexp: -------------------------------------------------------------------------------- 1 | 0 2 | -------------------------------------------------------------------------------- /tests/abn_tailleexp: -------------------------------------------------------------------------------- 1 | 4 2 | -------------------------------------------------------------------------------- /tests/arbrebinexp: -------------------------------------------------------------------------------- 1 | 0 2 | 1 3 | 2 4 | 3 5 | -------------------------------------------------------------------------------- /tests/fileexp: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3 4 | 4 5 | 1 6 | -------------------------------------------------------------------------------- /bootstrap: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | autoreconf -vfi 4 | -------------------------------------------------------------------------------- /tests/pileexp: -------------------------------------------------------------------------------- 1 | 3 2 | 3 3 | 4 4 | 2 5 | 1 6 | 1 7 | -------------------------------------------------------------------------------- /ft-detect-algo.vim: -------------------------------------------------------------------------------- 1 | au BufRead,BufNewFile *.algo set filetype=algo 2 | -------------------------------------------------------------------------------- /src/standard_lib/t_vecteurEntiers.c: -------------------------------------------------------------------------------- 1 | typedef int[100] t_vecteurEntiers; 2 | -------------------------------------------------------------------------------- /share/report1/cahier-des-charges/Makefile: -------------------------------------------------------------------------------- 1 | all: main.tex 2 | latexmk --pdf main.tex 3 | -------------------------------------------------------------------------------- /tests/emptyalgolist.algo: -------------------------------------------------------------------------------- 1 | variables 2 | debut 3 | ecrire("hello world") 4 | fin 5 | -------------------------------------------------------------------------------- /tests/intvectexp: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3 4 | 4 5 | 5 6 | 6 7 | 7 8 | 8 9 | 9 10 | 10 11 | -------------------------------------------------------------------------------- /share/cdc/img/max.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thibaudmichaud/a2c/HEAD/share/cdc/img/max.jpg -------------------------------------------------------------------------------- /share/cdc/lucien.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thibaudmichaud/a2c/HEAD/share/cdc/lucien.png -------------------------------------------------------------------------------- /share/cdc/logo-epita.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thibaudmichaud/a2c/HEAD/share/cdc/logo-epita.png -------------------------------------------------------------------------------- /share/slides1/bison.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thibaudmichaud/a2c/HEAD/share/slides1/bison.jpg -------------------------------------------------------------------------------- /tests/list.test: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | valgrind --leak-check=full --show-leak-kinds=all ./tests/list 4 | -------------------------------------------------------------------------------- /share/website/images/cdc.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thibaudmichaud/a2c/HEAD/share/website/images/cdc.pdf -------------------------------------------------------------------------------- /share/website/images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thibaudmichaud/a2c/HEAD/share/website/images/logo.png -------------------------------------------------------------------------------- /share/slides1/screen-grammar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thibaudmichaud/a2c/HEAD/share/slides1/screen-grammar.png -------------------------------------------------------------------------------- /share/website/images/preview.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thibaudmichaud/a2c/HEAD/share/website/images/preview.pdf -------------------------------------------------------------------------------- /share/website/src/guidelines.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thibaudmichaud/a2c/HEAD/share/website/src/guidelines.pdf -------------------------------------------------------------------------------- /share/website/src/rapport1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thibaudmichaud/a2c/HEAD/share/website/src/rapport1.pdf -------------------------------------------------------------------------------- /share/website/src/rapport2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thibaudmichaud/a2c/HEAD/share/website/src/rapport2.pdf -------------------------------------------------------------------------------- /share/website/images/reports1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thibaudmichaud/a2c/HEAD/share/website/images/reports1.pdf -------------------------------------------------------------------------------- /src/get_line.h: -------------------------------------------------------------------------------- 1 | #ifndef TOOL_BOX_H_ 2 | #define TOOL_BOX_H_ 3 | 4 | char* get_line(FILE *f, int line); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /tests/test-fail.c: -------------------------------------------------------------------------------- 1 | tests/test-fail.algo:7:8: error: incompatible types: reel and chaine 2 | c <- 4.5 + "a" 3 | ^^^^^^^^^ 4 | -------------------------------------------------------------------------------- /share/cdc/Makefile: -------------------------------------------------------------------------------- 1 | cdc.pdf: cdc.tex 2 | latexmk --pdf $< 3 | 4 | clean: 5 | rm *.aux *.fdb* *.fls *.log *~ *.pdf *.toc 6 | 7 | -------------------------------------------------------------------------------- /tests/globvalparam: -------------------------------------------------------------------------------- 1 | tests/globvalparam.algo:15:11: error: cannot pass a value as a global parameter 2 | test(1, 2) 3 | ^ 4 | -------------------------------------------------------------------------------- /share/report1/cahier-des-charges/website.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thibaudmichaud/a2c/HEAD/share/report1/cahier-des-charges/website.png -------------------------------------------------------------------------------- /share/report1/cahier-des-charges/logo-epita.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thibaudmichaud/a2c/HEAD/share/report1/cahier-des-charges/logo-epita.png -------------------------------------------------------------------------------- /share/report1/cahier-des-charges/website2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thibaudmichaud/a2c/HEAD/share/report1/cahier-des-charges/website2.png -------------------------------------------------------------------------------- /share/report1/cahier-des-charges/website3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thibaudmichaud/a2c/HEAD/share/report1/cahier-des-charges/website3.png -------------------------------------------------------------------------------- /tests/arrayfail.c: -------------------------------------------------------------------------------- 1 | tests/arrayfail.algo:3:16: error: identifier "a" is not an integer 2 | t_tab_bool = a * b * 5 booleen 3 | ^ 4 | -------------------------------------------------------------------------------- /src/error.h: -------------------------------------------------------------------------------- 1 | #ifndef ERROR_H_ 2 | #define ERROR_H_ 3 | 4 | #include "lexer.h" 5 | 6 | void error(struct pos pos, char *msg, ...); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /src/standard_lib/bin_tree.h: -------------------------------------------------------------------------------- 1 | typedef struct t_noeud_bin 2 | { 3 | int cle; 4 | struct t_noeud_bin *fg; 5 | struct t_noeud_bin *fd; 6 | } t_noeud_bin; 7 | -------------------------------------------------------------------------------- /tests/hashtable.test: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | valgrind --error-exitcode=1 --leak-check=full --show-leak-kinds=all ./tests/hashtable 5 | 6 | set +e 7 | -------------------------------------------------------------------------------- /src/standard_lib/t_liste.c: -------------------------------------------------------------------------------- 1 | typedef int[50] t_vectLmaxElts; 2 | 3 | typedef struct t_liste 4 | { 5 | t_vectLmaxElts elts; 6 | int longueur; 7 | } t_liste; 8 | -------------------------------------------------------------------------------- /tests/emptyalgolist.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int main(void) 5 | { 6 | printf("%s\n", "hello world"); 7 | } 8 | -------------------------------------------------------------------------------- /src/parser.h: -------------------------------------------------------------------------------- 1 | #ifndef PARSER_H_ 2 | #define PARSER_H_ 3 | 4 | #include 5 | 6 | struct expr *parse_expression(void); 7 | struct prog *parse(void); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /src/standard_lib/t_arbre_dyn.c: -------------------------------------------------------------------------------- 1 | typedef *t_noeud_ag t_arbre_dyn; 2 | 3 | typedef struct t_noeud_ag 4 | { 5 | int cle; 6 | t_arbre_dyn fils; 7 | t_arbre_dyn frere; 8 | } t_noeud_ag; 9 | -------------------------------------------------------------------------------- /tests/ptr.test: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | valgrind --error-exitcode=1 --leak-check=full --show-leak-kinds=all ./a2c tests/ptr.algo > tests/out 5 | diff tests/ptr.c tests/out 6 | set +e 7 | -------------------------------------------------------------------------------- /tests/array.test: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | valgrind --error-exitcode=1 --leak-check=full --show-leak-kinds=all ./a2c tests/array.algo > tests/out 5 | diff tests/array.c tests/out 6 | set +e 7 | -------------------------------------------------------------------------------- /tests/fibo.test: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | valgrind --error-exitcode=1 --leak-check=full --show-leak-kinds=all ./a2c tests/fibo.algo > tests/out 5 | diff tests/fibo.c tests/out 6 | set +e 7 | -------------------------------------------------------------------------------- /tests/parser.test: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | valgrind --error-exitcode=1 --leak-check=full --show-leak-kinds=all ./a2c tests/test.algo > tests/out 5 | diff tests/test.c tests/out 6 | set +e 7 | -------------------------------------------------------------------------------- /share/slides1/Makefile: -------------------------------------------------------------------------------- 1 | all: slides.pdf 2 | 3 | slides.pdf: slides.tex 4 | latexmk --pdf -interaction=nonstopmode slides.tex 5 | 6 | clean: 7 | rm -f *.{toc,snm,out,nav,aux,fls,log,fdb_latexmk} 8 | -------------------------------------------------------------------------------- /tests/allouer.test: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | valgrind --error-exitcode=1 --leak-check=full --show-leak-kinds=all ./a2c tests/allouer.algo > tests/out 5 | diff tests/allouer.c tests/out 6 | set +e 7 | -------------------------------------------------------------------------------- /tests/product.test: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | valgrind --error-exitcode=1 --leak-check=full --show-leak-kinds=all ./a2c tests/product.algo > tests/out 5 | diff tests/product.c tests/out 6 | set +e 7 | -------------------------------------------------------------------------------- /tests/struct.test: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | valgrind --error-exitcode=1 --leak-check=full --show-leak-kinds=all ./a2c tests/struct.algo > tests/out 5 | diff tests/struct.c tests/out 6 | set +e 7 | -------------------------------------------------------------------------------- /tests/switch.test: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | valgrind --error-exitcode=1 --leak-check=full --show-leak-kinds=all ./a2c tests/switch.algo > tests/out 5 | diff tests/switch.c tests/out 6 | set +e 7 | -------------------------------------------------------------------------------- /share/outline1/Makefile: -------------------------------------------------------------------------------- 1 | all: outline.pdf 2 | 3 | outline.pdf: outline.tex 4 | latexmk --pdf -interaction=nonstopmode outline.tex 5 | 6 | clean: 7 | rm -f *.{toc,snm,out,nav,aux,fls,log,fdb_latexmk} 8 | -------------------------------------------------------------------------------- /src/standard_lib/t_arbre_bin.h: -------------------------------------------------------------------------------- 1 | typedef *t_noeud_bin t_arbre_bin; 2 | 3 | typedef struct t_noeud_bin 4 | { 5 | int cle; 6 | struct t_noeud_bin *fg; 7 | struct t_noeud_bin *fd; 8 | } t_noeud_bin; 9 | -------------------------------------------------------------------------------- /src/standard_lib/t_arbre_nuplets.c: -------------------------------------------------------------------------------- 1 | typedef *t_noeud_nuplet t_arbre_nuplets; 2 | 3 | typedef struct t_noeud_nuplet 4 | { 5 | int cle; 6 | t_noeud_nuplet fils; 7 | int nbFils; 8 | } t_noeud_nuplet; 9 | -------------------------------------------------------------------------------- /tests/algolist.test: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | valgrind --error-exitcode=1 --leak-check=full --show-leak-kinds=all ./a2c tests/algolist.algo > tests/out 5 | diff tests/algolist.c tests/out 6 | set +e 7 | -------------------------------------------------------------------------------- /tests/multiply.test: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | valgrind --error-exitcode=1 --leak-check=full --show-leak-kinds=all ./a2c tests/multiply.algo > tests/out 5 | diff tests/multiply.c tests/out 6 | set +e 7 | -------------------------------------------------------------------------------- /tests/const-decl.test: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | valgrind --error-exitcode=1 --leak-check=full --show-leak-kinds=all ./a2c tests/const-decl.algo > tests/out 5 | diff tests/const-decl.c tests/out 6 | set +e 7 | -------------------------------------------------------------------------------- /tests/constarray.test: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | valgrind --error-exitcode=1 --leak-check=full --show-leak-kinds=all ./a2c tests/constarray.algo > tests/out 5 | diff tests/constarray.c tests/out 6 | set +e 7 | -------------------------------------------------------------------------------- /tests/param.test: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | valgrind --error-exitcode=1 --leak-check=full --show-leak-kinds=all \ 5 | ./a2c tests/test-param.algo > tests/out 6 | diff tests/test-param.c tests/out 7 | set +e 8 | -------------------------------------------------------------------------------- /tests/switchnodef.test: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | valgrind --error-exitcode=1 --leak-check=full --show-leak-kinds=all ./a2c tests/switchnodef.algo > tests/out 5 | diff tests/switchnodef.c tests/out 6 | set +e -------------------------------------------------------------------------------- /tests/typerec.test: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | valgrind --error-exitcode=1 --leak-check=full --show-leak-kinds=all ./a2c tests/test-typerec.algo > tests/out 5 | diff tests/test-typerec.c tests/out 6 | set +e 7 | -------------------------------------------------------------------------------- /tests/emptyalgolist.test: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | valgrind --error-exitcode=1 --leak-check=full --show-leak-kinds=all ./a2c tests/emptyalgolist.algo > tests/out 5 | diff tests/emptyalgolist.c tests/out 6 | set +e 7 | -------------------------------------------------------------------------------- /tests/test-ifthen.test: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | valgrind --error-exitcode=1 --leak-check=full --show-leak-kinds=all ./a2c \ 5 | tests/test-ifthen.algo > tests/out 6 | diff tests/test-ifthen.c tests/out 7 | set +e 8 | -------------------------------------------------------------------------------- /tests/arrayfail.test: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | valgrind -q --error-exitcode=1 --leak-check=full --show-leak-kinds=all ./a2c tests/arrayfail.algo 2> tests/out || true 5 | diff tests/arrayfail.c tests/out 6 | set +e 7 | 8 | -------------------------------------------------------------------------------- /tests/globvalparam.test: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | valgrind -q --error-exitcode=1 --leak-check=full --show-leak-kinds=all ./a2c tests/globvalparam.algo 2> tests/out || true 5 | diff tests/globvalparam tests/out 6 | set +e 7 | -------------------------------------------------------------------------------- /tests/parser-testfail.test: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | valgrind -q --error-exitcode=1 --leak-check=full --show-leak-kinds=all ./a2c tests/test-fail.algo 2> tests/out || true 5 | diff tests/test-fail.c tests/out 6 | set +e 7 | -------------------------------------------------------------------------------- /tests/test-typedecl.test: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | valgrind --error-exitcode=1 --leak-check=full --show-leak-kinds=all \ 5 | ./a2c tests/test-typedecl.algo > tests/out 6 | diff tests/test-typedecl.c tests/out 7 | set +e 8 | -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | AC_INIT([a2c], [1.00], [thibaud.michaud@epita.fr]) 2 | AC_CONFIG_AUX_DIR([build-aux]) 3 | AM_INIT_AUTOMAKE([foreign subdir-objects]) 4 | AC_PROG_CC 5 | AC_CONFIG_HEADER([config.h]) 6 | AC_CONFIG_FILES([Makefile]) 7 | AC_OUTPUT 8 | -------------------------------------------------------------------------------- /tests/intvect.test: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | valgrind --error-exitcode=1 --leak-check=full --show-leak-kinds=all \ 5 | ./a2c tests/intvect.algo > tests/intvect.c 6 | gcc -std=c99 tests/intvect.c -o tests/intvect 7 | ./tests/intvect | diff tests/intvectexp - 8 | set +e 9 | -------------------------------------------------------------------------------- /tests/globvalparam.algo: -------------------------------------------------------------------------------- 1 | algorithme procedure test 2 | parametres locaux 3 | entier a 4 | parametres globaux 5 | entier b 6 | variables 7 | entier c, d 8 | debut 9 | a <- b + c 10 | d <- b - c 11 | ecrire(d) 12 | fin algorithme procedure test 13 | 14 | debut 15 | test(1, 2) 16 | fin 17 | -------------------------------------------------------------------------------- /src/standard_lib/t_graph_stat.c: -------------------------------------------------------------------------------- 1 | const int Max_sommets = 100; 2 | 3 | int t_mat_adj[Max_sommets][Max_sommets]; 4 | float t_mat_cout[Max_sommets][Max_sommets]; 5 | 6 | typedef struct t_graph_stat 7 | { 8 | booleen orient; 9 | int ordre; 10 | t_mat_adj adj; 11 | t_mat_cout cout; 12 | } t_graph_stat; 13 | -------------------------------------------------------------------------------- /tests/liberer.test: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | valgrind --error-exitcode=1 --leak-check=full --show-leak-kinds=all ./a2c tests/liberer.algo > tests/liberer.c 5 | gcc -std=c99 tests/liberer.c -o tests/liberer.out 6 | valgrind --error-exitcode=1 --leak-check=full --show-leak-kinds=all ./tests/liberer.out 7 | set +e 8 | -------------------------------------------------------------------------------- /tests/test-ifthen.algo: -------------------------------------------------------------------------------- 1 | algorithme procedure test 2 | variables 3 | entier a, b 4 | reel c 5 | debut 6 | a <- 0 7 | c <- 4.5 8 | si (a = b) alors 9 | b <- a + b 10 | fin si 11 | fin algorithme procedure test 12 | 13 | variables 14 | booleen variable_globale 15 | debut 16 | test() 17 | fin 18 | -------------------------------------------------------------------------------- /tests/intvect.algo: -------------------------------------------------------------------------------- 1 | algorithme procedure foo 2 | variables 3 | entier i 4 | t_vect_entiers v 5 | debut 6 | pour i <- 1 jusqu'a 10 faire 7 | v[i] <- i 8 | fin pour 9 | pour i <- 1 jusqu'a 10 faire 10 | ecrire(v[i]) 11 | fin pour 12 | fin algorithme procedure foo 13 | 14 | debut 15 | foo() 16 | fin 17 | -------------------------------------------------------------------------------- /tests/multiply.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int multiply(int a, int b) 5 | { 6 | int p, i; 7 | p = 0; 8 | for (i = 1; i <= b; ++(i)) 9 | { 10 | p = (p + a); 11 | } 12 | return p; 13 | } 14 | int main(void) 15 | { 16 | printf("%d\n", multiply(3, 4)); 17 | } 18 | -------------------------------------------------------------------------------- /tests/test-ifthen.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int variable_globale; 5 | void test(void) 6 | { 7 | int a, b; 8 | double c; 9 | a = 0; 10 | c = 4.5; 11 | if ((a == b)) 12 | { 13 | b = (a + b); 14 | } 15 | } 16 | int main(void) 17 | { 18 | test(); 19 | } 20 | -------------------------------------------------------------------------------- /tests/arbrebin.test: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | valgrind --error-exitcode=1 --leak-check=full --show-leak-kinds=all \ 5 | ./a2c tests/arbrebin.algo > tests/arbrebin.c 6 | gcc -g -std=c99 tests/arbrebin.c -o tests/arbrebin 7 | ./tests/arbrebin > ./tests/arbrebin.out 8 | diff tests/arbrebinexp ./tests/arbrebin.out 9 | 10 | set +e 11 | -------------------------------------------------------------------------------- /tests/file.test: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | valgrind --error-exitcode=1 --leak-check=full --show-leak-kinds=all \ 5 | ./a2c tests/file.algo > tests/file.c 6 | gcc -g -std=c99 tests/file.c -o tests/file 7 | valgrind --error-exitcode=1 --leak-check=full --show-leak-kinds=all \ 8 | ./tests/file | diff tests/fileexp - 9 | 10 | set +e 11 | -------------------------------------------------------------------------------- /tests/test.algo: -------------------------------------------------------------------------------- 1 | algorithme procedure test 2 | variables 3 | entier a, b 4 | reel c 5 | debut 6 | a <- 0 7 | c <- 4.5 8 | si (a = b) alors 9 | b <- a + b 10 | sinon 11 | a <- a - b 12 | fin si 13 | fin algorithme procedure test 14 | 15 | variables 16 | booleen variable_globale 17 | debut 18 | test() 19 | fin 20 | -------------------------------------------------------------------------------- /tests/constarray.algo: -------------------------------------------------------------------------------- 1 | algorithme procedure blabla 2 | types 3 | t_tab_int = max * min entier 4 | variables 5 | entier i, j 6 | t_tab_int mat 7 | debut 8 | i <- 1 9 | j <- 2 10 | mat[i, j] <- 4 11 | fin algorithme procedure blabla 12 | 13 | constantes 14 | entier max = 5 15 | entier min = 3 16 | debut 17 | blabla() 18 | fin 19 | -------------------------------------------------------------------------------- /tests/multiply.algo: -------------------------------------------------------------------------------- 1 | algorithme fonction multiply : entier 2 | parametres locaux 3 | entier a, b 4 | variables 5 | entier p, i 6 | debut 7 | p <- 0 8 | pour i <- 1 jusqu'a b faire 9 | p <- p + a 10 | fin pour 11 | retourne p 12 | fin algorithme fonction multiply 13 | 14 | debut 15 | ecrire(multiply(3, 4)) 16 | fin 17 | -------------------------------------------------------------------------------- /tests/test-fail.algo: -------------------------------------------------------------------------------- 1 | algorithme procedure test 2 | variables 3 | entier a, b 4 | reel c 5 | debut 6 | a <- 0 7 | c <- 4.5 + "a" 8 | si (a = b) alors 9 | b <- a + b 10 | sinon 11 | a <- a - b 12 | fin si 13 | fin algorithme procedure test 14 | 15 | variables 16 | booleen variable_globale 17 | debut 18 | test() 19 | fin 20 | -------------------------------------------------------------------------------- /tests/abn_taille.test: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | valgrind --error-exitcode=1 --leak-check=full --show-leak-kinds=all \ 5 | ./a2c tests/abn_taille.algo > tests/abn_taille.c 6 | gcc -g -std=c99 tests/abn_taille.c -o tests/abn_taille 7 | ./tests/abn_taille > ./tests/abn_taille.out 8 | diff tests/abn_tailleexp ./tests/abn_taille.out 9 | 10 | set +e 11 | -------------------------------------------------------------------------------- /tests/array.algo: -------------------------------------------------------------------------------- 1 | algorithme procedure test 2 | types 3 | t_tab_bool = 5 * 6 entier 4 | variables 5 | entier i, j 6 | t_tab_bool tab 7 | debut 8 | pour i <- 1 jusqu'a 5 faire 9 | pour j <- 1 jusqu'a 6 faire 10 | tab[i,j] <- i * j 11 | fin pour 12 | fin pour 13 | fin algorithme procedure test 14 | 15 | debut 16 | test() 17 | fin 18 | -------------------------------------------------------------------------------- /tests/constarray.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | const int max = 5; 5 | const int min = 3; 6 | typedef int t_tab_int[max][min]; 7 | void blabla(void) 8 | { 9 | int i, j; 10 | t_tab_int mat; 11 | i = 1; 12 | j = 2; 13 | mat[i - 1][j - 1] = 4; 14 | } 15 | int main(void) 16 | { 17 | blabla(); 18 | } 19 | -------------------------------------------------------------------------------- /tests/abn_complet.test: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | valgrind --error-exitcode=1 --leak-check=full --show-leak-kinds=all \ 5 | ./a2c tests/abn_complet.algo > tests/abn_complet.c 6 | gcc -g -std=c99 tests/abn_complet.c -o tests/abn_complet 7 | ./tests/abn_complet > ./tests/abn_complet.out 8 | diff tests/abn_completexp ./tests/abn_complet.out 9 | 10 | set +e 11 | -------------------------------------------------------------------------------- /tests/struct.algo: -------------------------------------------------------------------------------- 1 | algorithme procedure test 2 | types 3 | t_enregistrement = enregistrement 4 | entier i, j, k 5 | booleen b 6 | caractere c 7 | fin enregistrement t_enregistrement 8 | t_ptr = ^t_enregistrement 9 | variables 10 | t_ptr p 11 | debut 12 | p^.i <- 1 13 | fin algorithme procedure test 14 | 15 | debut 16 | test() 17 | fin 18 | -------------------------------------------------------------------------------- /tests/fibo.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int variable_globale; 5 | int fibo(int n) 6 | { 7 | int i, a, b; 8 | a = 0; 9 | b = 1; 10 | for (i = 1; i <= n; ++(i)) 11 | { 12 | b = (a + b); 13 | a = (b - a); 14 | } 15 | return a; 16 | } 17 | int main(void) 18 | { 19 | printf("%d\n", fibo(10)); 20 | } 21 | -------------------------------------------------------------------------------- /tests/test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int variable_globale; 5 | void test(void) 6 | { 7 | int a, b; 8 | double c; 9 | a = 0; 10 | c = 4.5; 11 | if ((a == b)) 12 | { 13 | b = (a + b); 14 | } 15 | else 16 | { 17 | a = (a - b); 18 | } 19 | } 20 | int main(void) 21 | { 22 | test(); 23 | } 24 | -------------------------------------------------------------------------------- /tests/algolist.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int variable_globale; 5 | int truc(int b, int n, int m) 6 | { 7 | char c; 8 | n = (20 + 22); 9 | return n; 10 | } 11 | int machin(int n) 12 | { 13 | int i, a, b; 14 | return truc(0, 42, 4); 15 | } 16 | int main(void) 17 | { 18 | printf("%d\n", truc(1, 1, 2)); 19 | } 20 | -------------------------------------------------------------------------------- /tests/allouer.algo: -------------------------------------------------------------------------------- 1 | algorithme procedure test 2 | types 3 | t_enregistrement = enregistrement 4 | entier a 5 | booleen b 6 | fin enregistrement t_enregistrement 7 | t_ptr = ^t_enregistrement 8 | variables 9 | t_ptr p 10 | debut 11 | allouer(p) 12 | p^.a <- 1 13 | p^.b <- vrai 14 | fin algorithme procedure test 15 | 16 | debut 17 | test() 18 | fin 19 | -------------------------------------------------------------------------------- /tests/pile.test: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | valgrind --error-exitcode=1 --leak-check=full --show-leak-kinds=all \ 5 | ./a2c tests/pile.algo > tests/pile.c 6 | gcc -g -std=c99 tests/pile.c -o tests/pile 7 | valgrind --error-exitcode=1 --leak-check=full --show-leak-kinds=all \ 8 | ./tests/pile > tests/pile.out 9 | diff tests/pileexp tests/pile.out 10 | 11 | set +e 12 | -------------------------------------------------------------------------------- /tests/arrayfail.algo: -------------------------------------------------------------------------------- 1 | algorithme procedure fail 2 | types 3 | t_tab_bool = a * b * 5 booleen 4 | variables 5 | entier i, j, k 6 | t_tab_bool tab 7 | debut 8 | i <- 1 9 | j <- 2 10 | k <- 3 11 | tab[i, j, k] <- faux 12 | fin algorithme procedure fail 13 | 14 | constantes 15 | caractere a = 'a' 16 | entier b = 4 17 | debut 18 | fail() 19 | fin 20 | 21 | 22 | -------------------------------------------------------------------------------- /tests/ptr.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | typedef int *t_ptr; 5 | typedef t_ptr *t_ptr_ptr; 6 | int variable_globale; 7 | int n; 8 | t_ptr_ptr p; 9 | void test(t_ptr_ptr p) 10 | { 11 | p = NULL; 12 | **p = 1; 13 | } 14 | t_ptr_ptr foo(void) 15 | { 16 | return NULL; 17 | } 18 | int main(void) 19 | { 20 | test(p); 21 | } 22 | -------------------------------------------------------------------------------- /tests/test-param.c: -------------------------------------------------------------------------------- 1 | booleen variable_globale; 2 | entier n; 3 | void test(booleen b, entier *gp, entier *bla, caractere *z) 4 | { 5 | entier a, b; 6 | reel c; 7 | a = 0; 8 | c = 4.5; 9 | if ((a == b)) 10 | { 11 | b = (a + b); 12 | } 13 | else 14 | { 15 | a = (a - b); 16 | } 17 | } 18 | int main(void) 19 | { 20 | test(variable_globale, n); 21 | } 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Object files 2 | *.o 3 | *.ko 4 | *.obj 5 | *.elf 6 | 7 | # Precompiled Headers 8 | *.gch 9 | *.pch 10 | 11 | # Libraries 12 | *.lib 13 | *.a 14 | *.la 15 | *.lo 16 | 17 | # Shared objects (inc. Windows DLLs) 18 | *.dll 19 | *.so 20 | *.so.* 21 | *.dylib 22 | 23 | # Executables 24 | *.exe 25 | *.out 26 | *.app 27 | *.i*86 28 | *.x86_64 29 | *.hex 30 | 31 | _build 32 | -------------------------------------------------------------------------------- /tests/array.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | typedef int t_tab_bool[5][6]; 5 | void test(void) 6 | { 7 | int i, j; 8 | t_tab_bool tab; 9 | for (i = 1; i <= 5; ++(i)) 10 | { 11 | for (j = 1; j <= 6; ++(j)) 12 | { 13 | tab[i - 1][j - 1] = (i * j); 14 | } 15 | } 16 | } 17 | int main(void) 18 | { 19 | test(); 20 | } 21 | -------------------------------------------------------------------------------- /src/a2c.h: -------------------------------------------------------------------------------- 1 | #ifndef A2C_H_ 2 | #define A2C_H_ 3 | 4 | #include 5 | 6 | struct prog *prog; 7 | extern FILE *fin; 8 | extern char *srcfilename; 9 | 10 | enum e_lang 11 | { 12 | LANG_FR = 0, 13 | LANG_EN = 1 14 | }; 15 | 16 | int current_lang; 17 | 18 | // This is needed to free the global variables allocated by the lexer. 19 | int yylex_destroy(void); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /tests/liberer.algo: -------------------------------------------------------------------------------- 1 | algorithme procedure test 2 | types 3 | t_enregistrement = enregistrement 4 | entier a 5 | booleen b 6 | fin enregistrement t_enregistrement 7 | t_ptr = ^t_enregistrement 8 | variables 9 | t_ptr p 10 | debut 11 | allouer(p) 12 | p^.a <- 1 13 | p^.b <- vrai 14 | liberer(p) 15 | fin algorithme procedure test 16 | 17 | debut 18 | test() 19 | fin 20 | -------------------------------------------------------------------------------- /tests/fibo.algo: -------------------------------------------------------------------------------- 1 | algorithme fonction fibo : entier 2 | parametres locaux 3 | entier n 4 | variables 5 | entier i, a, b 6 | debut 7 | a <- 0 8 | b <- 1 9 | pour i <- 1 jusqu'a n faire 10 | b <- a + b 11 | a <- b - a 12 | fin pour 13 | retourne a 14 | fin algorithme fonction fibo 15 | 16 | variables 17 | booleen variable_globale 18 | debut 19 | ecrire(fibo(10)) 20 | fin 21 | -------------------------------------------------------------------------------- /tests/all.test: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | echo "French test:" 5 | valgrind --error-exitcode=1 --leak-check=full --show-leak-kinds=all ./a2c tests/all.algo > tests/out 6 | diff tests/all.c tests/out 7 | echo "English test:" 8 | valgrind --error-exitcode=1 --leak-check=full --show-leak-kinds=all ./a2c --en tests/all_en.algo > tests/out_en 9 | diff tests/all.c tests/out_en 10 | echo "Done !" 11 | set +e 12 | -------------------------------------------------------------------------------- /tests/switchnodef.algo: -------------------------------------------------------------------------------- 1 | algorithme fonction testswitch : entier 2 | parametres locaux 3 | entier n 4 | variables 5 | entier a, b 6 | debut 7 | a <- 0 8 | b <- 0 9 | selon n faire 10 | 1, 2 : b <- 1 11 | 3 : b <- 2 12 | fin selon 13 | retourne b 14 | fin algorithme fonction testswitch 15 | 16 | variables 17 | booleen variable_globale 18 | debut 19 | ecrire(testswitch(2)) 20 | fin 21 | -------------------------------------------------------------------------------- /tests/test-typerec.algo: -------------------------------------------------------------------------------- 1 | algorithme procedure test 2 | types 3 | t_liste = ^t_liste_struct 4 | t_liste_struct = enregistrement 5 | entier a 6 | t_liste next 7 | fin enregistrement t_liste_struct 8 | variables 9 | t_liste l 10 | debut 11 | l <- l^.next 12 | fin algorithme procedure test 13 | 14 | variables 15 | booleen variable_globale 16 | entier n 17 | debut 18 | test() 19 | fin 20 | -------------------------------------------------------------------------------- /src/get_line.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "get_line.h" 4 | 5 | char* get_line(FILE *f, int line) 6 | { 7 | char *l = NULL; 8 | long pos = ftell(f); 9 | size_t len = 0; 10 | 11 | if (f) 12 | { 13 | rewind(f); 14 | for (int i = 0; i < line && (getline(&l, &len, f) != -1); i++) 15 | ; 16 | } 17 | 18 | fseek(f, pos, SEEK_SET); 19 | return l; 20 | } 21 | 22 | -------------------------------------------------------------------------------- /tests/const-decl.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int variable_globale; 5 | int fibo(int n) 6 | { 7 | const int c = 0; 8 | const double d = 4.2; 9 | int i, a, b; 10 | a = 0; 11 | b = 1; 12 | for (i = 1; i <= n; ++(i)) 13 | { 14 | b = (a + b); 15 | a = (b - a); 16 | } 17 | return a; 18 | } 19 | int main(void) 20 | { 21 | printf("%d\n", fibo(10)); 22 | } 23 | -------------------------------------------------------------------------------- /tests/switch.algo: -------------------------------------------------------------------------------- 1 | algorithme fonction testswitch : entier 2 | parametres locaux 3 | entier n 4 | variables 5 | entier a, b 6 | debut 7 | a <- 0 8 | b <- 0 9 | selon n faire 10 | 1, 2 : b <- 1 11 | 3 : b <- 2 12 | autrement b <- 0 13 | fin selon 14 | retourne b 15 | fin algorithme fonction testswitch 16 | 17 | variables 18 | booleen variable_globale 19 | debut 20 | ecrire(testswitch(2)) 21 | fin 22 | -------------------------------------------------------------------------------- /tests/struct.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | struct t_enregistrement; 5 | typedef struct t_enregistrement t_enregistrement; 6 | typedef struct t_enregistrement 7 | { 8 | int i, j, k; 9 | int b; 10 | char c; 11 | } t_enregistrement; 12 | typedef t_enregistrement *t_ptr; 13 | void test(void) 14 | { 15 | t_ptr p; 16 | (*p).i = 1; 17 | } 18 | int main(void) 19 | { 20 | test(); 21 | } 22 | -------------------------------------------------------------------------------- /tests/switchnodef.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int variable_globale; 5 | int testswitch(int n) 6 | { 7 | int a, b; 8 | a = 0; 9 | b = 0; 10 | switch (n) 11 | { 12 | case 1: 13 | case 2: 14 | b = 1; 15 | break; 16 | case 3: 17 | b = 2; 18 | break; 19 | } 20 | return b; 21 | } 22 | int main(void) 23 | { 24 | printf("%d\n", testswitch(2)); 25 | } 26 | -------------------------------------------------------------------------------- /tests/ptr.algo: -------------------------------------------------------------------------------- 1 | algorithme procedure test 2 | parametres locaux 3 | t_ptr_ptr p 4 | debut 5 | p <- NUL 6 | p^^ <- 1 7 | fin algorithme procedure test 8 | 9 | algorithme fonction foo : t_ptr_ptr 10 | debut 11 | retourne NUL 12 | fin algorithme fonction t_ptr_ptr 13 | 14 | variables 15 | booleen variable_globale 16 | entier n 17 | t_ptr_ptr p 18 | types 19 | t_ptr = ^entier 20 | t_ptr_ptr = ^t_ptr 21 | debut 22 | test(p) 23 | fin 24 | -------------------------------------------------------------------------------- /tests/const-decl.algo: -------------------------------------------------------------------------------- 1 | algorithme fonction fibo : entier 2 | parametres locaux 3 | entier n 4 | variables 5 | entier i, a, b 6 | constantes 7 | entier c = 0 8 | reel d = 4.2 9 | debut 10 | a <- 0 11 | b <- 1 12 | pour i <- 1 jusqu'a n faire 13 | b <- a + b 14 | a <- b - a 15 | fin pour 16 | retourne a 17 | fin algorithme fonction fibo 18 | 19 | variables 20 | booleen variable_globale 21 | debut 22 | ecrire(fibo(10)) 23 | fin 24 | -------------------------------------------------------------------------------- /tests/file.algo: -------------------------------------------------------------------------------- 1 | algorithme procedure foo2 2 | variables 3 | entier i 4 | t_file f 5 | debut 6 | f <- file_vide() 7 | enfiler(f, 1) 8 | enfiler(f, 2) 9 | enfiler(f, 3) 10 | ecrire(defiler(f)) 11 | enfiler(f, 4) 12 | ecrire(defiler(f)) 13 | ecrire(defiler(f)) 14 | ecrire(defiler(f)) 15 | 16 | enfiler(f, 1) 17 | vide_file(f) 18 | ecrire(est_file_vide(f)) 19 | fin algorithme procedure foo2 20 | 21 | debut 22 | foo2() 23 | fin 24 | -------------------------------------------------------------------------------- /tests/test-typerec.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | struct t_liste_struct; 5 | typedef struct t_liste_struct t_liste_struct; 6 | typedef t_liste_struct *t_liste; 7 | typedef struct t_liste_struct 8 | { 9 | int a; 10 | t_liste next; 11 | } t_liste_struct; 12 | int variable_globale; 13 | int n; 14 | void test(void) 15 | { 16 | t_liste l; 17 | l = (*l).next; 18 | } 19 | int main(void) 20 | { 21 | test(); 22 | } 23 | -------------------------------------------------------------------------------- /tests/allouer.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | struct t_enregistrement; 5 | typedef struct t_enregistrement t_enregistrement; 6 | typedef struct t_enregistrement 7 | { 8 | int a; 9 | int b; 10 | } t_enregistrement; 11 | typedef t_enregistrement *t_ptr; 12 | void test(void) 13 | { 14 | t_ptr p; 15 | p = malloc(sizeof(*(p))); 16 | (*p).a = 1; 17 | (*p).b = 1; 18 | } 19 | int main(void) 20 | { 21 | test(); 22 | } 23 | -------------------------------------------------------------------------------- /tests/pile.algo: -------------------------------------------------------------------------------- 1 | algorithme procedure foo 2 | variables 3 | entier i 4 | t_pile p 5 | debut 6 | p <- pile_vide() 7 | empiler(p, 1) 8 | empiler(p, 2) 9 | empiler(p, 3) 10 | ecrire(p^.sommet) 11 | ecrire(depiler(p)) 12 | empiler(p, 4) 13 | ecrire(depiler(p)) 14 | ecrire(depiler(p)) 15 | ecrire(depiler(p)) 16 | 17 | empiler(p, 1) 18 | vide_pile(p) 19 | ecrire(est_vide(p)) 20 | fin algorithme procedure foo 21 | 22 | debut 23 | foo() 24 | fin 25 | -------------------------------------------------------------------------------- /tests/test-param.algo: -------------------------------------------------------------------------------- 1 | algorithme procedure test 2 | parametres locaux 3 | booleen b 4 | parametres globaux 5 | entier gp, bla 6 | caractere z 7 | variables 8 | entier a, b 9 | reel c 10 | debut 11 | a <- 0 12 | c <- 4.5 13 | si (a = b) alors 14 | b <- a + b 15 | sinon 16 | a <- a - b 17 | fin si 18 | fin algorithme procedure test 19 | 20 | variables 21 | booleen variable_globale 22 | entier n 23 | debut 24 | test(variable_globale, n) 25 | fin 26 | -------------------------------------------------------------------------------- /tests/switch.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int variable_globale; 5 | int testswitch(int n) 6 | { 7 | int a, b; 8 | a = 0; 9 | b = 0; 10 | switch (n) 11 | { 12 | case 1: 13 | case 2: 14 | b = 1; 15 | break; 16 | case 3: 17 | b = 2; 18 | break; 19 | default: 20 | b = 0; 21 | break; 22 | } 23 | return b; 24 | } 25 | int main(void) 26 | { 27 | printf("%d\n", testswitch(2)); 28 | } 29 | -------------------------------------------------------------------------------- /src/standard_lib/t_graph_dyn.c: -------------------------------------------------------------------------------- 1 | typedef *s_som t_listsom; 2 | typedef *s_adj t_listadj; 3 | 4 | typedef struct s_som 5 | { 6 | int som; 7 | t_listadj succ; 8 | t_listadj pred; 9 | t_listsom suiv; 10 | } s_som; 11 | 12 | typedef struct s_adj 13 | { 14 | int nb; 15 | float cout; 16 | t_listadj suiv; 17 | t_listsom som; 18 | } s_adj; 19 | 20 | typedef struct t_graph_stat 21 | { 22 | booleen orient; 23 | int ordre; 24 | t_mat_adj adj; 25 | t_mat_cout cout; 26 | } t_graph_stat; 27 | -------------------------------------------------------------------------------- /src/type_table.h: -------------------------------------------------------------------------------- 1 | #ifndef _TYPE_TABLE_H 2 | #define _TYPE_TABLE_H 3 | 4 | #include "data_struct/hashtable/hashtable.h" 5 | #include "type.h" 6 | #include 7 | 8 | typedef ht_tpl(struct type *) type_table_t; 9 | type_table_t* empty_type_table(void); 10 | void add_type(type_table_t* type_table, struct type *sym); 11 | void del_type(type_table_t* type_table, char *ident); 12 | struct type *find_type(type_table_t* type_table, char *name); 13 | void free_type_table(type_table_t* type_table); 14 | #endif 15 | -------------------------------------------------------------------------------- /tests/algolist.algo: -------------------------------------------------------------------------------- 1 | algorithme fonction truc : entier 2 | parametres locaux 3 | booleen b 4 | entier n, m 5 | variables 6 | caractere c 7 | debut 8 | n <- 20 + 22 9 | retourne n 10 | fin algorithme fonction truc 11 | 12 | algorithme fonction machin : entier 13 | parametres locaux 14 | entier n 15 | variables 16 | entier i, a, b 17 | debut 18 | retourne truc(faux, 42, 4) 19 | fin algorithme fonction machin 20 | 21 | variables 22 | booleen variable_globale 23 | debut 24 | ecrire(truc(vrai, 1, 2)) 25 | fin 26 | -------------------------------------------------------------------------------- /share/cdc/cout.tex: -------------------------------------------------------------------------------- 1 | \chapter{Coûts} 2 | \begin{tabular}{|c|c|} 3 | \hline 4 | materiel & cout\\ \hline \hline 5 | serveur & 4,99\euro/mois\\ \hline 6 | T-shirt & 40\euro \\ \hline 7 | lenovo yoga 2 & 1350\euro \\ \hline 8 | samsung & 700\euro \\ \hline 9 | samsung & 900\euro \\ \hline 10 | macbook pro(Lucien) & 10K\euro \\ \hline 11 | café & autant que pour le grec et sushi \\ \hline 12 | grec et sushi & autant que le café \\ \hline 13 | peripapeticienne / euphorisants & $\infty$ \\ \hline 14 | \end{tabular} 15 | -------------------------------------------------------------------------------- /tests/all_en.algo: -------------------------------------------------------------------------------- 1 | algorithm function coucou:int 2 | local parameters 3 | boolean a 4 | int b 5 | variables 6 | char c 7 | int i, n 8 | begin 9 | 10 | n <- 10 11 | 12 | for i <- 1 to n do 13 | b <- b + 1 14 | end for 15 | 16 | while b < 10 do 17 | b <- b + 1 18 | end while 19 | 20 | do 21 | a <- true 22 | while b < 20 23 | 24 | if b < 10 then 25 | a <- false 26 | else 27 | b <- 1 28 | end if 29 | 30 | caseof n do 31 | 1: b <- 1 32 | 2: b <- 2 33 | end caseof 34 | 35 | return 0 36 | 37 | end algorithm function coucou 38 | 39 | variables 40 | boolean variable_globale 41 | begin 42 | 43 | coucou(true, 1) 44 | 45 | end 46 | -------------------------------------------------------------------------------- /tests/all.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int variable_globale; 5 | int coucou(int a, int b) 6 | { 7 | char c; 8 | int i, n; 9 | n = 10; 10 | for (i = 1; i <= n; ++(i)) 11 | { 12 | b = (b + 1); 13 | } 14 | while ((b < 10)) 15 | { 16 | b = (b + 1); 17 | } 18 | do 19 | { 20 | a = 1; 21 | } while ((b < 20)); 22 | if ((b < 10)) 23 | { 24 | a = 0; 25 | } 26 | else 27 | { 28 | b = 1; 29 | } 30 | switch (n) 31 | { 32 | case 1: 33 | b = 1; 34 | break; 35 | case 2: 36 | b = 2; 37 | break; 38 | } 39 | return 0; 40 | } 41 | int main(void) 42 | { 43 | coucou(1, 1); 44 | } 45 | -------------------------------------------------------------------------------- /tests/all.algo: -------------------------------------------------------------------------------- 1 | algorithme fonction coucou:entier 2 | parametres locaux 3 | booleen a 4 | entier b 5 | variables 6 | caractere c 7 | entier i , n 8 | debut 9 | 10 | n <- 10 11 | 12 | pour i <- 1 jusqu'a n faire 13 | b <- b + 1 14 | fin pour 15 | 16 | tant que b < 10 faire 17 | b <- b + 1 18 | fin tant que 19 | 20 | faire 21 | a <- vrai 22 | tant que b < 20 23 | 24 | si b < 10 alors 25 | a <- faux 26 | sinon 27 | b <-1 28 | fin si 29 | 30 | selon n faire 31 | 1: b <- 1 32 | 2: b <- 2 33 | fin selon 34 | 35 | retourne 0 36 | 37 | fin algorithme fonction coucou 38 | 39 | variables 40 | booleen variable_globale 41 | debut 42 | 43 | coucou(vrai, 1) 44 | 45 | fin 46 | -------------------------------------------------------------------------------- /tests/product.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int multiply(int a, int b) 5 | { 6 | int p, i; 7 | p = 0; 8 | for (i = 1; i <= b; ++(i)) 9 | { 10 | p = (p + a); 11 | } 12 | return p; 13 | } 14 | int product(int a, int b) 15 | { 16 | if ((a == 0)) 17 | { 18 | return 0; 19 | } 20 | else 21 | { 22 | if ((a == 1)) 23 | { 24 | return b; 25 | } 26 | else 27 | { 28 | if ((b < 0)) 29 | { 30 | return multiply((- a), (- b)); 31 | } 32 | else 33 | { 34 | return multiply(a, b); 35 | } 36 | } 37 | } 38 | } 39 | int main(void) 40 | { 41 | printf("%d\n", product(2, (- 3))); 42 | } 43 | -------------------------------------------------------------------------------- /share/cdc/presLucien.tex: -------------------------------------------------------------------------------- 1 | \subsection{Lucien ``Luciano'' Boillod} 2 | \begin{wrapfigure}[13]{r}{2.5cm} 3 | \vspace{-7mm} 4 | \includegraphics[width=4cm]{lucien.png} 5 | \end{wrapfigure} 6 | Je me suis toujours intéressé aux nouvelles technologies et tout ce qui 7 | touche à 8 | l'informatique. Je suis quelqu'un d'investi et ambitieux dans tout ce que 9 | j'entreprends, seul ou en groupe. Durant mon temps libre je tiens un blog 10 | ainsi 11 | qu’un ensemble de sites web, où je poste des articles en rapport avec 12 | l’informatique. J’ai également contribué au projet Vcsn du LRDE pendant 13 | quelques 14 | mois en tant que stagiaire, ce qui m’a beaucoup inspiré et motivé à donner le 15 | meilleur de moi-même. 16 | -------------------------------------------------------------------------------- /src/standard_lib/lifo.h: -------------------------------------------------------------------------------- 1 | typedef struct stack 2 | { 3 | int data; 4 | struct stack *prev; 5 | } Stack; 6 | 7 | /* Fonctions */ 8 | 9 | void push(Stack **stack, int data) 10 | { 11 | Stack *new = malloc(sizeof *new); 12 | if(new != NULL) 13 | { 14 | new->data = data; 15 | new->prev = *stack; 16 | *stack = new; 17 | } 18 | 19 | } 20 | 21 | int pop(Stack **stack) 22 | { 23 | int r = -1; 24 | if(stack != NULL) 25 | { 26 | Stack *temp = (*stack)->prev; 27 | r = (*stack)->data; 28 | free(*stack); 29 | *stack = NULL; 30 | *stack = temp; 31 | } 32 | return r; 33 | } 34 | 35 | void clear(Stack **stack) 36 | { 37 | while(Stack **stack) 38 | { 39 | pop(stack); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/standard_lib/t_pile.h: -------------------------------------------------------------------------------- 1 | typedef struct t_pile 2 | { 3 | int data; 4 | struct t_pile *prev; 5 | } t_pile; 6 | 7 | /* Fonctions */ 8 | 9 | void empiler(t_pile **pile, int data) 10 | { 11 | t_pile *new = malloc(sizeof *new); 12 | if(new != NULL) 13 | { 14 | new->data = data; 15 | new->prev = *pile; 16 | *pile = new; 17 | } 18 | 19 | } 20 | 21 | int depiler(t_pile **pile) 22 | { 23 | int r = -1; 24 | if(pile != NULL) 25 | { 26 | t_pile *temp = (*pile)->prev; 27 | r = (*pile)->data; 28 | free(*pile); 29 | *pile = NULL; 30 | *pile = temp; 31 | } 32 | return r; 33 | } 34 | 35 | void vider(t_pile **pile) 36 | { 37 | while(pile) 38 | { 39 | depiler(pile); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /share/cdc/tech.tex: -------------------------------------------------------------------------------- 1 | \chapter{Technologies utilisées} 2 | \begin{center} 3 | \begin{tabular}{|c|c|} 4 | \hline 5 | Langage de programmation & C, HTML, CSS, PHP,\\ 6 | & Javascript, Python, Shell 7 | \\ \hline 8 | outils de versionnement & git, gitlab \\ \hline 9 | Compilateur & clang, gcc \\ \hline 10 | Editeur de texte & Vim, gedit, nano (et emacs...) \\ \hline 11 | OS & Unix \\ \hline 12 | Plateforme de développement continue & jenkins \\ \hline 13 | Analyseur de code statique & sonar \\ \hline 14 | autres (test) & flex, bison \\ \hline 15 | \end{tabular} 16 | \end{center} 17 | -------------------------------------------------------------------------------- /src/error.c: -------------------------------------------------------------------------------- 1 | #include "lexer.h" 2 | #include 3 | #include 4 | #include 5 | #include "lexer.h" 6 | #include "get_line.h" 7 | #include "a2c.h" 8 | 9 | void error(struct pos pos, char *msg, ...) 10 | { 11 | va_list args; 12 | va_start(args, msg); 13 | fprintf(stderr, "%s:%d:%d: error: ", 14 | srcfilename, pos.line, pos.charstart); 15 | vfprintf(stderr, msg, args); 16 | fprintf(stderr, "\n"); 17 | char *linestr = get_line(fin, pos.line); 18 | fprintf(stderr, "%s", linestr); 19 | free(linestr); 20 | for (unsigned i = 1; i < pos.charstart; ++i) 21 | fprintf(stderr, " "); 22 | for (unsigned i = 0; i < pos.len; ++i) 23 | fprintf(stderr, "^"); 24 | fprintf(stderr, "\n"); 25 | } 26 | -------------------------------------------------------------------------------- /src/var_table.h: -------------------------------------------------------------------------------- 1 | #ifndef _VAR_TABLE_H 2 | #define _VAR_TABLE_H 3 | 4 | #include "data_struct/hashtable/hashtable.h" 5 | #include "type.h" 6 | #include 7 | 8 | struct var_sym 9 | { 10 | char *ident; 11 | struct type* type; 12 | bool global; 13 | bool argref; // true if the symbol represents a global parameter 14 | bool constante; 15 | }; 16 | 17 | typedef ht_tpl(struct var_sym *) var_table_t; 18 | var_table_t* empty_var_table(void); 19 | void add_var(var_table_t* var_table, struct var_sym *sym); 20 | void del_var(var_table_t* var_table, char *ident); 21 | struct var_sym *find_var(var_table_t* var_table, char *ident); 22 | void var_table_del(var_table_t *var_table, char *ident); 23 | void free_var_table(var_table_t* var_table); 24 | #endif 25 | -------------------------------------------------------------------------------- /tests/product.algo: -------------------------------------------------------------------------------- 1 | algorithme fonction multiply : entier 2 | parametres locaux 3 | entier a, b 4 | variables 5 | entier p, i 6 | debut 7 | p <- 0 8 | pour i <- 1 jusqu'a b faire 9 | p <- p + a 10 | fin pour 11 | retourne p 12 | fin algorithme fonction multiply 13 | 14 | algorithme fonction product : entier 15 | parametres locaux 16 | entier a, b 17 | debut 18 | si a = 0 alors 19 | retourne 0 20 | sinon 21 | si a = 1 alors 22 | retourne b 23 | sinon 24 | si b < 0 alors 25 | retourne multiply(-a, -b) 26 | sinon 27 | retourne multiply(a, b) 28 | fin si 29 | fin si 30 | fin si 31 | fin algorithme fonction product 32 | 33 | debut 34 | ecrire(product(2, -3)) 35 | fin 36 | -------------------------------------------------------------------------------- /tests/test-typedecl.algo: -------------------------------------------------------------------------------- 1 | algorithme procedure test 2 | parametres locaux 3 | booleen d 4 | parametres globaux 5 | entier gp, bla 6 | types 7 | t_enum = (a1, a2, a3, a4) 8 | t_vect_entiers = 5 entier 9 | t_tab_bool = 5 * 6 booleen 10 | t_ptr = ^t_enregistrement 11 | t_enregistrement = enregistrement 12 | entier a, b 13 | booleen c 14 | fin enregistrement t_enregistrement 15 | t_int_ptr = ^entier 16 | variables 17 | t_tab_bool tab 18 | entier a, b 19 | reel c 20 | debut 21 | gp <- 0 22 | c <- 4.5 23 | si (a = b) alors 24 | b <- a + b 25 | sinon 26 | a <- a - b 27 | fin si 28 | fin algorithme procedure test 29 | 30 | variables 31 | booleen variable_globale 32 | entier m, n 33 | debut 34 | test(variable_globale, m, n) 35 | fin 36 | -------------------------------------------------------------------------------- /src/codegen.h: -------------------------------------------------------------------------------- 1 | #ifndef _CODEGEN_H 2 | #define _CODEGEN_H 3 | 4 | #include "grammar.h" 5 | 6 | void print_prog(struct prog *prog); 7 | void print_algo(struct algo *algo); 8 | void print_arglist(arglist_t l); 9 | void free_algo(struct algo *algo); 10 | void print_instructions(instructionlist_t instructions, int indent); 11 | void print_instruction(struct instruction *i, int indent); 12 | void free_instructions(instructionlist_t instructions); 13 | void free_instruction(struct instruction *i); 14 | void print_expression(struct expr *e); 15 | void print_exprlist(exprlist_t l); 16 | void print_const_decl(constdecllist_t const_decls, int indent); 17 | void free_expression(struct expr *e); 18 | void free_expressions(exprlist_t l); 19 | void free_prog(struct prog *prog); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /src/funtable.h: -------------------------------------------------------------------------------- 1 | #ifndef _FUNTABLE_H 2 | #define _FUNTABLE_H 3 | 4 | #include "data_struct/hashtable/hashtable.h" 5 | #include "data_struct/list/list.h" 6 | #include "type.h" 7 | #include 8 | 9 | struct argument 10 | { 11 | struct type* type; 12 | int global; 13 | }; 14 | 15 | typedef list_tpl(struct argument *) args_t; 16 | 17 | struct function 18 | { 19 | char* ident; 20 | struct type* ret; 21 | args_t arg; 22 | }; 23 | 24 | typedef ht_tpl(struct function*) fun_table_t; 25 | fun_table_t* empty_fun_table(void); 26 | void add_function(fun_table_t* fun, struct function* f); 27 | void delete_function(fun_table_t* table, struct function* f); 28 | struct function* get_function(fun_table_t* table, char *ident); 29 | void free_fun_table(fun_table_t* table); 30 | #endif 31 | -------------------------------------------------------------------------------- /src/standard_lib/t_file.h: -------------------------------------------------------------------------------- 1 | typedef struct t_file 2 | { 3 | int data; 4 | struct t_file *suiv; 5 | } t_file; 6 | 7 | /* Fonctions */ 8 | 9 | void enfiler(t_file **file, int data) 10 | { 11 | file *new = malloc(sizeof * new); 12 | if(new != NULL) 13 | { 14 | new->suiv = NULL; 15 | new->data = data; 16 | if(*file == NULL) 17 | *file = new; 18 | else 19 | { 20 | file *tmp = *queue; 21 | while(tmp->suiv != NULL) 22 | { 23 | tmp = tmp->suiv; 24 | } 25 | tmp->suiv = new; 26 | } 27 | } 28 | } 29 | 30 | int defiler(t_file **file) 31 | { 32 | int r = -1; 33 | if(*file != NULL) 34 | { 35 | t_file *tmp = (*file)->suiv; 36 | r = (*file)->data; 37 | free(*file); 38 | *file = NULL; 39 | *file = tmp; 40 | } 41 | return r; 42 | } 43 | -------------------------------------------------------------------------------- /src/standard_lib/fifo.h: -------------------------------------------------------------------------------- 1 | typedef struct queue 2 | { 3 | int data; 4 | struct queue *suiv; 5 | } Queue; 6 | 7 | /* Fonctions */ 8 | 9 | void enqueue(Queue **queue, int data) 10 | { 11 | Queue *new = malloc(sizeof * new); 12 | if(new != NULL) 13 | { 14 | new->suiv = NULL; 15 | new->data = data; 16 | if(*queue == NULL) 17 | *queue = new; 18 | else 19 | { 20 | Queue *tmp = *queue; 21 | while(tmp->suiv != NULL) 22 | { 23 | tmp = tmp->suiv; 24 | } 25 | tmp->suiv = new; 26 | } 27 | } 28 | } 29 | 30 | int dequeue(Queue **queue) 31 | { 32 | int r = -1; 33 | if(*queue != NULL) 34 | { 35 | Queue *tmp = (*queue)->suiv; 36 | r = (*queue)->data; 37 | free(*queue); 38 | *queue = NULL; 39 | *queue = tmp; 40 | } 41 | return r; 42 | } 43 | -------------------------------------------------------------------------------- /tests/abn_taille.algo: -------------------------------------------------------------------------------- 1 | algorithme fonction taille: entier 2 | parametres locaux 3 | t_arbre_bin B 4 | debut 5 | si B = NUL alors 6 | retourne 0 7 | sinon 8 | retourne (1 + taille(B^.fg) + taille(B^.fd)) 9 | fin si 10 | fin algorithme fonction taille 11 | 12 | algorithme fonction cree_abn : t_arbre_bin 13 | variables 14 | t_arbre_bin B 15 | debut 16 | allouer(B) 17 | B^.cle <- 3 18 | allouer(B^.fg) 19 | B^.fg^.cle <- 1 20 | B^.fg^.fg <- NUL 21 | B^.fg^.fd <- NUL 22 | allouer(B^.fd) 23 | B^.fd^.cle <- 0 24 | allouer(B^.fd^.fg) 25 | B^.fd^.fg^.cle <- 2 26 | B^.fd^.fg^.fg <- NUL 27 | B^.fd^.fg^.fd <- NUL 28 | B^.fd^.fd <- NUL 29 | retourne B 30 | fin algorithme fonction cree_abn 31 | 32 | variables 33 | t_arbre_bin B 34 | debut 35 | B <- cree_abn() 36 | ecrire(taille(B)) 37 | fin 38 | -------------------------------------------------------------------------------- /share/outline1/outline.tex: -------------------------------------------------------------------------------- 1 | \documentclass{article} 2 | 3 | \usepackage[hscale=0.7,vscale=0.8]{geometry} 4 | \usepackage[french]{babel} 5 | \usepackage[utf8]{inputenc} 6 | 7 | \pagenumbering{gobble} 8 | 9 | \author{Lucien Boillod \\ 10 | Maxime Gaudron \\ 11 | Thibaud Michaud \\ 12 | Charles Yaiche 13 | } 14 | \begin{document} 15 | 16 | \section*{Plan de soutenance} 17 | \noindent Team MALT (anciennement Ghom) :\\ 18 | Lucien Boillod \\ 19 | Maxime Gaudron \\ 20 | Thibaud Michaud \\ 21 | Charles Yaiche \\ 22 | 23 | \subsection*{Introduction} 24 | \subsection*{Organisation du groupe} 25 | \subsection*{Grammaire} 26 | \subsection*{Lexeur/Parseur} 27 | \subsection*{Arbre Syntaxique Abstrait} 28 | \subsection*{Génération de code} 29 | \subsection*{Analyse sémantique} 30 | \subsection*{Site web} 31 | \subsection*{Conclusion} 32 | \end{document} 33 | -------------------------------------------------------------------------------- /tests/test-typedecl.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | struct t_enregistrement; 5 | typedef struct t_enregistrement t_enregistrement; 6 | typedef enum 7 | { 8 | a1, 9 | a2, 10 | a3, 11 | a4, 12 | } t_enum; 13 | typedef int t_vect_entiers[5]; 14 | typedef int t_tab_bool[5][6]; 15 | typedef t_enregistrement *t_ptr; 16 | typedef struct t_enregistrement 17 | { 18 | int a, b; 19 | int c; 20 | } t_enregistrement; 21 | typedef int *t_int_ptr; 22 | int variable_globale; 23 | int m, n; 24 | void test(int d, int *gp, int *bla) 25 | { 26 | t_tab_bool tab; 27 | int a, b; 28 | double c; 29 | *(gp) = 0; 30 | c = 4.5; 31 | if ((a == b)) 32 | { 33 | b = (a + b); 34 | } 35 | else 36 | { 37 | a = (a - b); 38 | } 39 | } 40 | int main(void) 41 | { 42 | test(variable_globale, &(m), &(n)); 43 | } 44 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | [X] Utiliser les bons numéros de ligne/colonne dans les erreurs 2 | -- Fonctions prédéfinies: 3 | [X] ecrire 4 | [ ] lire 5 | [ ] allouer 6 | [ ] liberer 7 | ... ? 8 | [ ] Trouver une façon plus propre de gérer les erreurs de syntaxe 9 | [X] ajouter les headers manquant quand certaine fonctions prédéfinies sont 10 | utilisées (ecrire -> stdio.h, allouer -> stdlib.h, etc.) 11 | idée d'implem: créer une liste globale dans typechecking.c, et la remplir au 12 | fur et à mesure que l'AST est parcouru, puis la passer en parametre à 13 | print_prog() 14 | [X] Code de retour du programme (!= 0 quand il y a une erreur) 15 | [ ] bibliothèque standard 16 | [X] types récursifs 17 | [X] parametres globaux 18 | [X] constantes (e.g. pouvoir utiliser une constante pour la taille d'un tableau) 19 | => ajouter un champ const à var_sym, comme pour le champ global 20 | -------------------------------------------------------------------------------- /src/stdlibalgo.h: -------------------------------------------------------------------------------- 1 | #ifndef STDLIBALGO_H_ 2 | #define STDLIBALGO_H_ 3 | 4 | # include "a2c.h" 5 | 6 | enum e_types 7 | { 8 | E_TYPE_INT = 0 , 9 | E_TYPE_CHAR = 1 , 10 | E_TYPE_REAL , 11 | E_TYPE_BOOLEAN , 12 | E_TYPE_STRING 13 | }; 14 | 15 | static char *types_str[2][6] = 16 | { {"entier", "caractere", "reel", "booleen", "chaine"}, 17 | {"int", "char", "real", "boolean", "string"} }; 18 | 19 | /* types */ 20 | # define TYPE_INT types_str[current_lang][E_TYPE_INT] 21 | # define TYPE_CHAR types_str[current_lang][E_TYPE_CHAR] 22 | # define TYPE_REAL types_str[current_lang][E_TYPE_REAL] 23 | # define TYPE_BOOLEAN types_str[current_lang][E_TYPE_BOOLEAN] 24 | # define TYPE_STRING types_str[current_lang][E_TYPE_STRING] 25 | 26 | void fill_std_types(struct symtable *syms); 27 | void fill_std_fun(struct symtable *syms); 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /tests/arbrebin.algo: -------------------------------------------------------------------------------- 1 | algorithme procedure affiche_moi_mon_arbre 2 | parametres locaux 3 | t_arbre_bin a 4 | debut 5 | si (a <> NUL) alors 6 | ecrire(a^.cle) 7 | affiche_moi_mon_arbre(a^.fg) 8 | affiche_moi_mon_arbre(a^.fd) 9 | fin si 10 | fin algorithme procedure affiche_moi_mon_arbre 11 | 12 | algorithme fonction donne_moi_un_arbre : t_arbre_bin 13 | variables 14 | t_arbre_bin a 15 | debut 16 | allouer(a) 17 | a^.cle <- 0 18 | allouer(a^.fg) 19 | a^.fg^.cle <- 1 20 | a^.fg^.fg <- NUL 21 | a^.fg^.fd <- NUL 22 | allouer(a^.fd) 23 | a^.fd^.cle <- 2 24 | allouer(a^.fd^.fg) 25 | a^.fd^.fg^.cle <- 3 26 | a^.fd^.fg^.fg <- NUL 27 | a^.fd^.fg^.fd <- NUL 28 | a^.fd^.fd <- NUL 29 | retourne a 30 | fin algorithme fonction donne_moi_un_arbre 31 | 32 | variables 33 | t_arbre_bin a 34 | debut 35 | a <- donne_moi_un_arbre() 36 | affiche_moi_mon_arbre(a) 37 | fin 38 | -------------------------------------------------------------------------------- /share/cdc/chrono.tex: -------------------------------------------------------------------------------- 1 | \chapter{Organisation projet} 2 | 3 | \begin{tabular}{|c|c|c|c|} 4 | \hline 5 | & première soutenance & deuxième soutenance & troisième 6 | soutenance \\ \hline 7 | 8 | site web & done & done & done \\ 9 | \hline 10 | structure de donnés & done & done & done \\ 11 | \hline 12 | lexer & done & done & done \\ 13 | \hline 14 | construction gammaire & 75\% & done & done \\ 15 | \hline 16 | parseur & 75\% & done & done \\ 17 | \hline 18 | analyse sémantique & 0\% & 25\% & done \\ 19 | \hline 20 | génération de code & 0\% & 0\% & done \\ 21 | \hline 22 | 23 | \end{tabular} 24 | -------------------------------------------------------------------------------- /src/typecheck.h: -------------------------------------------------------------------------------- 1 | #ifndef _TYPECHECK_H 2 | #define _TYPECHECK_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include "parser.h" 8 | #include "codegen.h" 9 | #include "data_struct/list/list.h" 10 | #include "codegen.h" 11 | #include "funtable.h" 12 | #include "var_table.h" 13 | #include "type_table.h" 14 | #include "grammar.h" 15 | 16 | struct symtable 17 | { 18 | type_table_t *types; 19 | fun_table_t *functions; 20 | var_table_t *variables; 21 | }; 22 | 23 | char *algo_to_c_type(char *ident); 24 | bool check_algo(struct algo* al, struct symtable *syms); 25 | bool check_prog(struct prog* prog, struct symtable *syms); 26 | bool check_inst(struct instruction *e, struct type *ret, struct symtable *syms); 27 | char *check_expr(struct expr *e, struct symtable *syms); 28 | char* expr_type(struct expr *e); 29 | struct symtable *empty_symtable(void); 30 | void free_symtable(struct symtable *syms); 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /tests/hashtable.c: -------------------------------------------------------------------------------- 1 | #include "data_struct/hashtable/hashtable.h" 2 | #include 3 | #include 4 | 5 | #define N 10 6 | #define HT_CAPACITY 11 7 | 8 | size_t hash_int(int i) 9 | { 10 | return i; 11 | } 12 | 13 | int int_equal(int i, int j) 14 | { 15 | return i == j; 16 | } 17 | 18 | void noop(int i) 19 | { 20 | (void)i; 21 | } 22 | 23 | int main() 24 | { 25 | int a; 26 | ht_tpl(int) ht; 27 | ht_init(ht, HT_CAPACITY, hash_int, int_equal, noop); 28 | 29 | for (int n = 0; n < N; ++n) 30 | ht_add(ht, n); 31 | 32 | assert(ht.length == 10); 33 | 34 | for (int n = 0; n < 10; ++n) 35 | { 36 | assert(ht_find(ht, n, &a)); 37 | assert(a == n); 38 | } 39 | 40 | ht_del(ht, 5); 41 | assert(ht.length == N - 1); 42 | assert(!ht_find(ht, 5, &a)); 43 | 44 | ht_del(ht, 4); 45 | assert(ht.length == N - 2); 46 | assert(!ht_find(ht, 4, &a)); 47 | assert(ht_find(ht, 7, &a)); 48 | 49 | ht_free(ht); 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /share/cdc/pageGarde.tex: -------------------------------------------------------------------------------- 1 | \title{Cahier des charges} 2 | 3 | \author{Thibaud "zehir" Michaud 4 | Lucien "Luciano" Boillod 5 | Charles "Arys" Yaiche 6 | Maxime "Kylox" Gaudron} 7 | 8 | \date{\today} 9 | 10 | \newcommand{\hsp}{\hspace{20pt}} 11 | \newcommand{\HRule}{\rule{\linewidth}{0.5mm}} 12 | 13 | \begin{document} 14 | 15 | \begin{titlepage} 16 | \begin{sffamily} 17 | \begin{center} 18 | 19 | \includegraphics[scale=0.04]{logo-epita.png}~\\[1.5cm] 20 | 21 | \textsc{Cahier des Charges}\\[1.5cm] 22 | 23 | % Title 24 | \HRule \\[0.4cm] 25 | { \huge \bfseries A2C\\[0.4cm] } 26 | \HRule \\[1cm] 27 | % Ici notre logo 28 | %\\[1cm] 29 | 30 | {Team \textsc{Ghom}\\ 31 | Promo 2018}\\[1.5cm] 32 | 33 | Thibaud "zehir" Michaud\\ 34 | Lucien "Luciano" Boillod\\ 35 | Charles "Arys" Yaiche\\ 36 | Maxime "Kylox" Gaudro 37 | 38 | \vfill 39 | {\large 10 Janvier 2014} 40 | 41 | \end{center} 42 | \end{sffamily} 43 | \end{titlepage} 44 | -------------------------------------------------------------------------------- /tests/list.c: -------------------------------------------------------------------------------- 1 | #include "data_struct/list/list.h" 2 | #include 3 | #include 4 | #include 5 | 6 | int main() 7 | { 8 | int tab[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; 9 | int a; 10 | list_tpl(int) l; 11 | list_init(l); 12 | 13 | for (size_t n = 0; n < 10; ++n) 14 | list_push_back(l, tab[n]); 15 | 16 | // l == { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; 17 | assert(l.size == 10); 18 | 19 | for (size_t n = 0; n < 10; ++n) 20 | assert(list_nth(l, n) == tab[n]); 21 | 22 | // l == { 0, 1, 2, 3, 4, 5, 6, 7, 8 }; 23 | a = list_pop_back(l); 24 | assert(a == 9); 25 | assert(l.size == 9); 26 | 27 | // l == { 0, 1, 2, 3, 4, 5, 6, 7 }; 28 | a = list_pop_back(l); 29 | assert(a == 8); 30 | assert(l.size == 8); 31 | 32 | // l == { 0, 1, 2, 3, 4, 5, 6 }; 33 | a = list_pop_back(l); 34 | assert(a == 7); 35 | assert(l.size == 7); 36 | 37 | list_push_front(l, tab[9]); 38 | // l == { 9, 0, 1, 2, 3, 4, 5, 6 }; 39 | assert(list_nth(l, 0) == 9); 40 | assert(l.size == 8); 41 | 42 | list_insert(l, 3, tab[4]); 43 | // l == { 9, 0, 1, 4, 2, 3, 4, 5, 6 }; 44 | assert(list_nth(l, 3) == tab[4]); 45 | 46 | list_free(l); 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /src/type_table.c: -------------------------------------------------------------------------------- 1 | #include "type.h" 2 | #include "type_table.h" 3 | 4 | static size_t hash(struct type *s) 5 | { 6 | char *str = s->name; 7 | size_t hash = 5381; 8 | char c; 9 | while ((c = *str++)) 10 | hash = ((hash << 5) + hash) + c; 11 | return hash; 12 | } 13 | 14 | static int equal(struct type *s1, struct type *s2) 15 | { 16 | return (strcmp(s1->name, s2->name) == 0); 17 | } 18 | 19 | type_table_t* empty_type_table(void) 20 | { 21 | type_table_t* type_table= malloc(sizeof(type_table_t)); 22 | ht_init(*type_table, 97, hash, equal, free_type); 23 | return type_table; 24 | } 25 | 26 | void add_type(type_table_t* type_table, struct type *sym) 27 | { 28 | ht_add(*type_table, sym); 29 | } 30 | 31 | void del_type(type_table_t* type_table, char *name) 32 | { 33 | struct type sym; 34 | sym.name = name; 35 | ht_del(*type_table, &sym); 36 | } 37 | 38 | struct type *find_type(type_table_t* type_table, char *name) 39 | { 40 | if (!name) 41 | return NULL; 42 | struct type sym; 43 | sym.name = name; 44 | struct type *res = NULL; 45 | ht_find(*type_table, &sym, &res); 46 | return res; 47 | } 48 | 49 | void free_type_table(type_table_t* type_table) 50 | { 51 | ht_free(*type_table); 52 | free(type_table); 53 | } 54 | -------------------------------------------------------------------------------- /src/type.c: -------------------------------------------------------------------------------- 1 | #include "type.h" 2 | #include "codegen.h" 3 | 4 | void free_pointer(struct pointer* p) 5 | { 6 | free(p->type); 7 | free(p); 8 | } 9 | 10 | void free_records(struct records* r) 11 | { 12 | for (unsigned i = 0; i < r->fields.size; ++i) 13 | { 14 | free(r->fields.data[i]->type); 15 | free(r->fields.data[i]->ident); 16 | free(r->fields.data[i]); 17 | } 18 | list_free(r->fields); 19 | free(r); 20 | } 21 | void free_enum(struct enum_type* _enum) 22 | { 23 | free(_enum); 24 | } 25 | 26 | void free_array(struct array *a) 27 | { 28 | for (unsigned i = 0; i < a->dims.size; ++i) 29 | free_expression(a->dims.data[i]); 30 | list_free(a->dims); 31 | free(a); 32 | } 33 | 34 | void free_type(struct type *type) 35 | { 36 | switch (type->type_kind) 37 | { 38 | case primary_t: 39 | break; 40 | case records_t: 41 | free_records(type->type_val.records_type); 42 | break; 43 | case array_t: 44 | free_array(type->type_val.array_type); 45 | break; 46 | case pointer_t: 47 | free_pointer(type->type_val.pointer_type); 48 | break; 49 | case enum_t: 50 | free_enum(type->type_val.enum_type); 51 | break; 52 | } 53 | free(type->name); 54 | free(type); 55 | } 56 | -------------------------------------------------------------------------------- /src/lexer.h: -------------------------------------------------------------------------------- 1 | #ifndef A2C_LEXER_H 2 | # define A2C_LEXER_H 3 | 4 | #include 5 | 6 | enum tokentype { 7 | ALGORITHM, 8 | AND, 9 | ASSIGN, 10 | BEGIN, 11 | CHAR, 12 | COLON, 13 | COMMA, 14 | CONST, 15 | DECREASING, 16 | DEREF, 17 | DIV, 18 | DO, 19 | DOT, 20 | ELSE, 21 | END, 22 | ENDOFFILE, 23 | EOL, 24 | EQ, 25 | FALSE, 26 | FOR, 27 | FUNCTION, 28 | GE, 29 | GLOBAL, 30 | GT, 31 | IDENTIFIER, 32 | IF, 33 | INT, 34 | LE, 35 | LOCAL, 36 | LPAREN, 37 | LSQBRACKET, 38 | LT, 39 | MINUS, 40 | MOD, 41 | NEQ, 42 | NOT, 43 | NULLKW, 44 | OR, 45 | OTHERWISE, 46 | PARAM, 47 | PLUS, 48 | PROCEDURE, 49 | REAL, 50 | RECORD, 51 | RETURN, 52 | RPAREN, 53 | RSQBRACKET, 54 | SLASH, 55 | SO, 56 | STAR, 57 | STRING, 58 | SWITCH, 59 | THEN, 60 | TRUE, 61 | TYPES, 62 | UMINUS, 63 | UNRECOGNIZED, 64 | UNTIL, 65 | VARIABLES, 66 | WHILE, 67 | X, 68 | XOR 69 | }; 70 | 71 | struct pos 72 | { 73 | unsigned line; 74 | unsigned charstart; 75 | unsigned len; 76 | }; 77 | 78 | struct token { 79 | enum tokentype type; 80 | char *val; 81 | struct pos *pos; 82 | }; 83 | 84 | char *describe(enum tokentype toktype); 85 | struct token *gettok(void); 86 | void freetok(struct token *tok); 87 | 88 | #endif 89 | -------------------------------------------------------------------------------- /src/type.h: -------------------------------------------------------------------------------- 1 | #ifndef _TYPE_H 2 | #define _TYPE_H 3 | 4 | #include "data_struct/list/list.h" 5 | #include "grammar.h" 6 | struct field 7 | { 8 | char* ident; 9 | char *type; 10 | }; 11 | 12 | typedef list_tpl(struct field *) fieldlist_t; 13 | 14 | struct records { 15 | fieldlist_t fields; 16 | }; 17 | 18 | typedef enum { 19 | int_t, 20 | char_t, 21 | str_t, 22 | real_t, 23 | bool_t 24 | }primary_type; 25 | 26 | struct pointer 27 | { 28 | char *type; 29 | }; 30 | 31 | struct array 32 | { 33 | struct type* type; 34 | intlist_t dims; 35 | }; 36 | 37 | struct enum_type 38 | { 39 | identlist_t idents; 40 | }; 41 | 42 | struct type { 43 | enum 44 | { 45 | primary_t, 46 | records_t, 47 | array_t, 48 | pointer_t, 49 | enum_t, 50 | }type_kind; 51 | union 52 | { 53 | primary_type primary; 54 | struct records* records_type; 55 | struct array* array_type; 56 | struct pointer* pointer_type; 57 | struct enum_type* enum_type; 58 | }type_val; 59 | char *name; 60 | }; 61 | 62 | void free_pointer(struct pointer* p); 63 | void free_records(struct records* p); 64 | void free_enum(struct enum_type* _enum); 65 | void free_type(struct type *type); 66 | struct type *copy_type(struct type *type); 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /src/data_struct/hashtable/README: -------------------------------------------------------------------------------- 1 | hashtable: 2 | 3 | type : t_hashtable (* s_hashtable); 4 | 5 | function: 6 | 7 | make a new hashtable 8 | hash_table_init() 9 | return: t_hashtable 10 | 11 | find a key in the hashtable 12 | hash_table_find(t_hashtable t, void *key) 13 | return: 1 if found, 0 otherwise 14 | 15 | add a key in the hashtable 16 | hash_table_add(t_hashtable t, void *key) 17 | return: NONE 18 | 19 | remove a key in the hashtable 20 | hash_table_remove(t_hashtable t, void *key) 21 | return: NONE 22 | 23 | free a hashtable 24 | hash_table_free(t_hashtable t) 25 | return: NONE 26 | 27 | 28 | dictionary: 29 | 30 | type : t_dictionary (t_hashtable); 31 | 32 | function: 33 | 34 | make a new dictionary 35 | dictionary_init() 36 | return: t_dictionary 37 | 38 | find a key in the dictionary 39 | dictionary_find(t_dictionary t, void *key) 40 | return: 1 if found, 0 otherwise 41 | 42 | add a couple (key, value) in the dictionary 43 | dictionary_add(t_dictionary t, void *key, void *value) 44 | return: NONE 45 | 46 | get a value of a key 47 | dictionary_get_value(t_dictionary d, void *key) 48 | return: return the value of the given key (void*) 49 | 50 | remove a key in the dictionary 51 | dictionary_remove(t_dictionary t, void *key) 52 | return: NONE 53 | 54 | free a dictionary 55 | dictionary_free(t_dictionary t) 56 | return: NONE 57 | -------------------------------------------------------------------------------- /src/funtable.c: -------------------------------------------------------------------------------- 1 | #include "funtable.h" 2 | 3 | static size_t hash(struct function* f) 4 | { 5 | unsigned long hash = 5381; 6 | int c; 7 | char *str = f->ident; 8 | while ((c = *str++)) 9 | hash = ((hash << 5) + hash) + c; /* hash * 33 + c */ 10 | 11 | return hash; 12 | } 13 | 14 | void free_fun(struct function* f) 15 | { 16 | for (unsigned i = 0; i < f->arg.size; ++i) 17 | free(f->arg.data[i]); 18 | list_free(f->arg); 19 | free(f); 20 | } 21 | 22 | static int equal(struct function* f1, struct function *f2) 23 | { 24 | return (strcmp(f1->ident,f2->ident) == 0); 25 | } 26 | 27 | fun_table_t* empty_fun_table(void) 28 | { 29 | fun_table_t* table = malloc(sizeof(fun_table_t)); 30 | ht_init(*table, 97, hash, equal, free_fun); 31 | return table; 32 | } 33 | 34 | void add_function(fun_table_t* table, struct function* f) 35 | { 36 | ht_add(*table,f); 37 | } 38 | 39 | void delete_function(fun_table_t* table, struct function* f) 40 | { 41 | ht_del(*table, f); 42 | } 43 | 44 | struct function* get_function(fun_table_t* table, char* ident) 45 | { 46 | struct function *f = malloc(sizeof(struct function)); 47 | f->ident = ident; 48 | struct function *res = NULL; 49 | ht_find(*table, f, &res); 50 | free(f); 51 | return res; 52 | } 53 | 54 | void free_fun_table(fun_table_t* table) 55 | { 56 | ht_free(*table); 57 | free(table); 58 | } 59 | -------------------------------------------------------------------------------- /algo.vim: -------------------------------------------------------------------------------- 1 | " Vim syntax file 2 | " Language: Algo 3 | " Maintainer: Thibaud Michaud 4 | " Latest Revision: 21 April 2015 5 | 6 | if exists("b:current_syntax") 7 | finish 8 | endif 9 | 10 | " Keywords 11 | set iskeyword+=' 12 | syn keyword algoKeyword algorithme procedure fonction parametres 13 | syn keyword algoKeyword algorithm function parameters 14 | syn keyword algoKeyword globaux locaux variables types constantes 15 | syn keyword algoKeyword global local 16 | syn keyword algoKeyword jusqu'a 17 | syn keyword algoKeyword to 18 | syn keyword algoKeyword debut fin faire alors pour tant que si selon autrement 19 | syn keyword algoKeyword begin end do then for while if caseof default 20 | syn keyword algoKeyword sinon retourne vrai faux 21 | syn keyword algoKeyword else return true false 22 | syn keyword algoTypes entier chaine caractere booleen reel 23 | syn keyword algoTypes int string char boolean real 24 | syn keyword algoFunctions ecrire lire allouer liberer 25 | syn keyword algoFunctions write read malloc free 26 | syn region algoComment start="/\*" end="\*/" 27 | 28 | syn region algoString start="\"" skip="\\\"" end="\"" 29 | syn match algoNumbers "\s\d\+\(\.\d\+\)\?" 30 | 31 | let b:current_syntax = "algo" 32 | 33 | hi def link algoKeyword Statement 34 | hi def link algoString String 35 | hi def link algoNumbers Number 36 | hi def link algoTypes Type 37 | hi def link algoFunctions Function 38 | hi def link algoComment Comment 39 | -------------------------------------------------------------------------------- /src/var_table.c: -------------------------------------------------------------------------------- 1 | #include "var_table.h" 2 | #include 3 | 4 | static size_t hash(struct var_sym *s) 5 | { 6 | char *str = s->ident; 7 | size_t hash = 5381; 8 | char c; 9 | while ((c = *str++)) 10 | hash = ((hash << 5) + hash) + c; 11 | return hash; 12 | } 13 | 14 | void free_var(struct var_sym* sym) 15 | { 16 | free(sym); 17 | } 18 | 19 | static int equal(struct var_sym *s1, struct var_sym *s2) 20 | { 21 | return (strcmp(s1->ident, s2->ident) == 0); 22 | } 23 | 24 | var_table_t* empty_var_table(void) 25 | { 26 | var_table_t* var_table = malloc(sizeof(var_table_t)); 27 | ht_init(*var_table, 97, hash, equal, free_var); 28 | return var_table; 29 | } 30 | 31 | void add_var(var_table_t* var_table, struct var_sym *sym) 32 | { 33 | ht_add(*var_table, sym); 34 | } 35 | 36 | void del_var(var_table_t* var_table, char *ident) 37 | { 38 | struct var_sym sym; 39 | sym.ident = ident; 40 | ht_del(*var_table, &sym); 41 | } 42 | 43 | struct var_sym *find_var(var_table_t* var_table, char *ident) 44 | { 45 | struct var_sym sym; 46 | sym.ident = ident; 47 | struct var_sym *res = NULL; 48 | ht_find(*var_table, &sym, &res); 49 | return res; 50 | } 51 | 52 | void var_table_del(var_table_t *var_table, char *ident) 53 | { 54 | struct var_sym sym; 55 | sym.ident = ident; 56 | ht_del(*var_table, &sym); 57 | } 58 | 59 | void free_var_table(var_table_t* var_table) 60 | { 61 | ht_free(*var_table); 62 | free(var_table); 63 | } 64 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CFLAGS = -Wall -Werror -Wextra -g -std=c99 -I$(srcdir)/src -O0 -g -D_DEFAULT_SOURCE 2 | AM_YFLAGS = --report=state -d 3 | 4 | bin_PROGRAMS = a2c 5 | a2c_SOURCES = src/lexer.c \ 6 | src/parser.c \ 7 | src/type.c \ 8 | src/type_table.c \ 9 | src/get_line.c \ 10 | src/funtable.c \ 11 | src/var_table.c \ 12 | src/typecheck.c \ 13 | src/codegen.c \ 14 | src/a2c.c \ 15 | src/error.c \ 16 | src/stdlibalgo.c 17 | 18 | include_HEADERS = src/standard_lib/standard_lib.h 19 | 20 | check_PROGRAMS = tests/hashtable tests/list 21 | 22 | test_list_source= tests/list.c 23 | 24 | TESTS = tests/parser.test \ 25 | tests/test-ifthen.test \ 26 | tests/list.test \ 27 | tests/parser-testfail.test \ 28 | tests/hashtable.test \ 29 | tests/test-typedecl.test \ 30 | tests/algolist.test \ 31 | tests/emptyalgolist.test \ 32 | tests/const-decl.test \ 33 | tests/fibo.test \ 34 | tests/all.test \ 35 | tests/switch.test \ 36 | tests/switchnodef.test \ 37 | tests/multiply.test \ 38 | tests/array.test \ 39 | tests/struct.test \ 40 | tests/product.test \ 41 | tests/typerec.test \ 42 | tests/ptr.test \ 43 | tests/globvalparam.test \ 44 | tests/allouer.test \ 45 | tests/intvect.test \ 46 | tests/pile.test \ 47 | tests/file.test \ 48 | tests/arbrebin.test \ 49 | tests/abn_taille.test \ 50 | tests/abn_complet.test \ 51 | tests/constarray.test \ 52 | tests/arrayfail.test \ 53 | tests/liberer.test 54 | -------------------------------------------------------------------------------- /src/a2c.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "parser.h" 6 | #include "grammar.h" 7 | #include "codegen.h" 8 | #include "typecheck.h" 9 | #include "data_struct/list/list.h" 10 | #include "a2c.h" 11 | #include "lexer.h" 12 | 13 | FILE *fin = NULL; 14 | char *srcfilename = NULL; 15 | struct prog *prog = NULL; 16 | 17 | void usage(char **argv) 18 | { 19 | printf("usage: %s [--en] FILENAME\n", argv[0]); 20 | } 21 | 22 | int main(int argc, char **argv) 23 | { 24 | if (argc < 2) 25 | { 26 | usage(argv); 27 | return 1; 28 | } 29 | if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-h") == 0) 30 | { 31 | usage(argv); 32 | return 1; 33 | } 34 | 35 | current_lang = LANG_FR; 36 | 37 | if (strcmp(argv[1], "--en") == 0) 38 | { 39 | if (argc < 3) 40 | { 41 | usage(argv); 42 | return 1; 43 | } 44 | current_lang = LANG_EN; 45 | srcfilename = argv[2]; 46 | } 47 | else 48 | srcfilename = argv[1]; 49 | 50 | fin = fopen(srcfilename, "r"); 51 | if (fin == NULL) 52 | err(1, "Couldn't open file %s", argv[1]); 53 | 54 | bool error = false; 55 | prog = parse(); 56 | if (prog) 57 | { 58 | struct symtable *syms = empty_symtable(); 59 | if (check_prog(prog, syms)) 60 | print_prog(prog); 61 | else 62 | error = true; 63 | free_symtable(syms); 64 | free_prog(prog); 65 | } 66 | else 67 | error = true; 68 | 69 | fclose(fin); 70 | return error; 71 | } 72 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # A2C 2 | 3 | A2C is a compiler for the algorithmic language taught at EPITA. Specifications for the 4 | language are available in french 5 | [here](http://algo.infoprepa.epita.fr/index.php/Epita:Algo:M%C3%A9mo-Langage). 6 | It translates algorithms to C programs, and the result can be compiled 7 | with any C compiler. For ease of use, you can also try the [web 8 | interface](http://a2c.too.gy). 9 | 10 | # Installation 11 | Download and extract the zip file, or clone the project with git. Then from the 12 | root directory run: 13 | 14 | ./bootstrap 15 | 16 | ./configure 17 | 18 | make 19 | 20 | sudo make install 21 | 22 | ## Usage 23 | 24 | To compile in french version: 25 | 26 | ./a2c FILE > FILE.c 27 | 28 | To compile in english version: 29 | 30 | ./a2c --en FILE > FILE.c 31 | 32 | ## MALT 33 | 34 | A group of four students at EPITA (French Engineering IT School). 35 | 36 | Lucien Boillod (lucienboillod@gmail.com) 37 | 38 | Thibaud Michaud (thibaud.michaud@epita.fr) 39 | 40 | Maxime Gaudron (maxime.gaudron@epita.fr) 41 | 42 | Charles Yaiche (charles.yaiche@epita.fr) 43 | 44 | ## Documentation 45 | 46 | See the documentation section of the website (http://a2c.lucien-boillod.net/src/docs/index.html) 47 | 48 | Many examples are available in the tests/ directory. 49 | 50 | ## Contact List 51 | You can simply send a mail to one of our personal addresses, or contact us via our website (http://a2c.lucien-boillod.net). 52 | You can also send us a pull request on Github, if you want to participate. 53 | 54 | If you see any error, please let us know. 55 | -------------------------------------------------------------------------------- /tests/abn_complet.algo: -------------------------------------------------------------------------------- 1 | algorithme fonction max: entier 2 | parametres locaux 3 | entier x 4 | entier y 5 | debut 6 | si x > y alors 7 | retourne x 8 | sinon 9 | retourne y 10 | fin si 11 | fin algorithme fonction max 12 | 13 | algorithme fonction hauteur: entier 14 | parametres locaux 15 | t_arbre_bin B 16 | debut 17 | si B = NUL alors 18 | retourne (-1) 19 | sinon 20 | retourne (1 + max(hauteur(B^.fg),hauteur(B^.fd))) 21 | fin si 22 | fin algorithme fonction hauteur 23 | 24 | algorithme fonction complet_rec: booleen 25 | parametres locaux 26 | t_arbre_bin B 27 | entier h 28 | debut 29 | si(B^.fg <> NUL) et (B^.fd <> NUL) alors 30 | retourne (complet_rec(B^.fg, h-1) et complet_rec(B^.fd, h-1)) 31 | sinon 32 | retourne ((B^.fg = B^.fd) et (h = 0)) 33 | fin si 34 | fin algorithme fonction complet_rec 35 | 36 | algorithme fonction test_complet: booleen 37 | parametres locaux 38 | t_arbre_bin B 39 | debut 40 | retourne (B=NUL) ou complet_rec(B, hauteur(B)) 41 | fin algorithme fonction test_complet 42 | 43 | algorithme fonction cree_abn : t_arbre_bin 44 | variables 45 | t_arbre_bin B 46 | debut 47 | allouer(B) 48 | B^.cle <- 3 49 | allouer(B^.fg) 50 | B^.fg^.cle <- 1 51 | B^.fg^.fg <- NUL 52 | B^.fg^.fd <- NUL 53 | allouer(B^.fd) 54 | B^.fd^.cle <- 0 55 | allouer(B^.fd^.fg) 56 | B^.fd^.fg^.cle <- 2 57 | B^.fd^.fg^.fg <- NUL 58 | B^.fd^.fg^.fd <- NUL 59 | B^.fd^.fd <- NUL 60 | retourne B 61 | fin algorithme fonction cree_abn 62 | 63 | variables 64 | t_arbre_bin B 65 | debut 66 | B <- cree_abn() 67 | ecrire(test_complet(B)) 68 | fin 69 | -------------------------------------------------------------------------------- /share/cdc/presMax.tex: -------------------------------------------------------------------------------- 1 | \subsection{Maxime ``Kylox'' Gaudron} 2 | \begin{wrapfigure}[13]{r}{2.5cm} 3 | \vspace{-7mm} 4 | \includegraphics[width=4cm]{img/max.jpg} 5 | \end{wrapfigure} 6 | Seul représentant chevelu du groupe, suite aux mésaventures de sa destination 7 | à l'étranger entre complot illuminati et tactique de franc-maçon il a fallu 8 | refonder non pas une famille mais un groupe de projet pour démarrer ce S4 de 9 | la plus belle manière. c'est alors que proposant de travailler sur un kernel 10 | à zéphir, il lui répondit "non j'ai pas envie, viens on fait un compilateur" 11 | ne sachant que dire face à une telle détermination il accepta sans soucis, de 12 | toute manière les deux sont tout aussi intéressants. 13 | Il a alors fallu trouver d'autres gens parce que deux c'est sympas mais quatre 14 | c'est mieux ! Après avoir feuilleté le résultat des contrôles d'IP de leur 15 | nouvelle promos ils se rendirent alors compte qu'ils ne connaissaient pas grand 16 | monde ... problématique ... Lors d'un bref passage au LRDE zéphir rencontra la 17 | personne qui allait devenir notre responsable technologie annexe (a.k.a Apple) 18 | Luciano. Et ce fut à mon tour de trouver le dernier membre de notre compagnie, 19 | ayant en tête la bonne capacité de notre groupe il nous fallait quelqu'un de 20 | différent, c'est pour cela que notre choix s'est porté sur Arys le saltimbanque 21 | ! Bon élément, aimant développer et toujours souriant, il se lia alors au groupe 22 | . Pour ma part je trouve que ce groupe peut faire quelque chose d'intéressant 23 | ensemble si notre chemin n'est pas corrompu par les siestes interminables et 24 | les bouteilles de bière à finir. 25 | -------------------------------------------------------------------------------- /src/data_struct/list/list.h: -------------------------------------------------------------------------------- 1 | #ifndef LIST_H_ 2 | #define LIST_H_ 3 | 4 | #define BASE_CAPACITY 4 5 | 6 | #define list_tpl(t) \ 7 | struct { \ 8 | size_t capacity; \ 9 | size_t size; \ 10 | t *data; \ 11 | } 12 | 13 | #define define_list(t, name) \ 14 | struct name { \ 15 | size_t capacity; \ 16 | size_t size; \ 17 | t *data; \ 18 | } 19 | 20 | #define list_init(l) \ 21 | do { \ 22 | (l).capacity = BASE_CAPACITY; \ 23 | (l).size = 0; \ 24 | (l).data = malloc(sizeof(*(l).data) * (l).capacity); \ 25 | } while(0) 26 | 27 | #define list_push_back(l, elt) \ 28 | do { \ 29 | if ((l).size + 1 > (l).capacity) \ 30 | { \ 31 | (l).capacity *= 2; \ 32 | (l).data = realloc((l).data, (l).capacity * (sizeof(*(l).data))); \ 33 | } \ 34 | (l).data[(l).size] = (elt); \ 35 | (l).size++; \ 36 | } while (0) 37 | 38 | #define list_pop_back(l) (l).data[--(l).size]; \ 39 | 40 | #define list_insert(l, i, elt) \ 41 | do { \ 42 | if ((l).size + 1 > (l).capacity) \ 43 | { \ 44 | (l).data = realloc((l).data, (l).capacity * (sizeof(*(l).data)) * 2); \ 45 | (l).capacity *= 2; \ 46 | } \ 47 | size_t tmp = i; \ 48 | for (size_t j = (l).size; j > (tmp); --j) \ 49 | (l).data[j] = (l).data[j - 1]; \ 50 | (l).data[tmp] = elt; \ 51 | ++(l).size; \ 52 | } while (0) 53 | 54 | #define list_del(l, i) \ 55 | do { \ 56 | assert((l).size > 0); \ 57 | size_t tmp = i; \ 58 | for (size_t j = tmp; j < (l).size; ++j) \ 59 | (l).data[j] = (l).data[j + 1]; \ 60 | --(l).size; \ 61 | } while(0) 62 | 63 | #define list_push_front(l, elt) list_insert(l, 0, elt) 64 | 65 | #define list_pop_front(l) list_del(l, 0) 66 | 67 | #define list_nth(l, n) (l).data[n] 68 | 69 | #define list_free(l) \ 70 | do { \ 71 | free((l).data); \ 72 | } while(0) 73 | 74 | #endif /* LIST_H_ */ 75 | -------------------------------------------------------------------------------- /grammar.txt: -------------------------------------------------------------------------------- 1 | algo -> "algorithme" "procedure" IDENT 2 | declarations 3 | "debut" 4 | instructions 5 | "fin" "algorithme" "procedure" IDENT 6 | 7 | algo -> "algorithme" "fonction" IDENT ":" type 8 | declarations 9 | "debut" 10 | instructions 11 | "fin" "algorithme" "fonction" IDENT 12 | 13 | ############################### DECLARATIONS ################################# 14 | 15 | declarations -> 16 | parametres 17 | constantes 18 | types 19 | variables 20 | 21 | parametres -> parametres_globaux parametres_locaux 22 | | parametres_locaux parametres_globaux 23 | 24 | types -> IDENT = type_def 25 | 26 | parametres_globaux -> "parametres" "globaux" decl_var 27 | 28 | parametres_locaux -> "parametres" "locaux" decl_var 29 | 30 | decl_var -> IDENT identlist 31 | 32 | identlist -> IDENT | IDENT "," identlist 33 | 34 | variables -> "variables" decl_var 35 | 36 | type_def -> enum | tableau | enregistrement | pointeur 37 | 38 | enum -> (identlist) 39 | 40 | tableau -> IDENT = dimension IDENT 41 | 42 | enregistrement -> IDENT = "enregistrement" 43 | decl_var 44 | "fin" "enregistrement" IDENT 45 | 46 | pointeur -> IDENT = "^" IDENT 47 | 48 | dimension -> NUM | NUM "x" dimension 49 | 50 | ############################### EXPRESSIONS ################################# 51 | 52 | expression -> "NUL" | CHAR | STRING | NUM | IDENT | appel_fonction 53 | | expression opbin expression | opun expression | (expression) 54 | | expression "[" identlist "]" | expression "." IDENT | expression "^" 55 | 56 | exprlist -> expression | expression "," exprlist 57 | 58 | binop -> "+" | "-" | "*" | "/" | "div" | "mod" | "et" | "ou" | "oue" | "=" 59 | | "<>" | "<" | ">" | "<=" | ">=" 60 | 61 | opun -> "+" | "-" | "non" 62 | 63 | ############################### INSTRUCTIONS ################################# 64 | 65 | instruction -> appel_fonction | affectation 66 | | si | selon | fairetantque | tantquefaire | pour | retourne 67 | 68 | instructions -> instruction | instruction instructions 69 | 70 | affectation -> IDENT "<-" expression 71 | 72 | appel_fonction -> IDENT "(" exprlist ")" 73 | 74 | si -> "si" expression "alors" 75 | instructions 76 | sinon 77 | "fin" "si" 78 | 79 | sinon -> | "sinon" instructions 80 | 81 | selon -> "selon" expression "faire" liste_cas "fin" "selon" 82 | 83 | cas -> exprlist ":" instructions 84 | 85 | liste_cas -> cas | cas liste_cas 86 | 87 | fairetantque -> "faire" 88 | instructions 89 | TANTQUE expression 90 | 91 | tantquefaire -> TANTQUE expression "faire" 92 | instructions 93 | "fin" TANTQUE 94 | 95 | pour -> "pour" affectation JUSQUA expression decroissant "faire" 96 | instructions 97 | "fin" "pour" 98 | 99 | decroissant -> | "decroissant" 100 | 101 | retourne -> "retourne" | "retourne" expression 102 | -------------------------------------------------------------------------------- /share/website/images/OneClick.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | image/svg+xml 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 1-click Install 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /share/cdc/semantique.tex: -------------------------------------------------------------------------------- 1 | \section{Analyse semantique} 2 | L'analyse sémantique consiste à verifier l'exactitude des types, des 3 | déclarations,... . Elle a pour but de verifier le sens de la phrase ecrite. 4 | 5 | \begin{figure}[h] 6 | \begin{lstlisting}[style=base] 7 | si Vrai == 0 alors 8 | Vrai + 1 9 | fin si \end{lstlisting} 10 | Cette phrase est syntaxiquement juste mais sémentiquement fausse 11 | \end{figure} 12 | 13 | Pour palier a ce problème on va mettre un place un système d'attribut, qui 14 | donnera un sens, une valeur aux outils de la grammaire avec lesquels nous 15 | avons réalisé l'analyse syntaxique ce sens sera definis par les attributs. 16 | 17 | \subsection{Les attributs} 18 | L'analyse sémantique repose sur un principe : 19 | Un attribut est une valeur quantifiée associée à un 20 | élément du langage. L'élément peut être n'importe quoi, un type d'expression 21 | , une valeur, etc etc . Chaque élément du langage est représenté par un 22 | symbole 23 | auquel l'attribut sera associé. on note alors, A.a ou a est l'attribut de 24 | l'élément A. Le calcule de ces attributs se fait en fonction de la 25 | grammaire utilisée dans l'analyse syntaxique on associes donc à chaque 26 | aspects de la grammaire des règles sémentiques. cette grammaire est alors 27 | dites attribuée et l'arbre syntaxique qui porte alors en chacun de ses 28 | noeud la valeurs des attributs du même noeud sera appelés arbre syntaxique 29 | décoré. Il existe deux types d'attributs. 30 | 31 | \subsubsection{Attributs synthétisé} 32 | Un attributs synthétisé se calcule au niveau d'un noeud A en fonction de la valeur d'attribut de ses fils \\ 33 | 34 | \ovalbox{ 35 | \begin{tikzpicture}[level/.style={sibling distance=60mm/#1}] 36 | \node [circle,draw] (z){$A$} 37 | child {node [circle,draw] (a) {$B$} 38 | } 39 | child {node [circle,draw] (b) {$C$} 40 | child [grow=right]{node (e) {$B.a, \cdots, C.a$} edge from parent[draw=none] 41 | child [grow=up] {node (c) {$A.a = f(B.a, \cdots, C.a) $} edge from parent[draw=none] 42 | } 43 | } 44 | }; 45 | \path (a) -- (b) node (f) [midway] {$\cdots$}; 46 | 47 | \path (b) -- (e) node [midway] {$\Rightarrow$}; 48 | \path (z) -- (c) node [midway] {$\Rightarrow$}; 49 | \path (e) -- (c) node [midway] {$\vdots$}; 50 | \end{tikzpicture}} 51 | 52 | Il s'agit donc d'un analyse ascendante. 53 | 54 | \subsubsection{Attributs hérités} 55 | Ces attributs sont un peu l'inverse des attributs synthétisés car ils ne sont 56 | pas calculé a l'aide des fils mais à l'aide des noeuds parents et des noeuds 57 | frères. Cette analyse est qualifié de descendante et permet de situé chaque 58 | noeud dans un contexte. 59 | \\ 60 | Une fois ces calculs effectués notre analyse va pouvoir verifier si la phrase a 61 | un sens en fonction des attributs calculés. Si le resultats en tout noeud de 62 | notre arbre est logique (reviens basiquement a dire que 1+1 = 2) alors notre 63 | sémantique et respecter et nous pouvons passer a la génération de code. 64 | 65 | \subsection{Ouverture de l'analyse sémantique} 66 | L'analyse sémantique peut devenir vraiment complexe si l'on decide de 67 | traiter plusieurs sources et plusieurs destinations. C'est a ce moment 68 | qu'intervient les schemas de compilation qui permettront de definir 69 | plusieurs analyses differente mais pour le moment nous resterons uniquement 70 | sur une compilation d'une source vers une destination. 71 | -------------------------------------------------------------------------------- /share/cdc/algo.tex: -------------------------------------------------------------------------------- 1 | 2 | \section{Presentation langage algo et equivalence C} 3 | 4 | Le langage algo est un langage inventé dans le but de faire 5 | comprendre les cours d'algo aux élèves de prépa à l'EPITA, ce qui n'est pas 6 | chose aisée. Ce langage a donc intérêt à offrir moins de souplesse que le C 7 | et à bien faire la distinction entre les différents types, les procédures les 8 | fonctions, etc. Nous allons donc faire un bref aperçu de la 9 | structure générale de ce langage. 10 | 11 | \subsection{structure de base} 12 | \noindent de base le langage se structure de la sorte : 13 | 14 | \begin{lstlisting}[style=base] 15 | @[procedure ou fonction]@ µalgorithmeµ [nom algo] 16 | [declaration des variables et des parametres] 17 | µdebutµ 18 | [implementation] 19 | µfin algorithmeµ [nom algo]\end{lstlisting} 20 | qui pourrait alors se traduire en C par : 21 | \begin{lstlisting}[style=base] 22 | @[type de retour]@ [nom algo]{[definition des parametres]){ 23 | [declaration des variables] 24 | [implementation] 25 | } 26 | \end{lstlisting} 27 | 28 | On voit déjà apparaître que le langage algo est plus éxigeant en terme de mots 29 | clefs que le C. Passons maintenant à la déclaration des variables et paramètres. 30 | 31 | \subsection{Déclaration des variables et des paramètres} 32 | \noindent Parmis les déclarations des variables et des paramètres il existe 33 | plusieurs déclarations possible suivant la composante algorithmique utilisée. 34 | 35 | \begin{lstlisting}[style=base] 36 | µconstantesµ 37 | id_const = valeur 38 | µtypesµ 39 | declaration de type 40 | µvariablesµ 41 | @id_type@ id_var 1 42 | \end{lstlisting} 43 | \newpage 44 | qui pourrait alors se traduire en C par : 45 | 46 | \begin{itemize} 47 | \item[-]\noindent pour les constantes : 48 | \begin{lstlisting}[style=base] 49 | @const [type]@ id = valeur;\end{lstlisting} 50 | \item[-] pour les types : 51 | \begin{lstlisting}[style=base] 52 | @typedef [type] @id = [type];\end{lstlisting} 53 | \item[-] pour les variables : 54 | \begin{lstlisting}[style=base] 55 | @[type]@ id = valeur;\end{lstlisting} 56 | \end{itemize} 57 | 58 | \subsection{Structure de choix} 59 | 60 | Passons maintenant à la presentation des structures de choix et à leurs 61 | équivalences en C. La structure est un peu verbeuse mais sa traduction vers le C 62 | ne pose pose pas de problème majeur.\\ 63 | Algo: 64 | \begin{lstlisting}[style=base] 65 | µsiµ [condition] µalorsµ 66 | [instruction 1] 67 | µsinonµ 68 | [instruction 2] 69 | µfin siµ 70 | \end{lstlisting} 71 | 72 | \noindent C : 73 | 74 | \begin{lstlisting}[style=base] 75 | if([condition]){ 76 | [instruction 1] 77 | } 78 | else{ 79 | [instruction 2] 80 | } 81 | \end{lstlisting} 82 | 83 | \subsection{Les boucles} 84 | 85 | Comme en C, en algo il existe deux types de boucles : \texttt{tant que} et 86 | \texttt{pour}, respectivement \texttt{while} et \texttt{for} en C. Les deux 87 | boucles sont là aussi sensiblement équivalentes dans les deux langages, leurs syntaxes sont : 88 | en algo 89 | \begin{lstlisting}[style=base] 90 | µtant queµ [condition] µfaireµ 91 | [instruction] 92 | µfin tant queµ 93 | \end{lstlisting} 94 | 95 | en C 96 | \begin{lstlisting}[style=base] 97 | while([condition]){ 98 | 99 | } 100 | \end{lstlisting} 101 | 102 | Il existe aussi la boucle \texttt{faire tant que} qui est l'équivalent de la 103 | boucle \texttt{do while} en C : 104 | en Algo 105 | \begin{lstlisting}[style=base] 106 | µfaireµ 107 | [instruction] 108 | µtant queµ [condition] 109 | \end{lstlisting} 110 | en C 111 | \begin{lstlisting}[style=base] 112 | do{ 113 | 114 | 115 | }while([condition]) 116 | \end{lstlisting} 117 | 118 | Et finalement la boucle \texttt{pour} : 119 | en algo 120 | \begin{lstlisting}[style=base] 121 | µpourµ i <- [valeur 1] µjusqu aµ [valeur 2] µfaireµ 122 | [instruction] 123 | µfin pourµ 124 | \end{lstlisting} 125 | 126 | en C 127 | \begin{lstlisting}[style=base] 128 | µforµ([initialisation];[existance];[incrementation]){ 129 | [instruction] 130 | } 131 | \end{lstlisting} 132 | 133 | 134 | Voilà les bases de la syntaxe du langage algo. Il nous est alors évident que le 135 | passage du langage algo vers un langage plus courant comme le C nous semble 136 | facile, on arrive assez facilement à trouver les correspondances entre les 137 | différentes syntaxes. C'est pour cela que nous avons choisis le C, pour sa 138 | syntaxe simple et par sa grande utilisation. 139 | \\ 140 | 141 | l'ensemble de document de cour sur le langage peuvent etre trouver sur le 142 | site (si il est à jour) de junior : 143 | http://algo-td.infoprepa.epita.fr/algo/langage/ 144 | -------------------------------------------------------------------------------- /share/slides1/slides.tex: -------------------------------------------------------------------------------- 1 | \documentclass{beamer} 2 | 3 | \usetheme{Warsaw} 4 | \setbeamertemplate{footline}[frame number] 5 | \usepackage[french]{babel} 6 | \usepackage{hyperref} 7 | \usepackage[utf8]{inputenc} 8 | \usepackage[version=0.96]{pgf} 9 | \usepackage{tikz} 10 | \usetikzlibrary{arrows, positioning} 11 | 12 | 13 | \title{A2C} 14 | \author{Team MALT : \\ 15 | Lucien Boillod \\ 16 | Maxime Gaudron \\ 17 | Thibaud Michaud \\ 18 | Charles Yaiche } 19 | 20 | \AtBeginSection[] 21 | { 22 | \begin{frame} 23 | \tableofcontents[ 24 | currentsection, 25 | sectionstyle=show/shaded, 26 | subsectionstyle=show/shaded/hide 27 | ] 28 | \end{frame} 29 | } 30 | 31 | \AtBeginSubsection[] 32 | { 33 | \begin{frame} 34 | \tableofcontents[ 35 | currentsection, 36 | sectionstyle=show/shaded, 37 | subsectionstyle=show/shaded/hide 38 | ] 39 | \end{frame} 40 | } 41 | 42 | \begin{document} 43 | \maketitle 44 | 45 | \begin{frame} 46 | \tableofcontents 47 | \end{frame} 48 | 49 | \begin{frame} 50 | \begin{center} 51 | La team MALT (anciennement Ghom) \\ 52 | vous présente le projet A2C 53 | \end{center} 54 | \end{frame} 55 | \section{lexeur/parseur} 56 | \begin{frame} 57 | \begin{center} 58 | \includegraphics[scale=0.3]{bison.jpg} 59 | \end{center} 60 | \end{frame} 61 | \section{AST} 62 | \begin{frame} 63 | \begin{center} 64 | \begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=2cm, thick,main node/.style={fill=blue!20,draw,font=\sffamily}] 65 | % 66 | \node[main node] (6) {instruction (assignation)}; 67 | \node[main node] (7) [below left of=6]{identifiant (a)}; 68 | \node[main node] (1) [below right of=6]{expression (*)}; 69 | \node[main node] (2) [below left of=1] {expression (2)}; 70 | \node[main node] (3) [below right of=1] {expression (+)}; 71 | \node[main node] (4) [below left of=3] {expression (20)}; 72 | \node[main node] (5) [below right of=3] {expression (1)}; 73 | \path[every node/.style={font=\sffamily\small}] 74 | (1) edge node {} (2) 75 | (1) edge node {} (3) 76 | (3) edge node {} (4) 77 | (3) edge node {} (5) 78 | (6) edge node {} (7) 79 | (6) edge node {} (1) 80 | ; 81 | \end{tikzpicture} 82 | \end{center} 83 | \end{frame} 84 | 85 | \section{génération de code} 86 | \begin{frame} 87 | \begin{center} 88 | \begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=2cm, thick,main node/.style={fill=blue!20,draw,font=\sffamily}] 89 | % 90 | \node[main node] (6) {instruction (assignation)}; 91 | \node[main node] (7) [below left of=6]{identifiant (a)}; 92 | \node[main node] (1) [below right of=6]{expression (*)}; 93 | \node[main node] (2) [below left of=1] {expression (2)}; 94 | \node[main node] (3) [below right of=1] {expression (+)}; 95 | \node[main node] (4) [below left of=3] {expression (20)}; 96 | \node[main node] (5) [below right of=3] {expression (1)}; 97 | \path[every node/.style={font=\sffamily\small}] 98 | (1) edge node {} (2) 99 | (1) edge node {} (3) 100 | (3) edge node {} (4) 101 | (3) edge node {} (5) 102 | (6) edge node {} (7) 103 | (6) edge node {} (1) 104 | ; 105 | \end{tikzpicture} 106 | \\\vspace{0.5cm}\textbf{a = (2 * ( 20 + 1));} 107 | \end{center} 108 | \end{frame} 109 | 110 | \section{analyse semantique} 111 | \begin{frame} 112 | \begin{center} 113 | \begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=2cm, thick,main node/.style={fill=blue!20,draw,font=\sffamily}] 114 | % 115 | \node[main node] (6) {instruction (assignation)}; 116 | \node[main node] (7) [below left of=6]{identifiant (a)}; 117 | \node[main node] (1) [below right of=6]{expression (*)}; 118 | \node[main node] (2) [below left of=1] {type INT : 2}; 119 | \node[main node] (3) [below right of=1] {expression (+)}; 120 | \node[main node] (4) [below left of=3] {type INT : 20}; 121 | \node[main node] (5) [below right of=3] {type INT : 1}; 122 | \path[every node/.style={font=\sffamily\small}] 123 | (1) edge node {} (2) 124 | (1) edge node {} (3) 125 | (3) edge node {} (4) 126 | (3) edge node {} (5) 127 | (6) edge node {} (7) 128 | (6) edge node {} (1) 129 | ; 130 | \end{tikzpicture} 131 | \\\vspace{0.5cm}\textbf{a = (2 * ( 20 + 1));} 132 | \end{center} 133 | \end{frame} 134 | \begin{frame} 135 | \begin{center} 136 | \begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=2cm, thick,main node/.style={fill=blue!20,draw,font=\sffamily}] 137 | % 138 | \node[main node] (6) {instruction (assignation)}; 139 | \node[main node] (7) [below left of=6]{identifiant (a)}; 140 | \node[main node] (1) [below right of=6]{expression (*)}; 141 | \node[main node] (2) [below left of=1] {type INT : 2}; 142 | \node[main node] (3) [below right of=1] {expression (+)}; 143 | \node[main node] (4) [below left of=3] {type INT : 20}; 144 | \node[main node] (5) [below right of=3] {type BOOL : vrai}; 145 | \path[every node/.style={font=\sffamily\small}] 146 | (1) edge node {} (2) 147 | (1) edge node {} (3) 148 | (3) edge node {} (4) 149 | (3) edge node {} (5) 150 | (6) edge node {} (7) 151 | (6) edge node {} (1) 152 | ; 153 | \end{tikzpicture} 154 | \\\vspace{0.5cm}\textbf{a = (2 * ( 20 + 1));} 155 | \end{center} 156 | \end{frame} 157 | \section{Site web} 158 | \begin{frame} 159 | \begin{center} 160 | \url{http://a2c.lucien-boillod.net/} 161 | \end{center} 162 | \end{frame} 163 | \section{Conclusion} 164 | 165 | 166 | \begin{frame} 167 | \begin{center} 168 | \Large{Questions?}\\ 169 | \end{center} 170 | \end{frame} 171 | 172 | \end{document} 173 | -------------------------------------------------------------------------------- /share/website/src/community/members/members.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Members | A2C 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 |
23 | 55 |
56 | 57 |
58 |
59 |

Lucien Boillod

60 | 61 |

Je me suis toujours interesse aux nouvelles technologies 62 | et tout ce qui touche a l'informatique. Je suis quelqu'un d'investi et ambitieu dans tout ce que j'entreprends, seul ou en 63 | groupe. Durant mon temps libre je tiens un blog ainsi qu'un 64 | ensemble de sites web, ou je poste des articles en rapport 65 | avec l'informatique. J'ai egalement contribue au projet Vcsn 66 | du LRDE pendant quelques mois en tant que stagiaire, ce 67 | qui m'a beaucoup inspire et motive a donner le meilleur de 68 | moi-meme

69 |

Github

70 |

Thibaud Michaud

71 |

72 |
73 |
74 | 75 | 76 |
77 |
78 | 79 |
80 |
81 |
82 |
83 | © 2015 A2C Project 84 |
85 | 88 |
89 |
90 | 91 | 92 | 93 |   94 | 95 | 96 | 97 |
98 |
99 |
100 |
101 | 102 | 103 | 104 | 105 | 106 | 107 | 123 | 124 | 125 | 126 | 127 | -------------------------------------------------------------------------------- /share/website/src/news/2015/20150215.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | A2C 0.0! | A2C 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 |
23 | 55 |
56 | 57 |
58 |
59 |
60 |

A2C 0.0 !

61 |
62 | 63 | 64 | Lucien Boillod 65 | 66 | 67 | 68 | 69 | 70 | releases 71 | 72 | 73 |
74 | 75 |
76 |

We are happy to introduce A2C!

77 | 78 |

The project has now over 20 commits ! (Thx to Thibaud)

79 | 80 |
81 | 82 |
83 | 84 |
85 |
86 | 87 |
88 | 89 |
90 | 91 |
92 |
93 |
94 |
95 | 96 | 97 |
98 |
99 | 100 |
101 |
102 |
103 |
104 | © 2015 A2C Project 105 |
106 | 109 |
110 |
111 | 112 | 113 | 114 |   115 | 116 | 117 | 118 |
119 |
120 |
121 |
122 | 123 | 124 | 125 | 126 | 127 | 128 | 144 | 145 | 146 | 147 | 148 | -------------------------------------------------------------------------------- /share/website/src/download.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Download | A2C 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 |
23 | 56 |
57 | 58 |
59 |
60 |

61 |

Sources of the Project

62 |
The latest A2C release is: 1.0
63 |

Source code is available on GitHub or as a Tarball.

64 | 65 |

Reports

66 | 73 |

74 | 75 | 76 |
77 |

78 | 79 | 80 |

81 |
82 | 83 |
84 | 85 |

If you have any problem with the download please let us know.

86 |
87 | 88 | 89 |
90 |
91 | 92 |
93 |
94 |
95 |
96 | © 2015 A2C Project 97 |
98 | 101 |
102 |
103 | 104 | 105 | 106 |   107 | 108 | 109 | 110 |
111 |
112 |
113 |
114 | 115 | 116 | 117 | 118 | 119 | 120 | 136 | 137 | 138 | 139 | 140 | -------------------------------------------------------------------------------- /share/website/css/main.css: -------------------------------------------------------------------------------- 1 | /* ### GLOBAL STYLES ### */ 2 | 3 | h1, h2, h3, h4, h5, h6 { 4 | font-family: 'Open Sans', sans-serif; 5 | } 6 | 7 | code { 8 | font-weight: normal; 9 | font-size: 0.95em; 10 | line-height: 1.5; 11 | margin-bottom: 10px; 12 | } 13 | 14 | img.resize{ 15 | height: 100px; 16 | width: 50px; 17 | } 18 | 19 | img.resize{ 20 | max-width:100%; 21 | max-height:100%; 22 | } 23 | 24 | .panel.info { 25 | background: #F2FAFC; 26 | border-left-color: #258FAF; 27 | border-left-width: 5px; 28 | } 29 | 30 | .panel.success { 31 | background: #E0FFE6; 32 | border-left-color: #43AC6A; 33 | border-left-width: 5px; 34 | } 35 | 36 | .panel.alert { 37 | background: #F0D6C4; 38 | border-left-color: #F04124; 39 | border-left-width: 5px; 40 | } 41 | 42 | .mfp-figure > figure { 43 | margin: 0px; 44 | } 45 | 46 | #push { 47 | height: 140px; 48 | } 49 | 50 | footer { 51 | background-color: #EBEBEB; 52 | color: #707070; 53 | border-top: 1px solid #D9D8D7; 54 | height: 100px; 55 | padding: 25px 0; 56 | } 57 | 58 | #footer-notes { 59 | margin-top: 5px; 60 | font-size: 15px; 61 | } 62 | 63 | #footer-notes a { 64 | color: #969696; 65 | } 66 | 67 | footer ul { 68 | font-size: 0.85em; 69 | } 70 | 71 | footer h6 a { 72 | color: #000; 73 | } 74 | 75 | /* ### ### */ 76 | 77 | /* ### HEADER STYLES ### */ 78 | #header-logo { 79 | width: 90px; 80 | height: 50px; 81 | margin-top: -6px; 82 | margin-right: 10px; 83 | } 84 | 85 | #header-nav { 86 | margin-bottom: 5px; 87 | webkit-box-shadow: 0 1px 6px rgba(34, 25, 25, 0.6); 88 | moz-box-shadow: 0 1px 6px rgba(34, 25, 25, 0.6); 89 | box-shadow: 0 1px 6px rgba(34, 25, 25, 0.6); 90 | } 91 | 92 | .top-bar { 93 | height: 60px; 94 | line-height: 60px; 95 | } 96 | 97 | .top-bar .name { 98 | height: 60px; 99 | } 100 | 101 | .top-bar .name h1 { 102 | line-height: 60px; 103 | font-size: 1.8em; 104 | } 105 | 106 | .top-bar .name h1 a { 107 | width: 100%; 108 | } 109 | 110 | .top-bar-section > ul { 111 | margin-top: 8px; 112 | } 113 | 114 | .top-bar .toggle-topbar { 115 | margin-top: 8px; 116 | } 117 | 118 | .top-bar #header-searchform { 119 | margin-top: -3px; 120 | } 121 | 122 | @media only screen and (max-width: 56.875em) and (min-width: 40.063em) { 123 | .top-bar-section li:not(.has-form) a:not(.button), 124 | .top-bar-section li.active:not(.has-form) a:not(.button) { 125 | padding: 0 5px; 126 | } 127 | 128 | .top-bar-section li.has-form { 129 | max-width: 100px; 130 | padding: 0 5px; 131 | } 132 | 133 | .top-bar .name h1 a { 134 | padding: 0 5px; 135 | } 136 | 137 | #mono-download.tabs dd > a { 138 | padding-left: 0.5rem; 139 | padding-right: 0.5rem; 140 | } 141 | } 142 | /* ### ### */ 143 | 144 | /* ### PAGE-SPECIFIC STYLES ### */ 145 | 146 | /* --- Index page --- */ 147 | #index-hero { 148 | background: #5C7280; 149 | color: #E2E8EB; 150 | text-align: center; 151 | margin-top: -5px; 152 | padding-top: 15px; 153 | } 154 | 155 | #index-hero h1 { 156 | color: #E2E8EB; 157 | margin-bottom: 15px; 158 | font-weight: bold; 159 | } 160 | 161 | #index-teaser { 162 | background: #EBEBEB; 163 | color: #222; 164 | margin-top: 10px; 165 | padding-top: 10px; 166 | margin-bottom: 20px; 167 | padding-bottom: 10px; 168 | border-bottom: 1px solid #D9D8D7; 169 | } 170 | /* --- --- */ 171 | 172 | /* --- Download page --- */ 173 | #mono-download.tabs dd > a { 174 | font-size: 1.5em; 175 | white-space: nowrap; 176 | } 177 | 178 | #mono-download.tabs dd.active a { 179 | background-color: #333; 180 | color: #fff; 181 | } 182 | 183 | #mono-download.tabs dd { 184 | line-height: 0.9em; 185 | } 186 | 187 | #download-mac, #download-lin, #download-win { 188 | padding-top: 10px; 189 | } 190 | 191 | /* --- --- */ 192 | 193 | /* ### ### */ 194 | 195 | /* ### SECTION-SPECIFIC STYLES ### */ 196 | 197 | /* --- Blog post --- */ 198 | .meta { 199 | margin-left: 2px; 200 | color: #999; 201 | margin-bottom: 20px; 202 | } 203 | 204 | .meta span { 205 | margin-right: 10px; 206 | } 207 | 208 | .meta .author:before { 209 | font: 1.0em FontAwesome; 210 | content: "\f007" 211 | } 212 | 213 | .meta .date:before { 214 | font: 1.0em FontAwesome; 215 | content: "\f073" 216 | } 217 | 218 | .meta .tags:before { 219 | font: 1.0em FontAwesome; 220 | content: "\f02c" 221 | } 222 | 223 | .meta a { 224 | color: #999 225 | } 226 | /* --- --- */ 227 | 228 | /* --- Doc page --- */ 229 | .heading-anchor-link { 230 | display: none; 231 | color: #666; 232 | font-size: 0.7em; 233 | padding-left: 1%; 234 | } 235 | 236 | .heading-anchor-link:hover { 237 | color: #222; 238 | } 239 | 240 | h1:hover .heading-anchor-link, 241 | h2:hover .heading-anchor-link, 242 | h3:hover .heading-anchor-link, 243 | h4:hover .heading-anchor-link, 244 | h5:hover .heading-anchor-link, 245 | h6:hover .heading-anchor-link { 246 | display: inline; 247 | } 248 | 249 | ul.doc-breadcrumbs-nav { 250 | margin-top: 5px; 251 | margin-bottom: 0px; 252 | padding-top: 0px; 253 | padding-bottom: 5px; 254 | } 255 | 256 | ul.doc-breadcrumbs-nav > *:before { 257 | margin-right: 0.4rem; 258 | margin-left: 0.4rem; 259 | } 260 | 261 | ul.doc-breadcrumbs-nav li { 262 | margin-top: 12px; 263 | margin-bottom: 5px; 264 | } 265 | 266 | ul.doc-breadcrumbs-nav li.toc { 267 | margin-top: 0px; 268 | margin-bottom: 0px; 269 | } 270 | 271 | ul.doc-breadcrumbs-nav li.toc:before{ 272 | display: none; 273 | } 274 | 275 | ul.doc-breadcrumbs-nav li.toc a:hover { 276 | text-decoration: none; 277 | } 278 | 279 | ul.doc-breadcrumbs-nav .here-note { 280 | text-transform: none; 281 | color: #000; 282 | } 283 | 284 | #toc-dropdown-button-inline { 285 | padding: 5px 20px 5px 5px; 286 | margin-top: 5px; 287 | margin-bottom: 0px; 288 | } 289 | 290 | #toc-dropdown-button-inline:after { 291 | right: 5px; 292 | } 293 | 294 | #toc-dropdown-button-separate { 295 | margin-top: 10px; 296 | margin-bottom: 0px; 297 | text-transform: uppercase; 298 | } 299 | 300 | #toc-dropdown li.toc-indent-h2 { 301 | text-indent: 10px; 302 | } 303 | 304 | #toc-dropdown li.toc-indent-h3 { 305 | line-height: 10px; 306 | font-size: 12px; 307 | text-indent: 20px; 308 | } 309 | 310 | #toc-dropdown li.toc-indent-h4 { 311 | line-height: 8px; 312 | font-size: 11px; 313 | text-indent: 30px; 314 | } 315 | 316 | /* trick to make anchor links not jump to the very top of screen */ 317 | .doc-content h1:not(#page-title):before, 318 | .doc-content h2:before, 319 | .doc-content h3:before, 320 | .doc-content h4:before { 321 | display: block; 322 | content: " "; 323 | margin-top: -15px; 324 | height: 15px; 325 | visibility: hidden; 326 | } 327 | 328 | /* --- --- */ 329 | 330 | /* ### ### */ 331 | -------------------------------------------------------------------------------- /share/website/src/community/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Community | A2C 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 |
23 | 56 |
57 | 58 |
59 |
60 |

Who we are

61 | 62 |
63 |
64 | 65 |
66 |
67 |

We are a group of Student from EPITA, actually in second year.

68 |

See our individual presentation Here 69 |

70 |
71 | 72 |

Contribute to the Project

73 | 74 |
75 |
76 | 77 |
78 |
79 |

A2C is an open source project and the code is available on GitHub. To contribute bug fixes or new features, just fork the repository and send us a pull request!

80 |
81 |
82 | 83 |
84 | 85 |

Report Bugs

86 | 87 |
88 |
89 | 90 |
91 |
92 |

Whenever you encounter something that doesn't work as it should, we'd love it if you could contact us with our email adresse

93 |
94 |

Lucien Boillod: lucienboillod@gmail.com, 95 | Thibaud Michaud: michaud_n@epita.fr, 96 | Maxime Gaudron: gaudro_m@epita.fr, 97 | Charles Yaiche: yaiche_c@epita.fr

98 |
99 |
100 |
101 | 102 |
103 |
104 |
105 | 106 | 107 |
108 |
109 | 110 |
111 |
112 |
113 |
114 | © 2015 A2C Project 115 |
116 | 119 |
120 |
121 | 122 | 123 | 124 |   125 | 126 | 127 | 128 |
129 |
130 |
131 |
132 | 133 | 134 | 135 | 136 | 137 | 138 | 154 | 155 | 156 | 157 | 158 | -------------------------------------------------------------------------------- /src/standard_lib/standard_lib.h: -------------------------------------------------------------------------------- 1 | #include 2 | /* ****************** */ 3 | /* VECTEURS D'ENTIERS */ 4 | /* ****************** */ 5 | typedef int t_vect_entiers[1000]; 6 | 7 | /* ******************** */ 8 | /* VECTEURS DE BOOLEENS */ 9 | /* ******************** */ 10 | typedef int t_vect_booleens[1000]; 11 | 12 | typedef struct t_list 13 | { 14 | t_vect_entiers elts; 15 | int longueur; 16 | } t_list; 17 | 18 | static inline 19 | int supprimer(t_list L, int k) 20 | { 21 | if((k<1) || (k>L.longueur)) 22 | return 0; 23 | else { 24 | for(int i=k; i< L.longueur - 1;i++) 25 | { 26 | } 27 | L.longueur = L.longueur -1; 28 | return 1; 29 | } 30 | } 31 | 32 | static inline 33 | int inserer(t_list L, int k, int e) 34 | { 35 | if((L.longueur >= 1000) || (k < 1) || (k>L.longueur + 1)) 36 | { 37 | return 0; 38 | } 39 | else 40 | { 41 | for(int i = L.longueur; i > k; i--) 42 | { 43 | L.elts[i+1] = L.elts[i]; 44 | } 45 | L.elts[k] = e; 46 | L.longueur ++; 47 | return 1; 48 | } 49 | } 50 | 51 | static inline 52 | void concatener(t_list L1, t_list L2, t_list Lres) 53 | { 54 | if((L1.longueur + L2.longueur) <= 1000) 55 | { 56 | for(int i = 1; i< L1.longueur; i++) 57 | Lres.elts[i] = L1.elts[i]; 58 | for(int i = L1.longueur +1; ival = e; 89 | new->suiv = L; 90 | return new; 91 | } 92 | 93 | static inline 94 | int longueur(t_pList L) 95 | { 96 | int lg = 0; 97 | while(L != NULL) 98 | { 99 | lg++; 100 | L=L->suiv; 101 | } 102 | return lg; 103 | } 104 | 105 | static inline 106 | t_pList acces(t_pList L, int k) 107 | { 108 | while((L != NULL) && (k != 1)) 109 | { 110 | k--; 111 | L = L->suiv; 112 | } 113 | return L; 114 | } 115 | 116 | static inline 117 | t_pList rechercher(t_pList L, int x) 118 | { 119 | while((L != NULL) && (x != L->val)) 120 | { 121 | L = L->suiv; 122 | } 123 | return L; 124 | } 125 | 126 | // void concatener(t_pList L1, t_pList L2) 127 | // { 128 | // t_pList p; 129 | // if(L1 == NULL) 130 | // L1 = L2; 131 | // else{ 132 | // if(L2 != NULL) 133 | // { 134 | // p = L1; 135 | // while(p->suiv != NULL) 136 | // { 137 | // p = p->suiv; 138 | // } 139 | // p->suiv = L2; 140 | // } 141 | // } 142 | // } 143 | 144 | /* PILES DYNAMIQUES */ 145 | typedef struct t_node_pile t_node_pile; 146 | typedef t_node_pile *t_pile; 147 | struct t_node_pile 148 | { 149 | int sommet; 150 | t_pile suiv; 151 | }; 152 | 153 | static inline 154 | t_pile pile_vide() 155 | { 156 | return NULL; 157 | } 158 | 159 | static inline 160 | int est_vide(t_pile p) 161 | { 162 | return (p == NULL); 163 | } 164 | 165 | static inline 166 | void empiler(t_pile *pile, int e) 167 | { 168 | t_pile new = malloc(sizeof(struct t_node_pile)); 169 | if(new != NULL) 170 | { 171 | new->sommet = e; 172 | new->suiv = *pile; 173 | *pile = new; 174 | } 175 | } 176 | 177 | static inline 178 | int depiler(t_pile *pile) 179 | { 180 | int r = -1; 181 | if (*pile != NULL) 182 | { 183 | t_pile temp = (*pile)->suiv; 184 | r = (*pile)->sommet; 185 | free(*pile); 186 | *pile = temp; 187 | } 188 | return r; 189 | } 190 | 191 | static inline 192 | void vide_pile(t_pile *pile) 193 | { 194 | while(*pile) 195 | { 196 | depiler(pile); 197 | } 198 | } 199 | 200 | /* FILES */ 201 | typedef struct t_node_file t_node_file; 202 | typedef t_node_file *t_file; 203 | struct t_node_file 204 | { 205 | int val; 206 | t_file suiv; 207 | }; 208 | 209 | static inline 210 | t_file file_vide() 211 | { 212 | return NULL; 213 | } 214 | 215 | static inline 216 | int est_file_vide(t_file f) 217 | { 218 | return (f == NULL); 219 | } 220 | 221 | static inline 222 | void enfiler(t_file *file, int e) 223 | { 224 | t_file new = malloc(sizeof(struct t_node_file)); 225 | new->val = e; 226 | if(*file == NULL) 227 | new->suiv = new; 228 | else 229 | { 230 | new->suiv = (*file)->suiv; 231 | (*file)->suiv = new; 232 | } 233 | *file = new; 234 | } 235 | 236 | static inline 237 | int defiler(t_file *file) 238 | { 239 | int r = -1; 240 | if (!*file) 241 | return -1; 242 | else if ((*file)->suiv == *file) 243 | { 244 | r = (*file)->val; 245 | free(*file); 246 | *file = NULL; 247 | return r; 248 | } 249 | else 250 | { 251 | t_file tmp = (*file)->suiv->suiv; 252 | r = (*file)->suiv->val; 253 | free((*file)->suiv); 254 | (*file)->suiv = tmp; 255 | } 256 | return r; 257 | } 258 | 259 | static inline 260 | void vide_file(t_file *file) 261 | { 262 | while(*file) 263 | { 264 | defiler(file); 265 | } 266 | } 267 | 268 | /* ARBRES BINAIRES */ 269 | typedef struct t_noeud_bin t_noeud_bin; 270 | typedef t_noeud_bin *t_arbre_bin; 271 | 272 | struct t_noeud_bin 273 | { 274 | int cle; 275 | t_arbre_bin fg; 276 | t_arbre_bin fd; 277 | }; 278 | 279 | /* /\* ARBRES GENERAUX DYN *\/ */ 280 | /* typedef *t_noeud_ag t_arbre_dyn; */ 281 | 282 | /* typedef struct t_noeud_ag */ 283 | /* { */ 284 | /* int cle; */ 285 | /* t_arbre_dyn fils; */ 286 | /* t_arbre_dyn frere; */ 287 | /* } t_noeud_ag; */ 288 | 289 | /* /\* ARBRES GENERAUX STAT *\/ */ 290 | /* typedef *s_som t_listsom; */ 291 | /* typedef *s_adj t_listadj; */ 292 | 293 | /* typedef struct s_som */ 294 | /* { */ 295 | /* int som; */ 296 | /* t_listadj succ; */ 297 | /* t_listadj pred; */ 298 | /* t_listsom suiv; */ 299 | /* } s_som; */ 300 | 301 | /* typedef struct s_adj */ 302 | /* { */ 303 | /* int nb; */ 304 | /* float cout; */ 305 | /* t_listadj suiv; */ 306 | /* t_listsom som; */ 307 | /* } s_adj; */ 308 | 309 | /* typedef struct t_graph_stat */ 310 | /* { */ 311 | /* booleen orient; */ 312 | /* int ordre; */ 313 | /* t_mat_adj adj; */ 314 | /* t_mat_cout cout; */ 315 | /* } t_graph_stat; */ 316 | 317 | /* /\* ARBRES REPRESENTATION NUPLETS *\/ */ 318 | /* typedef *t_noeud_nuplet t_arbre_nuplets; */ 319 | 320 | /* typedef struct t_noeud_nuplet */ 321 | /* { */ 322 | /* int cle; */ 323 | /* t_noeud_nuplet fils; */ 324 | /* int nbFils; */ 325 | /* } t_noeud_nuplet; */ 326 | 327 | /* /\* GRAPHES STAT *\/ */ 328 | /* const int Max_sommets = 100; */ 329 | 330 | /* int t_mat_adj[Max_sommets][Max_sommets]; */ 331 | /* float t_mat_cout[Max_sommets][Max_sommets]; */ 332 | 333 | /* typedef struct t_graph_stat */ 334 | /* { */ 335 | /* booleen orient; */ 336 | /* int ordre; */ 337 | /* t_mat_adj adj; */ 338 | /* t_mat_cout cout; */ 339 | /* } t_graph_stat; */ 340 | /* */ 341 | -------------------------------------------------------------------------------- /src/data_struct/hashtable/hashtable.h: -------------------------------------------------------------------------------- 1 | #ifndef _DATA_STRUCT_HASHTABLE_H 2 | #define _DATA_STRUCT_HASHTABLE_H 3 | 4 | #include 5 | #include 6 | 7 | #define ht_tpl(type) \ 8 | struct \ 9 | { \ 10 | size_t size; \ 11 | size_t length; \ 12 | size_t (*hash)(type); \ 13 | int (*equal)(type, type); \ 14 | void(*free_elt)(type); \ 15 | struct { type elt; void *next; } **buckets; \ 16 | } 17 | 18 | #define ht_init(_ht, _size, _hash, _equal, _free) \ 19 | do \ 20 | { \ 21 | (_ht).size = (_size); \ 22 | (_ht).length = 0; \ 23 | (_ht).hash = _hash; \ 24 | (_ht).equal = _equal; \ 25 | (_ht).free_elt = _free; \ 26 | (_ht).buckets = calloc(_size, sizeof(*(_ht).buckets)); \ 27 | } while(0) 28 | 29 | #define ht_add(_ht, _elt) \ 30 | do { \ 31 | typedef __typeof__((_ht).buckets[0]) bucket; \ 32 | typedef __typeof__(_elt) type; \ 33 | size_t i = (_ht).hash(_elt) % (_ht).size; \ 34 | bucket nhead = malloc(sizeof(struct { type elt; bucket next; })); \ 35 | nhead->elt = (_elt); \ 36 | nhead->next = (_ht).buckets[i]; \ 37 | (_ht).buckets[i] = nhead; \ 38 | ++(_ht).length; \ 39 | } while(0) 40 | 41 | #define ht_del(_ht, _elt) \ 42 | do { \ 43 | typedef __typeof__((_ht).buckets[0]) bucket; \ 44 | size_t i = (_ht).hash(_elt) % (_ht).size; \ 45 | bucket prev = NULL; \ 46 | bucket b = (_ht).buckets[i]; \ 47 | while(b) \ 48 | { \ 49 | if ((_ht).equal(b->elt, _elt)) \ 50 | { \ 51 | if (prev) \ 52 | { \ 53 | prev->next = b->next; \ 54 | (_ht).free_elt(b->elt); \ 55 | free(b); \ 56 | b = prev; \ 57 | } \ 58 | else \ 59 | { \ 60 | (_ht).buckets[i] = b->next; \ 61 | (_ht).free_elt(b->elt); \ 62 | free(b); \ 63 | b = (_ht).buckets[i]; \ 64 | } \ 65 | --(_ht).length; \ 66 | } \ 67 | } \ 68 | } while(0) 69 | 70 | #define ht_find(_ht, _elt, _res) ({ \ 71 | typedef __typeof__((_ht).buckets[0]) bucket; \ 72 | int found = 0; \ 73 | size_t i = (_ht).hash(_elt) % (_ht).size; \ 74 | for (bucket b = (_ht).buckets[i]; b != NULL; b = (bucket)b->next) \ 75 | { \ 76 | if ((_ht).equal(b->elt, _elt)) \ 77 | { \ 78 | *_res = b->elt; \ 79 | found = 1; \ 80 | break; \ 81 | } \ 82 | } \ 83 | found; }) 84 | 85 | #define ht_free(_ht) \ 86 | do { \ 87 | typedef __typeof__((_ht).buckets[0]) bucket; \ 88 | for (unsigned i = 0; i < (_ht).size; ++i) \ 89 | { \ 90 | bucket next; \ 91 | bucket b = (_ht).buckets[i]; \ 92 | while (b) \ 93 | { \ 94 | next = (bucket)b->next; \ 95 | (_ht).free_elt(b->elt); \ 96 | free(b); \ 97 | b = next; \ 98 | } \ 99 | } \ 100 | free((_ht).buckets); \ 101 | } while(0) 102 | 103 | #endif 104 | -------------------------------------------------------------------------------- /src/stdlibalgo.c: -------------------------------------------------------------------------------- 1 | #include "typecheck.h" 2 | #include "stdlibalgo.h" 3 | 4 | void fill_std_types(struct symtable *syms) 5 | { 6 | struct type *t_bool = malloc(sizeof(struct type)); 7 | t_bool->type_kind = primary_t; 8 | t_bool->name = strdup(TYPE_BOOLEAN); 9 | t_bool->type_val.primary = bool_t; 10 | add_type(syms->types, t_bool); 11 | 12 | struct type *t_int = malloc(sizeof(struct type)); 13 | t_int->type_kind = primary_t; 14 | t_int->name = strdup(TYPE_INT); 15 | t_int->type_val.primary = int_t; 16 | add_type(syms->types, t_int); 17 | 18 | struct type *t_str = malloc(sizeof(struct type)); 19 | t_str->type_kind = primary_t; 20 | t_str->name = strdup(TYPE_STRING); 21 | t_str->type_val.primary = str_t; 22 | add_type(syms->types, t_str); 23 | 24 | struct type *t_reel = malloc(sizeof(struct type)); 25 | t_reel->type_kind = primary_t; 26 | t_reel->name = strdup(TYPE_REAL); 27 | t_reel->type_val.primary = real_t; 28 | add_type(syms->types,t_reel); 29 | 30 | struct type *t_char = malloc(sizeof(struct type)); 31 | t_char->type_kind = primary_t; 32 | t_char->name = strdup(TYPE_CHAR); 33 | t_char->type_val.primary = char_t; 34 | add_type(syms->types, t_char); 35 | 36 | struct type *t = malloc(sizeof(struct type)); 37 | t->name = strdup("t_node_pile"); 38 | t->type_kind = records_t; 39 | t->type_val.records_type = malloc(sizeof(struct records)); 40 | list_init(t->type_val.records_type->fields); 41 | struct field *f = malloc(sizeof(struct field)); 42 | f->type = strdup(TYPE_INT); 43 | f->ident = strdup("sommet"); 44 | list_push_back(t->type_val.records_type->fields, f); 45 | f = malloc(sizeof(struct field)); 46 | f->type = strdup("t_pile"); 47 | f->ident = strdup("suiv"); 48 | list_push_back(t->type_val.records_type->fields, f); 49 | add_type(syms->types, t); 50 | 51 | t = malloc(sizeof(struct type)); 52 | t->name = strdup("t_pile"); 53 | t->type_kind = pointer_t; 54 | t->type_val.pointer_type = malloc(sizeof(struct pointer)); 55 | t->type_val.pointer_type->type = strdup("t_node_pile"); 56 | add_type(syms->types, t); 57 | 58 | t = malloc(sizeof(struct type)); 59 | t->name = strdup("t_file"); 60 | t->type_kind = pointer_t; 61 | t->type_val.pointer_type = malloc(sizeof(struct pointer)); 62 | t->type_val.pointer_type->type = strdup("t_node_file"); 63 | add_type(syms->types, t); 64 | 65 | t = malloc(sizeof(struct type)); 66 | t->name = strdup("t_vect_entiers"); 67 | t->type_kind = array_t; 68 | t->type_val.array_type = malloc(sizeof(struct array)); 69 | t->type_val.array_type->type = find_type(syms->types, TYPE_INT); 70 | list_init(t->type_val.array_type->dims); 71 | list_push_back(t->type_val.array_type->dims, expr_from_val(intval(1000))); 72 | add_type(syms->types, t); 73 | 74 | t = malloc(sizeof(struct type)); 75 | t->name = strdup("t_vect_booleens"); 76 | t->type_kind = array_t; 77 | t->type_val.array_type = malloc(sizeof(struct array)); 78 | t->type_val.array_type->type = find_type(syms->types, TYPE_INT); 79 | list_init(t->type_val.array_type->dims); 80 | list_push_back(t->type_val.array_type->dims, expr_from_val(intval(1000))); 81 | add_type(syms->types, t); 82 | 83 | t = malloc(sizeof(struct type)); 84 | t->name = strdup("t_noeud_bin"); 85 | t->type_kind = records_t; 86 | t->type_val.records_type = malloc(sizeof(struct records)); 87 | list_init(t->type_val.records_type->fields); 88 | f = malloc(sizeof(struct field)); 89 | f->type = strdup(TYPE_INT); 90 | f->ident = strdup("cle"); 91 | list_push_back(t->type_val.records_type->fields, f); 92 | f = malloc(sizeof(struct field)); 93 | f->type = strdup("t_arbre_bin"); 94 | f->ident = strdup("fg"); 95 | list_push_back(t->type_val.records_type->fields, f); 96 | f = malloc(sizeof(struct field)); 97 | f->type = strdup("t_arbre_bin"); 98 | f->ident = strdup("fd"); 99 | list_push_back(t->type_val.records_type->fields, f); 100 | add_type(syms->types, t); 101 | 102 | t = malloc(sizeof(struct type)); 103 | t->name = strdup("t_arbre_bin"); 104 | t->type_kind = pointer_t; 105 | t->type_val.pointer_type = malloc(sizeof(struct pointer)); 106 | t->type_val.pointer_type->type = strdup("t_noeud_bin"); 107 | add_type(syms->types, t); 108 | } 109 | 110 | void fill_std_fun(struct symtable *syms) 111 | { 112 | struct function *f = malloc(sizeof(struct function)); 113 | f->ident = "empiler"; 114 | f->ret = NULL; 115 | list_init(f->arg); 116 | struct argument *arg = malloc(sizeof(struct argument)); 117 | arg->type = find_type(syms->types, "t_pile"); 118 | arg->global = true; 119 | list_push_back(f->arg, arg); 120 | arg = malloc(sizeof(struct argument)); 121 | arg->type = find_type(syms->types, TYPE_INT); 122 | arg->global = false; 123 | list_push_back(f->arg, arg); 124 | add_function(syms->functions, f); 125 | 126 | f = malloc(sizeof(struct function)); 127 | f->ident = "pile_vide"; 128 | f->ret = find_type(syms->types, "t_pile"); 129 | list_init(f->arg); 130 | add_function(syms->functions, f); 131 | 132 | f = malloc(sizeof(struct function)); 133 | f->ident = "depiler"; 134 | f->ret = find_type(syms->types, TYPE_INT); 135 | list_init(f->arg); 136 | arg = malloc(sizeof(struct argument)); 137 | arg->type = find_type(syms->types, "t_pile"); 138 | arg->global = true; 139 | list_push_back(f->arg, arg); 140 | add_function(syms->functions, f); 141 | 142 | f = malloc(sizeof(struct function)); 143 | f->ident = "vide_pile"; 144 | f->ret = find_type(syms->types, TYPE_INT); 145 | list_init(f->arg); 146 | arg = malloc(sizeof(struct argument)); 147 | arg->type = find_type(syms->types, "t_pile"); 148 | arg->global = true; 149 | list_push_back(f->arg, arg); 150 | add_function(syms->functions, f); 151 | 152 | f = malloc(sizeof(struct function)); 153 | f->ident = "est_vide"; 154 | f->ret = find_type(syms->types, TYPE_BOOLEAN); 155 | list_init(f->arg); 156 | arg = malloc(sizeof(struct argument)); 157 | arg->type = find_type(syms->types, "t_pile"); 158 | arg->global = false; 159 | list_push_back(f->arg, arg); 160 | add_function(syms->functions, f); 161 | 162 | f = malloc(sizeof(struct function)); 163 | f->ident = "enfiler"; 164 | f->ret = NULL; 165 | list_init(f->arg); 166 | arg = malloc(sizeof(struct argument)); 167 | arg->type = find_type(syms->types, "t_file"); 168 | arg->global = true; 169 | list_push_back(f->arg, arg); 170 | arg = malloc(sizeof(struct argument)); 171 | arg->type = find_type(syms->types, TYPE_INT); 172 | arg->global = false; 173 | list_push_back(f->arg, arg); 174 | add_function(syms->functions, f); 175 | 176 | f = malloc(sizeof(struct function)); 177 | f->ident = "file_vide"; 178 | f->ret = find_type(syms->types, "t_file"); 179 | list_init(f->arg); 180 | add_function(syms->functions, f); 181 | 182 | f = malloc(sizeof(struct function)); 183 | f->ident = "defiler"; 184 | f->ret = find_type(syms->types, TYPE_INT); 185 | list_init(f->arg); 186 | arg = malloc(sizeof(struct argument)); 187 | arg->type = find_type(syms->types, "t_file"); 188 | arg->global = true; 189 | list_push_back(f->arg, arg); 190 | add_function(syms->functions, f); 191 | 192 | f = malloc(sizeof(struct function)); 193 | f->ident = "vide_file"; 194 | f->ret = find_type(syms->types, TYPE_INT); 195 | list_init(f->arg); 196 | arg = malloc(sizeof(struct argument)); 197 | arg->type = find_type(syms->types, "t_file"); 198 | arg->global = true; 199 | list_push_back(f->arg, arg); 200 | add_function(syms->functions, f); 201 | 202 | f = malloc(sizeof(struct function)); 203 | f->ident = "est_file_vide"; 204 | f->ret = find_type(syms->types, TYPE_BOOLEAN); 205 | list_init(f->arg); 206 | arg = malloc(sizeof(struct argument)); 207 | arg->type = find_type(syms->types, "t_file"); 208 | arg->global = false; 209 | list_push_back(f->arg, arg); 210 | add_function(syms->functions, f); 211 | 212 | } 213 | -------------------------------------------------------------------------------- /share/website/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Home | A2C 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 |
23 | 56 |
57 | 58 |
59 |

Algo Language compiler, C code generation

60 | 61 |
62 | 63 | 64 |
65 |
66 | 67 | 68 |
69 |
70 | 71 | 72 |
73 | 74 |
75 | A2C is designed for everyone who wants to compile the abstract Algorithmic Language (especially EPITA students) 76 |
77 |
78 | 79 |
80 |
81 |

82 | A2C is an open source software, based on the C language. 83 | Ghom is a group of 4 EPITA Students, 84 | which is a French IT Engeenering School. 85 | This project is a part of the free schoolar project of the second year, and 86 | it's integrally written in C. If you want to know more about us, go to 87 | group presentation. 88 |

89 |
90 |
91 | 92 |
93 |
94 |
95 |
96 |

Get A2C

97 |

The latest A2C release is waiting for you!

98 |

Download

99 |
100 | 101 |
102 |

Read the docs

103 |

104 | We cover everything you need to know, from configuring A2C to how the internals are implemented. 105 |
106 | Our documentation is open source too, so you can help us improve it. 107 |

108 |

Learn more

109 | 110 |
111 | 112 |
113 |

Community

114 |

115 | As an open source project, we love getting contributions from the community. 116 |
117 | File a bug report, add new code or chat with the developers. 118 |

119 |

Contribute to A2C

120 |
121 |
122 |
123 |
124 | 125 | 126 |
127 |
128 | 129 |
130 |
131 |
132 |
133 | © 2015 A2C Project 134 |
135 | 138 |
139 |
140 | 141 | 142 | 143 |   144 | 145 | 146 | 147 |
148 |
149 |
150 |
151 | 152 | 153 | 154 | 155 | 156 | 157 | 173 | 174 | 175 | -------------------------------------------------------------------------------- /share/website/src/docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Documentation | A2C 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 |
23 | 56 |
57 | 58 |
59 |
60 | 68 | 69 | Table of contents 70 |
    71 |
    72 |
    73 |
    74 |
    75 |

    Documentation

    76 | 77 |
    78 | 79 | Edit page on GitHub 80 | 81 |
    82 |

    83 | 84 |
    85 | 86 |

    Our website is open source on GitHub. If you find errors or think a page could be improved, just click the “Edit page on GitHub” link beneath the page title.

    87 | 88 |
    89 | 90 |
    91 |
    92 |

    Getting Started

    93 |
    94 | 99 |
    100 |
    101 |
    102 | 103 |
    104 |

    About A2C

    105 |
    106 | 113 |
    114 |
    115 |
    116 | 117 |
    118 |

    Compiling A2c

    119 |
    120 | 124 |
    125 |
    126 |
    127 | 128 |
    129 |

    CDC & Presentations Reports

    130 |
    131 | 135 |
    136 |
    137 |
    138 | 139 |
    140 |

    Tools and Libraries

    141 |
    142 |
      143 | 144 |
    145 |
    146 |
    147 |
    148 | 149 |
    150 |

    The algo language

    151 |
    152 | 156 |
    157 |
    158 |
    159 | 160 |
    161 |

    FAQ

    162 |
    163 | 166 |
    167 |
    168 |
    169 | 170 |
    171 |
    172 | 173 | 209 | 210 | 211 |
    212 |
    213 | 214 |
    215 |
    216 |
    217 |
    218 | © 2015 A2C Project 219 |
    220 | 223 |
    224 |
    225 | 226 | 227 | 228 |   229 | 230 | 231 | 232 |
    233 |
    234 |
    235 |
    236 | 237 | 238 | 239 | 240 | 241 | 242 | 258 | 259 | 260 | 261 | 262 | -------------------------------------------------------------------------------- /src/lexer.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "lexer.h" 7 | #include "a2c.h" 8 | #include 9 | #include "error.h" 10 | 11 | static int curline = 1; 12 | static int curchar = 1; 13 | 14 | char nextnonblank() 15 | { 16 | char c; 17 | while (true) 18 | { 19 | switch (c = getc(fin)) 20 | { 21 | case ' ': 22 | case '\t': 23 | break; 24 | case '\n': 25 | curchar = 1; 26 | do ++curline; while ((c = getc(fin)) == '\n'); 27 | ungetc(c, fin); 28 | return '\n'; 29 | default: 30 | return c; 31 | } 32 | ++curchar; 33 | } 34 | } 35 | 36 | char *getalnumstr(void) 37 | { 38 | unsigned i = -1; 39 | size_t len = 8; 40 | char *str = malloc(len); 41 | 42 | do 43 | { 44 | ++i; 45 | str[i] = getc(fin); 46 | if (i + 1 >= len) 47 | { 48 | len *= 2; 49 | str = realloc(str, 2 * len); 50 | } 51 | } 52 | while (isalnum(str[i]) || str[i] == '\'' || str[i] == '_'); 53 | curchar += i; 54 | ungetc(str[i], fin); 55 | str[i] = '\0'; 56 | return str; 57 | } 58 | 59 | # define KEYWORDS_LEN 33 60 | 61 | static char* keywords[2][KEYWORDS_LEN] = { 62 | {"algorithme","debut","types","constantes","ou","oue","et","div","mod","non", 63 | "tant","que","faire","fin","retourne","pour","jusqu'a","decroissant","si","sinon","alors","selon", 64 | "autrement","procedure","variables","fonction","vrai","faux","parametres","locaux","globaux", 65 | "enregistrement","NUL" 66 | }, 67 | {"algorithm","begin","types","constants","or","xor","and","div","mod","not", 68 | "while","","do","end","return","for","to","downto","if","else","then","caseof", 69 | "default","procedure","variables","function","true","false","parameters","local","global", 70 | "record","NUL"}}; 71 | 72 | void getalnum(struct token *tok) 73 | { 74 | tok->val = getalnumstr(); 75 | 76 | if (strcmp(tok->val, keywords[current_lang][0]) == 0) 77 | tok->type = ALGORITHM; 78 | else if (strcmp(tok->val, keywords[current_lang][1]) == 0) 79 | tok->type = BEGIN; 80 | else if (strcmp(tok->val, keywords[current_lang][2]) == 0) 81 | tok->type = TYPES; 82 | else if (strcmp(tok->val, keywords[current_lang][3]) == 0) 83 | tok->type = CONST; 84 | else if (strcmp(tok->val, keywords[current_lang][4]) == 0) 85 | tok->type = OR; 86 | else if (strcmp(tok->val, keywords[current_lang][5]) == 0) 87 | tok->type = XOR; 88 | else if (strcmp(tok->val, keywords[current_lang][6]) == 0) 89 | tok->type = AND; 90 | else if (strcmp(tok->val, keywords[current_lang][7]) == 0) 91 | tok->type = DIV; 92 | else if (strcmp(tok->val, keywords[current_lang][8]) == 0) 93 | tok->type = MOD; 94 | else if (strcmp(tok->val, keywords[current_lang][9]) == 0) 95 | tok->type = NOT; 96 | else if (strcmp(tok->val, keywords[current_lang][10]) == 0) 97 | tok->type = WHILE; 98 | else if (strcmp(tok->val, keywords[current_lang][11]) == 0) 99 | tok->type = SO; 100 | else if (strcmp(tok->val, keywords[current_lang][12]) == 0) 101 | tok->type = DO; 102 | else if (strcmp(tok->val, keywords[current_lang][13]) == 0) 103 | tok->type = END; 104 | else if (strcmp(tok->val, keywords[current_lang][14]) == 0) 105 | tok->type = RETURN; 106 | else if (strcmp(tok->val, keywords[current_lang][15]) == 0) 107 | tok->type = FOR; 108 | else if (strcmp(tok->val, keywords[current_lang][16]) == 0) 109 | tok->type = UNTIL; 110 | else if (strcmp(tok->val, keywords[current_lang][17]) == 0) 111 | tok->type = DECREASING; 112 | else if (strcmp(tok->val, keywords[current_lang][18]) == 0) 113 | tok->type = IF; 114 | else if (strcmp(tok->val, keywords[current_lang][19]) == 0) 115 | tok->type = ELSE; 116 | else if (strcmp(tok->val, keywords[current_lang][20]) == 0) 117 | tok->type = THEN; 118 | else if (strcmp(tok->val, keywords[current_lang][21]) == 0) 119 | tok->type = SWITCH; 120 | else if (strcmp(tok->val, keywords[current_lang][22]) == 0) 121 | tok->type = OTHERWISE; 122 | else if (strcmp(tok->val, keywords[current_lang][23]) == 0) 123 | tok->type = PROCEDURE; 124 | else if (strcmp(tok->val, keywords[current_lang][24]) == 0) 125 | tok->type = VARIABLES; 126 | else if (strcmp(tok->val, keywords[current_lang][25]) == 0) 127 | tok->type = FUNCTION; 128 | else if (strcmp(tok->val, keywords[current_lang][26]) == 0) 129 | tok->type = TRUE; 130 | else if (strcmp(tok->val, keywords[current_lang][27]) == 0) 131 | tok->type = FALSE; 132 | else if (strcmp(tok->val, keywords[current_lang][28]) == 0) 133 | tok->type = PARAM; 134 | else if (strcmp(tok->val, keywords[current_lang][29]) == 0) 135 | tok->type = LOCAL; 136 | else if (strcmp(tok->val, keywords[current_lang][30]) == 0) 137 | tok->type = GLOBAL; 138 | else if (strcmp(tok->val, keywords[current_lang][31]) == 0) 139 | tok->type = RECORD; 140 | else if (strcmp(tok->val, keywords[current_lang][32]) == 0) 141 | tok->type = NULLKW; 142 | else 143 | tok->type = IDENTIFIER; 144 | } 145 | 146 | void getnum(struct token *tok) 147 | { 148 | tok->type = INT; 149 | unsigned i = -1; 150 | size_t len = 4; 151 | tok->val = malloc(len); 152 | do 153 | { 154 | ++i; 155 | ++curchar; 156 | tok->val[i] = getc(fin); 157 | if (tok->val[i] == '.') 158 | tok->type = REAL; 159 | if (i + 1 >= len) 160 | tok->val = realloc(tok->val, 2 * len); 161 | } 162 | while (isdigit(tok->val[i]) || tok->val[i] == '.'); 163 | ungetc(tok->val[i], fin); 164 | --curchar; 165 | tok->val[i] = '\0'; 166 | } 167 | 168 | void getop(struct token *tok) 169 | { 170 | char c = getc(fin); 171 | ++curchar; 172 | tok->val = calloc(3, sizeof(char)); 173 | tok->val[0] = c; 174 | char lookahead; 175 | switch (c) 176 | { 177 | case '+': tok->type = PLUS; break; 178 | case '-': tok->type = MINUS; break; 179 | case '*': tok->type = STAR; break; 180 | case '=': tok->type = EQ; break; 181 | case '(': tok->type = LPAREN; break; 182 | case ')': tok->type = RPAREN; break; 183 | case ',': tok->type = COMMA; break; 184 | case '^': tok->type = DEREF; break; 185 | case '[': tok->type = LSQBRACKET; break; 186 | case ']': tok->type = RSQBRACKET; break; 187 | case ':': tok->type = COLON; break; 188 | case '.': tok->type = DOT; break; 189 | case '/': 190 | ++curchar; 191 | lookahead = getc(fin); 192 | tok->val[1] = lookahead; 193 | if (lookahead == '*') 194 | { 195 | lookahead = getc(fin); 196 | ++curchar; 197 | do 198 | { 199 | while (lookahead != '*') 200 | { 201 | lookahead = getc(fin); 202 | if (lookahead == '\n') 203 | { 204 | curchar = 1; 205 | ++curline; 206 | } 207 | ++curchar; 208 | } 209 | lookahead = getc(fin); 210 | ++curchar; 211 | } while (lookahead != '/'); 212 | *tok = *gettok(); 213 | break; 214 | } 215 | else 216 | { 217 | tok->val[1] = '\0'; 218 | tok->type = SLASH; 219 | ungetc(lookahead, fin); 220 | --curchar; 221 | break; 222 | } 223 | case '<': 224 | ++curchar; 225 | lookahead = getc(fin); 226 | tok->val[1] = lookahead; 227 | switch (lookahead) 228 | { 229 | case '-': tok->type = ASSIGN; break; 230 | case '=': tok->type = LE; break; 231 | case '>': tok->type = NEQ; break; 232 | default: 233 | tok->val[1] = '\0'; 234 | tok->type = LT; 235 | ungetc(lookahead, fin); 236 | --curchar; 237 | break; 238 | } 239 | break; 240 | case '>': 241 | ++curchar; 242 | lookahead = getc(fin); 243 | tok->val[1] = lookahead; 244 | switch (lookahead = getc(fin)) 245 | { 246 | case '=': tok->type = GE; break; 247 | default: 248 | tok->type = GT; 249 | ungetc(lookahead, fin); 250 | --curchar; 251 | break; 252 | } 253 | break; 254 | default: 255 | tok->type = UNRECOGNIZED; 256 | break; 257 | } 258 | } 259 | 260 | void getstring(struct token *tok) 261 | { 262 | tok->type = STRING; 263 | ++curchar; 264 | char c = getc(fin); 265 | assert(c == '"'); 266 | unsigned i = -1; 267 | size_t len = 8; 268 | tok->val = malloc(len); 269 | do 270 | { 271 | ++i; 272 | ++curchar; 273 | tok->val[i] = getc(fin); 274 | if (i + 1 >= len) 275 | tok->val = realloc(tok->val, 2 * len); 276 | } 277 | while (tok->val[i] != '"'); 278 | tok->val[i] = '\0'; 279 | } 280 | 281 | struct token *gettok() 282 | { 283 | struct token *tok = malloc(sizeof(struct token)); 284 | tok->pos = malloc(sizeof(struct pos)); 285 | char c = nextnonblank(); 286 | tok->pos->line = curline; 287 | tok->pos->charstart = curchar; 288 | if (c != '\n') 289 | ungetc(c, fin); 290 | if (isdigit(c)) 291 | getnum(tok); 292 | else if (isalnum(c)) 293 | getalnum(tok); 294 | else if (c == '\'') 295 | { 296 | getc(fin); 297 | c = getc(fin); 298 | tok->type = CHAR; 299 | tok->val = malloc(3); 300 | tok->val[0] = tok->val[2] = '\''; 301 | tok->val[1] = c; 302 | c = getc(fin); 303 | if (c != '\'') 304 | { 305 | tok->pos->len = 2; 306 | error(*tok->pos, "missing ' to end character"); 307 | } 308 | } 309 | else if (c == '\"') 310 | getstring(tok); 311 | else if (c == EOF) 312 | { 313 | tok->type = ENDOFFILE; 314 | tok->val = "EOF"; 315 | } 316 | else if (c == '\n') 317 | { 318 | tok->type = EOL; 319 | tok->val = "EOL"; 320 | } 321 | else 322 | getop(tok); 323 | tok->pos->len = curchar - tok->pos->charstart; 324 | return tok; 325 | } 326 | 327 | void freetok(struct token *tok) 328 | { 329 | if (tok->type != EOL && tok->type != ENDOFFILE) 330 | free(tok->val); 331 | free(tok->pos); 332 | free(tok); 333 | } 334 | 335 | char *describe(enum tokentype toktype) 336 | { 337 | switch (toktype) 338 | { 339 | case ALGORITHM: return keywords[current_lang][0]; 340 | case AND: return keywords[current_lang][6]; 341 | case ASSIGN: return "<-"; 342 | case BEGIN: return keywords[current_lang][1]; 343 | case CHAR: return "char"; 344 | case COLON: return ":"; 345 | case COMMA: return ","; 346 | case CONST: return keywords[current_lang][3]; 347 | case DECREASING: return keywords[current_lang][17]; 348 | case DEREF: return ""; 349 | case DIV: return keywords[current_lang][7]; 350 | case DO: return keywords[current_lang][12]; 351 | case ELSE: return keywords[current_lang][19]; 352 | case END: return keywords[current_lang][13]; 353 | case ENDOFFILE: return "EOF"; 354 | case EOL: return "EOL"; 355 | case EQ: return "="; 356 | case FALSE: return keywords[current_lang][27]; 357 | case FOR: return keywords[current_lang][15]; 358 | case FUNCTION: return keywords[current_lang][25]; 359 | case GE: return ">="; 360 | case GLOBAL: return keywords[current_lang][30]; 361 | case GT: return ">"; 362 | case IDENTIFIER: return "identifier"; 363 | case IF: return keywords[current_lang][18]; 364 | case INT: return "int"; 365 | case LE: return "<"; 366 | case LOCAL: return keywords[current_lang][29]; 367 | case LPAREN: return "("; 368 | case LSQBRACKET: return "["; 369 | case LT: return "<"; 370 | case MINUS: return "-"; 371 | case MOD: return "mod"; 372 | case NEQ: return "<>"; 373 | case NOT: return keywords[current_lang][9]; 374 | case NULLKW: return keywords[current_lang][32]; 375 | case OR: return keywords[current_lang][4]; 376 | case OTHERWISE: return keywords[current_lang][19]; 377 | case PARAM: return keywords[current_lang][28]; 378 | case PLUS: return "+"; 379 | case PROCEDURE: return keywords[current_lang][23]; 380 | case REAL: return "real"; 381 | case RECORD: return keywords[current_lang][31]; 382 | case RETURN: return keywords[current_lang][14]; 383 | case RPAREN: return ")"; 384 | case RSQBRACKET: return "]"; 385 | case SLASH: return "/"; 386 | case SO: return keywords[current_lang][11]; 387 | case STAR: return "*"; 388 | case STRING: return "string"; 389 | case SWITCH: return keywords[current_lang][21]; 390 | case THEN: return keywords[current_lang][20]; 391 | case TRUE: return "vrai"; 392 | case TYPES: return keywords[current_lang][2]; 393 | case UMINUS: return "-"; 394 | case UNTIL: return keywords[current_lang][16]; 395 | case VARIABLES: return keywords[current_lang][24]; 396 | case WHILE: return keywords[current_lang][10]; 397 | case X: return "x"; 398 | case XOR: return keywords[current_lang][5]; 399 | default: return ""; 400 | } 401 | } 402 | -------------------------------------------------------------------------------- /src/parser.y: -------------------------------------------------------------------------------- 1 | %debug 2 | %error-verbose 3 | %define api.pure full 4 | 5 | %destructor {; free($$); } 6 | 7 | %code top 8 | { 9 | #include 10 | #include 11 | #include 12 | 13 | extern struct prog *prog; 14 | extern FILE *yyin; 15 | extern int syntax_error; 16 | int yylineno; 17 | char *srcfilename; 18 | } 19 | 20 | 21 | %code requires 22 | { 23 | #include "grammar.h" 24 | extern FILE *yyin; 25 | } 26 | 27 | %code provides 28 | { 29 | #define YY_DECL enum yytokentype yylex(YYSTYPE *yylval) 30 | YY_DECL; 31 | void yyerror (const char* msg); 32 | char* get_line(FILE *f, int line); 33 | } 34 | 35 | %union 36 | { 37 | struct expr *expression; 38 | struct instruction *instruction; 39 | instructionlist_t instructions; 40 | caseblocklist_t caseblocklist; 41 | struct algo *algo; 42 | exprlist_t exprlist; 43 | identlist_t identlist; 44 | struct single_var_decl *single_var_decl; 45 | vardecllist_t var_decl; 46 | struct declarations *decls; 47 | struct assignment *assignment; 48 | struct entry_point *entry_point; 49 | struct prog *prog; 50 | struct local_param *lp; 51 | struct global_param *gp; 52 | struct param_decl *param_decl; 53 | struct const_decl *const_decl; 54 | struct type_decl *type_decl; 55 | struct type_def *type_def; 56 | struct enum_def *enum_def; 57 | struct val *val; 58 | constdecllist_t const_decls; 59 | typedecllist_t type_decls; 60 | intlist_t intlist; 61 | algolist_t algolist; 62 | char *str; 63 | int integer; 64 | }; 65 | 66 | %type algo 67 | %type fun 68 | %type proc 69 | %type algolist 70 | %type assign 71 | %type const_decls 72 | %type const_decl_list 73 | %type const_decl 74 | %type caseblocklist 75 | %type decls 76 | %type entry_point 77 | %type exp 78 | %type explist nonempty_explist 79 | %type gp_decl 80 | %type identlist 81 | %type instruction 82 | %type instructions 83 | %type dims 84 | %type lp_decl 85 | %type param_decl 86 | %type prog 87 | %type single_var_decl 88 | %type type_decl 89 | %type type_decl_list 90 | %type type_decls 91 | %type array_def 92 | %type enum_def 93 | %type pointer_def 94 | %type record_def 95 | %type type_def 96 | %type val 97 | %type var_decl var_decl2 98 | 99 | /* ################# */ 100 | /* TOKEN DECLARATION */ 101 | /* ################# */ 102 | 103 | %token ALGORITHM "algorithme" 104 | %token PROCEDURE "procedure" 105 | %token FUNCTION "fonction" 106 | %token RETURN "retourne" 107 | %token START "debut" 108 | %token END "fin" 109 | %token ASLONG AS DO 110 | %token FOR 111 | %token DECREASING 112 | %token UPTO 113 | %token IF 114 | %token THEN 115 | %token ELSE 116 | %token SWITCH 117 | %token COLON ":" 118 | %token DEREF "^" 119 | %token PARAMETERS "parametres" 120 | %token LOCAL "locaux" 121 | %token GLOBAL "globaux" 122 | %token IDENT 123 | %token STRING 124 | %token VARIABLES "variables" 125 | %token TYPES "types" 126 | %token CROSS "x" 127 | %token RECORD "enregistrement" 128 | %token CHAR 129 | %token CONST "constantes" 130 | %token OTHERWISE 131 | 132 | /* operators */ 133 | %token PLUS "+" MINUS "-" 134 | STAR "*" SLASH "/" 135 | DIV "div" 136 | MOD "mod" 137 | LT "<" LE "<=" 138 | GT ">" GE ">=" 139 | EQ "=" NEQ "<>" 140 | LPAREN "(" RPAREN ")" 141 | LBRACKET "[" RBRACKET "]" 142 | EOL "\n" 143 | %token AND "et" OR "ou" XOR "oue" 144 | NO "non" 145 | %token ASSIGN "<-" 146 | %token COMMA "," 147 | %token _EOL 148 | %token _EOF 0 149 | 150 | /* expressions */ 151 | %token INT 152 | %token REAL 153 | %token TRUE 154 | %token FALSE 155 | 156 | /* priority */ 157 | %right ASSIGN 158 | %precedence IDENT WHILE ":" 159 | %left "=" "<>" 160 | %left "<" ">" "<=" ">=" 161 | %left PLUS MINUS OR XOR 162 | %left STAR SLASH DIV AND MOD 163 | %right NO "^" 164 | %precedence "[" "]" "(" ")" 165 | 166 | %% 167 | 168 | prog: 169 | algolist 170 | entry_point _EOL { prog = make_prog($1, $2); } 171 | 172 | entry_point: 173 | var_decl 174 | "debut" _EOL 175 | instructions 176 | "fin" { $$ = make_entry_point($1, $4); } 177 | 178 | algolist: 179 | { $$ = empty_algolist(); } 180 | | algolist algo _EOL { $$ = $1; list_push_back($$, $2); } 181 | 182 | algo: 183 | proc | fun 184 | 185 | proc: 186 | "algorithme" "procedure" IDENT _EOL 187 | decls 188 | "debut" _EOL 189 | instructions 190 | "fin" "algorithme" "procedure" IDENT 191 | { $$ = algo($3, NULL, $5, $8); free($12); } 192 | /* NOTE: $12 will be needed for the semantic analysis phase but for now the 193 | free is here to prevent valgrind from reporting the error */ 194 | 195 | fun: 196 | "algorithme" "fonction" IDENT ":" IDENT _EOL 197 | decls 198 | "debut" _EOL 199 | instructions 200 | "fin" "algorithme" "fonction" IDENT 201 | { $$ = algo($3, $5, $7, $10); free($14); } 202 | 203 | decls: 204 | param_decl type_decls var_decl { $$ = make_declarations($1, empty_constdecllist(), $2, $3); } 205 | | param_decl var_decl type_decls { $$ = make_declarations($1, empty_constdecllist(), $3, $2); } 206 | | param_decl var_decl { $$ = make_declarations($1, empty_constdecllist(), empty_typedecllist(), $2); } 207 | | param_decl type_decls { $$ = make_declarations($1, empty_constdecllist(), $2, empty_vardecllist()); } 208 | | param_decl { $$ = make_declarations($1, empty_constdecllist(), empty_typedecllist(), empty_vardecllist()); } 209 | | param_decl const_decls type_decls var_decl { $$ = make_declarations($1, $2, $3, $4); } 210 | | param_decl type_decls const_decls var_decl { $$ = make_declarations($1, $3, $2, $4); } 211 | | param_decl type_decls var_decl const_decls { $$ = make_declarations($1, $4, $2, $3); } 212 | | param_decl const_decls var_decl type_decls { $$ = make_declarations($1, $2, $4, $3); } 213 | | param_decl var_decl const_decls type_decls { $$ = make_declarations($1, $3, $4, $2); } 214 | | param_decl var_decl type_decls const_decls { $$ = make_declarations($1, $4, $3, $2); } 215 | | param_decl const_decls var_decl { $$ = make_declarations($1, $2, empty_typedecllist(), $3); } 216 | | param_decl var_decl const_decls { $$ = make_declarations($1, $3, empty_typedecllist(), $2); } 217 | | param_decl const_decls type_decls { $$ = make_declarations($1, $2, $3, empty_vardecllist()); } 218 | | param_decl type_decls const_decls { $$ = make_declarations($1, $3, $2, empty_vardecllist()); } 219 | | param_decl const_decls { $$ = make_declarations($1, $2, empty_typedecllist(), empty_vardecllist()); } 220 | 221 | const_decls: 222 | "constantes" _EOL const_decl_list { $$ = $3; } 223 | 224 | const_decl_list: 225 | const_decl { $$ = empty_constdecllist(); list_push_back($$, $1); } 226 | | const_decl_list const_decl { $$ = $1; list_push_back($$, $2); } 227 | 228 | const_decl: 229 | IDENT IDENT "=" val _EOL { $$ = make_constdecl($1, $2, $4); } 230 | 231 | type_decls: 232 | "types" _EOL type_decl_list { $$ = $3; } 233 | 234 | type_decl_list: 235 | type_decl { $$ = empty_typedecllist(); list_push_back($$, $1); } 236 | | type_decl_list type_decl { $$ = $1; list_push_back($$, $2); } 237 | 238 | type_decl: 239 | IDENT "=" type_def _EOL { $$ = make_type_decl($1, $3); } 240 | 241 | type_def: 242 | enum_def { $$ = $1; } 243 | | array_def { $$ = $1; } 244 | | record_def { $$ = $1; } 245 | | pointer_def { $$ = $1; } 246 | 247 | enum_def: 248 | "(" identlist ")" { $$ = make_enum_def($2); } 249 | 250 | array_def: 251 | dims IDENT { $$ = make_array_def($1, $2); } 252 | 253 | record_def: 254 | "enregistrement" _EOL var_decl2 "fin" "enregistrement" IDENT { $$ = make_record($3, $6); } 255 | 256 | pointer_def: 257 | "^" IDENT { $$ = make_pointer_def($2); } 258 | 259 | dims: 260 | INT { $$ = empty_intlist(); list_push_back($$, $1); } 261 | | dims "x" INT { $$ = $1; list_push_back($$, $3); } 262 | 263 | param_decl: 264 | lp_decl gp_decl { $$ = make_param_decl(true, $1, $2); } 265 | | gp_decl lp_decl { $$ = make_param_decl(false, $2, $1); } 266 | | lp_decl { $$ = make_param_decl(true, $1, empty_vardecllist()); } 267 | | gp_decl { $$ = make_param_decl(true, empty_vardecllist(), $1); } 268 | | { $$ = make_param_decl(true, empty_vardecllist(), empty_vardecllist()); } 269 | 270 | lp_decl: 271 | "parametres" "locaux" _EOL 272 | var_decl2 { $$ = $4; } 273 | 274 | gp_decl: 275 | "parametres" "globaux" _EOL 276 | var_decl2 { $$ = $4; } 277 | 278 | var_decl: 279 | "variables" _EOL 280 | var_decl2 { $$ = $3; } 281 | 282 | var_decl2: 283 | { $$ = empty_var_decl(); } 284 | | var_decl2 single_var_decl { $$ = $1; list_push_back($$, $2); } 285 | 286 | single_var_decl: 287 | IDENT identlist _EOL { $$ = single_var_decl($1, $2); } 288 | 289 | caseblocklist: 290 | nonempty_explist ":" instructions { $$ = empty_caseblocklist(); list_push_front($$,make_block($1,$3));} 291 | | nonempty_explist ":" instructions caseblocklist {$$ = $4; list_push_front($$, make_block($1,$3));} 292 | 293 | identlist: 294 | IDENT { $$ = empty_identlist(); list_push_back($$, $1); } 295 | | identlist "," IDENT { $$ = $1; list_push_back($$, $3); } 296 | 297 | instructions: { list_init($$); } 298 | | instructions error 299 | | instructions instruction { list_push_back(($1), $2); $$ = $1; } 300 | 301 | 302 | 303 | 304 | instruction: 305 | assign _EOL { $$ = assigninstr($1); } 306 | | ASLONG AS exp DO _EOL 307 | instructions 308 | END ASLONG AS _EOL { $$ = whileblock($3, $6); } 309 | | DO _EOL 310 | instructions 311 | ASLONG AS exp _EOL { $$ = dowhileblock($3, $6); } 312 | | FOR assign UPTO exp DO _EOL 313 | instructions 314 | END FOR _EOL { $$ = forblock($2, $4, 0, $7); } 315 | | FOR assign UPTO exp DECREASING DO _EOL 316 | instructions 317 | END FOR _EOL { $$ = forblock($2, $4, 1, $8); } 318 | | IDENT "(" explist ")" _EOL { $$ = funcallinstr($1, $3); $$->lineno = yylineno; } 319 | | IF exp THEN _EOL 320 | instructions 321 | END IF _EOL { $$ = ifthenelseblock($2, $5, empty_instructionlist()); } 322 | | IF exp THEN _EOL 323 | instructions 324 | ELSE _EOL 325 | instructions 326 | END IF _EOL { $$ = ifthenelseblock($2, $5, $8); } 327 | | SWITCH exp DO _EOL 328 | caseblocklist 329 | END SWITCH _EOL { $$ = switchblock($2, $5, empty_instructionlist());} 330 | | SWITCH exp DO _EOL 331 | caseblocklist 332 | OTHERWISE instructions 333 | END SWITCH _EOL { $$ = switchblock($2, $5, $7);} 334 | | "retourne" exp _EOL { $$ = return_stmt($2); } 335 | | "retourne" _EOL { $$ = return_stmt(NULL); } 336 | 337 | assign: 338 | exp "<-" exp { $$ = assign($1, $3); } 339 | 340 | exp: 341 | val { $$ = expr_from_val($1); $$->lineno = yylineno; } 342 | | IDENT { $$ = identexpr($1); $$->lineno = yylineno; } 343 | | exp "+" exp { $$ = binopexpr($1, PLUS, $3); $$->lineno = $1->lineno; } 344 | | exp "-" exp { $$ = binopexpr($1, MINUS, $3); $$->lineno = $1->lineno; } 345 | | exp "ou" exp { $$ = binopexpr($1, OR, $3); $$->lineno = $1->lineno; } 346 | | exp "oue" exp { $$ = binopexpr($1, XOR, $3); $$->lineno = $1->lineno; } 347 | | exp "*" exp { $$ = binopexpr($1, STAR, $3); $$->lineno = $1->lineno; } 348 | | exp "/" exp { $$ = binopexpr($1, SLASH, $3); $$->lineno = $1->lineno; } 349 | | exp "div" exp { $$ = binopexpr($1, DIV, $3); $$->lineno = $1->lineno; } 350 | | exp "et" exp { $$ = binopexpr($1, AND, $3); $$->lineno = $1->lineno; } 351 | | exp "mod" exp { $$ = binopexpr($1, MOD, $3); $$->lineno = $1->lineno; } 352 | | exp "=" exp { $$ = binopexpr($1, EQ, $3); $$->lineno = $1->lineno; } 353 | | exp "<=" exp { $$ = binopexpr($1, LE, $3); $$->lineno = $1->lineno; } 354 | | exp ">=" exp { $$ = binopexpr($1, GE, $3); $$->lineno = $1->lineno; } 355 | | exp "<" exp { $$ = binopexpr($1, LT, $3); $$->lineno = $1->lineno; } 356 | | exp ">" exp { $$ = binopexpr($1, GT, $3); $$->lineno = $1->lineno; } 357 | | exp "<>" exp { $$ = binopexpr($1, NEQ, $3); $$->lineno = $1->lineno; } 358 | | "(" exp ")" { $$ = $2; $$->lineno = $2->lineno; } 359 | | "non" exp { $$ = unopexpr(NO, $2); $$->lineno = $2->lineno; } 360 | | "+" exp { $$ = $2; $$->lineno = $2->lineno; } 361 | | "-" exp { $$ = unopexpr(MINUS, $2); $$->lineno = $2->lineno; } 362 | | IDENT "(" explist ")" { $$ = funcallexpr($1, $3); $$->lineno = yylineno; } 363 | | "^" exp { $$ = derefexpr($2); $$->lineno = $2->lineno; } 364 | | exp "[" nonempty_explist "]" { $$ = arrayexpr($1, $3); $$->lineno = $1->lineno; } 365 | 366 | explist: 367 | { $$ = empty_exprlist(); } 368 | | nonempty_explist { $$ = $1; } 369 | 370 | val: 371 | INT { $$ = intval($1); } 372 | | REAL { $$ = $1; } 373 | | STRING { $$ = strval($1); } 374 | | TRUE { $$ = boolval(true); } 375 | | FALSE { $$ = boolval(false); } 376 | | CHAR { $$ = $1; } 377 | 378 | nonempty_explist: 379 | exp { $$ = empty_exprlist(); list_push_back($$, $1); } 380 | | explist "," exp { $$ = $1; list_push_back($$, $3); } 381 | 382 | %% 383 | 384 | void 385 | yyerror (const char* msg) 386 | { 387 | syntax_error = 1; 388 | fprintf (stderr, "%s:%d: %s\n", srcfilename ,yylineno, msg); 389 | } 390 | 391 | 392 | 393 | -------------------------------------------------------------------------------- /share/website/src/news/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | News | A2C 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 |
    22 |
    23 | 56 |
    57 | 58 |
    59 |
    60 |
    61 |
    62 | 81 |
    82 | 83 |

    84 |
    85 | 86 | 87 | Lucien Boillod 88 | 89 | 90 | 91 | 92 | 93 | releases 94 | 95 |
    96 |
    97 |

    We are happy to introduce you the first release of the project. It is now stable and support every Algo langage features.

    98 |
    99 |
    100 |
    101 | 102 |

    103 |
    104 | 105 | 106 | Lucien Boillod 107 | 108 | 109 | 110 | 111 | 112 | releases 113 | 114 |
    115 |
    116 |

    Project is now over 200 commits. We are proud to say we are almost at stable version of it.

    117 |
    118 |
    119 |
    120 | 121 |

    122 |
    123 | 124 | 125 | Lucien Boillod 126 | 127 | 128 | 129 | 130 | 131 | releases 132 | 133 |
    134 |
    135 |

    New Parser has been created, we do not use Bison and Flex anymore.

    136 |
    137 |
    138 |
    139 | 140 |

    141 |
    142 | 143 | 144 | Lucien Boillod 145 | 146 | 147 | 148 | 149 | 150 | releases 151 | 152 |
    153 |
    154 |

    We are again the best grade of the promotion !

    155 |
    156 |
    157 |
    158 | 159 |

    160 |
    161 | 162 | 163 | Lucien Boillod 164 | 165 | 166 | 167 | 168 | 169 | releases 170 | 171 |
    172 |
    173 |

    There has been a lot of improvements in A2C

    174 |

    The second presentation is soon !

    175 |
    176 |
    177 |
    178 | 179 |

    180 |
    181 | 182 | 183 | Lucien Boillod 184 | 185 | 186 | 187 | 188 | 189 | releases 190 | 191 |
    192 |
    193 |

    There has been a lot of improvements in A2C

    194 |

    The second presentation is soon !

    195 |
    196 |
    197 |
    198 | 199 |

    200 |
    201 | 202 | 203 | Lucien Boillod 204 | 205 | 206 | 207 | 208 | 209 | releases 210 | 211 |
    212 |
    213 |

    We are Top of the Year !! A2C has the best grade of the promotion !

    214 |
    215 |
    216 | 217 |
    218 | 219 |

    220 |
    221 | 222 | 223 | Lucien Boillod 224 | 225 | 226 | 227 | 228 | 229 | releases pdf 230 | 231 |
    232 |
    233 |

    This is the project for the jury presentation 1. The A2C 0.0.1 has been released

    234 | 235 |

    A2C now work for a mini algo language.

    236 |

    You can get the report here

    237 |
    238 |
    239 |
    240 | 241 |

    242 |
    243 | 244 | 245 | Lucien Boillod 246 | 247 | 248 | 249 | 250 | 251 | releases 252 | 253 |
    254 |
    255 |

    We are happy to introduce A2C!

    256 | 257 |

    The project has now over 20 commits. See on Github

    258 | 259 |
    260 |
    261 |
    262 | 263 |

    264 |
    265 | 266 | 267 | Lucien Boillod 268 | 269 | 270 | 271 | 272 | 273 | pdf 274 | 275 |
    276 |
    277 |

    Here are the specifications of the project "Cahier des Charges"

    278 | 279 |
    280 |
    281 |
    282 | 283 |

    284 |
    285 | 286 | 287 | Lucien Boillod 288 | 289 | 290 | 291 | 292 | 293 | pdf 294 | 295 |
    296 |
    297 |

    Here is a presentation of the Project. See the pdf

    298 | 299 |
    300 |
    301 | 302 |
    303 | 304 |
    305 | 306 |
    307 |
    308 | 309 | 310 |
    311 |
    312 | 313 |
    314 |
    315 |
    316 |
    317 | © 2015 A2C Project 318 |
    319 | 322 |
    323 |
    324 | 325 | 326 | 327 |   328 | 329 | 330 | 331 |
    332 |
    333 |
    334 |
    335 | 336 | 337 | 338 | 339 | 340 | 341 | 357 | 358 | 359 | 360 | 361 | --------------------------------------------------------------------------------