Skip to content

Commit 3e2e937

Browse files
author
Charlotte Thomas
committed
Merge branch 'master' of github.com:coco33920/ocaml-baguettesharp-interpreter
2 parents 918e717 + 71f166e commit 3e2e937

File tree

8 files changed

+197
-1
lines changed

8 files changed

+197
-1
lines changed

examples/conditions.baguette

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ CROISSANT CHOUQUETTE FLAN CHOUQUETTE CUPCAKE POPCAKE CLAFOUTIS CLAFOUTIS BAGUETT
1414
CROISSANT CHOUQUETTE PAINDEPICE CHOUQUETTE CUPCAKE CUPCAKE CLAFOUTIS CLAFOUTIS BAGUETTE
1515
//FALSE
1616
CROISSANT CHOUQUETTE CREPE CHOUQUETTE CUPCAKE CUPCAKE CLAFOUTIS CLAFOUTIS BAGUETTE
17-
//FALSE
17+
//TRUE
1818
CROISSANT CHOUQUETTE CREPE CHOUQUETTE CUPCAKE POPCAKE CLAFOUTIS CLAFOUTIS BAGUETTE

examples/emoji_condition.baguette

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//FALSE
2+
🥐 🧅 🥮🍵🍫 🧅 5 4 🧄 🧄 🥖
3+
//TRUE
4+
🥐 🧅 🥚 🧅 8 8 🧄 🧄 🥖
5+
//FALSE
6+
🥐 🧅 🎂🍋 🧅 8 8 🧄 🧄 🥖
7+
//TRUE
8+
🥐 🧅 🍞🥐 🧅 10 5 🧄 🧄 🥖
9+
//FALSE
10+
🥐 🧅 🥧 🧅 10 10 🧄 🧄 🥖
11+
//FALSE
12+
🥐 🧅 🎂🥚 🧅 🧁 🎂 🧄 🧄 🥖
13+
//TRUE
14+
🥐 🧅 🍞🌶️ 🧅 🧁 🧁 🧄 🧄 🥖
15+
//FALSE
16+
🥐 🧅 🍞🥚 🧅 🧁 🧁 🧄 🧄 🥖
17+
//TRUE
18+
🥐 🧅 🍞🥚 🧅 🧁 🎂 🧄 🧄 🥖
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
🥐 🧅 🍉 Hello, World ! 🍉 🧄 🥖

examples/emoji_math.baguette

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Addition a+b
2+
🥐 🧅 🧁🍷 🧅 2 , 3 , 12 , 20 🧄 🧄 🥖
3+
// Subtraction a-b
4+
🥐 🧅 🍞🍇 🧅 2 , 2 🧄 🧄 🥖
5+
// Division a/b
6+
🥐 🧅 🥐🍫 🧅 2 , 2 🧄 🧄 🥖
7+
// Random [[a,b]]
8+
🥐 🧅 🥨 🧅 2 , 10 🧄 🧄 🥖
9+
// Power a^b
10+
🥐 🧅 🎂🧈 🧅 2 , 3 🧄 🧄 🥖
11+
// Logarithm a base b
12+
🥐 🧅 🥮🖼️ 🧅 1000 , 10 🧄 🧄 🥖
13+
// n-ième nombre de fibonnacci
14+
🥐 🧅 🧁💰 🧅 10 🧄 🧄 🥖
15+
// Racine carré
16+
🥐 🧅 🧁🍫 🧅 16 🧄 🧄 🥖

examples/emoji_read.baguette

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
🥐 🧅 🥐🍫 🧅 🧄 🧄 🥖

