Skip to content

Instantly share code, notes, and snippets.

@tyler569
Last active September 22, 2018 01:05
Show Gist options
  • Save tyler569/233522b2a929fe2af21d68f9eef50a69 to your computer and use it in GitHub Desktop.
Save tyler569/233522b2a929fe2af21d68f9eef50a69 to your computer and use it in GitHub Desktop.
tyler@xps:~/lcc$ python3 parse_test.py
>
> 2+2
[2, '+', 2]
('+', 2, 2)
4
> 2*2+2
[2, '*', 2, '+', 2]
('+', ('*', 2, 2), 2)
6
> 2+2*2
[2, '+', 2, '*', 2]
('+', 2, ('*', 2, 2))
6
> 2-2-2
[2, '-', 2, '-', 2]
('-', ('-', 2, 2), 2)
-2
> 4/2-1
[4, '/', 2, '-', 1]
('-', ('/', 4, 2), 1)
1.0
> 1-4/2
[1, '-', 4, '/', 2]
('-', 1, ('/', 4, 2))
-1.0
> 2*2+3*4/5-3-4
[2, '*', 2, '+', 3, '*', 4, '/', 5, '-', 3, '-', 4]
('-', ('-', ('+', ('*', 2, 2), ('*', 3, ('/', 4, 5))), 3), 4)
-0.5999999999999996
>
tyler@xps:~/lcc$ python3 parse_test.py
>
>
>
> 2 - (2 - 2)
[2, '-', '(', 2, '-', 2, ')']
('-', 2, ('-', 2, 2))
2
>
> (2 - 2) - 2
['(', 2, '-', 2, ')', '-', 2]
('-', ('-', 2, 2), 2)
-2
>
> (1 + 1) * 2
['(', 1, '+', 1, ')', '*', 2]
('*', ('+', 1, 1), 2)
4
> 1 + (1 * 2)
[1, '+', '(', 1, '*', 2, ')']
('+', 1, ('*', 1, 2))
3
>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment