M
M
Maxim Vlasov2015-06-18 23:43:53
JavaScript
Maxim Vlasov, 2015-06-18 23:43:53

How to implement a simple interpreter in JavaScript?

You need to write a simple interpreter in JS. A minimum set of features is required. How can I do that? Tell me at least the principle. For example, we have text to interpret:

[сайт="http://site.ru"] [найти="a(href="xxx"),div(class="yyy")->текст"] [результат="span("класс="res")"]

How to convert something like this into JS?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2015-06-18
@tr0yka

Well, we have a simple DSL with a fairly simple structure. First we need to parse the string. You can try parsing your example with regular expressions. If regular expressions are difficult, you can try to write a character-by-character parser. Well, another good idea would be to use parser generators: pegjs.org We
collect task details from a string. Something along the lines of:

var task = {
    site: 'http://site.ru',
    find: 'selector', // селектор у вас не стандартный, придется парсить и его еще отдельно ..
    result: '' // и описание результата тоже 
}

Well, then carry out the task.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question