examples/emoji_turing.baguette

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
//Program reading subroutine, the input line must like STATE-TAPESTATE-TOWRITE-DIRECTION-NEWSTATE (0-1-0-r-0 :
2+
//when the machine is in state 0 and reads 1 in the tape it writes 0, move the head to the write and stay in the state 0
3+
🍨 🍉 program_read 🍉
4+
🥮
5+
🌰 🧅 🍉 line 🍉 , ⛈️🍫 🧅 0 🧄 🧄
6+
🌰 🧅 🍉 rline 🍉 , 🧇 🧅 🧈 🧅 🍉 line 🍉 🧄 🍉 - 🍉 🧄 🧄
7+
🌰 🧅 🍉 temp_state 🍉 🎂🥕 🧅 🥧🍓 🧅 0 , 🧈 🧅 🍉 rline 🍉 🧄 🧄 🧄 🧄
8+
🌰 🧅 🍉 tapestate 🍉 🎂🥕 🧅 🥧🍓 🧅 1 , 🧈 🧅 🍉 rline 🍉 🧄 🧄 🧄 🧄
9+
🌰 🧅 🍉 towrite 🍉 🎂🥕 🧅 🥧🍓 🧅 2 , 🧈 🧅 🍉 rline 🍉 🧄 🧄 🧄 🧄
10+
🌰 🧅 🍉 direction 🍉 🥧🍓 🧅 3 , 🧈 🧅 🍉 rline 🍉 🧄 🧄 🧄
11+
🌰 🧅 🍉 newstate 🍉 🥧🍓 🧅 4 , 🧈 🧅 🍉 rline 🍉 🧄 🧄 🧄
12+
13+
🥧🫐 🧅 🧈 🧅 🍉 tapestate 🍉 🧄 , 🥧🍓 🧅 🧈 🧅 🍉 temp_state 🍉 🧄 🧈 🧅 🍉 delta0 🍉 🧄 🧄 🧈 🧅 🍉 towrite 🍉 🧄 🧄
14+
🥧🫐 🧅 🧈 🧅 🍉 tapestate 🍉 🧄 , 🥧🍓 🧅 🧈 🧅 🍉 temp_state 🍉 🧄 🧈 🧅 🍉 delta1 🍉 🧄 🧄 🧈 🧅 🍉 direction 🍉 🧄 🧄
15+
🥧🫐 🧅 🧈 🧅 🍉 tapestate 🍉 🧄 , 🥧🍓 🧅 🧈 🧅 🍉 temp_state 🍉 🧄 🧈 🧅 🍉 delta2 🍉 🧄 🧄 🧈 🧅 🍉 newstate 🍉 🧄 🧄
16+
17+
🌰 🧅 🍉 i 🍉 , 🧁🍷 🧅 1 , 🧈 🧅 🍉 i 🍉 🧄 🧄 🧄
18+
19+
🥠 🎂🍋 🧅 🧈 🧅 🍉 i 🍉 🧄 , 🧈 🧅 🍉 n 🍉 🧄 🧄
20+
🍰 🥮
21+
🍞 🍉 program_read 🍉
22+
🍪 🥖
23+
🍪 🥖
24+
25+
//Step subroutine, updates the tape, head position and state of the machine
26+
🍨 🍉 step 🍉
27+
🥮
28+
🥠 🍞🍎 🧅 🥮🍵🍫 🧅 🧈 🧅 🍉 state 🍉 🧄 , 🍉 H 🍉 🧄 🧄
29+
🍰 🥮
30+
🌰 🧅 🍉 current_tapestate 🍉 , 🎂🥕 🧅 🧇🇧🇪 🧅 🧈 🧅 🍉 head 🍉 🧄 , 🧈 🧅 🍉 tape 🍉 🧄 🧄 🧄 🧄
31+
🌰 🧅 🍉 current0 🍉 , 🥧🍓 🧅 🎂🥕 🧅 🧈 🧅 🍉 state 🍉 🧄 🧄 🧈 🧅 🍉 delta0 🍉 🧄 🧄 🧄
32+
🌰 🧅 🍉 current1 🍉 , 🥧🍓 🧅 🎂🥕 🧅 🧈 🧅 🍉 state 🍉 🧄 🧄 🧈 🧅 🍉 delta1 🍉 🧄 🧄 🧄
33+
🌰 🧅 🍉 current2 🍉 , 🥧🍓 🧅 🎂🥕 🧅 🧈 🧅 🍉 state 🍉 🧄 🧄 🧈 🧅 🍉 delta2 🍉 🧄 🧄 🧄
34+
35+
🌰 🧅 🍉 towrite_steptemp 🍉 , 🥧🍓 🧅 🧈 🧅 🍉 current_tapestate 🍉 🧄 , 🧈 🧅 🍉 current0 🍉 🧄 🧄 🧄
36+
🌰 🧅 🍉 direction_steptemp 🍉 , 🥧🍓 🧅 🧈 🧅 🍉 current_tapestate 🍉 🧄 , 🧈 🧅 🍉 current1 🍉 🧄 🧄 🧄
37+
🌰 🧅 🍉 newstate_steptemp 🍉 , 🥧🍓 🧅 🧈 🧅 🍉 current_tapestate 🍉 🧄 , 🧈 🧅 🍉 current2 🍉 🧄 🧄 🧄
38+
39+
🌰 🧅 🍉 arr_tape 🍉 , 🥞 🧅 🧈 🧅 🍉 tape 🍉 🧄 🧄 🧄
40+
🥧🫐 🧅 🧈 🧅 🍉 head 🍉 🧄 , 🧈 🧅 🍉 arr_tape 🍉 🧄 , 🥯 🧅 🧈 🧅 🍉 towrite_steptemp 🍉 🧄 🧄 🧄
41+
🌰 🧅 🍉 tape 🍉 , 🇨🇦🍁 🧅 🧈 🧅 🍉 arr_tape 🍉 🧄 🧄 🧄
42+
🌰 🧅 🍉 state 🍉 , 🧈 🧅 🍉 newstate_steptemp 🍉 🧄 🧄
43+
44+
🌰 🧅 🍉 head 🍉 , 🧁🍷 🧅 -1 , 🧈 🧅 🍉 head 🍉 🧄 🧄 🧄
45+
🍞🍫 🧅 🍉 Step (tape,state): (%d,%d) 🍉 , 🍩 🧅 🧈 🧅 🍉 tape 🍉 🧄 , 🍉 2 🍉 , 🍉 🍉 🧄 , 🧈 🧅 🍉 state 🍉 🧄 🧄
46+
47+
🥠 🥮🍵🍫 🧅 🧈 🧅 🍉 direction_steptemp 🍉 🧄 , 🍉 * 🍉 🧄
48+
🍰 🥮
49+
🌰 🧅 🍉 head 🍉 , 🧁🍷 🧅 1 , 🧈 🧅 🍉 head 🍉 🧄 🧄 🧄
50+
🍪
51+
🥠 🥮🍵🍫 🧅 🧈 🧅 🍉 direction_steptemp 🍉 🧄 , 🍉 r 🍉 🧄
52+
🍰 🥮
53+
🌰 🧅 🍉 head 🍉 , 🧁🍷 🧅 2 , 🧈 🧅 🍉 head 🍉 🧄 🧄 🧄
54+
🍪 🥖
55+
🍪 🥖
56+
🍪 🥖
57+
58+
🍨 🍉 run 🍉
59+
🥮
60+
🍞 🍉 step 🍉
61+
🥠 🍞🍎 🧅 🥮🍵🍫 🧅 🧈 🧅 🍉 state 🍉 🧄 , 🍉 H 🍉 🧄 🧄
62+
🍰 🥮
63+
🍞 🍉 run 🍉
64+
🍪 🥖
65+
🍪 🥖
66+
67+
68+
//Turing machine initialization
69+
//Creation of three 100 by 3 matrices to represent the transition function
70+
//Declaraton of the initial state and the tape with the head at the first bit of the input
71+
🌰 🧅 🍉 state 🍉 , 🍉 0 🍉 🧄 🥖
72+
🥐 🧅 🍉 Please type the input tape 🍉 🧄 🥖
73+
🌰 🧅 🍉 tape 🍉 , 🧇🍫 🧅 🧇🍫 🧅 🎂🎄 🧅 500 , 🍉 2 🍉 🧄 , ⛈️🍫 🧅 0 🧄 🧄 , 🎂🎄 🧅 500 , 🍉 2 🍉 🧄 🧄 🧄 🥖
74+
🌰 🧅 🍉 head 🍉 , 500 🧄 🥖
75+
🥐 🧅 🍉 Please type the number of line of the program 🍉 🧄 🥖
76+
🌰 🧅 🍉 n 🍉 , ⛈️🍫 🧅 🧄 🧄 🥖
77+
🌰 🧅 🍉 i 🍉 , 0 🧄 🥖
78+
🌰 🧅 🍉 delta0 🍉 , 🥧🍋 🧅 100 , 3 , 0 🧄 🥖
79+
🌰 🧅 🍉 delta1 🍉 , 🥧🍋 🧅 100 , 3 , 0 🧄 🥖
80+
🌰 🧅 🍉 delta2 🍉 , 🥧🍋 🧅 100 , 3 , 0 🧄 🥖
81+
82+
//Reading program from STDIN
83+
🍞 🍉 program_read 🍉 🥖
84+
85+
//Running the machine
86+
🍞 🍉 run 🍉 🥖
87+
88+
//Printing output (tape), final state (which should be H), and position of the head
89+
🍞🍫 🧅 🍉 Final (tape,state,head): (%d,%d,%d) 🍉 , 🍩 🧅 🧈 🧅 🍉 tape 🍉 🧄 , 🍉 2 🍉 , 🍉 🍉 🧄 , 🧈 🧅 🍉 state 🍉 🧄 , 🧈 🧅 🍉 head 🍉 🧄 🧄 🥖

