欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

第二人生的源碼分析(106)腳本的詞法分析(4)

系統 2194 0
?

前面介紹了 flex 文件的格式,那么 flex 程序又把這個文件生成怎么樣的文件呢?下面就來仔細分析這個文件,由于 flex 程序生成 C++ 的文件格式,那么就需要 C++ 的編譯器才可以編譯了。它的代碼如下:

#001 ? #line 2 "lex_yy.cpp"

這行是行號同步使用。

?

#002 ? /* A lexical scanner generated by flex */

#003 ?

#004 ? /* Scanner skeleton version:

#005 ?? * $Header: /home/daffy/u0/vern/flex/RCS/flex.skl,v 2.91 96/09/10 16:58:48 vern Exp $

#006 ?? */

上面這段說明這個文件是由詞法分析程序 flex 生成的。

?

#007 ?

#008 ? #define FLEX_SCANNER

#009 ? #define YY_FLEX_MAJOR_VERSION 2

#010 ? #define YY_FLEX_MINOR_VERSION 5

?

上面這段說明 flex 的版本號。

?

#011 ?

#012 ? #include <stdio.h>

#013 ? #include <errno.h>

#014 ?

#015 ? /* cfront 1.2 defines "c_plusplus" instead of "__cplusplus" */

#016 ? #ifdef c_plusplus

#017 ? #ifndef __cplusplus

#018 ? #define __cplusplus

#019 ? #endif

#020 ? #endif

#021 ?

#022 ?

#023 ? #ifdef __cplusplus

#024 ?

#025 ? #include <stdlib.h>

#026 ? #ifndef _WIN32

#027 ? #include <unistd.h>

#028 ? #endif

上面這段不同的 flex 程序和平臺生成不一樣,一定要小心了。

?

#029 ?

#030 ? /* Use prototypes in function declarations. */

#031 ? #define YY_USE_PROTOS

#032 ?

#033 ? /* The "const" storage-class-modifier is valid. */

#034 ? #define YY_USE_CONST

#035 ?

#036 ? #else ? /* ! __cplusplus */

#037 ?

#038 ? #if __STDC__

#039 ?

#040 ? #define YY_USE_PROTOS

#041 ? #define YY_USE_CONST

#042 ?

#043 ? #endif /* __STDC__ */

#044 ? #endif /* ! __cplusplus */

#045 ?

?

?

?

下面再來分析下一段代碼:

#001 ? #ifndef YY_DECL

#002 ? #define YY_DECL int yylex YY_PROTO(( void ))

#003 ? #endif

上面這行定義詞法分析的函數。

?

#004 ?

#005 ? /* Code executed at the beginning of each rule, after yytext and yyleng

#006 ?? * have been set up.

#007 ?? */

#008 ? #ifndef YY_USER_ACTION

#009 ? #define YY_USER_ACTION

#010 ? #endif

#011 ?

#012 ? /* Code executed at the end of each rule. */

#013 ? #ifndef YY_BREAK

#014 ? #define YY_BREAK break;

#015 ? #endif

#016 ?

#017 ? #define YY_RULE_SETUP /

#018 ? ?? YY_USER_ACTION

#019 ?

?

下面開始定義詞法分析。

#020 ? YY_DECL

#021 ? ?? {

#022 ? ?? register yy_state_type yy_current_state;

#023 ? ?? register char *yy_cp, *yy_bp;

#024 ? ?? register int yy_act;

#025 ?

#026 ? #line 62 "indra.l"

#027 ?

#028 ? #line 2582 "lex_yy.cpp"

#029 ?

?

判斷是否初始化。

#030 ? ?? if ( yy_init )

#031 ? ?????? {

#032 ? ?????? yy_init = 0;

#033 ?

#034 ? #ifdef YY_USER_INIT

#035 ? ?????? YY_USER_INIT;

#036 ? #endif

#037 ?

#038 ? ?????? if ( ! yy_start )

#039 ? ?????????? yy_start = 1; ?? /* first start state */

#040 ?

?

設置詞法分析的文件輸入。

#041 ? ?????? if ( ! yyin )

#042 ? ?????????? yyin = stdin;

#043 ?

?

設置詞法分析的文件輸出。

#044 ? ?????? if ( ! yyout )

#045 ? ?????????? yyout = stdout;

#046 ?

?

創建詞法分析的緩沖區。

#047 ? ?????? if ( ! yy_current_buffer )

#048 ? ?????????? yy_current_buffer =

#049 ? ?????????????? yy_create_buffer( yyin, YY_BUF_SIZE );

#050 ?

#051 ? ?????? yy_load_buffer_state();

#052 ? ?????? }

#053 ?

?

?

下面一段是詞法動作的分析:

#001 ? do_action: /* This label is used only to access EOF actions. */

#002 ?

#003 ?

?

根據動作的狀態來響應。

#004 ? ?????? switch ( yy_act )

#005 ? ?? { /* beginning of action switch */

#006 ? ?????????? case 0: /* must back up */

#007 ? ?????????? /* undo the effects of YY_DO_BEFORE_ACTION */

#008 ? ?????????? *yy_cp = yy_hold_char;

#009 ? ?????????? yy_cp = yy_last_accepting_cpos;

#010 ? ?????????? yy_current_state = yy_last_accepting_state;

#011 ? ?????????? goto yy_find_action;

#012 ?

?

不同的規則處理。

#013 ? case 1:

#014 ? YY_RULE_SETUP

#015 ? #line 63 "indra.l"

#016 ? { gInternalLine++; gInternalColumn = 0; comment(); }

#017 ? ?? YY_BREAK

#018 ? case 2:

#019 ? YY_RULE_SETUP

#020 ? #line 65 "indra.l"

#021 ? { count(); return(INTEGER); }

#022 ? ?? YY_BREAK

#023 ? case 3:

#024 ? YY_RULE_SETUP

#025 ? #line 66 "indra.l"

#026 ? { count(); return(FLOAT_TYPE); }

#027 ? ?? YY_BREAK

?

接著下來就是不斷地處理不同的規則,下一次再來通過調試來分析怎么樣處理一個腳本的。

第二人生的源碼分析(106)腳本的詞法分析(4)


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 一级在线播放 | 久久亚洲精品中文字幕二区 | 操操日| 日本在线视频不卡 | 色婷婷国产精品欧美毛片 | 欧美综合区 | 三级网页| 欧美日韩中文在线 | 中文字幕三区 | 午夜丰满少妇高清毛片1000部 | 96国产精品久久久久aⅴ四区 | 国产www色| 夜夜夜操操操 | 久草视频福利在线观看 | 国产免费av在线 | 一区二区三区免费看 | 亚洲精品美女久久777777 | 夜班护士在线观看 | 久久99综合国产精品亚洲首页 | a4yy午夜| 午夜免费 | 九热视频在线观看 | 草草国产成人免费视频 | 精品一区二区久久久久久久网站 | 成人激情综合网 | 国产视频1| 亚洲永久中文字幕在线 | 日韩福利在线 | www.99re| 欧美视频在线观看 | 爱爱视频网站 | 日本在线国产 | 精品视频久久久久 | 国产精品片aa在线观看 | 天天操夜夜做 | 毛片在线不卡 | 国产综合视频在线 | 天天夜干 | 黄色视屏免费看 | 国产精品中文字幕在线观看 | 十八勿入 |