Module: Hilbert::Parser
- Includes:
- Lexer::Tokens
- Defined in:
- lib/hilbert/parser.rb,
lib/hilbert/parser/base.rb,
lib/hilbert/parser/func_parser.rb,
lib/hilbert/parser/list_parser.rb,
lib/hilbert/parser/limit_parser.rb,
lib/hilbert/parser/sigma_parser.rb,
lib/hilbert/parser/world_parser.rb,
lib/hilbert/parser/matrix_parser.rb,
lib/hilbert/parser/vector_parser.rb,
lib/hilbert/parser/formula_parser.rb,
lib/hilbert/parser/integral_parser.rb
Defined Under Namespace
Modules: Base, FormulaParser, FuncParser, IntegralParser, LimitParser, ListParser, MatrixParser, SigmaParser, VectorParser Classes: LangEqualizer, WorldParser
Constant Summary collapse
Constants included from Lexer::Tokens
Lexer::Tokens::ANYSP, Lexer::Tokens::ANYSTR, Lexer::Tokens::BICO, Lexer::Tokens::BRCS, Lexer::Tokens::BRCT, Lexer::Tokens::CLN, Lexer::Tokens::CMA, Lexer::Tokens::COND, Lexer::Tokens::CONJ, Lexer::Tokens::DEFLOGIC, Lexer::Tokens::DIFF_SYM, Lexer::Tokens::DISJ, Lexer::Tokens::DIV, Lexer::Tokens::E, Lexer::Tokens::EMBEDDED_FUNC, Lexer::Tokens::EQL, Lexer::Tokens::EVALOGIC, Lexer::Tokens::EXP, Lexer::Tokens::FLO, Lexer::Tokens::FORMULA, Lexer::Tokens::FUNCCN, Lexer::Tokens::FUNCCV, Lexer::Tokens::FUNCCVN, Lexer::Tokens::FUNCV, Lexer::Tokens::INF, Lexer::Tokens::INT, Lexer::Tokens::INTE_SYM, Lexer::Tokens::LBRCS, Lexer::Tokens::LBRCT, Lexer::Tokens::LDARW, Lexer::Tokens::LIM_SYM, Lexer::Tokens::LPRN, Lexer::Tokens::LSARW, Lexer::Tokens::MUL, Lexer::Tokens::NEGA, Lexer::Tokens::NLIN, Lexer::Tokens::NONL, Lexer::Tokens::NUM, Lexer::Tokens::NUMS_BY_CMA, Lexer::Tokens::NUMS_BY_SP, Lexer::Tokens::NUMS_BY_SP_BY_SCLN_OR_NELN, Lexer::Tokens::OPE, Lexer::Tokens::PI, Lexer::Tokens::PLS, Lexer::Tokens::PRN, Lexer::Tokens::PROVAR, Lexer::Tokens::RBRCS, Lexer::Tokens::RBRCT, Lexer::Tokens::RDARW, Lexer::Tokens::RPRN, Lexer::Tokens::RSARW, Lexer::Tokens::SCLN, Lexer::Tokens::SCLN_OR_NELN, Lexer::Tokens::SGM_SYM, Lexer::Tokens::SPC, Lexer::Tokens::SPCS, Lexer::Tokens::SUB, Lexer::Tokens::USER_FUNC, Lexer::Tokens::VAR, Lexer::Tokens::VARNUM, Lexer::Tokens::VARNUMS_BY_CMA, Lexer::Tokens::VARS_BY_CMA
Class Method Summary collapse
Class Method Details
.execute(lexed) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/hilbert/parser.rb', line 22 def execute(lexed) time = Time.now until lexed.token_str =~ /\A:(NLIN|R)\d+\z/ if Time.now > time + 10 fail <<-ERROR I'm so sorry, something wrong. Please feel free to report this. [DEBUG CODE:29] ========== DEBUG INFO ========== lexed.token_str: #{lexed.token_str} $defning_sym: #{$defning_sym} ERROR end case lexed.token_str when /:(POST_ZFC)(\d+)/ Hilbert::Lexer::MainLexer.zfc_analysis! lexed.parsed!('"success! :)"', $2) when /:(P_PARAD)(\d+)/ lexed.parsed!($world.paradox?, $2) when /:(DEFLOGIC)(\d+)/ value = lexed.get_value($1).delete("\n") rslt = $world << value lexed.parsed!(rslt, $2) when /:(EVALOGIC)(\d+)/ value = lexed.get_value($1).rm(/ *\?/).delete("\n") rslt = $world.impl value lexed.parsed!(rslt, $2) when /:(VECTOR)(\d+)/, /:(MATRIX)(\d+)/, /:(TMATRIX)(\d+)/, /:(INTEGRAL)(\d+)/, /:(DEF_FUNC)(\d+)/, /:(DIFFERENTIAL)(\d+)/, /:(LIMIT)(\d+)/, /:(SIGMA)(\d+)/ token_els = lexed.get_els($2) parsed = case $1 when 'VECTOR' then VectorParser.execute(token_els) when 'MATRIX' then MatrixParser.execute(token_els) when 'TMATRIX' then MatrixParser.execute(token_els, trans: true) when 'LIMIT' then LimitParser.execute(token_els) when 'INTEGRAL' then IntegralParser.execute(token_els) when 'DEF_FUNC' then FuncParser.execute(token_els) when 'SIGMA' then SigmaParser.execute(token_els) when 'DIFFERENTIAL' del_var, formula = token_els "d/d#{del_var}(#{FormulaParser.execute(formula)})" end lexed.parsed!(parsed, $2) when /:LPRN(\d+):CONT(\d+):RPRN(\d+)/ tokens_range = $1.to_i..$3.to_i token_val = lexed.parsed!( lexed.get_value($2).parentheses, tokens_range ) when /:LBRCS(\d+):CONT(\d+):RBRCS(\d+)/ tokens_range = $1.to_i..$3.to_i token_val = lexed.get_value($2) cont = case token_val when /#{ONEHASH}(#{CMA}#{ONEHASH})*/ ListParser.execute(token_val) else token_val end lexed.parsed!(cont, tokens_range) when /:FUNCCN(\d+)/ token_val = lexed.get_value($1) lexed.parsed!(token_val.parentheses, $1) when /:CONT(\d+)/ lexed.parsed!(lexed.get_value($1), $1) when /:UNKNOW(\d+)/ raise "#{lexed.get_value($1)} can not be parsed ;(" end lexed.squash!(($1.to_i)..($1.to_i+1)) if lexed.token_str =~ /:(?:CONT|R)(\d+):(?:CONT|R)(\d+)/ end LangEqualizer.execute( lexed.values.join ) end |