S S + | S S * | a1. Show how the string can be generated by this grammar.a " />
  • <em id="6vhwh"><rt id="6vhwh"></rt></em>

    <style id="6vhwh"></style>

    <style id="6vhwh"></style>
    1. <style id="6vhwh"></style>
        <sub id="6vhwh"><p id="6vhwh"></p></sub>
        <p id="6vhwh"></p>
          1. 国产亚洲欧洲av综合一区二区三区 ,色爱综合另类图片av,亚洲av免费成人在线,久久热在线视频精品视频,成在人线av无码免费,国产精品一区二区久久毛片,亚洲精品成人片在线观看精品字幕 ,久久亚洲精品成人av秋霞

            【編譯原理】龍書(shū)第二章課后題答案

            更新時(shí)間:2023-11-24 11:40:21 閱讀: 評(píng)論:0

            這次看你往哪跑-乾隆十公主

            【編譯原理】龍書(shū)第二章課后題答案
            2023年11月24日發(fā)(作者:myroom英語(yǔ)作文)

            【編譯原理】龍書(shū)第?章課后題答案

            Exercis for Section 2.2

            2.2.1

            Consider the context-free grammar:

            S -> S S + | S S * | a

            1. Show how the string can be generated by this grammar.

            aa+a*

            2. Construct a par tree for this string.

            3. What language does this grammar generate? Justify your answer.

            Answer

            1. -> S * -> S + S * -> a + S * -> a a + * -> a a + a *

            SSSSS

            2.

            3. L = {Postfix expression consisting of digits, plus and multiple signs}

            2.2.2

            What language is generated by the following grammars? In each ca justify your answer.

            1. S -> 0 S 1 | 0 1

            2. S -> + S S | - S S | a

            3. S -> S ( S ) S | ε

            4. S -> a S b S | b S a S | ε

            1. No

            2. No

            3. Yes

            1. Arithmetic expressions in postfix notation.

            2. Left-associative lists of identifiers parated by commas.

            3. Right-associative lists of identifiers parated by commas.

            1. Proof

            Any string derived from the grammar can be considered to be a quence consisting of 11 and 1001, where each

            quence element is possibly suffixed with a 0.

            Let be the t of positions where is placed. is said to be at position if the first in is at position ,

            n1111i111i

            where starts at 0 and

            i

            grows from least significant to most significant bit.

            Let be the equivalent t for .

            m1001

            The sum of any string produced by the grammar is:

            sum

            = Σ (2 + 2) * 2 + Σ (2 + 2) * 2

            nm

            10n30m

            = Σ 3 * 2 + Σ 9 * 2

            nm

            nm

            This is clearly divisible by 3.

            2. No. Consider the string “10101”, which is divisible by 3, but cannot be

            derived from the grammar.

            Readers eking a more formal proof can read about it below:

            Proof:

            Every number divisible by 3 can be written in the form . We will consider (though it would be valid to consider

            3kk > 0

            k

            to be an arbitrary integer).

            Note that every part of num(11, 1001 and 0) is divisible by 3, if the grammar could generate all the numbers divisible

            by 3, we can get a production for binary k from num’s production:

            3k = num -> 11 | 1001 | num 0 | num num

            k = num/3 -> 01 | 0011 | k 0 | k k

            k -> 01 | 0011 | k 0 | k k

            It is obvious that any value of that has more than 2 concutive bits t to 1 can never be produced. This can be

            k

            confirmed by the example given in the beginning:

            10101 is 3*7, hence, k = 7 = 111 in binary. Becau 111 has more than 2

            concutive 1’s in binary, the grammar will never produce 21.

            2.2.6

            Construct a context-free grammar for roman numerals.

            Note: we just consider a subt of roman numerals which is less than 4k.

            Answer

            via wikipedia, we can categorize the single roman numerals into 4 groups:

            I, II, III | I V | V, V I, V II, V III | I X

            then get the production:

            digit -> smallDigit | I V | V smallDigit | I X

            smallDigit -> I | II | III | ε

            and we can find a simple way to map roman to arabic numerals. For example:

            XII => X, II => 10 + 2 => 12

            CXCIX => C, XC, IX => 100 + 90 + 9 => 199

            MDCCCLXXX => M, DCCC, LXXX => 1000 + 800 + 80 => 1880

            via the upper two rules, we can derive the production:

            romanNum -> thousand hundred ten digit

            thousand -> M | MM | MMM | ε

            hundred -> smallHundred | C D | D smallHundred | C M

            smallHundred -> C | CC | CCC | ε

            ten -> smallTen | X L | L smallTen | X C

            smallTen -> X | XX | XXX | ε

            digit -> smallDigit | I V | V smallDigit | I X

            smallDigit -> I | II | III | ε

            What language is generated by the following grammars? In each ca justify your answer.

            1. S -> 0 S 1 | 0 1

            2. S -> + S S | - S S | a

            3. S -> S ( S ) S | ε

            4. S -> a S b S | b S a S | ε

            5. S -> a | S + S | S S | S * | ( S )

            Answer

            Construct unambiguous context-free grammars for each of

            the following languages. In each ca show that your grammar is correct.

            1. Arithmetic expressions in postfix notation.

            1. Proof

            Any string derived from the grammar can be considered to be a quence consisting of 11 and 1001, where each

            quence element is possibly suffixed with a 0.

            Let be the t of positions where is placed. is said to be at position if the first in is at position ,

            n1111i111i

            where starts at 0 and

            i

            grows from least significant to most significant bit.

            Let be the equivalent t for .

            m1001

            The sum of any string produced by the grammar is:

            sum

            = Σ (2 + 2) * 2 + Σ (2 + 2) * 2

            nm

            10n30m

            = Σ 3 * 2 + Σ 9 * 2

            nm

            nm

            This is clearly divisible by 3.

            2. No. Consider the string “10101”, which is divisible by 3, but cannot be

            derived from the grammar.

            Readers eking a more formal proof can read about it below:

            Proof:

            Every number divisible by 3 can be written in the form . We will consider (though it would be valid to consider

            3kk > 0

            k

            to be an arbitrary integer).

            Note that every part of num(11, 1001 and 0) is divisible by 3, if the grammar could generate all the numbers divisible

            by 3, we can get a production for binary k from num’s production:

            3k = num -> 11 | 1001 | num 0 | num num

            k = num/3 -> 01 | 0011 | k 0 | k k

            k -> 01 | 0011 | k 0 | k k

            It is obvious that any value of that has more than 2 concutive bits t to 1 can never be produced. This can be

            k

            confirmed by the example given in the beginning:

            10101 is 3*7, hence, k = 7 = 111 in binary. Becau 111 has more than 2

            concutive 1’s in binary, the grammar will never produce 21.

            2.2.6

            Construct a context-free grammar for roman numerals.

            Note: we just consider a subt of roman numerals which is less than 4k.

            Answer

            via wikipedia, we can categorize the single roman numerals into 4 groups:

            I, II, III | I V | V, V I, V II, V III | I X

            then get the production:

            digit -> smallDigit | I V | V smallDigit | I X

            2.3.2

            num -> thousand hundred ten digit

            { = || || || ;

            print()}

            thousand -> low { = repeat('M', low.v)}

            hundred -> low { = repeat('C', low.v)}

            | 4 { = 'CD'}

            | high { = 'D' || repeat('X', high.v - 5)}

            romanNum -> thousand hundred ten digit {romanNum.v = thousand.v || hundred.v || ten.v || digit.v; print(romanNun.v)}

            thousand -> M {thousand.v = 1}

            | MM {thousand.v = 2}

            | MMM {thousand.v = 3}

            | ε {thousand.v = 0}

            hundred -> smallHundred {hundred.v = smallHundred.v}

            | C D {hundred.v = smallHundred.v}

            槐樹(shù)花開(kāi)-探親蔓茹

            【編譯原理】龍書(shū)第二章課后題答案

            本文發(fā)布于:2023-11-24 11:40:21,感謝您對(duì)本站的認(rèn)可!

            本文鏈接:http://www.newhan.cn/zhishi/a/1700797221224996.html

            版權(quán)聲明:本站內(nèi)容均來(lái)自互聯(lián)網(wǎng),僅供演示用,請(qǐng)勿用于商業(yè)和其他非法用途。如果侵犯了您的權(quán)益請(qǐng)與我們聯(lián)系,我們將在24小時(shí)內(nèi)刪除。

            本文word下載地址:【編譯原理】龍書(shū)第二章課后題答案.doc

            本文 PDF 下載地址:【編譯原理】龍書(shū)第二章課后題答案.pdf

            標(biāo)簽:small
            留言與評(píng)論(共有 0 條評(píng)論)
               
            驗(yàn)證碼:
            推薦文章
            排行榜
            Copyright ?2019-2022 Comsenz Inc.Powered by ? 實(shí)用文體寫(xiě)作網(wǎng)旗下知識(shí)大全大全欄目是一個(gè)全百科類(lèi)寶庫(kù)! 優(yōu)秀范文|法律文書(shū)|專(zhuān)利查詢|
            主站蜘蛛池模板: 欧美 亚洲 国产 日韩 综AⅤ| 女人与公狍交酡女免费| a国产一区二区免费入口| 亚洲日本精品国产第一区| 99国产精品国产精品久久 | 免费观看的AV毛片的网站不卡| 国产av一区二区三区丝袜| 国模少妇无码一区二区三区| 东方av四虎在线观看| 亚洲精品第一国产综合精品| 国产无遮挡吃胸膜奶免费看| 三上悠亚ssⅰn939无码播放 | 日韩一卡2卡3卡4卡新区亚洲 | 亚洲精品国产男人的天堂| 9久久精品视香蕉蕉| 国产AV一区二区精品凹凸| 黄男女激情一区二区三区| 亚洲精品日韩中文字幕| 人妻系列中文字幕精品| 亚洲不卡av不卡一区二区| 国产综合色产在线视频欧美| 少妇久久久被弄到高潮| 久久夜色精品国产亚洲a| 亚洲VA中文字幕无码久久| 国产精品久久久久久久久久免费| 国产精品视频中文字幕| 1024国产基地永久免费| 国产精品午夜福利清纯露脸| 无码伊人久久大杳蕉中文无码| 国产欧美久久一区二区| 国色天香成人一区二区| 国产国产午夜福利视频| 不卡一区二区三区四区视频| 免费又爽又大又高潮视频| 久久久精品94久久精品| 91无码人妻精品一区二区蜜桃| 99久久国产综合精品成人影院| 欧洲美熟女乱又伦AV影片| 国产一区二区波多野结衣| 日本高清色WWW在线安全| 最新国产精品精品视频|