Class: Ascode::Parser::Function

Inherits:
Object
  • Object
show all
Defined in:
lib/ascode/parser/function.rb

Constant Summary collapse

CODE =
{
  io: [
    %w[I input],
    %w[O output],
    %w[N new_line]
  ],

  env: [
    %w[P pop],
    %w[C reg_copy],
    %w[V reg_paste],
    %w[S swap],
    %w[D duplicate]
  ],

  condition: [
    %w([ begin),
    %w[: else],
    %w(] end)
  ],

  math: [
    %w[+ plus],
    %w[- minus],
    %w[* multiply],
    %w[/ divide],
    %w[i increment],
    %w[d decrement],
    %w[> bigger_than],
    %w[< less_than],
    %w[= equal],
    %w[e even],
    %w[! invert],
    %w[s change_sign]
  ]
}.freeze

Instance Method Summary collapse

Instance Method Details

#ast(type, name) ⇒ Object



15
16
17
18
19
20
# File 'lib/ascode/parser/function.rb', line 15

def ast(type, name)
  {
    type: type,
    action: name
  }
end

#parse(char) ⇒ Object



4
5
6
7
8
9
10
11
12
13
# File 'lib/ascode/parser/function.rb', line 4

def parse(char)
  CODE.find do |type|
    type[1].find do |function|
      @ast = ast type[0], function[1] if function[0] == char
    end
  end

  return unless @ast
  @ast
end