Class: Yadriggy::Algebra

Inherits:
Object
  • Object
show all
Defined in:
lib/yadriggy/algebra.rb

Overview

An interface inspired by object algebra (and tag-less final)

Instance Method Summary collapse

Constructor Details

#initialize(expr) ⇒ Algebra

Returns a new instance of Algebra.



11
12
13
# File 'lib/yadriggy/algebra.rb', line 11

def initialize(expr)
  EvalAlgebra.new(self).evaluate(expr)
end

Instance Method Details

#array(elements) ⇒ Object

An array literal. ELEMENTS is an array.

Raises:

  • (NotImplementedError)


146
147
148
# File 'lib/yadriggy/algebra.rb', line 146

def array(elements)
  raise NotImplementedError.new('array')
end

#array_ref(array, index) ⇒ Object

Raises:

  • (NotImplementedError)


127
128
129
# File 'lib/yadriggy/algebra.rb', line 127

def array_ref(array, index)
  raise NotImplementedError.new('array')
end

#array_ref_field(array, index) ⇒ Object

Array reference as L-value



133
134
135
# File 'lib/yadriggy/algebra.rb', line 133

def array_ref_field(array, index)
  array_ref(array, index)
end

#assign(left, op, right) ⇒ Object

Parameters:

  • left (Object|Array)

    the left value.

  • op (Symbol)

    the operator.

  • right (Object|Array)

    the right value.



119
120
121
122
123
124
125
# File 'lib/yadriggy/algebra.rb', line 119

def assign(left, op, right)
  if left.is_a?(Array) || right.is_a?(Array)
    raise NotImplementedError.new('multiple assignment')
  else
    binary(left, op, right)
  end
end

#begin_end(body, rescue_clause) ⇒ Object

Raises:

  • (NotImplementedError)


234
235
236
# File 'lib/yadriggy/algebra.rb', line 234

def begin_end(body, rescue_clause)
  raise NotImplementedError.new('begin_end')
end

#binary(left, op, right) ⇒ Object

Raises:

  • (NotImplementedError)


108
109
110
# File 'lib/yadriggy/algebra.rb', line 108

def binary(left, op, right)
  raise NotImplementedError.new('binary')
end

#block(params, optionals, rest_params, params_after_rest, keywords, rest_of_keywords, block_param, body) ⇒ Object

A block. BODY is a thunk.

Raises:

  • (NotImplementedError)


211
212
213
214
# File 'lib/yadriggy/algebra.rb', line 211

def block(params, optionals, rest_params, params_after_rest, keywords,
          rest_of_keywords, block_param, body)
  raise NotImplementedError.new('block')
end

#break_out(op, values) ⇒ Object

break, next, redo, retry.

Raises:

  • (NotImplementedError)


198
199
200
# File 'lib/yadriggy/algebra.rb', line 198

def break_out(op, values)
  raise NotImplementedError.new('break_out')
end

#call(receiver, op, name, args, block_arg, block) ⇒ Object

Method call. ARGS is an array. BLOCK is a thunk.

Raises:

  • (NotImplementedError)


161
162
163
# File 'lib/yadriggy/algebra.rb', line 161

def call(receiver, op, name, args, block_arg, block)
  raise NotImplementedError.new('call')
end

#class_def(name, superclass, body, rescue_clause) ⇒ Object

Raises:

  • (NotImplementedError)


252
253
254
# File 'lib/yadriggy/algebra.rb', line 252

def class_def(name, superclass, body, rescue_clause)
  raise NotImplementedError.new('class_def')
end

#command(receiver, op, name, args, block_arg, block) ⇒ Object

Method call without parentheses. ARGS is an array. BLOCK is a thunk.



168
169
170
# File 'lib/yadriggy/algebra.rb', line 168

def command(receiver, op, name, args, block_arg, block)
  call(receiver, op, name, args, block_arg, block)
end

#conditional(op, cond, then_exprs, all_elsif, else_exprs) ⇒ Object

if, unless, modifier if/unless, and ternary if (?:) THEN_EXPRS is a thunk. ALL_ELSIF is an array of pairs of elsif condition and its body. Both are thunks. ELSE_EXPRS is a thiuk or nil.

Raises:

  • (NotImplementedError)


178
179
180
# File 'lib/yadriggy/algebra.rb', line 178

def conditional(op, cond, then_exprs, all_elsif, else_exprs)
  raise NotImplementedError.new('conditional')
