LEPL 递归解析器

程序名称:LEPL

授权协议: LGPL

操作系统: 跨平台

开发语言: Python

LEPL 介绍

LEPL是一个用 Python 开发的向下递归解析器。It is based on parser combinator libraries popular
in functional programming, but also exploits Python language features.
Operators provide a friendly syntax, and the consistent use of generators
supports full backtracking and resource management. Backtracking implies that
a wide variety of grammars are supported; appropriate memoisation ensures that
even left-recursive grammars terminate.

>>> from lepl import *

>>> class Term(Node): pass  
>>> class Factor(Node): pass  
>>> class Expression(Node): pass

>>> expr   = Delayed()  
>>> number = Digit()[1:,...]                          > 'number'  
>>> spaces = Drop(Regexp(r'\s*'))

>>> with Separator(spaces):  
>>>     term    = number | '(' & expr & ')'           > Term  
>>>     muldiv  = Any('*/')                           > 'operator'  
>>>     factor  = term & (muldiv & term)[:]           > Factor  
>>>     addsub  = Any('+-')                           > 'operator'  
>>>     expr   += factor & (addsub & factor)[:]       > Expression  
>>>     line    = expr & Eos()

>>> parser = line.parse_string  
>>> parser('1 + 2 * (3 + 4 - 5)')[0]

Expression  
 +- Factor  
 |   +- Term  
 |   |   `- number '1'  
 |   `- ' '  
 +- operator '+'  
 +- ' '  
 `- Factor  
     +- Term  
     |   `- number '2'  
     +- ' '  
     +- operator '*'  
     +- ' '  
     `- Term  
         +- '('  
         +- Expression  
         |   +- Factor  
         |   |   +- Term  
         |   |   |   `- number '3'  
         |   |   `- ' '  
         |   +- operator '+'  
         |   +- ' '  
         |   +- Factor  
         |   |   +- Term  
         |   |   |   `- number '4'  
         |   |   `- ' '  
         |   +- operator '-'  
         |   +- ' '  
         |   `- Factor  
         |       `- Term  
         |           `- number '5'  
         `- ')

LEPL 官网

http://www.acooke.org/lepl/

相关编程语言

BlazeDS 是一个基于服务器的Java 远程控制(remoting...
OVal 是一个可扩展的Java对象数据验证框架,验证的规...
Volta 是一套开发工具,专为开发分布式、实时系统应...
OpenDDS 是一个开源的 C++ 实现的 对象管理组织 OMG...
JADE (Java Agent DEvelopment Framework) 是一个完...
FastMM ,在D2006和2007中已代替了原来的内存管理器。