I need a logic understanding for Rivescript Conditional syntaxes

168 Views Asked by At
! var name = Alex

+ my name is *
* <formal>   == <bot name> => Wow, we have the same name!<set name=<formal>>
* <get name> == undefined  => <set name=<formal>>Nice to meet you!
- <set oldname=<get name>><set name=<formal>> I thought your name was <get oldname>?

I don't understand how the rivescript interpreter will interpret this code in a sequence especially the 4th line confused me alot. Can somebody walk me through how this code will execute line by line?

For example:- In 4th line (<set oldname=><set name=>), if I have to return the first name which the user said then I can still do so without this logic (mentioned above) and set the variable name to instead of .

Hence, if user says Alex and then says John. The 4th line will be triggered and bot will tell user that his name was Alex.

1

There are 1 best solutions below

0
On

In every languege script is first tokenized than parsed to AST (abstract syntax tree) and than AST is interpreted.

Example of Rivescript AST from https://github.com/aichaos/rivescript-python/blob/master/rivescript/parser.py

...
"triggers": [   # array of triggers
                            {
                                "trigger": "hello bot",
                                "reply": [], # array of replies
                                "condition": [], # array of conditions
                                "redirect": None, # redirect command
                                "previous": None, # 'previous' reply
                            },...

If you dont have experience with implementin your own programin language i recommand try this course https://github.com/kanaka/mal/blob/master/process/guide.md