开发者

javascript parse parenthesis

开发者 https://www.devze.com 2023-01-02 10:39 出处:网络
I need parse a string inside a pare开发者_StackOverflow中文版nthesis, which looks like (A, B, C), where A, B, and C are string that can contain any legal JavaScript code. For example, B might be a ver

I need parse a string inside a pare开发者_StackOverflow中文版nthesis, which looks like (A, B, C), where A, B, and C are string that can contain any legal JavaScript code. For example, B might be a very long string with nested structures similar to (A, B, C). What would be the best way to parse such a string?

An example of the string to parser is invoking a function:

func( parameter 1, parameter 2, parameter 3)

where all the three parameters could be other function definitions.


One of the simplest ways to create such a parser is to write a recursive descent parser. This type of parser is relatively easy to create and is certainly easier to understand than more complex parser generators (such as "yacc" and the like).

0

精彩评论

暂无评论...
验证码 换一张
取 消