[Tutor] syntax parsing and ast

Flynn, Stephen (Life & Pensions) Steve.Flynn at capita.com
Thu Nov 3 14:07:48 EDT 2022


There are a number of parsers already built as libraries - I strongly recommend you take a look at some of them ,have a play and see which one suits your application.

A pretty comprehensive list is kept (up-to-date too) on Github in the webmaven/python-parsing-tools repo.

S.

-----Original Message-----
From: Tutor <tutor-bounces+steve.flynn=capita.co.uk at python.org> On Behalf Of Nathan Smith
Sent: Thursday, November 3, 2022 5:35 PM
To: tutor <tutor at python.org>
Subject: [Tutor] syntax parsing and ast

**EXTERNAL**

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


_______________________________________________
Tutor maillist  -  Tutor at python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


This message has been scanned by Capita systems, but if you believe it to be spam, please send it to spam at forcepoint.com.

Messages sent to spam at forcepoint.com are queued for email analysis by Forcepoint Threat Lab.
This email originates from outside of Capita.
Keep this in mind before responding, opening attachments or clicking any links. Unless you recognise the sender and know the content is safe.
If in any doubt, the grammar and spelling are poor, or the name doesn't match the email address then please contact the sender via an alternate known method.



This email is security checked and subject to the disclaimer on web-page: https://www.capita.com/email-disclaimer.aspx


More information about the Tutor mailing list