Using a parser not only for expressions?

Can any parsing operator or bypass algorithm be used for a simple programming language? For example, if this language has only expressions, functions, and variable declarations.

What are the pros and cons of this path? Could this be much faster than traditional LL / LR guerrillas?

+4
source share
1 answer

To answer your first question, yes, you can parse operator priorities as part of the language. If you are interested in this, you should study the Pratt guerrillas . This is usually a top-down parsing option, so it should be in the same performance area as other parsing options. In general, I think people are too concerned about the speed of parsing. The compiler will spend most of its time optimizing, and sweating a few milliseconds at the parsing stage does not seem to me necessary.

There is a magpie language that implements the Pratt parser. Therefore, the big advantage is that they defined all the operators for the language in the library instead of the main language. This makes the kernel language incredibly compact and extensible. However, the disadvantage is that other users always ask what the priority of a particular operator will be, since the usual built-in rules may not apply.

+4
source

Source: https://habr.com/ru/post/1343293/


All Articles