diff --git a/src/fichiersRat/src-rat-tam-test/struct1.rat b/src/fichiersRat/src-rat-tam-test/struct1.rat index e69de29..de4be1c 100644 --- a/src/fichiersRat/src-rat-tam-test/struct1.rat +++ b/src/fichiersRat/src-rat-tam-test/struct1.rat @@ -0,0 +1,5 @@ +main{ + typedef Point = struct { int x int y }; + Point p = {1 2} + print (p.x); +} diff --git a/src/parser.mly b/src/parser.mly index 0ea32c2..cb9f1d8 100644 --- a/src/parser.mly +++ b/src/parser.mly @@ -63,7 +63,6 @@ main : lfi=prog EOF {lfi} prog : | ltd=td lf=fonc lfi=prog {let (Programme (_, lf1, li))=lfi in (Programme (ltd, lf::lf1,li))} -(* | lf=fonc lfi=prog {let (Programme ( lf1, li))=lfi in (Programme ( lf::lf1,li))} *) | ID li=bloc {Programme ([], [], li)} td : @@ -76,8 +75,8 @@ fonc : bloc : AO li = is AF {li} is : -| {[]} -| i1=i li=is {i1::li} +| {[]} +| i1=i li=is {i1::li} i : | t=typ n=ID EQUAL exp=e PV {Declaration (t,n,exp)} @@ -92,15 +91,15 @@ i : | TYPEDEF tid=TID EQUAL type1=typ PV {LocalTypeDef (TypeDef(tid, type1))} dp : -| {[]} -| t=typ n=ID lp=dp {(t,n)::lp} +| {[]} +| t=typ n=ID lp=dp {(t,n)::lp} typ : -| BOOL {Bool} -| INT {Int} -| RAT {Rat} -| t1=typ MULT {Pointeur (t1)} -| t1=TID {TIdent (t1)} +| BOOL {Bool} +| INT {Int} +| RAT {Rat} +| t1=typ MULT {Pointeur (t1)} +| t1=TID {TIdent (t1)} | STRUCT AO p=dp AF {Struct (p)} e : diff --git a/src/passeCodeRatToTam.ml b/src/passeCodeRatToTam.ml index 785dd68..e385e04 100644 --- a/src/passeCodeRatToTam.ml +++ b/src/passeCodeRatToTam.ml @@ -98,9 +98,13 @@ and analyse_code_instruction i taille_return taille_args taille_var = end | Dref(a, t) -> - (analyse_code_expression e) ^ - (analyse_code_affectable a) ^ - "STOREI (" ^ string_of_int (getTaille t) ^ ")\n" + (analyse_code_expression e) ^ + (analyse_code_affectable a) ^ + "STOREI (" ^ string_of_int (getTaille t) ^ ")\n" + + | Attribut(aff, info) -> + (analyse_code_affectable a) + (* TODO *) end diff --git a/src/testTam.ml b/src/testTam.ml index a0f2437..66d8911 100644 --- a/src/testTam.ml +++ b/src/testTam.ml @@ -134,4 +134,8 @@ let%expect_test "typedef1" = let%expect_test "typedef2" = runtam "../../fichiersRat/src-rat-tam-test/typedef2.rat"; - [%expect{| 2 |}] \ No newline at end of file + [%expect{| 2 |}] + +let%expect_test "struct1" = + runtam "../../fichiersRat/src-rat-tam-test/struct1.rat"; + [%expect{| 1 |}] \ No newline at end of file