namarara/lib/parser.rb

64 lines
1.9 KiB
Ruby
Raw Normal View History

2017-09-04 09:19:29 +00:00
module Mm2ep
module Depend
2017-09-07 15:05:06 +00:00
class Parser < Rly::Yacc
rule 'statement : expr' do |st, e|
st.value = e.value
end
rule 'expr : NOT_OP SPACE expr' do |ex, l, s, e|
ex.value = "#{l.value} #{s.value} #{e.value}"
end
rule 'expr : expr SPACE AND_OP SPACE expr' do |ex, l, s, e, sp, r|
ex.value = "#{l.value} #{s.value} #{e.value} #{sp.value} #{r.value}"
end
rule 'expr : expr SPACE OR_OP SPACE expr' do |ex, l, s, e, sp, r|
ex.value = "#{l.value} #{s.value} #{e.value} #{sp.value} #{r.value}"
end
rule 'expr : L_PAR SPACE expr SPACE R_PAR' do |ex, l, s, e, sp, r|
ex.value = "#{l.value} #{s.value} #{e.value} #{sp.value} #{r.value}"
end
rule 'expr : VAR SPACE EQ_OP SPACE F_BOOL' do |ex, v, s, eq, _, n|
ex.value = "#{v.value} #{s.value} #{eq.value} #{s.value} #{n.value}"
end
rule 'expr : VAR SPACE EQ_OP SPACE T_BOOL' do |ex, v, s, eq, _, n|
ex.value = "#{v.value} #{s.value} #{eq.value} #{s.value} #{n.value}"
end
rule 'expr : VAR SPACE EQ_OP SPACE STRING' do |ex, v, s, eq, _, n|
ex.value = "#{v.value} #{s.value} #{eq.value} #{s.value} #{n.value}"
end
rule 'expr : VAR SPACE EQ_OP SPACE NUMBER' do |ex, v, s, eq, _, n|
ex.value = "#{v.value} #{s.value} #{eq.value} #{s.value} #{n.value}"
end
# lexer do
#
# end
#
# def initialize
# @tokens = []
# end
#
# def parse s
# s = s.split(' ')
# s.each_with_index do |element, idx|
# TOKEN.each do |token, regex|
# next if element.sub!(regex, '').nil?
# @tokens << token
# break if element.nil?
# end
# @tokens <<'SPACE' unless idx == s.length-1
# end
# puts @tokens
# end # def
2017-09-04 09:19:29 +00:00
end # class
end # module
end # module