Sunday, February 10, 2008

Playing python: syntax tree of python expressions

Done: Working version of program for python expressions parsing.

Source is available on my page.

Below is example of how it works, and tree generated/presented.

Good explanation of python's slowness.

Marked blue - is input in terminal

------------------%<-------------------------------
./parse_python.py
2 + 2

[257, [266, [267, [268, [269, [326, [303, [304, [305, [306, [307, [309, [310, [311, [312, [313, [314, [315, [316, [317, [2, '2']]]]], [14, '+'], [314, [315, [316, [317, [2, '2']]]]]]]]]]]]]]]]]], [4, '']]], [0, '']]
['symbol=file_input', ['symbol=stmt', ['symbol=simple_stmt', ['symbol=small_stmt', ['symbol=expr_stmt', ['symbol=testlist', ['symbol=test', ['symbol=or_test', ['symbol=and_test', ['symbol=not_test', ['symbol=comparison', ['symbol=expr', ['symbol=xor_expr', ['symbol=and_expr', ['symbol=shift_expr', ['symbol=arith_expr', ['symbol=term', ['symbol=factor', ['symbol=power', ['symbol=atom', ['token=NUMBER', 'value=2']]]]], ['token=PLUS', 'value=+'], ['symbol=term', ['symbol=factor', ['symbol=power', ['symbol=atom', ['token=NUMBER', 'value=2']]]]]]]]]]]]]]]]]], ['token=NEWLINE', 'value=']]], ['token=ENDMARKER', 'value=']]
------------------>%-------------------------------

No comments: