Answer the question
In order to leave comments, you need to log in
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")"]
Answer the question
In order to leave comments, you need to log in
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: '' // и описание результата тоже
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question