end

#const(name, line_no, column) ⇒ Object



35
36
37
# File 'lib/yadriggy/algebra.rb', line 35

def const(name, line_no, column)
  name(name, line_no, column)
end

#const_path_field(scope, name) ⇒ Object

A constant value in a scope as a L-value.



100
101
102
# File 'lib/yadriggy/algebra.rb', line 100

def const_path_field(scope, name)
  const_path_ref(scope, name)
end

#const_path_ref(scope, name) ⇒ Object

A constant value in a scope, such as Foo::Bar.

Raises:

  • (NotImplementedError)


94
95
96
# File 'lib/yadriggy/algebra.rb', line 94

def const_path_ref(scope, name)
  raise NotImplementedError.new('const_path_ref')
end

#define(name, params, optionals, rest_of_params, params_after_rest, keywords, rest_of_keywords, block_param, body, rescue_clause) ⇒ Object

def.

BODY and RESCUE_CLAUSE are thunks.

Raises:

  • (NotImplementedError)


242
243
244
245
246
# File 'lib/yadriggy/algebra.rb', line 242

def define(name, params, optionals, rest_of_params, params_after_rest,
           keywords, rest_of_keywords, block_param,
           body, rescue_clause)
  raise NotImplementedError.new('define')
end

#dots(left, op, right) ⇒ Object



112
113
114
# File 'lib/yadriggy/algebra.rb', line 112

def dots(left, op, right)
  binary(left, op, right)
end

#exprs(result, expr) ⇒ Object

exprs() sequentially processes each expression in a series of expressions. So, for example, { e1, e2, ..., e_n } is processed by exprs(.. exprs(exprs(nil, e1), e2).., e_n). In other words, it is by [e1, e2, ..., e_n].inject(nil) {|r,e| exprs(r, evaluate(e))}.

RESULT specifies the result of the previous expression. It is nil if EXPR is the first expression.

Raises:

  • (NotImplementedError)


77
78
79
# File 'lib/yadriggy/algebra.rb', line 77

def exprs(result, expr)
  raise NotImplementedError.new('exprs')
end

#for_loop(var, set, body) ⇒ Object

for loop. BODY is a thunk.

Raises:

  • (NotImplementedError)


192
193
194
# File 'lib/yadriggy/algebra.rb', line 192

def for_loop(var, set, body)
  raise NotImplementedError.new('for_loop')
end

#global_variable(name, line_no, column) ⇒ Object



47
48
49
# File 'lib/yadriggy/algebra.rb', line 47

def global_variable(name, line_no, column)
  name(name, line_no, column)
end

#hash(pairs) ⇒ Object

PAIRS is an array of pairs. Each pair is an array where the first element is a key and the second element is a value.

Raises:

  • (NotImplementedError)


154
155
156
# File 'lib/yadriggy/algebra.rb', line 154

def hash(pairs)
  raise NotImplementedError.new('hash')
end

#identifier(name, line_no, column) ⇒ Object



27
28
29
# File 'lib/yadriggy/algebra.rb', line 27

def identifier(name, line_no, column)
  identifier_or_call(name, line_no, column)
end

#identifier_or_call(name, line_no, column) ⇒ Object



23
24
25
# File 'lib/yadriggy/algebra.rb', line 23

def identifier_or_call(name, line_no, column)
  name(name, line_no, column)
end

#instance_variable(name, line_no, column) ⇒ Object



51
52
53
# File 'lib/yadriggy/algebra.rb', line 51

def instance_variable(name, line_no, column)
  name(name, line_no, column)
end

#label(name, line_no, column) ⇒ Object



39
40
41
# File 'lib/yadriggy/algebra.rb', line 39

def label(name, line_no, column)
  name(name, line_no, column)
end

#lambda_expr(params, optionals, rest_params, params_after_rest, keywords, rest_of_keywords, block_param, body) ⇒ Object

A lambda expression. BODY is a thunk.



219
220
221
222
223
# File 'lib/yadriggy/algebra.rb', line 219

def lambda_expr(params, optionals, rest_params, params_after_rest,
                keywords, rest_of_keywords, block_param, body)
  block(params, optionals, rest_params, params_after_rest,
        keywords, rest_of_keywords, block_param, body)
end

#loop(op, cond, body) ⇒ Object

while, until, and modifier while/until. COND and BODY are thunks.

Raises:

  • (NotImplementedError)


