第二人生源码分析(103)脚本词法分析(1)x

来源:五年级 发布时间:2020-08-31 点击:

 第二人生的源码分析(103) 脚本的词法分析(1 )

 从前面的脚本可以看到它的代码,也理解它的意思了,但是它是怎么样执行的呢?又是怎么样变成可执行的脚本呢?下面就来分析这部份相关的代码。要了解脚本执行,就得把脚本中的每一个单词识别出来,如下:

 default {

 state_entry()

 {

  llSay(0, “Hello, Avatar!”);

 }

 touch_start(integer total_number)

 {

  llSay(0, “Touched.”);

 } }

  把上面的脚本识别为下面的字符串流:default {

  state_entry()等等。这样识别单词的过程,就叫做词法分析。在编译原理里有详细的介绍,在第二人生里并不是手工地构造词法分析器,而是通过 flex 程序来生成词法分析程序。

  flex 是一个将包含了正则表达式的文本文件作为其输入的程序,还包括每一个表达式被匹配时所采用的动作。flex 其实是 The Fast Lexical Analyzer 的缩写。

  flex 输入文件的格式如下:

 {定义} %% {规则} %% {辅助代码}

  下面就来仔细地分析第二人生的脚本 flex 文件,它的定部份如下:

 1

 2 N

 [0-9] 3 L

 [a-zZ_] 4 H

 [a-fA-F0-9] 5 E

 [Ee][+-]?{N}+ 6 FS

  (f|F) 7 %e 10000 8 %n 4 09 %p 5000 0

 1 %{ 2 #include "linden_common.h" 3 // Deal with the fact that lex/yacc generates unreachable code 4 #ifdef LL_WINDOWS 5 #pragma warning (disable : 4702) // warning C4702: unreachable code #016 #endif // LL_WINDOWS

 7 lmath.h" 8 ree.h" 19 typecheck.h" 0 nclude "lscript_resource.h" 1 f LL_WINDOWS 2 #include "ytab.h" 3 #else 4 #include "indra.y.h" 5 #endif 6 lltimer.h" 7 indra_constants.h" 8 agentconstants.h" 29 lslconstants.h" 0 uuid.h" 1 assetstorage.h" 2 partdata.h" 3 vehicleparams.h" 4 permissionsflags.h" 5 followcamparams.h" 6 parcelflags.h" 7 lregionflags.h" 8 script_http.h" 39 #include "llclickaction.h" 0

 1 unt(); 2 comment(); 3 void parse_string(); 4

 5 LMAX 16384 6 #define YY_NEVER_INTERACTIVE 1 /* stops flex from calling isatty() */ 7

 8 #ifdef ECHO 49 #undef ECHO 0 #endif 1

 2 #define ECHO do { } while (0) 3

 4 #if defined(__cplusplus) 5 lex( void ); } #056 extern "C" { int yyparse( void ); }

 7 extern "C" { int yyerror(const char *fmt, ...); } 8 #endif 59

 #060 %}

  1 行到第 10 行是定义一些正则表达式匹配的字符。

 第 11 行到第第 60 行是声明 flex 的定义部份。

  这一次就介绍到这里,下一次再来分析它的下一部份内容:规则定义部份。

推荐访问:词法 分析 脚本
上一篇:AA大学科研院作风建设活动评选条件
下一篇:知识讲座主持词开场白范文

Copyright @ 2013 - 2018 优秀啊教育网 All Rights Reserved

优秀啊教育网 版权所有