• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            升C小調狂想曲

            <遞歸的憂傷>
            posts - 10, comments - 71, trackbacks - 0, articles - 0
               :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理
            要寫一個腳本引擎,首先要明確腳本長什么樣,具備哪些功能,需要有怎樣的能力。
            Since昨天我說第一版是面向過程,強類型,無閉包,無自定義結構,支持數組,那么我將腳本設計如下:

            CNScript 0.1 Draft

             

            Functionality:

            Procedure Oriented, No Custom Data Structures, No Closures, Strong Typed, Array Supported.

             

            Keywords:

            int,double,char,string,bool,void,if,else,for,do,while,return

             

            Statements:

            Single Expression:

            expression;

             

            Chunk:

            {

                     Statement1

                     Statement2

            }

             

            Array Declaration:

            type name[size];

             

            Variable Declaration:

            type name [= expression];

             

            Function definition:

            type FunctionName(type paramName1, type paramName2)

            Chunk

             

            IF-ELSE:

            if(expression)

            Statement1

            else

            Statement2

             

            FOR-LOOP:

            for(statement1 expression2;expression3)

            Statement

             

            WHILE-LOOP:

            while(expression)

            Statement

             

            DO-WHILE-LOOP:

            do

            Statement                                              

            while(expression);

             

            Expressions:

                     Values:

                               true

                               false

                               number

                               string

                               char

                               Variable Name

                               Array Name[index]

             

                     Assign:

                     name = expression

             

                     Function Call:

                     name(expression1,expression2)

             

                     Compares:

                               expression1 == expression2

                               expression1 != expression2

                               expression1 < expression2

                               expression1 > expression2

                               expression1 <= expression2

                               expression1 >= expression2

             

                     Boolean Operations:

                               !expression

                               expression1 && expression2

                               expression1 || expression2

             

                     Calculating:

                               expression++

                               expression

                               ++expression

                               --expression

                               expression1 + expression2

                               expression1expression2

                               expression1 * expression2

                               expression1 / expression2

                               expression1 % expression2

                               expression1 ^ expression2

                               (expression)

             

            Lexical Tokens:

            Spaces:

                     Space:                         (space_bar+)|(\n+) (\r+)|(\t+)

            TypeNames:

                     Type:                           (int)|(double)|(char)|(string)|(bool)|(void)

            Keywords:

                     Keyword_if:               if

                     Keyword_else:          else

                     Keyword_for:            for

                     Keyword_do:             do

                     Keyword_while:       while

                     Keyword_return:     return

            Brackets:

                     BigLeftBracket:        {

                     BigRightBracket:     }

                     MidLeftBracket:       [

                     MidRightBracket:    ]

                     SmallLeftBracket:    \(

                     SmallRightBracket: \)

            Identifier:

                     Identifier:                  (_+[a-zA-Z0-9_]+)|([a-zA-Z][a-zA-Z0-9_]*)

            Number Value:

                     Integer:                      0|[1-9][0-9]*

                     Double:                       (0|[1-9][0-9]*)\.[0-9]+

            Bool Value:

                     BoolValue:                 true|false

            Char:

                     CharValue:                 ‘(\\[^\r\n\t])|([^’\r\n\t])’

            String:

                     StringValue:               “((\\”)|[^\r\n])*”                                                                                       

            Operators:

                     Operator:                    =|\+|-|\*|/|%|^|(++)|(--)|(&&)|(\|\|)|(!)|<|>|(<=)|(>=)|(==)|(!=)

            Seprators:

                     Seprator:                    ;

             

            以上就是腳本設計初稿,如果后面發現有錯誤,會去更正的。

            按這個設計,寫出來的程序大概是下面這樣:

             1 int Foo(int value)
             2 {
             3    return value;
             4 }
             5 
             6 void main()
             7 {
             8    int a = 100;
             9    for(int i=0;i<100;i++)
            10    {
            11       --a;
            12    }
            13    if(a>0)
            14    {
            15       Foo(a);
            16    }
            17 }


            基本上就是個沒模板,沒類,沒指針的C++了。

            設計就這樣了,明天開始寫詞法分析喔!上面的Lexical Tokens就是給詞法分析用的,因為代碼是字符串,我們先要把整個字符串讀成一個一個的Token,才方便進行語法分析和更深入的處理,比如
            int a = 100;
            要先拆成[type:int] [space] [identifier:a] [space] [operator:=] [space] [integer:100] [seperator:;]
            這個過程就是詞法分析了。

            詞法分析完了得出這些Tokens然后再匹配到

            Variable Declaration:

            type name [= expression];

            才能建立起語法樹來。
            Lexical Tokens中是每種Token對應的正則表達式。

            Feedback

            # re: 繪制藍圖 --- CNScript 成長日記(2)  回復  更多評論   

            2008-08-06 07:07 by foxtail
            恩 非常有參考價值

            # re: 繪制藍圖 --- CNScript 成長日記(2)[未登錄]  回復  更多評論   

            2008-08-06 17:46 by ngaut
            @foxtail
            c-like的,設計目標和inger基本一致:) 不錯,期待下一篇,
            久久久久人妻一区精品| 午夜欧美精品久久久久久久| 久久91精品国产91久久小草| 2021久久精品国产99国产精品| 国产一级持黄大片99久久| 久久国产成人午夜aⅴ影院| 蜜桃麻豆WWW久久囤产精品| 日本强好片久久久久久AAA| 伊人色综合久久天天| 久久精品亚洲AV久久久无码| 久久久久亚洲AV成人片| 99久久国产免费福利| 国产毛片欧美毛片久久久| 国产巨作麻豆欧美亚洲综合久久| 婷婷久久综合九色综合九七| 久久综合狠狠色综合伊人| 国产精品久久久香蕉| 国产精品99久久久久久董美香| 久久人人爽人人爽人人AV| 国内精品欧美久久精品| 久久无码av三级| 69SEX久久精品国产麻豆| 伊人久久一区二区三区无码| 一本一道久久精品综合| 1000部精品久久久久久久久| 久久精品成人欧美大片| 一本久久精品一区二区| 久久精品亚洲精品国产欧美| 久久精品国产一区二区三区日韩| 精品久久久久久中文字幕人妻最新| 亚洲v国产v天堂a无码久久| 国内精品久久久久影院网站| 中文字幕亚洲综合久久2| 99久久er这里只有精品18| 久久天天躁狠狠躁夜夜96流白浆| 亚洲国产另类久久久精品小说| 久久99热这里只频精品6| 久久成人小视频| 日韩精品久久久久久免费| 色狠狠久久AV五月综合| 久久精品水蜜桃av综合天堂|