Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lexical Analysis of Python Programming Language

Does anyone know where a FLEX or LEX specification file for Python exists? For example, this is a lex specification for the ANSI C programming language: http://www.quut.com/c/ANSI-C-grammar-l-1998.html

FYI, I am trying to write code highlighting into a Cocoa application. Regex won't do it because I also want grammar parsing to fold code and recognize blocks.

like image 393
pokstad Avatar asked Nov 14 '09 00:11

pokstad


1 Answers

Lex is typically just used for tokenizing, not full parsing. Projects that use flex/lex for tokenizing typically use yacc/bison for the actual parsing.

You may want to take a look at ANTLR, a more "modern" alternative to lexx & yacc.

The ANTLR Project has a Github repo containing many ANTLR 4 grammars including at least one for Python 3.

like image 140
Laurence Gonsalves Avatar answered Oct 14 '22 14:10

Laurence Gonsalves