Example #1
0
 def testABCD(self):
   A, B, C, D = vars('A, B, C, D')
   ruleList = [(A,function(((), B()|C()))), 
               (B,function(((), D()+char('b')))), 
               (C,function(((), D()+char('c')))), 
               (D,function(((), char('d')))), 
              ]
   eq_(eval(letr(ruleList, parse_text(A()+eoi,  'dc'))), True)
Example #2
0
 def testABCD(self):
     A, B, C, D = vars('A, B, C, D')
     ruleList = [
         (A, function(((), B() | C()))),
         (B, function(((), D() + char('b')))),
         (C, function(((), D() + char('c')))),
         (D, function(((), char('d')))),
     ]
     eq_(eval(letr(ruleList, parse_text(A() + eoi, 'dc'))), True)
Example #3
0
 def testIndirectLeftRecursive(self):
   #assert 0, 'temporary mask'
   A, B, C = vars('A, B, C')
   ruleList = [(A, function(((), B()))), 
               (B, function(
                     ((), A()+char('a')),
                      ((), char('b')),
                    ))]
   eq_(eval(letr(ruleList, parse_text(A()+eoi,  'b'))), True)
   eq_(eval(letr(ruleList, parse_text(A()+eoi,  'ba'))), True)
   eq_(eval(letr(ruleList, parse_text(A()+eoi,  'baa'))), True)
Example #4
0
 def testIndirectLeftRecursive(self):
     #assert 0, 'temporary mask'
     A, B, C = vars('A, B, C')
     ruleList = [(A, function(((), B()))),
                 (B, function(
                     ((), A() + char('a')),
                     ((), char('b')),
                 ))]
     eq_(eval(letr(ruleList, parse_text(A() + eoi, 'b'))), True)
     eq_(eval(letr(ruleList, parse_text(A() + eoi, 'ba'))), True)
     eq_(eval(letr(ruleList, parse_text(A() + eoi, 'baa'))), True)
Example #5
0
# -*- coding: utf-8 -*-

from dao.term import vars, cons2tuple
from dao.special import begin, set, to_sexpression, in_module, eval_, from_, function
from dao.builtins.control import and_p
from dao.builtins.io import prin
from dao.builtins.parser import set_text
from dao.builtins.terminal import eoi
from dao.builtins.term import is_, define, pycall

from dao.t.builtins.globalenv import grammar, sexpression, classic
from dao.t.sexpression import defines as sexpression_defines
from dao.t.classic import defines as classic_defines

start, exp, sexpression1, program, result = vars(
  'start, exp, sexpression, program, result')

def make_expression(text):
  code = begin(
    sexpression_defines, 
    classic_defines, 
    set_text(text),
    from_(classic, program)(exp), 
    eoi,
    eval_(pycall(cons2tuple, exp)))
  return to_sexpression(code)

Example #6
0
            return head(bindings, *body)
        elif head == lambda_:
            vars = tuple(item.tail.head)
            body = tuple(sexpression2daoexpression(x) for x in item.tail.tail)
            return head(vars, *body)
        elif head == FunctionForm or head == MacroForm:
            return head(*tuple(
                (cons2tuple(rule.head), ) +
                tuple(sexpression2daoexpression(stmt) for stmt in rule.tail)
                for rule in item.tail))
        return head(*tuple(sexpression2daoexpression(x) for x in item.tail))
    else:
        return item


X, Expr, ExprList, Result, Y, Expr2 = vars(
    'X, Expr, ExprList, Result, Y, Expr2')

(
    sexpression1, sexpression, bracketExpression, puncExpression,
    sexpressionList, atom_expression, spaces_on_condition, eval_parse_result
) = vars(
    'sexpression1, sexpression, bracketExpression, puncExpression, sexpressionList, '
    'atom_expression, spaces_on_condition, eval_parse_result')

_ = DummyVar('_')

