递归解析器 LEPL

码农软件 · 软件分类 · 其他开发相关 · 2019-11-01 16:13:36

软件介绍

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'
`- ')

本文地址:https://codercto.com/soft/d/18045.html

失控

失控

[美] 凯文·凯利 / 东西文库 / 新星出版社 / 2010-12 / 88.00元

《失控》,全名为《失控:机器、社会与经济的新生物学》(Out of Control: The New Biology of Machines, Social Systems, and the Economic World)。 2006年,《长尾》作者克里斯·安德森在亚马逊网站上这样评价该书: “这可能是90年代最重要的一本书”,并且是“少有的一年比一年卖得好的书”。“尽管书中的一些例子......一起来看看 《失控》 这本书的介绍吧!

在线进制转换器
在线进制转换器

各进制数互转换器

html转js在线工具
html转js在线工具

html转js在线工具

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试