CAS command question
|
01-11-2017, 06:46 AM
Post: #74
|
|||
|
|||
RE: CAS command question
I'm really not an expert in the process of parsing. I'm using flex and bison to do that, you can refer to their documentation for much better explanation. In short, the C++ code output from flex reads the strings and cut it into words with a token value according to the rules in the file input_lexer.ll from giac source code (for example "(" has token value T_BEGIN_PAR). Then the C++ code output from bison translate the string into a giac::gen expression by grouping tokens according to the grammar in the file input_parser.yy. During that step, nothing is evaluated.
If you write a program from commandline, for example "f(x):=x^2;", it is parsed to the gen expression f:=x->x^2, then evaled, evaluation stores the expression x->x^2 (of rootnode 'program') into the variable f. After that if you write from commandline "f(a+1)" it is parsed to the giac::gen of(f,a+1), an expression of rootnode 'of' (the command to eval user programs), then it is evaled. During evaluation if a is assigned, it is replaced by the value of a, then + is done, f is replaced by x->x^2, 'program' is called, the argument x is replaced by a+1 (or the value of a+1), x^2 is executed and it returns (a+1)^2. You can see these steps in action with gdb if you compile the native version of giac. |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 2 Guest(s)