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 was written in. Every format you can parse must have deterministic grammar consisting of vocabulary and syntax rules. It is called a context free grammar. Human languages are not such languages and therefore cannot be parsed with conventional parsing techniques.

Parser–Lexer combination

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

Lexical analysis is the process of breaking the input into tokens. Tokens are the language vocabulary: the collection of valid building blocks. In human language it will 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 two components: the lexer (sometimes called tokenizer) that is responsible for breaking the input into valid tokens, and the parser that is 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 will 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 will be added to the parse tree and the parser will ask for another token.

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

How Browsers Work: Behind the scenes of modern web browsers的更多相关文章

  1. (转载)How browsers work--Behind the scenes of modern web browsers (前端必读)

    浏览器可以被认为是使用最广泛的软件,本文将介绍浏览器的工 作原理,我们将看到,从你在地址栏输入google.com到你看到google主页过程中都发生了什么. 将讨论的浏览器 今天,有五种主流浏览器— ...

  2. 【转载】How browsers work--Behind the scenes of modern web browsers (前端必读)

    浏览器可以被认为是使用最广泛的软件,本文将介绍浏览器的工 作原理,我们将看到,从你在地址栏输入google.com到你看到google主页过程中都发生了什么. 将讨论的浏览器 今天,有五种主流浏览器- ...

  3. Building Modern Web Apps-构建现代的 Web 应用程序

    Building Modern Web Apps-构建现代的 Web 应用程序 视频长度:1 小时左右 视频作者:Scott Hunter 和 Scott Hanselman 视频背景:Visual ...

  4. a buzzword to refer to modern Web technologies

    https://html.spec.whatwg.org/multipage/introduction.html#is-this-html5? HTML Living Standard — Last ...

  5. Building Modern Web Apps-构建现代的 Web 应用程序(一些感想)

    <iframe src="http://channel9.msdn.com/Series/MVA-China/Web20140611A01/player?h=540&w=960 ...

  6. modern web application

    http://www.codeproject.com/Reference/597538/Modern-Web-Development http://www.west-wind.com/presenta ...

  7. lineman 的理念与 modern web app

    无意中翻到javascript 有个 lineman工具, 提供了一些脚手架 以及 默认的app目录结构,同时还附带了诸多前端的性能优化工具,在他的主页还发现其理念与我之前关于web app的开发模型 ...

  8. Cheatsheet: 2016 04.01 ~ 04.30

    .NET String format Setting up Ubuntu for .NET Development ASP.​NET Core and Angular2 - Part 1 - Upda ...

  9. 深入理解requestAnimationFrame

    前言 本文主要参考w3c资料,从底层实现原理的角度介绍了requestAnimationFrame.cancelAnimationFrame,给出了相关的示例代码以及我对实现原理的理解和讨论. 先来看 ...

随机推荐

  1. Java Hour 10

    有句名言,叫做10000小时成为某一个领域的专家.姑且不辩论这句话是否正确,让我们到达10000小时的时候再回头来看吧. 本文作者Java 现经验约为10 Hour,请各位不吝赐教. Hour 10 ...

  2. PHP 文件上传类

    FileUpload.;                $];                $_newname = date(,). :                             To ...

  3. Web service project中导入的库JAX-RS(Java EE 6.0新产品)

    JAX-RS是JAVA EE6 引入的一个新技术. JAX-RS即Java API for RESTful Web Services,是一个Java 编程语言的应用程序接口,支持按照表述性状态转移(R ...

  4. VS2010 VB 连接数据库SQL2005

    示例一:  Dim conn As New OleDb.OleDbConnection         Dim cmmd As New OleDb.OleDbCommand         conn. ...

  5. SU suwind命令学习

  6. BZOJ2584 : [Wc2012]memory

    xy方向分开考虑 用扫描线处理出拓扑序,第二问直接回答拓扑序, 第一问: 将操作倒过来,变成加入线段,用线段树维护区间拓扑序的最值 #include<cstdio> #include< ...

  7. 【转】Eclipse Plugin 在 Console上打印出message

    org.eclipse.ui.console 转自:http://blog.csdn.net/rujielaisusan/article/details/4505188 首先这里主要用到的是org.e ...

  8. HDU 2364 (记忆化BFS搜索)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2364 题目大意:走迷宫.从某个方向进入某点,优先走左或是右.如果左右都走不通,再考虑向前.绝对不能往 ...

  9. MySql Replication配置

    一.前言 Mysql Replication作为读写分离的廉价解决方案,支持一主多备的方式进行数据存储,采用二进制日志传送,目前存在着广泛应用,网上相关概念也比较多,不再重复介绍.引用一张官方提供的R ...

  10. CentOS Git的还原和操作

    $ git log --graph --oneline $ git reset --hard 版本号 用 reflog 挽救错误的重置 [jackluo@localhost demo]$ git re ...