Beispiel #1
0
"""A simple haskell-like grammar for basic lambda-calculus.

A GLR(0) parser can be used to find LR(0)-conflicts as well as
contruct partial parse trees.

"""

import preamble
import pprint as pp

from metaparse import *

from collections import namedtuple as data

Let = data('Let', 'binds body')
Abst = data('Abst', 'par body')
Appl = data('Appl', 'func arg')
Var = data('Var', 'symbol')
Value = data('Value', 'value')

Expr = [Let, Abst, Appl, Var, Value]
for E in Expr:
    E.__repr__ = tuple.__repr__

TW = r'[ \t]*'
TWN = r'[ \t\n]*'


class Lam(metaclass=LALR.meta):

    "A haskell like grammar."
Beispiel #2
0
"""A simple haskell-like grammar for basic lambda-calculus.

A GLR(0) parser can be used to find LR(0)-conflicts as well as
contruct partial parse trees.

"""

import preamble
import pprint as pp

from metaparse import *

from collections import namedtuple as data

Let = data("Let", "binds body")
Abst = data("Abst", "par body")
Appl = data("Appl", "func arg")
Var = data("Var", "symbol")
Value = data("Value", "value")

Expr = [Let, Abst, Appl, Var, Value]
for E in Expr:
    E.__repr__ = tuple.__repr__

TW = r"[ \t]*"
TWN = r"[ \t\n]*"


class Lam(metaclass=cfg):

    "A haskell like grammar."
Beispiel #3
0
# Experimental implementation for Parser Expression Grammar,
# represented by EBNF-like notation.

import re

from collections import namedtuple as data

Rule = data('Rule', 'lhs rhs')

# Expression is a superclass, which can be subclassed into
# - Terminal
# - Nonterminal
# - Alternatves
# - Sequence
# - Repeated/Star
# - Optional/Opt

Expr = data('Symbol', 'symbol')

Nonterminal = data('Nonterminal', 'symb')
Nonterminal = str
Terminal = data('Terminal', 'symb regexp')
Star = data('Star', 'sub')
Opt  = data('Opt', 'sub')
Plus = data('Plus', 'sub')
Seq  = data('Seq', 'subs')      # Using python list rather than CONS structure.
Alt  = data('Alt', 'subs')      # Using python list rather than CONS structure.
Nil  = None

is_a = isinstance
Beispiel #4
0
# Experimental implementation for Parser Expression Grammar,
# represented by EBNF-like notation.

import re

from collections import namedtuple as data

Rule = data('Rule', 'lhs rhs')

# Expression is a superclass, which can be subclassed into
# - Terminal
# - Nonterminal
# - Alternatves
# - Sequence
# - Repeated/Star
# - Optional/Opt

Expr = data('Symbol', 'symbol')

Nonterminal = data('Nonterminal', 'symb')
Nonterminal = str
Terminal = data('Terminal', 'symb regexp')
Star = data('Star', 'sub')
Opt = data('Opt', 'sub')
Plus = data('Plus', 'sub')
Seq = data('Seq', 'subs')  # Using python list rather than CONS structure.
Alt = data('Alt', 'subs')  # Using python list rather than CONS structure.
Nil = None

is_a = isinstance