Fixed dictionary support. Added dict.py
This commit is contained in:
parent
c70481804a
commit
136aa364c5
3
dict.py
Normal file
3
dict.py
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
names = {"James": "May", "Morgan": "Freeman", "Jeff": "Alo"}
|
||||||
|
|
||||||
|
print(names["Jeff"])
|
@ -47,6 +47,7 @@ type tokens =
|
|||||||
| Not
|
| Not
|
||||||
| Nonlocal
|
| Nonlocal
|
||||||
| Global
|
| Global
|
||||||
|
| Class
|
||||||
|
|
||||||
let program = ref Bytes.empty
|
let program = ref Bytes.empty
|
||||||
|
|
||||||
@ -152,6 +153,7 @@ let tokenise program =
|
|||||||
| "while" -> tokens := !tokens @ [While]
|
| "while" -> tokens := !tokens @ [While]
|
||||||
| "global" -> tokens := !tokens @ [Global]
|
| "global" -> tokens := !tokens @ [Global]
|
||||||
| "nonlocal" -> tokens := !tokens @ [Nonlocal]
|
| "nonlocal" -> tokens := !tokens @ [Nonlocal]
|
||||||
|
| "class" -> tokens := !tokens @ [Class]
|
||||||
| _ -> tokens := !tokens @ [ID !text]
|
| _ -> tokens := !tokens @ [ID !text]
|
||||||
)
|
)
|
||||||
| '"' -> (
|
| '"' -> (
|
||||||
@ -265,6 +267,7 @@ let string_of_token tok =
|
|||||||
| Newline -> "Newline"
|
| Newline -> "Newline"
|
||||||
| EOF -> "End of File"
|
| EOF -> "End of File"
|
||||||
| Assign -> "Assign"
|
| Assign -> "Assign"
|
||||||
|
| Class -> "Class"
|
||||||
| _ -> "NOT IMPLEMENTED YET"
|
| _ -> "NOT IMPLEMENTED YET"
|
||||||
|
|
||||||
let print_tokens tokens =
|
let print_tokens tokens =
|
||||||
@ -454,6 +457,7 @@ let build_ast tokens =
|
|||||||
let tmp_value = ref (factor ()) in
|
let tmp_value = ref (factor ()) in
|
||||||
Hashtbl.replace tmp_Hashtbl !tmp_key !tmp_value;
|
Hashtbl.replace tmp_Hashtbl !tmp_key !tmp_value;
|
||||||
done;
|
done;
|
||||||
|
eat RightCBrace;
|
||||||
node := DictValue tmp_Hashtbl
|
node := DictValue tmp_Hashtbl
|
||||||
) else (
|
) else (
|
||||||
node := variable ();
|
node := variable ();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user