递归解析器 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

文本上的算法——深入浅出自然语言处理

文本上的算法——深入浅出自然语言处理

路彦雄 / 人民邮电出版社 / 2018-3-1 / 69.00元

本书结合作者多年学习和从事自然语言处理相关工作的经验,力图用生动形象的方式深入浅出地介绍自然语言处理的理论、方法和技术。本书抛弃掉繁琐的证明,提取出算法的核心,帮助读者尽快地掌握自然语言处理所必备的知识和技能。本书主要分两大部分。第一部分是理论篇,包含前3章内容,主要介绍一些基础的数学知识、优化理论知识和一些机器学习的相关知识。第二部分是应用篇,包含第4章到第8章,分别针对计算性能、文本处理的术语......一起来看看 《文本上的算法——深入浅出自然语言处理》 这本书的介绍吧!

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

URL 编码/解码
URL 编码/解码

URL 编码/解码

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具