Module: ScannerGenerator

Defined in:
lib/scanner_generator.rb,
lib/scanner_generator/version.rb,
lib/scanner_generator/finite_state_machine.rb

Defined Under Namespace

Classes: FiniteStateMachine

Constant Summary collapse

VERSION =
"0.0.3"
LAMBDA =
"LAMBDA"
SOURCE =
0
DEST =
1
LABEL =
2
ERROR =

Action Table codes [E, MA, HR]

0
MACHINE_ACCEPT =
1
HALT_RETURN =
2
ACC =
3
WIDTH =
3

Instance Method Summary collapse

Instance Method Details

#subset(needle, haystack) ⇒ Object

True if the needle (subset) is found in the haystack (superset).



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/scanner_generator/finite_state_machine.rb', line 12

def subset(needle,haystack)
  a = needle.sort
  b = haystack.sort
  ii = 0
  jj = 0
  a_last_index = a.length-1
  b_last_index = b.length-1
  loop do
    if(a[ii]==b[jj])
      return true if(ii==a_last_index)
      ii+=1
      jj+=1
    elsif(a[ii] > b[jj])
      return false if(jj>=b_last_index)
      jj+= 1
    else # a[ii] < b[jj]
      return false
    end
  end
end

#subset_of_list_element?(needle, list_of_haystacks) ⇒ Boolean

is needle contained in a haystack?

Returns:

  • (Boolean)


34
35
36
37
# File 'lib/scanner_generator/finite_state_machine.rb', line 34

def subset_of_list_element?(needle,list_of_haystacks)
  list_of_haystacks.each{|haystack| return true if subset(needle,haystack)}
  return false
end