<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          LEPL遞歸解析器

          聯(lián)合創(chuàng)作 · 2023-10-01 04:46

          LEPL是一個(gè)用 Python 開發(fā)的向下遞歸解析器。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'
          `- ')
          瀏覽 27
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          評(píng)論
          圖片
          表情
          推薦
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  在线观看国内精品人 | 做爱视频网站网址 | www.天天好逼 | 天堂色在线 | 可以免费看黄片的网站 |