Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6140349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:06:26+00:00 2026-05-23T18:06:26+00:00

Which Python tool can you recommend to parse programming languages? It should allow for

  • 0

Which Python tool can you recommend to parse programming languages? It should allow for a readable representation of the language grammar inside the source, and it should be able to scale to complicated languages (something with a grammar as complex as e.g. Python itself).

When I search, I mostly find pyparsing, which I will be evaluating, but of course I’m interested in other alternatives.

Edit: Bonus points if it comes with good error reporting and source code locations attached to syntax tree elements.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T18:06:27+00:00Added an answer on May 23, 2026 at 6:06 pm

    I really like pyPEG. Its error reporting isn’t very friendly, but it can add source code locations to the AST.

    pyPEG doesn’t have a separate lexer, which would make parsing Python itself hard (I think CPython recognises indent and dedent in the lexer), but I’ve used pyPEG to build a parser for subset of C# with surprisingly little work.

    An example adapted from fdik.org/pyPEG/: A simple language like this:

    function fak(n) {
        if (n==0) { // 0! is 1 by definition
            return 1;
        } else {
            return n * fak(n - 1);
        };
    }
    

    A pyPEG parser for that language:

    def comment():          return [re.compile(r"//.*"),
                                    re.compile("/\*.*?\*/", re.S)]
    def literal():          return re.compile(r'\d*\.\d*|\d+|".*?"')
    def symbol():           return re.compile(r"\w+")
    def operator():         return re.compile(r"\+|\-|\*|\/|\=\=")
    def operation():        return symbol, operator, [literal, functioncall]
    def expression():       return [literal, operation, functioncall]
    def expressionlist():   return expression, -1, (",", expression)
    def returnstatement():  return keyword("return"), expression
    def ifstatement():      return (keyword("if"), "(", expression, ")", block,
                                    keyword("else"), block)
    def statement():        return [ifstatement, returnstatement], ";"
    def block():            return "{", -2, statement, "}"
    def parameterlist():    return "(", symbol, -1, (",", symbol), ")"
    def functioncall():     return symbol, "(", expressionlist, ")"
    def function():         return keyword("function"), symbol, parameterlist, block
    def simpleLanguage():   return function
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a Python script or tool available which can remove comments and docstrings
I am looking for a Windows tool (exe) or Python script which can be
How can I build a regular expression in python which can match all the
Is there tool out there which can be used to graphically represent the structure
The software tool SWIG can be used to create a programming interface (bindings) to
I wrote a function in Python which is used to tell me whether the
I have list in python which has following entries name-1 name-2 name-3 name-4 name-1
I'm writing a script in python which basically queries WMI and updates the information
I have an array of strings in python which each string in the array
I created a little web spider in Python which I'm using to collect URLs.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.