當(dāng)玩家書寫一個(gè)腳本時(shí),如果寫錯(cuò)了腳本,那么肯定運(yùn)行不了。現(xiàn)在就來分析怎么樣確保腳本是正確的問題,如果不正確就需要顯示出來那里不正確。腳本是否正確,其實(shí)是根據(jù)腳本的語法來判斷的。那么又怎么樣來構(gòu)造語法分析的程序呢?在第二人生里是通過使用程序
bison.exe
來創(chuàng)建的。
下面先來看看
bison.exe
是做什么東西的:
Yacc
代表
Yet Another Compiler Compiler
。
Yacc
的
GNU
版叫做
Bison
。它是一種工具,將任何一種編程語言的所有語法翻譯成針對此種語言的
Yacc
語 法解析器。它用巴科斯范式
(BNF, Backus Naur Form)
來書寫。按照慣例,
Yacc
文件有
.y
后綴。編譯行如下調(diào)用
Yacc
編譯器:
??????
$ yacc <options>
??
<filename ending with .y>
我們看到
Lex
從輸入序列中識(shí)別標(biāo)記。如果你在查看標(biāo)記序列,你可能想在這一序列出現(xiàn)時(shí)執(zhí)行某一動(dòng)作。這種情況下有效序列的規(guī)范稱為語法。
Yacc
語法文件包括這一語法規(guī)范。它還包含了序列匹配時(shí)你想要做的事。
bison
的語法文件,也是定義、規(guī)則和輔助代碼部份。第二人生里的定義語法文件如下:
#001
?
%{
#002
?
??
#include "linden_common.h"
#003
?
??
#include "lscript_tree.h"
#004
?
#005
?????
#ifdef __cplusplus
#006
?????
extern "C" {
#007
?????
#endif
#008
?
#009
?
??
int yylex(void);
#010
?
??
int yyparse( void );
#011
?
??
int yyerror(const char *fmt, ...);
#012
?
#013
?????
#if LL_LINUX
#014
?????
// broken yacc codegen...
?
--ryan.
#015
?????
#define getenv getenv_workaround
#016
?????
#endif
#017
?
#018
?????
#ifdef LL_WINDOWS
#019
?
??
#pragma warning (disable : 4702) // warning C4702: unreachable code
#020
?
??
#pragma warning( disable : 4065 )
??
// warning: switch statement contains 'default' but no 'case' labels
#021
?
??
#endif
#022
?
#023
?????
#ifdef __cplusplus
#024
?????
}
#025
?????
#endif
#026
?
%}
#027
?
#028
?
%union
#029
?
{
#030
?
??
S32
????????????????????????????
ival;
#
#032
?
??
char
???????????????????????????
*sval;
#033
?
??
class LLScriptType
?????????????
*type;
#034
?
??
class LLScriptConstant
?????????
*constant;
#035
?
??
class LLScriptIdentifier
???????
*identifier;
#036
?
??
class LLScriptSimpleAssignable
?
*assignable;
#037
?
??
class LLScriptGlobalVariable
???
*global;
#038
?
??
class LLScriptEvent
????????????
*event;
#039
?
??
class LLScriptEventHandler
?????
*handler;
#040
?
??
class LLScriptExpression
???
???
*expression;
#041
?
??
class LLScriptStatement
????????
*statement;
#042
?
??
class LLScriptGlobalFunctions
??
*global_funcs;
#043
?
??
class LLScriptFunctionDec
??????
*global_decl;
#044
?
??
class LLScriptState
????????????
*state;
#045
?
??
class LLScritpGlobalStorage
????
*global_store;
#046
?
??
class LLScriptScript
???????????
*script;
#047
?
};
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號(hào)聯(lián)系: 360901061
您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長非常感激您!手機(jī)微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
