I was just reading the Wikipedia page for WebAssembly and it says: WebAssembly is designed to be faster to parse than JavaScript , which got me thinking, what makes a certain language or data format faster to parse than others and what parsing algorithms are used?
What makes some things easier to parse than others?
data structures;parsing;syntax
This topic is very complex. You can google for parser Algorithms and you'll get plenty of detailed material.In general: the less ambiguities must be resolved, the faster the parsing process.The more tokens have to be considered before a desicion can be made, the more complex it gets.For example:When a JS parser sees the function keyword in this code: function xy(a, b) {}, the function keyword is ambigous. It first has to process the next token xyz and see that it is an identifier before it can decide that it is a function declaration.However, if the next token were a ( we are dealing with a function literal: function(a, b) {}. That requires the parser to behave very differently, thus more code in the parser, thus slower execution.If there were different keywords for these two purposes, there would be no ambiguity:function_decl xyz(a, b, c) {} and function_lit(a, b, c) {}However, noone would want to write in such a language... But WebAssembly is not supposed to be written by hand. That allows the language to be tailored towards machines, rather than humans.