# # DO NOT MODIFY!!!! # This file is automatically generated by Racc 1.5.0 # from Racc grammar file "". # require 'racc/parser.rb' require 'symath' module SyMath class Parser < Racc::Parser module_eval(<<'...end parser.y/module_eval...', 'parser.y', 47) attr_reader :exp def function(name, subnodes) args = subnodes if name.is_a?(String) # SyMathntactic sugar for 'flat' function name = 'flat' if name.eql?('b') if name.include? "'" raise ParseError, "\nparse error on function name '#{name}'" end if name == 'lmd' return SyMath::Definition::Lmd.new(*args) end end return SyMath::Operator.create(name, args.map { |a| a.nil? ? a : a }) end # Create a variable or constant def named_node(name) if name.length >= 2 and name.match(/^d/) return name.to_sym.to_m('dform') end if name.match(/\'$/) name = name[0..-2] return name.to_sym.to_m('vector') end return name.to_sym.to_m end def parse(str) @q = [] cmd = [ 'eval', 'normalize', 'expand', 'factorize', 'factorize_simple', 'combine_fractions', ] until str.empty? case str when /\A\s+/ # whitespace, do nothing when *cmd # command @q.push [:CMD, $&] when /\A[A-Za-z_]+[A-Za-z_0-9]*\'?/ # name (char + (char|num)) @q.push [:NAME, $&] when /\A\d+/ # number (digits) @q.push [:NUMBER, $&] when /\A\*\*/ # two character operators s = $& @q.push [s, s] when /\A.|\n/o # other signs s = $& @q.push [s, s] end str = $' end @q.push [false, '$end'] exp = do_parse return if exp.nil? return exp end def next_token() @q.shift end ...end parser.y/module_eval... ##### State transition tables begin ### racc_action_table = [ 18, 15, 16, 17, 13, 14, 12, 11, 19, 5, 45, 28, 29, 3, 4, 42, 46, 7, 8, 9, 10, 5, 48, 37, 18, 3, 4, 18, 46, 7, 8, 9, 10, 5, 23, 18, 24, 3, 4, 44, nil, 7, 8, 9, 10, 5, nil, nil, nil, 3, 4, nil, nil, 7, 8, 9, 10, 5, nil, nil, nil, 3, 4, nil, nil, 7, 8, 9, 10, 5, nil, nil, nil, 3, 4, nil, nil, 7, 8, 9, 10, 5, nil, nil, nil, 3, 4, nil, nil, 7, 8, 9, 10, 5, nil, nil, nil, 3, 4, nil, nil, 7, 8, 9, 10, 5, nil, nil, nil, 3, 4, nil, nil, 7, 8, 9, 10, 5, nil, nil, nil, 3, 4, nil, nil, 7, 8, 9, 10, 5, nil, nil, nil, 3, 4, nil, nil, 7, 8, 9, 10, 5, nil, nil, nil, 3, 4, nil, nil, 7, 8, 9, 10, 18, 15, 16, 17, 13, 14, 12, nil, 19, 5, nil, 38, nil, 3, 4, nil, nil, 7, 8, 9, 10, 5, nil, nil, nil, 3, 4, nil, nil, 7, 8, 9, 10, 5, nil, nil, nil, 3, 4, nil, nil, 7, 8, 9, 10, 18, 15, 16, 17, 13, 14, 12, nil, 19, 5, nil, 47, nil, 3, 4, nil, nil, 7, 8, 9, 10, 18, 15, 16, 17, 13, 14, 12, nil, 19, 18, 15, 16, 17, 13, 14, 12, nil, 19, 18, 15, 16, 17, 13, 14, 12, 25, 19, nil, 7, 8, 9, 10, 18, 15, 16, 17, 13, 14, 18, 15, 16, 17, 13, 14, 18, 15, 16, 17, 18, 15, 16, 17 ] racc_action_check = [ 27, 27, 27, 27, 27, 27, 27, 1, 27, 0, 40, 10, 11, 0, 0, 27, 40, 0, 0, 0, 0, 3, 43, 19, 33, 3, 3, 34, 43, 3, 3, 3, 3, 4, 7, 35, 7, 4, 4, 38, nil, 4, 4, 4, 4, 5, nil, nil, nil, 5, 5, nil, nil, 5, 5, 5, 5, 9, nil, nil, nil, 9, 9, nil, nil, 9, 9, 9, 9, 12, nil, nil, nil, 12, 12, nil, nil, 12, 12, 12, 12, 13, nil, nil, nil, 13, 13, nil, nil, 13, 13, 13, 13, 14, nil, nil, nil, 14, 14, nil, nil, 14, 14, 14, 14, 15, nil, nil, nil, 15, 15, nil, nil, 15, 15, 15, 15, 16, nil, nil, nil, 16, 16, nil, nil, 16, 16, 16, 16, 17, nil, nil, nil, 17, 17, nil, nil, 17, 17, 17, 17, 18, nil, nil, nil, 18, 18, nil, nil, 18, 18, 18, 18, 21, 21, 21, 21, 21, 21, 21, nil, 21, 23, nil, 21, nil, 23, 23, nil, nil, 23, 23, 23, 23, 25, nil, nil, nil, 25, 25, nil, nil, 25, 25, 25, 25, 37, nil, nil, nil, 37, 37, nil, nil, 37, 37, 37, 37, 41, 41, 41, 41, 41, 41, 41, nil, 41, 46, nil, 41, nil, 46, 46, nil, nil, 46, 46, 46, 46, 2, 2, 2, 2, 2, 2, 2, nil, 2, 39, 39, 39, 39, 39, 39, 39, nil, 39, 49, 49, 49, 49, 49, 49, 49, 8, 49, nil, 8, 8, 8, 8, 20, 20, 20, 20, 20, 20, 30, 30, 30, 30, 30, 30, 31, 31, 31, 31, 32, 32, 32, 32 ] racc_action_pointer = [ 1, 7, 216, 13, 25, 37, nil, 21, 231, 49, -4, 12, 61, 73, 85, 97, 109, 121, 133, 10, 248, 150, nil, 154, nil, 166, nil, -3, nil, nil, 254, 260, 264, 21, 24, 32, nil, 178, 24, 225, -4, 195, nil, 8, nil, nil, 199, nil, nil, 234 ] racc_action_default = [ -2, -26, -1, -26, -26, -26, -15, -22, -26, -26, -20, -26, -26, -26, -26, -26, -26, -26, -26, -26, -3, -26, -13, -26, -23, -26, -18, -26, -21, 50, -4, -5, -6, -7, -8, -9, -10, -26, -12, -25, -26, -26, -19, -26, -11, -16, -26, -17, -14, -24 ] racc_goto_table = [ 2, 1, 26, 20, 21, 22, 40, nil, nil, 27, nil, nil, 30, 31, 32, 33, 34, 35, 36, nil, 43, nil, nil, nil, nil, 41, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 49 ] racc_goto_check = [ 2, 1, 4, 2, 2, 2, 3, nil, nil, 2, nil, nil, 2, 2, 2, 2, 2, 2, 2, nil, 3, nil, nil, nil, nil, 2, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 2 ] racc_goto_pointer = [ nil, 1, 0, -17, -6 ] racc_goto_default = [ nil, nil, 39, nil, 6 ] racc_reduce_table = [ 0, 0, :racc_error, 1, 22, :_reduce_none, 0, 22, :_reduce_2, 2, 23, :_reduce_3, 3, 23, :_reduce_4, 3, 23, :_reduce_5, 3, 23, :_reduce_6, 3, 23, :_reduce_7, 3, 23, :_reduce_8, 3, 23, :_reduce_9, 3, 23, :_reduce_10, 4, 23, :_reduce_11, 3, 23, :_reduce_12, 2, 23, :_reduce_13, 5, 23, :_reduce_14, 1, 23, :_reduce_none, 4, 25, :_reduce_16, 4, 25, :_reduce_17, 2, 25, :_reduce_18, 3, 25, :_reduce_19, 1, 25, :_reduce_20, 2, 25, :_reduce_21, 1, 25, :_reduce_22, 2, 25, :_reduce_23, 3, 24, :_reduce_24, 1, 24, :_reduce_25 ] racc_reduce_n = 26 racc_shift_n = 50 racc_token_table = { false => 0, :error => 1, :UMINUS => 2, "**" => 3, "*" => 4, "/" => 5, "^" => 6, "+" => 7, "-" => 8, "=" => 9, :unassoc => 10, "." => 11, :CMD => 12, "(" => 13, ")" => 14, "!" => 15, :NAME => 16, "#" => 17, "|" => 18, :NUMBER => 19, "," => 20 } racc_nt_base = 21 racc_use_result_var = true Racc_arg = [ racc_action_table, racc_action_check, racc_action_default, racc_action_pointer, racc_goto_table, racc_goto_check, racc_goto_default, racc_goto_pointer, racc_nt_base, racc_reduce_table, racc_token_table, racc_shift_n, racc_reduce_n, racc_use_result_var ] Racc_token_to_s_table = [ "$end", "error", "UMINUS", "\"**\"", "\"*\"", "\"/\"", "\"^\"", "\"+\"", "\"-\"", "\"=\"", "unassoc", "\".\"", "CMD", "\"(\"", "\")\"", "\"!\"", "NAME", "\"#\"", "\"|\"", "NUMBER", "\",\"", "$start", "target", "exp", "args", "func" ] Racc_debug_parser = false ##### State transition tables end ##### # reduce 0 omitted # reduce 1 omitted module_eval(<<'.,.,', 'parser.y', 14) def _reduce_2(val, _values, result) result = nil result end .,., module_eval(<<'.,.,', 'parser.y', 15) def _reduce_3(val, _values, result) result = val[1].send(val[0]) result end .,., module_eval(<<'.,.,', 'parser.y', 16) def _reduce_4(val, _values, result) result = eq(val[0], val[2]) result end .,., module_eval(<<'.,.,', 'parser.y', 17) def _reduce_5(val, _values, result) result = val[0].add(val[2]) result end .,., module_eval(<<'.,.,', 'parser.y', 18) def _reduce_6(val, _values, result) result = val[0].sub(val[2]) result end .,., module_eval(<<'.,.,', 'parser.y', 19) def _reduce_7(val, _values, result) result = val[0].mul(val[2]) result end .,., module_eval(<<'.,.,', 'parser.y', 20) def _reduce_8(val, _values, result) result = val[0].div(val[2]) result end .,., module_eval(<<'.,.,', 'parser.y', 21) def _reduce_9(val, _values, result) result = val[0].wedge(val[2]) result end .,., module_eval(<<'.,.,', 'parser.y', 22) def _reduce_10(val, _values, result) result = val[0].power(val[2]) result end .,., module_eval(<<'.,.,', 'parser.y', 23) def _reduce_11(val, _values, result) result = function('fact', [val[1]]) result end .,., module_eval(<<'.,.,', 'parser.y', 24) def _reduce_12(val, _values, result) result = val[1] result end .,., module_eval(<<'.,.,', 'parser.y', 25) def _reduce_13(val, _values, result) result = val[1].neg result end .,., module_eval(<<'.,.,', 'parser.y', 26) def _reduce_14(val, _values, result) result = function(val[0], val[3]) result end .,., # reduce 15 omitted module_eval(<<'.,.,', 'parser.y', 29) def _reduce_16(val, _values, result) result = function(val[0], val[2]) result end .,., module_eval(<<'.,.,', 'parser.y', 30) def _reduce_17(val, _values, result) result = function('sharp', [val[2]]) result end .,., module_eval(<<'.,.,', 'parser.y', 31) def _reduce_18(val, _values, result) result = function('sharp', [val[1]]) result end .,., module_eval(<<'.,.,', 'parser.y', 32) def _reduce_19(val, _values, result) result = function('abs', [val[1]]) result end .,., module_eval(<<'.,.,', 'parser.y', 33) def _reduce_20(val, _values, result) result = val[0].to_i.to_m result end .,., module_eval(<<'.,.,', 'parser.y', 34) def _reduce_21(val, _values, result) result = function('fact', [val[0].to_i.to_m]) result end .,., module_eval(<<'.,.,', 'parser.y', 35) def _reduce_22(val, _values, result) result = named_node(val[0]) result end .,., module_eval(<<'.,.,', 'parser.y', 36) def _reduce_23(val, _values, result) result = function('fact', [named_node(val[0])]) result end .,., module_eval(<<'.,.,', 'parser.y', 38) def _reduce_24(val, _values, result) result = val[0].push(val[2]) result end .,., module_eval(<<'.,.,', 'parser.y', 39) def _reduce_25(val, _values, result) result = [val[0]] result end .,., def _reduce_none(val, _values, result) val[0] end end # class Parser end