dynamic - Implementing a solver in c++ for problems described in some scripting syntax -
i have generic question on how write c++ code solve general class of problems. class of problems described in scripting language read dynamically c++ program. e.g. problem can described following:
syms b c x sol = solve(a*x^2 + b*x + c == 0) sola = solve(a*x^2 + b*x + c == 0, a)
here using matlab illustration purposes, , not trying build matlab. after find out how, in general, 1 go designing c++ program take in script, describes calculation instructions, , read/interpret logic described in script , perform calculations described.
the general architecture of program follows:
(from parsing article on wikipedia)
there plenty of tutorials covering lexical analysis, parsing , building parse trees or, more often, abstract syntax trees (ast). see, example, kaleidoscope tutorial llvm.
once constructed ast, you'll need translate internal representation such byte code , pass interpreter or virtual machine. in cases possible skip step , work directly ast.
interpreter take input generated on previous step, construct runtime representation of algebraic problem (which tree-like data structure) , pass actual solver.
the solver analyze structure of problem , apply relevant methods find solution equation. example, if x
variable , a
, b
, c
parameters in example, can detect quadratic equation , apply known formulas find solution.
Comments
Post a Comment