Fixed dictionary support. Added dict.py

This commit is contained in:
Xnoe 2020-09-27 18:43:37 +01:00
parent c70481804a
commit 136aa364c5
2 changed files with 7 additions and 0 deletions

3
dict.py Normal file
View File

@ -0,0 +1,3 @@
names = {"James": "May", "Morgan": "Freeman", "Jeff": "Alo"}
print(names["Jeff"])

View File

@ -47,6 +47,7 @@ type tokens =
| Not
| Nonlocal
| Global
| Class
let program = ref Bytes.empty
@ -152,6 +153,7 @@ let tokenise program =
| "while" -> tokens := !tokens @ [While]
| "global" -> tokens := !tokens @ [Global]
| "nonlocal" -> tokens := !tokens @ [Nonlocal]
| "class" -> tokens := !tokens @ [Class]
| _ -> tokens := !tokens @ [ID !text]
)
| '"' -> (
@ -265,6 +267,7 @@ let string_of_token tok =
| Newline -> "Newline"
| EOF -> "End of File"
| Assign -> "Assign"
| Class -> "Class"
| _ -> "NOT IMPLEMENTED YET"
let print_tokens tokens =
@ -454,6 +457,7 @@ let build_ast tokens =
let tmp_value = ref (factor ()) in
Hashtbl.replace tmp_Hashtbl !tmp_key !tmp_value;
done;
eat RightCBrace;
node := DictValue tmp_Hashtbl
) else (
node := variable ();