185
186
187
# File 'lib/yadriggy/algebra.rb', line 185

def loop(op, cond, body)
  raise NotImplementedError.new('loop')
end

#module_def(name, body, rescue_clause) ⇒ Object

Raises:

  • (NotImplementedError)


248
249
250
# File 'lib/yadriggy/algebra.rb', line 248

def module_def(name, body, rescue_clause)
  raise NotImplementedError.new('module_def')
end

#name(name, line_no, column) ⇒ Object

Raises:

  • (NotImplementedError)


19
20
21
# File 'lib/yadriggy/algebra.rb', line 19

def name(name, line_no, column)
  raise NotImplementedError.new('name')
end

#nil_valueObject

Raises:

  • (NotImplementedError)


15
16
17
# File 'lib/yadriggy/algebra.rb', line 15

def nil_value()
  raise NotImplementedError.new('nil_value')
end

#number(value, line_no, column) ⇒ Object

Raises:

  • (NotImplementedError)


63
64
65
# File 'lib/yadriggy/algebra.rb', line 63

def number(value, line_no, column)
  raise NotImplementedError.new('number')
end

#paren(element) ⇒ Object

An expression surrounded with ().

Raises:

  • (NotImplementedError)


139
140
141
# File 'lib/yadriggy/algebra.rb', line 139

def paren(element)
  raise NotImplementedError.new('paren')
end

#program(elements) ⇒ Object

A whole program.

ELEMENTS is the result of processing the program elements.

Raises:

  • (NotImplementedError)


264
265
266
# File 'lib/yadriggy/algebra.rb', line 264

def program(elements)
  raise NotImplementedError.new('program')
end

#rescue_end(types, parameter, body, nested_rescue, else_clause, ensure_clause) ⇒ Object

rescue-else-ensure-end. BODY, NESTED_RESCUE, ELSE_CLAUSE, and ENSURE_CLAUSE are thunks.

Raises:

  • (NotImplementedError)


229
230
231
232
# File 'lib/yadriggy/algebra.rb', line 229

def rescue_end(types, parameter, body, nested_rescue,
               else_clause, ensure_clause)
  raise NotImplementedError.new('rescue_end')
end

#reserved(name, line_no, column) ⇒ Object



31
32
33
# File 'lib/yadriggy/algebra.rb', line 31

def reserved(name, line_no, column)
  name(name, line_no, column)
end

#return_values(values) ⇒ Object

An expression with return.

Raises:

  • (NotImplementedError)


204
205
206
# File 'lib/yadriggy/algebra.rb', line 204

def return_values(values)
  raise NotImplementedError.new('return_values')
end

#singular_class_def(name, body, rescue_clause) ⇒ Object

Raises:

  • (NotImplementedError)


256
257
258
# File 'lib/yadriggy/algebra.rb', line 256

def singular_class_def(name, body, rescue_clause)
  raise NotImplementedError.new('singular_class_def')
end

#string_interpolation(contents) ⇒ Object

CONTENTS is an array of the results of evaluating each component.

Raises:

  • (NotImplementedError)


84
85
86
# File 'lib/yadriggy/algebra.rb', line 84

def string_interpolation(contents)
  raise NotImplementedError.new('string_interpolation')
end

#string_literal(value, line_no, column) ⇒ Object

Raises:

  • (NotImplementedError)


88
89
90
# File 'lib/yadriggy/algebra.rb', line 88

def string_literal(value, line_no, column)
  raise NotImplementedError.new('string_literal')
end

#super_method(expr) ⇒ Object

Raises:

  • (NotImplementedError)


59
60
61
# File 'lib/yadriggy/algebra.rb', line 59

def super_method(expr)
  raise NotImplementedError.new('super_method')
end

#symbol(name, line_no, column) ⇒ Object

Raises:

  • (NotImplementedError)


43
44
45
# File 'lib/yadriggy/algebra.rb', line 43

def symbol(name, line_no, column)
  raise NotImplementedError.new('symbol')
end

#unary(op, expr) ⇒ Object

Raises:

  • (NotImplementedError)


104
105
106
# File 'lib/yadriggy/algebra.rb', line 104

def unary(op, expr)
  raise NotImplementedError.new('unary')
end

#variable_call(name, line_no, column) ⇒ Object



55
56
57
# File 'lib/yadriggy/algebra.rb', line 55

def variable_call(name, line_no, column)
  identifier_or_call(name, line_no, column)
end