CN102202242A - Realization method of JavaScript interpreter based on set-top box browser - Google Patents
Realization method of JavaScript interpreter based on set-top box browser Download PDFInfo
- Publication number
- CN102202242A CN102202242A CN2011101314040A CN201110131404A CN102202242A CN 102202242 A CN102202242 A CN 102202242A CN 2011101314040 A CN2011101314040 A CN 2011101314040A CN 201110131404 A CN201110131404 A CN 201110131404A CN 102202242 A CN102202242 A CN 102202242A
- Authority
- CN
- China
- Prior art keywords
- module
- interpreter
- interpretation
- execution
- browser
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Images
Landscapes
- Devices For Executing Special Programs (AREA)
Abstract
本发明公开了一种基于机顶盒浏览器的JavaScript解释器实现方法。本发明的方法包括:解释器系统包括解释前端和解释后端及解释执行控制模块。解释前端包括词法分析器模块、语法分析器模块、源文件模块、出错处理模块、中间码生成模块;解释后端包括执行栈模块、对象库模块、子句解释器模块、表达式规约模块、对象解释模块、与浏览器交互模块、系统资源管理模块等。本发明的解释器能够在嵌入式浏览器中快速、高效地执行网页中嵌入的JavaScript语言,提高了嵌入式浏览器与用户的实时性、动态性以及交互性。能够有效地降低了小内存块的大规模使用,提高了内存利用率,效果良好。
The invention discloses a JavaScript interpreter implementation method based on a set-top box browser. The method of the invention includes: the interpreter system includes an interpreter front end, an interpreter back end and an interpreter execution control module. The interpretation front-end includes a lexical analyzer module, a syntax analyzer module, a source file module, an error handling module, and an intermediate code generation module; the interpretation back-end includes an execution stack module, an object library module, a clause interpreter module, an expression specification module, and an object Interpretation module, browser interaction module, system resource management module, etc. The interpreter of the present invention can quickly and efficiently execute the JavaScript language embedded in the webpage in the embedded browser, and improves the real-time, dynamic and interactive properties between the embedded browser and users. It can effectively reduce the large-scale use of small memory blocks, improve the memory utilization rate, and the effect is good.
Description
技术领域technical field
本发明涉及数字家庭技术领域,具体涉及一种基于机顶盒浏览器的JavaScript解释器实现方法。The invention relates to the technical field of digital home, in particular to a JavaScript interpreter implementation method based on a set-top box browser.
背景技术Background technique
数字电视的一个重要功能就是实现条件接收功能:机顶盒又是一种基于Internet的终端,因此,需要一种平台支付的手段。为了支持平台支付,需要JavaScript扩充其内置函数库,提供与平台支付相关的函数,如,扣费函数,终端消息签名函数等。另外,随着数字电视的部署,机顶盒将大规模的进入百姓家里,这样要求严格控制机顶盒的成本。因此机顶盒的配置将非常低,目前市场上常见的数字电视机顶盒配置是4M Flash,16M内存,CPU处理主频在130M左右(近期已有很多高主频产品出现),这样对浏览器和解释器的要求非常高。一般来说,要求数字电视机顶盒的嵌入式浏览器运行期间占用内存在6M下,代码大小小于1M。IPTV机顶盒的配置会相对比数字电视机顶盒高,使嵌入式浏览器发挥空间更大。在性能方面针对嵌入式系统的特点,要求解释效率高,对JavaScript的支持能够进行方便的扩充;同时要求与浏览器间的交叉尽可能少以便将JavaScript解释引擎向插件的形式方向发展。An important function of digital TV is to realize the conditional access function: the set-top box is also a terminal based on the Internet, therefore, a means of platform payment is needed. In order to support platform payment, JavaScript needs to expand its built-in function library to provide functions related to platform payment, such as deduction function, terminal message signature function, etc. In addition, with the deployment of digital TV, set-top boxes will enter people's homes on a large scale, which requires strict control of the cost of set-top boxes. Therefore, the configuration of the set-top box will be very low. The common configuration of the digital TV set-top box on the market is 4M Flash, 16M memory, and the main frequency of CPU processing is about 130M (many high-frequency products have appeared recently). The requirements are very high. Generally speaking, the embedded browser of the digital TV set-top box is required to occupy less than 6M of memory during operation, and the code size is less than 1M. The configuration of the IPTV set-top box will be relatively higher than that of the digital TV set-top box, so that the embedded browser will have more room to play. In terms of performance, according to the characteristics of embedded systems, it is required to have high interpretation efficiency and convenient expansion of JavaScript support; at the same time, it is required to have as little cross-over as possible with the browser so that the JavaScript interpretation engine can be developed in the form of plug-ins.
在对此方法的研究和实践过程中,本发明的发明人发现:本发明的解释器能够在嵌入式浏览器中快速、 高效地执行网页中嵌入的JavaScript语言 ,提高了嵌入式浏览器与用户的实时性、 动态性以及交互性。能够有效地降低了小内存块的大规模使用,提高了内存利用率,效果良好。During the research and practice of this method, the inventor of the present invention found that the interpreter of the present invention can quickly and efficiently execute the JavaScript language embedded in the webpage in the embedded browser, which improves the interaction between the embedded browser and the user. real-time, dynamic and interactive. It can effectively reduce the large-scale use of small memory blocks, improve the memory utilization rate, and the effect is good.
发明内容Contents of the invention
本发明要解决的技术问题是提供一种基于机顶盒浏览器的JavaScript解释器实现方法能够在嵌入式浏览器中快速、 高效地执行网页中嵌入的JavaScript语言 ,提高了嵌入式浏览器与用户的实时性、 动态性以及交互性。能够有效地降低小内存块的大规模使用,提高内存利用率。The technical problem to be solved by the present invention is to provide a JavaScript interpreter implementation method based on a set-top box browser, which can quickly and efficiently execute the JavaScript language embedded in the webpage in the embedded browser, and improve the real-time interaction between the embedded browser and the user. Sexuality, dynamicity and interactivity. It can effectively reduce the large-scale use of small memory blocks and improve memory utilization.
一种基于机顶盒浏览器的JavaScript解释器实现方法,其特征在于:包括解释器系统包括解释前端和解释后端及解释执行控制模块。解释前端包括词法分析器模块、语法分析器模块、源文件模块、出错处理模块、中间码生成模块;解释后端包括执行栈模块、对象库模块、子句解释器模块、表达式规约模块、对象解释模块、与浏览器交互模块、系统资源管理模块;其中,A JavaScript interpreter implementation method based on a set-top box browser is characterized in that: the interpreter system includes an interpreter front end, an interpreter back end and an interpreter execution control module. Interpretation front-end includes lexical analyzer module, syntax analyzer module, source file module, error handling module, intermediate code generation module; interpretation back-end includes execution stack module, object library module, clause interpreter module, expression specification module, object Explanation module, browser interaction module, system resource management module; among them,
词法分析器模块将源程序以字符串的方式读入,并将其分为若干个记号,记号于自然语言中的单词类似。我们将JavaScript语言的单词分为标识符、字符串、整数、浮点数、布尔值、运算符等。源程序经过词法分析后生成一个单词双向链表,供后面的语法分析器模块调用。The lexical analyzer module reads the source program as a character string and divides it into several tokens, which are similar to words in natural language. We classify the words of the JavaScript language into identifiers, strings, integers, floats, booleans, operators, etc. After the source program undergoes lexical analysis, a word doubly linked list is generated for calling by the subsequent syntax analyzer module.
语法分析器模块以单词链表作为输入,分别调用不同的语句识别器,识别它们是否符合给定文法,并最终生成一个语法树结构的中间代码,供后面解释执行控制模块执行。The syntax analyzer module takes the word linked list as input, calls different sentence recognizers respectively, recognizes whether they conform to the given grammar, and finally generates an intermediate code with a syntax tree structure, which will be executed by the later interpretation and execution control module.
中间码生成模块是把源程序经词法分析和语法分析后产生的结果生成为中间结果。它包含程序流程结构和数据字典两方面的内容。程序流程结构中包含了各种语句结构,数据字典是用来存放程序数据的地方,它是指存贮的全局变量、子程序中的局部变量和复合语句中的局部变量的集合。数据字典供表达式归约模块在归约过程中查找所需要的数据。The intermediate code generating module is to generate the result of the source program after lexical analysis and syntax analysis as an intermediate result. It includes two aspects of program flow structure and data dictionary. The program flow structure contains various statement structures. The data dictionary is used to store program data. It refers to the collection of stored global variables, local variables in subprograms and local variables in compound statements. The data dictionary is used by the expression reduction module to find the required data during the reduction process.
解释执行控制模块解释执行控制器负责根据预先生成好的中间数据结构,按照语句的语义对源程序语句进行逐条解释执行。它控制程序的顺序执行过程。执行过程中调用语句解释器解释执行单条语句,并根据解释结果控制程序的继续执行或终止。Interpretation and execution control module The interpretation and execution controller is responsible for interpreting and executing the source program statements one by one according to the semantics of the statement according to the pre-generated intermediate data structure. It controls the sequential execution of the program. During the execution process, the statement interpreter is called to interpret and execute a single statement, and control the continuation or termination of the program according to the interpretation result.
执行栈模块是表达式归约模块所要用到的数据结构,它包含一个符号栈和一个操作数栈,分别用来存放表达式归约过程中的终结符号和操作数。The execution stack module is the data structure used by the expression reduction module. It includes a symbol stack and an operand stack, which are used to store terminal symbols and operands in the expression reduction process.
对象库模块也是用来存放程序数据的地方,它是指存贮的系统定义对象、The object library module is also used to store program data, which refers to the stored system-defined objects,
浏览器文档模型中的对象和用户自定义对象的集合。对象库为解释器的对象解释提供了运行基础,同时也为解释器与浏览器的交互提供了运行机制。它包含了对象的属性、方法和事件处理等方面的内容。A collection of objects in the browser's document model and user-defined objects. The object library provides the operating basis for the object interpretation of the interpreter, and also provides the operating mechanism for the interaction between the interpreter and the browser. It contains the properties of the object, methods and event processing and other aspects of the content.
出错处理模块负责处理词法分析、语法分析及解释执行过程中出现的错The error handling module is responsible for dealing with lexical analysis, syntax analysis and explaining errors that occur during execution.
误,如果源程序词法语法不符合JavaScript语言的规则,或者执行时出现错误,则记录当前执行的语句,并立即返回。Error, if the lexical syntax of the source program does not conform to the rules of the JavaScript language, or an error occurs during execution, it will record the currently executed statement and return immediately.
子句解释器模块完成单条语句的解释执行。每一种类型的语句都对应一个语句解释器。它根据语句类型完成相应的语义动作。子句解释器在解释过程中调用表达式归约模块计算表达式的值,并根据计算结果控制语句流程。The clause interpreter module completes the interpretation and execution of a single statement. Each type of statement corresponds to a statement interpreter. It completes the corresponding semantic action according to the statement type. The clause interpreter calls the expression reduction module to calculate the value of the expression during the interpretation process, and controls the flow of the statement according to the calculation result.
表达式归约模块完成在语句执行过程中组成语句的各种表达式的运算。表达式归约模块按照表达式的产生式规则找出子表达式进行归约最终得出表达式的运算结果。The expression reduction module completes the operation of various expressions that make up the statement during the execution of the statement. The expression reduction module finds sub-expressions according to the production rules of the expression and performs reduction to finally obtain the operation result of the expression.
对象解释模块实现JavaScript语言基于对象的特性,它包含对象的引用、方法调用和事件处理。在对象解释过程中,解释器通过对象属性值的变化、对象的方法调用或事件处理完成与浏览器的交互。与浏览器交互模块完成脚本程序的解释执行对网页产生的副作用,修改浏览器对象的属性,影响或改变浏览器的输出显示。如引起网页中的控件位置变化、触发网页中表单的提交等。The object interpretation module implements the object-based features of the JavaScript language, which includes object references, method calls, and event processing. In the process of object interpretation, the interpreter completes the interaction with the browser through the change of object property value, object method call or event processing. The interactive module with the browser completes the interpretation and execution of the script program to produce side effects on the web page, modifies the properties of the browser object, and affects or changes the output display of the browser. For example, it causes the position of the control in the web page to change, triggers the submission of the form in the web page, and so on.
系统资源管理模块系统资源管理作用于整个解释器,对解释器所用到的内存资源进行分配和回收,对CPU资源进行合理控制。System resource management module System resource management acts on the entire interpreter, allocates and recycles memory resources used by the interpreter, and controls CPU resources reasonably.
所述的解释前端的设计上,语法分析器模块在逻辑上高于词法分析器模块和语义动作部件,采取“即用即取”的策略,节省了单词链表等中间数据结构的内存开销。In the design of the explanation front end, the syntax analyzer module is logically higher than the lexical analyzer module and the semantic action components, and adopts the strategy of "ready-to-use" to save the memory overhead of intermediate data structures such as word linked lists.
解释器的后端系统实际上是一个解释自定义字节码的虚拟机。后端虚拟机系统是由字节码解释控制程序和函数调用关系栈、操作数栈、变量数据栈和对象信息记录表五部分组成的。The interpreter's backend system is actually a virtual machine that interprets custom bytecode. The back-end virtual machine system is composed of five parts: bytecode interpretation control program and function call relation stack, operand stack, variable data stack and object information record table.
其中,字节码字节控制程序根据字节码的操作符码,对操作数进行操作,比如进栈出栈等。 函数调用关系栈记录了JavaScript各种可执行代码的相互调用关系,每当进入一个新的可执行代码,就在函数调用关系栈栈顶压入当前可执行代码的的执行上下文环境信息。操作数栈主要用于进行各种计算和中间结果的保存。中间字节码的所有计算均基于它来进行。变量数据栈用于记录字节码执行时的变量信息。每当进入一个新的可执行代码,就在变量数据栈压入当前可执行代码的局部变量信息(包括变量名称、类型、值等),一旦当前的可执行代码执行完毕,变量数据栈顶元素即被弹出,同时函数调用关系栈和操作数栈中相关元素弹出。对象信息记录表是存储各种JavaScript对象的内存区。由于手机中间件平台的可用内存资源有限和小内存块利用不充分的特点,将固定长度的结构数组作为对象信息记录表。对象记录表中记录包括对象的属性个数、对象的属性信息等。在JavaScript中,对象的方法也被视作对象的属性。Wherein, the bytecode byte control program operates on the operand according to the operator code of the bytecode, such as stacking and popping. The function call relationship stack records the mutual call relationship of various JavaScript executable codes. Whenever a new executable code is entered, the execution context information of the current executable code is pushed on the top of the function call relationship stack. The operand stack is mainly used for various calculations and storage of intermediate results. All calculations of the intermediate bytecode are performed based on it. The variable data stack is used to record variable information during bytecode execution. Whenever a new executable code is entered, the local variable information (including variable name, type, value, etc.) of the current executable code is pushed into the variable data stack. Once the current executable code is executed, the top element of the variable data stack That is, it is popped up, and the relevant elements in the function call relation stack and the operand stack are popped up at the same time. The object information record table is a memory area that stores various JavaScript objects. Due to the limited available memory resources of the mobile phone middleware platform and the insufficient utilization of small memory blocks, the fixed-length structure array is used as the object information record table. The records in the object record table include the number of attributes of the object, the attribute information of the object, and so on. In JavaScript, methods of an object are also considered properties of the object.
上述技术方案可以看出,本发明具有如下有益效果:It can be seen from the foregoing technical scheme that the present invention has the following beneficial effects:
本发明的解释器能够在嵌入式浏览器中快速、 高效地执行网页中嵌入的JavaScript语言 ,提高了嵌入式浏览器与用户的实时性、 动态性以及交互性。能够有效地降低了小内存块的大规模使用,提高了内存利用率,效果良好。The interpreter of the present invention can quickly and efficiently execute the JavaScript language embedded in the webpage in the embedded browser, and improves the real-time, dynamic and interactivity between the embedded browser and the user. It can effectively reduce the large-scale use of small memory blocks, improve the memory utilization rate, and the effect is good.
附图说明Description of drawings
为了更清楚地说明本发明实施例或现有技术中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本发明的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其它的附图。In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the drawings that need to be used in the description of the embodiments or the prior art. Obviously, the accompanying drawings in the following description are only These are some embodiments of the present invention. Those skilled in the art can also obtain other drawings based on these drawings without creative work.
图1是本发明一种基于机顶盒浏览器的JavaScript解释器实现方法的系统结构图;Fig. 1 is a system structure diagram of a JavaScript interpreter implementation method based on a set-top box browser of the present invention;
图2是本发明一种基于机顶盒浏览器的JavaScript解释器实现方法的词法分析器模块结构图;Fig. 2 is a kind of lexical analyzer module structural diagram of the JavaScript interpreter implementation method based on set-top box browser of the present invention;
图3是本发明一种基于机顶盒浏览器的JavaScript解释器实现方法的语法分析器模块结构图。FIG. 3 is a structural diagram of a syntax analyzer module of a method for implementing a JavaScript interpreter based on a set-top box browser in the present invention.
具体实施方式Detailed ways
下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有作出创造性劳动前提下所获得的所有其它实施例,都属于本发明保护的范围。The following will clearly and completely describe the technical solutions in the embodiments of the present invention with reference to the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only some, not all, embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by persons of ordinary skill in the art without creative efforts fall within the protection scope of the present invention.
本发明实施例提供一种基于机顶盒浏览器的JavaScript解释器实现方法,以下分别进行详细说明。An embodiment of the present invention provides a method for implementing a JavaScript interpreter based on a set-top box browser, which will be described in detail below.
如图1所示解释器系统包括解释前端和解释后端及解释执行控制模块。解释前端包括词法分析器模块、语法分析器模块、源文件模块、出错处理模块、中间码生成模块;解释后端包括执行栈模块、对象库模块、子句解释器模块、表达式规约模块、对象解释模块、与浏览器交互模块、系统资源管理模块;As shown in Figure 1, the interpreter system includes an interpreter front end, an interpreter back end, and an interpreter execution control module. The interpretation front-end includes a lexical analyzer module, a syntax analyzer module, a source file module, an error handling module, and an intermediate code generation module; the interpretation back-end includes an execution stack module, an object library module, a clause interpreter module, an expression specification module, and an object Explanation module, interaction module with browser, system resource management module;
其中,词法分析器模块将源程序以字符串的方式读入,并将其分为若干个记号,记号于自然语言中的单词类似。我们将JavaScript语言的单词分为标识符、字符串、整数、浮点数、布尔值、运算符等。源程序经过词法分析后生成一个单词双向链表,供后面的语法分析器模块调用。Among them, the lexical analyzer module reads the source program in the form of character strings and divides it into several tokens, which are similar to words in natural language. We classify the words of the JavaScript language into identifiers, strings, integers, floats, booleans, operators, etc. After the source program undergoes lexical analysis, a word doubly linked list is generated for calling by the subsequent syntax analyzer module.
语法分析器模块以单词链表作为输入,分别调用不同的语句识别器,识别它们是否符合给定文法,并最终生成一个语法树结构的中间代码,供后面解释执行控制模块执行。The syntax analyzer module takes the word linked list as input, calls different sentence recognizers respectively, recognizes whether they conform to the given grammar, and finally generates an intermediate code with a syntax tree structure, which will be executed by the later interpretation and execution control module.
中间码生成模块是把源程序经词法分析和语法分析后产生的结果生成为中间结果。它包含程序流程结构和数据字典两方面的内容。程序流程结构中包含了各种语句结构,数据字典是用来存放程序数据的地方,它是指存贮的全局变量、子程序中的局部变量和复合语句中的局部变量的集合。数据字典供表达式归约模块在归约过程中查找所需要的数据。The intermediate code generating module is to generate the result of the source program after lexical analysis and syntax analysis as an intermediate result. It includes two aspects of program flow structure and data dictionary. The program flow structure contains various statement structures. The data dictionary is used to store program data. It refers to the collection of stored global variables, local variables in subprograms and local variables in compound statements. The data dictionary is used by the expression reduction module to find the required data during the reduction process.
解释执行控制模块解释执行控制器负责根据预先生成好的中间数据结构,按照语句的语义对源程序语句进行逐条解释执行。它控制程序的顺序执行过程。执行过程中调用语句解释器解释执行单条语句,并根据解释结果控制程序的继续执行或终止。Interpretation and execution control module The interpretation and execution controller is responsible for interpreting and executing the source program statements one by one according to the semantics of the statement according to the pre-generated intermediate data structure. It controls the sequential execution of the program. During the execution process, the statement interpreter is called to interpret and execute a single statement, and control the continuation or termination of the program according to the interpretation result.
执行栈模块是表达式归约模块所要用到的数据结构,它包含一个符号栈和一个操作数栈,分别用来存放表达式归约过程中的终结符号和操作数。The execution stack module is the data structure used by the expression reduction module. It includes a symbol stack and an operand stack, which are used to store terminal symbols and operands in the expression reduction process.
对象库模块也是用来存放程序数据的地方,它是指存贮的系统定义对象、The object library module is also used to store program data, which refers to the stored system-defined objects,
浏览器文档模型中的对象和用户自定义对象的集合。对象库为解释器的对象解释提供了运行基础,同时也为解释器与浏览器的交互提供了运行机制。它包含了对象的属性、方法和事件处理等方面的内容。A collection of objects in the browser's document model and user-defined objects. The object library provides the operating basis for the object interpretation of the interpreter, and also provides the operating mechanism for the interaction between the interpreter and the browser. It contains the properties of the object, methods and event processing and other aspects of the content.
出错处理模块负责处理词法分析、语法分析及解释执行过程中出现的错The error handling module is responsible for dealing with lexical analysis, syntax analysis and explaining errors that occur during execution.
误,如果源程序词法语法不符合JavaScript语言的规则,或者执行时出现错误,则记录当前执行的语句,并立即返回。Error, if the lexical syntax of the source program does not conform to the rules of the JavaScript language, or an error occurs during execution, it will record the currently executed statement and return immediately.
子句解释器模块完成单条语句的解释执行。每一种类型的语句都对应一个语句解释器。它根据语句类型完成相应的语义动作。子句解释器在解释过程中调用表达式归约模块计算表达式的值,并根据计算结果控制语句流程。The clause interpreter module completes the interpretation and execution of a single statement. Each type of statement corresponds to a statement interpreter. It completes the corresponding semantic action according to the statement type. The clause interpreter calls the expression reduction module to calculate the value of the expression during the interpretation process, and controls the flow of the statement according to the calculation result.
表达式归约模块完成在语句执行过程中组成语句的各种表达式的运算。表达式归约模块按照表达式的产生式规则找出子表达式进行归约最终得出表达式的运算结果。The expression reduction module completes the operation of various expressions that make up the statement during the execution of the statement. The expression reduction module finds sub-expressions according to the production rules of the expression and performs reduction to finally obtain the operation result of the expression.
对象解释模块实现JavaScript语言基于对象的特性,它包含对象的引用、方法调用和事件处理。在对象解释过程中,解释器通过对象属性值的变化、对象的方法调用或事件处理完成与浏览器的交互。与浏览器交互模块完成脚本程序的解释执行对网页产生的副作用,修改浏览器对象的属性,影响或改变浏览器的输出显示。如引起网页中的控件位置变化、触发网页中表单的提交等。The object interpretation module implements the object-based features of the JavaScript language, which includes object references, method calls, and event processing. In the process of object interpretation, the interpreter completes the interaction with the browser through the change of object property value, object method call or event processing. The interactive module with the browser completes the interpretation and execution of the script program to produce side effects on the web page, modifies the properties of the browser object, and affects or changes the output display of the browser. For example, it causes the position of the control in the web page to change, triggers the submission of the form in the web page, and so on.
系统资源管理模块系统资源管理作用于整个解释器,对解释器所用到的内存资源进行分配和回收,对CPU资源进行合理控制。System resource management module System resource management acts on the entire interpreter, allocates and recycles memory resources used by the interpreter, and controls CPU resources reasonably.
所述的解释前端的设计上,语法分析器模块在逻辑上高于词法分析器模块和语义动作部件,采取“即用即取”的策略,节省了单词链表等中间数据结构的内存开销。In the design of the explanation front end, the syntax analyzer module is logically higher than the lexical analyzer module and the semantic action components, and adopts the strategy of "ready-to-use" to save the memory overhead of intermediate data structures such as word linked lists.
解释器的后端系统实际上是一个解释自定义字节码的虚拟机。后端虚拟机系统是由字节码解释控制程序和函数调用关系栈、操作数栈、变量数据栈和对象信息记录表五部分组成的。The interpreter's backend system is actually a virtual machine that interprets custom bytecode. The back-end virtual machine system is composed of five parts: bytecode interpretation control program and function call relation stack, operand stack, variable data stack and object information record table.
其中,字节码字节控制程序根据字节码的操作符码,对操作数进行操作,比如进栈出栈等。 函数调用关系栈记录了JavaScript各种可执行代码的相互调用关系,每当进入一个新的可执行代码,就在函数调用关系栈栈顶压入当前可执行代码的的执行上下文环境信息。操作数栈主要用于进行各种计算和中间结果的保存。中间字节码的所有计算均基于它来进行。变量数据栈用于记录字节码执行时的变量信息。每当进入一个新的可执行代码,就在变量数据栈压入当前可执行代码的局部变量信息(包括变量名称、类型、值等),一旦当前的可执行代码执行完毕,变量数据栈顶元素即被弹出,同时函数调用关系栈和操作数栈中相关元素弹出。对象信息记录表是存储各种JavaScript对象的内存区。由于手机中间件平台的可用内存资源有限和小内存块利用不充分的特点,将固定长度的结构数组作为对象信息记录表。对象记录表中记录包括对象的属性个数、对象的属性信息等。在JavaScript中,对象的方法也被视作对象的属性。Wherein, the bytecode byte control program performs operations on operands, such as stacking and popping, according to the operator code of the bytecode. The function call relationship stack records the mutual call relationship of various JavaScript executable codes. Whenever a new executable code is entered, the execution context information of the current executable code is pushed on the top of the function call relationship stack. The operand stack is mainly used for various calculations and storage of intermediate results. All calculations of the intermediate bytecode are performed based on it. The variable data stack is used to record variable information during bytecode execution. Whenever a new executable code is entered, the local variable information (including variable name, type, value, etc.) of the current executable code is pushed into the variable data stack. Once the current executable code is executed, the top element of the variable data stack That is, it is popped up, and the relevant elements in the function call relation stack and the operand stack are popped up at the same time. The object information record table is a memory area that stores various JavaScript objects. Due to the limited available memory resources of the mobile phone middleware platform and the insufficient utilization of small memory blocks, the fixed-length structure array is used as the object information record table. The records in the object record table include the number of attributes of the object, the attribute information of the object, and so on. In JavaScript, methods of an object are also considered properties of the object.
如图2所示词法分析器模块处理流程是:当词法分析器调用预处理子程序剔除无用的空格、跳格、回车和换行等编辑性文字,处理出一串输入字符放进扫描缓冲区之后,扫描器就从缓冲区中逐一识别单词符号。当缓冲区里的字符串被处理之后,它又调用预处理程序装入新串。As shown in Figure 2, the processing flow of the lexical analyzer module is: when the lexical analyzer calls the preprocessing subroutine to eliminate useless editing text such as spaces, tabs, carriage returns, and line feeds, a string of input characters is processed and put into the scan buffer After that, the scanner recognizes word symbols one by one from the buffer. When the string in the buffer is processed, it calls the preprocessor to load the new string.
如图3所示语法分析器模块处理流程是:以词法分析所生成的单词符号双向链表为输入,依据语法分析法,对源程序语句进行逐一分析,最终生成源程序的语句流程图和数据字典。执行过程中调用语句识别器,对不同种类的语句进行识别,同时还要生成数据字典,以供解释执行控制模块对表达式规约使用。As shown in Figure 3, the processing flow of the syntax analyzer module is: taking the word symbol doubly linked list generated by lexical analysis as input, analyzing the source program statements one by one according to the syntax analysis method, and finally generating the source program statement flow chart and data dictionary . During the execution, the statement recognizer is called to identify different kinds of statements, and at the same time, a data dictionary is also generated for the interpretation and execution control module to use for the expression specification.
语句识别器完成对单条语句的识别,对于不同种类的语句都有一语句识别器与之相对应。语句识别器是按照语句的语法规则和语义进行语句识别的。数据字典是存放程序数据的地方,它包括全局变量、函数形参变量以及语句块中的局部变量。数据字典供解释执行模块的表达式规约模块在进行表达式规约时查找所需要的数据。The sentence recognizer completes the recognition of a single sentence, and there is a sentence recognizer corresponding to different types of sentences. Sentence recognizer recognizes sentences according to the grammatical rules and semantics of the sentence. The data dictionary is the place where program data is stored, including global variables, function parameter variables, and local variables in statement blocks. The data dictionary is used for the expression specification module of the interpretation execution module to find the required data when performing expression specification.
需要说明的是,上述装置和系统内的各单元之间的信息交互、执行过程等内容,由于与本发明方法实施例基于同一构思,具体内容可参见本发明方法实施例中的叙述,此处不再赘述。It should be noted that, since the information interaction and execution process between the above-mentioned devices and units in the system are based on the same idea as the method embodiment of the present invention, the specific content can refer to the description in the method embodiment of the present invention, here No longer.
本领域普通技术人员可以理解上述实施例的各种方法中的全部或部分步骤是可以通过程序来指令相关的硬件来完成,该程序可以存储于一计算机可读存储介质中,存储介质可以包括:只读存储器(ROM,Read Only Memory)、随机存取存储器(RAM,Random Access Memory)、磁盘或光盘等。Those of ordinary skill in the art can understand that all or part of the steps in the various methods of the above-mentioned embodiments can be completed by instructing related hardware through a program, and the program can be stored in a computer-readable storage medium, and the storage medium can include: Read Only Memory (ROM, Read Only Memory), Random Access Memory (RAM, Random Access Memory), disk or CD, etc.
以上对本发明实施例所提供的一种基于机顶盒浏览器的JavaScript解释器实现方法,进行了详细介绍,本文中应用了具体个例对本发明的原理及实施方式进行了阐述,以上实施例的说明只是用于帮助理解本发明的方法及其核心思想;同时,对于本领域的一般技术人员,依据本发明的思想,在具体实施方式及应用范围上均会有改变之处,综上所述,本说明书内容不应理解为对本发明的限制。The implementation method of a JavaScript interpreter based on a set-top box browser provided by the embodiment of the present invention has been introduced in detail above. In this paper, specific examples have been used to illustrate the principle and implementation of the present invention. The description of the above embodiments is only It is used to help understand the method of the present invention and its core idea; at the same time, for those of ordinary skill in the art, according to the idea of the present invention, there will be changes in the specific implementation and scope of application. In summary, this The content of the description should not be construed as limiting the present invention.
Claims (3)
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN2011101314040A CN102202242A (en) | 2011-05-19 | 2011-05-19 | Realization method of JavaScript interpreter based on set-top box browser |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN2011101314040A CN102202242A (en) | 2011-05-19 | 2011-05-19 | Realization method of JavaScript interpreter based on set-top box browser |
Publications (1)
Publication Number | Publication Date |
---|---|
CN102202242A true CN102202242A (en) | 2011-09-28 |
Family
ID=44662569
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN2011101314040A Pending CN102202242A (en) | 2011-05-19 | 2011-05-19 | Realization method of JavaScript interpreter based on set-top box browser |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN102202242A (en) |
Cited By (13)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102495890A (en) * | 2011-12-09 | 2012-06-13 | 上海全景数字技术有限公司 | Embedded browser application extension system and method |
CN102736943A (en) * | 2012-06-12 | 2012-10-17 | 电子科技大学 | Dynamic compiling and executing method of embedded browser engine |
CN103019830A (en) * | 2012-12-31 | 2013-04-03 | 深圳Tcl新技术有限公司 | Method and device for achieving browser script language execution fault tolerance |
CN103152641A (en) * | 2011-12-07 | 2013-06-12 | 深圳市快播科技有限公司 | Method and system for manipulating set top box through webpage interface |
CN103793644A (en) * | 2014-02-28 | 2014-05-14 | 天地融科技股份有限公司 | Method for information safety device to achieve multiple applications, and information safety device and system |
CN104778282A (en) * | 2015-05-07 | 2015-07-15 | 烽火通信科技股份有限公司 | Browser webpage fault-tolerance method and system for IPTV set top box |
WO2016206440A1 (en) * | 2015-06-25 | 2016-12-29 | 中兴通讯股份有限公司 | Page processing method and multimedia terminal |
CN106663094A (en) * | 2014-07-11 | 2017-05-10 | 洛林·G·克雷默三世 | Method and system for linear generalized LL recognition and context-aware parsing |
CN108595166A (en) * | 2018-05-09 | 2018-09-28 | 中国科学院计算技术研究所 | A kind of distribution Internet of Things application execution engine implementing method and system |
CN109614104A (en) * | 2018-11-23 | 2019-04-12 | 北京字节跳动网络技术有限公司 | The method, apparatus and electronic equipment of new semantic structure are added based on template pretreatment |
CN110597502A (en) * | 2019-08-20 | 2019-12-20 | 北京东方国信科技股份有限公司 | Single-step debugging method for realizing PL/SQL language based on java |
CN110853327A (en) * | 2019-11-02 | 2020-02-28 | 杭州雅格纳科技有限公司 | Ship cabin equipment data field debugging and collecting method and device based on single chip microcomputer |
US10664655B2 (en) | 2014-07-11 | 2020-05-26 | Loring G. Craymer, III | Method and system for linear generalized LL recognition and context-aware parsing |
Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US5812850A (en) * | 1995-11-13 | 1998-09-22 | Object Technology Licensing Corp. | Object-oriented symbolic debugger using a compiler driven database and state modeling to control program execution |
US6226791B1 (en) * | 1997-07-23 | 2001-05-01 | International Business Machines Corporation | Compiler-assisted or interpreter-assisted compression solution to the year 2000 problem for computer programs |
CN101196812A (en) * | 2007-12-14 | 2008-06-11 | 上海科泰世纪科技有限公司 | Method for script language calling multiple output parameter interface by component software system |
CN101710273A (en) * | 2009-10-28 | 2010-05-19 | 金蝶软件(中国)有限公司 | Method and device for analyzing multi-dimensional query sentence in online analysis processing server |
-
2011
- 2011-05-19 CN CN2011101314040A patent/CN102202242A/en active Pending
Patent Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US5812850A (en) * | 1995-11-13 | 1998-09-22 | Object Technology Licensing Corp. | Object-oriented symbolic debugger using a compiler driven database and state modeling to control program execution |
US6226791B1 (en) * | 1997-07-23 | 2001-05-01 | International Business Machines Corporation | Compiler-assisted or interpreter-assisted compression solution to the year 2000 problem for computer programs |
CN101196812A (en) * | 2007-12-14 | 2008-06-11 | 上海科泰世纪科技有限公司 | Method for script language calling multiple output parameter interface by component software system |
CN101710273A (en) * | 2009-10-28 | 2010-05-19 | 金蝶软件(中国)有限公司 | Method and device for analyzing multi-dimensional query sentence in online analysis processing server |
Non-Patent Citations (2)
Title |
---|
刘仕坤等: "基于手机中间件的JavaScript解释器设计与实现", 《计算机系统应用》 * |
柯宏: "嵌入式JavaScript解释器在机顶盒中的设计与实现", 《中国优秀硕士学位论文全文数据库 信息科技辑》 * |
Cited By (22)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN103152641A (en) * | 2011-12-07 | 2013-06-12 | 深圳市快播科技有限公司 | Method and system for manipulating set top box through webpage interface |
CN102495890A (en) * | 2011-12-09 | 2012-06-13 | 上海全景数字技术有限公司 | Embedded browser application extension system and method |
CN102736943A (en) * | 2012-06-12 | 2012-10-17 | 电子科技大学 | Dynamic compiling and executing method of embedded browser engine |
CN102736943B (en) * | 2012-06-12 | 2015-06-17 | 电子科技大学 | Dynamic compiling and executing method of embedded browser engine |
CN103019830B (en) * | 2012-12-31 | 2016-09-21 | 深圳Tcl新技术有限公司 | Realize the method and device of browser script language execution fault tolerance |
CN103019830A (en) * | 2012-12-31 | 2013-04-03 | 深圳Tcl新技术有限公司 | Method and device for achieving browser script language execution fault tolerance |
CN103793644B (en) * | 2014-02-28 | 2017-09-19 | 天地融科技股份有限公司 | Information safety devices realize method, information safety devices and the system of many applications |
CN103793644A (en) * | 2014-02-28 | 2014-05-14 | 天地融科技股份有限公司 | Method for information safety device to achieve multiple applications, and information safety device and system |
CN106663094B (en) * | 2014-07-11 | 2020-03-27 | 洛林·G·克雷默三世 | Method and system for linear generalized LL recognition and context-aware parsing |
CN106663094A (en) * | 2014-07-11 | 2017-05-10 | 洛林·G·克雷默三世 | Method and system for linear generalized LL recognition and context-aware parsing |
US10664655B2 (en) | 2014-07-11 | 2020-05-26 | Loring G. Craymer, III | Method and system for linear generalized LL recognition and context-aware parsing |
CN104778282A (en) * | 2015-05-07 | 2015-07-15 | 烽火通信科技股份有限公司 | Browser webpage fault-tolerance method and system for IPTV set top box |
CN104778282B (en) * | 2015-05-07 | 2018-01-02 | 烽火通信科技股份有限公司 | The webpage fault-tolerance approach and system of a kind of IPTV set top box browser |
WO2016206440A1 (en) * | 2015-06-25 | 2016-12-29 | 中兴通讯股份有限公司 | Page processing method and multimedia terminal |
CN108595166B (en) * | 2018-05-09 | 2020-12-11 | 中国科学院计算技术研究所 | A method and system for implementing a distributed Internet of Things application execution engine |
CN108595166A (en) * | 2018-05-09 | 2018-09-28 | 中国科学院计算技术研究所 | A kind of distribution Internet of Things application execution engine implementing method and system |
CN109614104A (en) * | 2018-11-23 | 2019-04-12 | 北京字节跳动网络技术有限公司 | The method, apparatus and electronic equipment of new semantic structure are added based on template pretreatment |
CN109614104B (en) * | 2018-11-23 | 2022-04-05 | 北京字节跳动网络技术有限公司 | Method and device for adding new semantic structure based on template preprocessing and electronic equipment |
CN110597502A (en) * | 2019-08-20 | 2019-12-20 | 北京东方国信科技股份有限公司 | Single-step debugging method for realizing PL/SQL language based on java |
CN110597502B (en) * | 2019-08-20 | 2023-05-23 | 北京东方国信科技股份有限公司 | Single step debugging method for realizing PL/SQL language based on java |
CN110853327A (en) * | 2019-11-02 | 2020-02-28 | 杭州雅格纳科技有限公司 | Ship cabin equipment data field debugging and collecting method and device based on single chip microcomputer |
CN110853327B (en) * | 2019-11-02 | 2021-04-02 | 杭州雅格纳科技有限公司 | Ship cabin equipment data field debugging and collecting method and device based on single chip microcomputer |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN102202242A (en) | Realization method of JavaScript interpreter based on set-top box browser | |
JP7324831B2 (en) | DEPLOYMENT METHOD, DEPLOYMENT DEVICE AND ELECTRONIC DEVICE OF OPERATORS IN DEEP LEARNING FRAMEWORK | |
US20210004443A1 (en) | Pinning artifacts for expansion of search keys and search spaces in a natural language understanding (nlu) framework | |
US9239710B2 (en) | Programming language transformations with abstract syntax tree extensions | |
US20180136914A1 (en) | Programming Language with Extensions using a Strict Meta-Model | |
CN113031932B (en) | Project development method, apparatus, electronic device and storage medium | |
WO2013036703A2 (en) | Profile guided jit code generation | |
CN111831384A (en) | Language switching method and device, equipment and storage medium | |
KR20080018160A (en) | A method for representing speech recognition grammars in software programs using strong data types | |
JP7344259B2 (en) | Pattern transformation methods, apparatus, electronic devices, computer storage media and computer program products in deep learning frameworks | |
CN114996619A (en) | Page display method and device, computer equipment and storage medium | |
WO2024234614A1 (en) | Information processing method and apparatus, device, computer-readable storage medium and computer program product | |
EP4330810A1 (en) | Code injection from natural language derived intent | |
CN112948419A (en) | Query statement processing method and device | |
CN110377371B (en) | Style sheet system management method based on Web tag | |
CN110874350A (en) | Method and device for processing structured log data | |
JP4768984B2 (en) | Compiling method, compiling program, and compiling device | |
CN110058849A (en) | Generation method, device, computer equipment and the storage medium of flow chart | |
WO2023097750A1 (en) | Order booking method based on cross-terminal program generation system | |
US20100023924A1 (en) | Non-constant data encoding for table-driven systems | |
CN112527272A (en) | Method for butting TVM and related equipment | |
US8056063B2 (en) | Method and apparatus minimizing code duplication in a statically typeable language program | |
Purve et al. | Stack and queue based parser approach for parsing expression grammar | |
CN115809294A (en) | Rapid ETL method based on Spark SQL temporary view | |
CN117111933A (en) | Front-end code generation method, device and computer readable storage medium |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
C10 | Entry into substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
C12 | Rejection of a patent application after its publication | ||
RJ01 | Rejection of invention patent application after publication |
Application publication date: 20110928 |