src/base/token.ml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,23 @@ let string_to_token str =
4141
| "CRUMBLE" -> PARAM_BEGIN
4242
| "//" -> COMMENT
4343
| "," -> COMMA
44+
| "🧅" -> LEFT_PARENTHESIS
45+
| "🧄" -> RIGHT_PARENTHESIS
46+
| "🍉" -> QUOTE
47+
| "🥖" -> SEMI_COLON
48+
| "🧁" -> BOOL_TOKEN true
49+
| "🎂" -> BOOL_TOKEN false
50+
| "🥮" -> KEYWORD "BEGIN"
51+
| "🍪" -> KEYWORD "END"
52+
| "🍨" -> KEYWORD "LABEL"
53+
| "🍞" -> KEYWORD "GOTO"
54+
| "🥠" -> KEYWORD "IF"
55+
| "🍰" -> KEYWORD "THEN"
56+
| "🍊" -> KEYWORD "LOAD"
57+
| "🍫" -> ARRAY_BEGIN
58+
| "🍬" -> ARRAY_END
59+
| "🍭" -> PARAM_END
60+
| "🍮" -> PARAM_BEGIN
4461
| str -> (
4562
try INT_TOKEN (int_of_string str) with
4663
| Failure _ -> (

src/functions/functions.ml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ let recognize_function name list_of_args =
142142
| "MILLEFEUILLE" -> Math.floor list_of_args
143143
| "FRAISIER" -> Math.ceil list_of_args
144144
| "QUATREQUART" -> add_variable list_of_args
145+
145146
| "TIRAMISU" ->
146147
Conditions.equality list_of_args (*operateur de conditions & binaire*)
147148
| "MERINGUE" -> Conditions.inferior_large list_of_args
@@ -152,13 +153,15 @@ let recognize_function name list_of_args =
152153
| "PAINDEPICE" -> Conditions.binary_or list_of_args
153154
| "CREPE" -> Conditions.binary_xor list_of_args
154155
| "CHAUSSONAUXPOMMES" -> Conditions.binary_not list_of_args
156+
155157
| "TARTEAUXFRAISES" -> Array_manipulation.access list_of_args (*ACCESS*)
156158
| "TARTEAUXFRAMBOISES" -> Array_manipulation.replace list_of_args (*REPLACE*)
157159
| "TARTEAUXPOMMES" -> Array_manipulation.create_array list_of_args (*CREATE*)
158160
| "TARTEALARHUBARBE" ->
159161
Array_manipulation.create_matrix list_of_args (*MCREATE*)
160162
| "GLACE" -> Array_manipulation.display_array list_of_args (*DISPLAY*)
161163
| "BEIGNET" -> Array_manipulation.populate list_of_args (*POPULATE*)
164+
162165
| "DOUGHNUT" -> String_manipulation.replace list_of_args (*SREPLACE*)
163166
| "BUCHE" -> String_manipulation.create list_of_args (*SCREATE*)
164167
| "GAUFFREDELIEGE" -> String_manipulation.concat list_of_args (*SADD*)
@@ -174,6 +177,57 @@ let recognize_function name list_of_args =
174177
String_manipulation.double_from_string list_of_args (*DFS*)
175178
| "FRANGIPANE" -> String_manipulation.bool_from_string list_of_args (*BFS*)
176179
| "APFELSTRUDEL" -> return list_of_args
180+
181+
| "🍞🍫" -> printf list_of_args
182+
| "🥐" -> print list_of_args
183+
| "🧈" -> read_variable list_of_args
184+
| "⛈️🍫" -> read_entry list_of_args
185+
| "🌰" -> add_variable list_of_args
186+
187+
| "🧁🍷" -> Math.add list_of_args
188+
| "🍒" -> Math.mult list_of_args
189+
| "🎂🧈" -> Math.power list_of_args
190+
| "🧁🍫" -> Math.sqrt list_of_args
191+
| "🧁💰" -> Math.fibonacci list_of_args
192+
| "🍞🍇" -> Math.substract list_of_args
193+
| "🥐🍫" -> Math.divide list_of_args
194+
| "🥨" -> Math.randint list_of_args
195+
| "🥮🖼️" -> Math.logb list_of_args
196+
| "🎂🎵" -> Math.opposite list_of_args
197+
| "🥮🧈" -> Math.floor list_of_args
198+
| "🎂🍓" -> Math.ceil list_of_args
199+
200+
| "🥮🍵🍫" -> Conditions.equality list_of_args
201+
| "🥚" -> Conditions.inferior_large list_of_args
202+
| "🎂🍋" -> Conditions.inferior_strict list_of_args
203+
| "🍞🥐" -> Conditions.superior_large list_of_args
204+
| "🥧" -> Conditions.superior_strict list_of_args
205+
| "🎂🥚" -> Conditions.binary_and list_of_args
206+
| "🍞🌶️" -> Conditions.binary_or list_of_args
207+
| "🍞🥚" -> Conditions.binary_xor list_of_args
208+
| "🍞🍎" -> Conditions.binary_not list_of_args
209+
210+
| "🥧🍓" -> Array_manipulation.access list_of_args
211+
| "🥧🫐" -> Array_manipulation.replace list_of_args
212+
| "🥧🍎" -> Array_manipulation.create_array list_of_args
213+
| "🥧🍋" -> Array_manipulation.create_matrix list_of_args
214+
| "🍦" -> Array_manipulation.display_array list_of_args
215+
| "🇫🇷🍩" -> Array_manipulation.populate list_of_args
216+
217+
| "🍩" -> String_manipulation.replace list_of_args
218+
| "🎂🎄" -> String_manipulation.create list_of_args
219+
| "🧇🍫" -> String_manipulation.concat list_of_args
220+
| "🧇🇧🇪" -> String_manipulation.access list_of_args
221+
| "🧇" -> String_manipulation.split list_of_args
222+
| "🥞" -> String_manipulation.transform_to_array list_of_args
223+
| "🇨🇦🍁" -> String_manipulation.transform_from_array list_of_args
224+
| "🥯" -> String_manipulation.convert_to_string list_of_args
225+
| "🎂🥕" -> String_manipulation.int_from_string list_of_args
226+
| "🎂👑" -> String_manipulation.double_from_string list_of_args
227+
| "🥮👑" -> String_manipulation.bool_from_string list_of_args
228+
229+
| "🥧🍎🇩🇪" -> return list_of_args
230+
177231
| _ ->
178232
let word = Levenshtein.select_minimal_distance_word name in
179233
Parser.Exception

0 commit comments

Comments
 (0)