How Browsers work:behind The scenes of modern web Browsers

Source: Internet
Author: User
Tags lexer

http://www.html5rocks.com/en/tutorials/internals/howbrowserswork/#Parser_Lexer_combination

Grammars

Parsing is based on the syntax rules the document obeys:the language or format it were written in. Every format you can parse must has deterministic grammar consisting of vocabulary and syntax rules. It's called a Context free grammar. Human languages is not such languages and therefore cannot is parsed with conventional parsing techniques.

Parser–lexer Combination

Parsing can separated into a sub processes:lexical analysis and syntax analysis.

Lexical analysis was the process of breaking the input into tokens. Tokens is the language vocabulary:the collection of valid building blocks. In human language it would consist of all the words that appear in the dictionary for that language.

Syntax analysis is the applying of the language Syntax rules.

Parsers usually divide the work between a components:the lexer (sometimes called tokenizer) that's Responsibl E for breaking the input to valid tokens, and the parser that's responsible for constructing the parse tree by Analyzing the document structure according to the language syntax rules.
The lexer knows how to strip irrelevant characters like white spaces and line breaks.

Figure:from source document to parse trees

The parsing process is iterative.   The parser would usually ask the lexer for a new token and try to match the token with one of the syntax rules. If a rule is matched, a node corresponding to the token would be added to the parse tree and the parser would ask for anothe R token.

If No rule matches, the parser would store the token internally, and keep asking for tokens until a rule matching all the I Nternally stored tokens is found.  If no rule is found then the parser would raise an exception. This means the document is not valid and contained syntax errors.

How Browsers work:behind The scenes of modern web Browsers

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.