sexpression_rules = [
    (atom_expression,
     function(([X], integer(X)), ([X], dqstring(X)), ([X], symbol(X)))),
    (bracketExpression,
     function(([ExprList],
Example #7
0
    if head==let or head==letr:
      bindings = tuple((var, sexpression2daoexpression(exp)) for var, exp in item.tail.head)
      body = tuple(sexpression2daoexpression(x) for x in item.tail.tail)
      return head(bindings, *body)
    elif head==lambda_:
      vars = tuple(item.tail.head)
      body = tuple(sexpression2daoexpression(x) for x in item.tail.tail)
      return head(vars, *body)
    elif head==FunctionForm or head==MacroForm:
      return head(*tuple((cons2tuple(rule.head),)+tuple(sexpression2daoexpression(stmt)
                                              for stmt in rule.tail) 
                    for rule in item.tail)) 
    return head(*tuple(sexpression2daoexpression(x) for x in item.tail))
  else: return item

X, Expr, ExprList, Result, Y, Expr2 = vars('X, Expr, ExprList, Result, Y, Expr2')

(sexpression1, sexpression, bracketExpression, puncExpression, sexpressionList, 
 atom_expression, spaces_on_condition, eval_parse_result) = vars(
   'sexpression1, sexpression, bracketExpression, puncExpression, sexpressionList, '
 'atom_expression, spaces_on_condition, eval_parse_result')

_ = DummyVar('_')

sexpression_rules = [
  
  (atom_expression, function(
    ([X], number(X)),
    ([X], dqstring(X)),
    ([X], symbol(X))
    )),
Example #8
0
pyset = set

from dao.special import begin, set, iff, case, if_, block, exit_block, continue_block

from dao.builtins.arith import eq, sub, not_
from dao.builtins.matcher import matcher

keywords = pyset([
    'let', 'recur', 'do', 'case', 'of', 'while', 'when', 'until', 'block',
    'loop', 'if', 'elif', 'else', 'print', 'break', 'redo', 'pass', 'return',
    'fun', 'macro', 'on'
])

# variables

x, y, z, = vars('x, y, z')

from dao.t.operator import operator, left, right

# function names

statement, statement_list, program = vars('statement, statement_list, program')

assign_statement, expression_statement = vars(
    'assign_statement, expression_statement ')
statement_body, statement_end, statement_sequence, = vars(
    'statement_body, statement_end, statement_sequence')

expression, dec_inc_expression, binary_expression, assign_expression = vars(
    'expression, dec_inc_expression, binary_expression, assign_expression')
Example #9
0
  if pos>=len(text): return
  char = text[pos]
  if char in _SYMBOL_FORBID_CHARS or '0'<=char<='9':
    return
  p = pos
  while p<len(text): 
    if text[p] in _SYMBOL_FORBID_CHARS: break 
    else: p += 1
  name = text[pos:p]
  sym = var(name)
  for _ in term.unify(result, sym, solver.env):
    solver.parse_state = text, p
    yield cont, True
  solver.parse_state = text, pos

x, exp, exp_list, result, y, exp2 = vars('x, exp, exp_list, result, y, exp2')

(sexpression1, sexpression, bracket_expression, punct_expression, sexpression_list, 
 atom, maybe_spaces, eval_parse_result) = vars(
   'sexpression1, sexpression, bracket_expression, punct_expression, sexpression_list, '
 'atom, maybe_spaces, eval_parse_result')

_ = DummyVar('_')

def from_sexp(var):
  return from_(sexpression_module, var)

defines = in_module(sexpression_module, 
  
  define(atom, function(
    ([x], integer(x)),
Example #10
0
from dao.term import Var, var, vars, dummies, nullvars #, Command, CommandCall
from dao.term import unify
pyset = set

from dao.special import begin, set, iff, case, if_, block, exit_block, continue_block

from dao.builtins.arith import eq, sub, not_
from dao.builtins.matcher import matcher

keywords = pyset(['let', 'recur', 'do', 'case', 'of', 'while', 'when', 'until', 'block',
                  'loop', 'if', 'elif', 'else', 'print', 'break', 'redo', 'pass', 'return',
                  'fun', 'macro', 'on'])

# variables

x, y, z, = vars('x, y, z')

from dao.t.operator import operator, left, right

# function names

statement, statement_list, program = vars('statement, statement_list, program')

assign_statement, expression_statement = vars('assign_statement, expression_statement ')
statement_body, statement_end, statement_sequence, = vars(
  'statement_body, statement_end, statement_sequence')

expression, dec_inc_expression, binary_expression, assign_expression  = vars(
  'expression, dec_inc_expression, binary_expression, assign_expression')

assign, let_bindings, binding, loop, loop_times = vars(