[Tutor] syntax parsing and ast

Nathan Smith nathan-tech at hotmail.com
Thu Nov 3 13:35:01 EDT 2022


Hi guys,


I'm hoping someone can give me direction here (this is not to do with my 
main project which I mentioned a little while ago and turned out to be 
unrelated to what I suspected) typical.


This time I want to parse code of another language into python.

It's not a mainstream language and is relatively simple in that in that 
it has only a couple of rules:

1. Everything can be a considered a function.

2. There is a small number of builtins (about 50 in total).

3. It uses spaces to separate arguments, unless a space is needed in 
which case the argument is inclosed in brackets like so: {arg with 
spaces} {arg 2 with spaces}


I want to pass this into some objects that would allow a tree like so:

main

   main.func1

   main.func2

main2:

   main.if

     main.func4


I was thinking ast maybe be the way to go about this, and perhaps rejex 
for syntax matching, but beyond that I may need some pointers.


thanks in advance for anything you can offer in the way of help.

-- 

Best Wishes,

Nathan Smith, BSC


My Website: https://nathantech.net




More information about the Tutor mailing list