白和鑫
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # 系統程式期末報告 > **筆記閱讀自系統程式 第八章 編譯器加上自己部份理解** 參考資料 https://www.slideshare.net/ccckmit/8-73472916 http://sp1.wdfiles.com/local--files/slide/ch08.pdf 程式碼閱讀自系統程式 第十二章 系統軟體實作 看完部分了解 https://www.slideshare.net/ccckmit/12-73472945 --- ![](https://hackmd.io/_uploads/BJ-IfhHL3.png) 編譯器的功能:將高階語言轉換成組合語言的工具 **C0 語言** C 語言第0版(較小型的C語言),只能做for迴圈跟基本運算,不包含if 函式呼叫 結構等功能 範例: ![](https://hackmd.io/_uploads/rJy6whr83.png) ![](https://hackmd.io/_uploads/Hk8kAhBLn.png) * 星號* 代表重複零次以上,因此BaseList可以由許多個Base組成,而第十一列的number是由0到9等數字重複組成 * 加號+ 代表重複一次以上 * 問號? 代表重複 0 或 1 次,第七列的![](https://hackmd.io/_uploads/rkxaL-UUh.png)區域可以出現0次獲1次 ![](https://hackmd.io/_uploads/rJxCD-UI3.png) 可以透過下列的生成方式生成多層次的FOR語句 ![](https://hackmd.io/_uploads/H14tuWIIh.png) **編譯器的六大階段** ![](https://hackmd.io/_uploads/rk8KAhH8h.png) * sum = sum + 1這個語句會被輸入到掃描器中,掃描器會將整個程式分成一個一個的基本詞彙,並將每個詞彙標註型態=>(sum:id)(=)(sum:id)(+)(i:id) * 接著詞彙會被輸入到剖析器,接著剖析器會利用語法規則對比以建立出完整的語法樹 * 在語意分析階段時,編譯器會將語法樹標註節點型態,並檢查是否相容,接著輸出。 * 然後在中間碼階段,語意樹會被轉換成一種很像組合語言的一種平坦結構,被稱為中間碼。 * 接著編譯器會進行最佳化的動作後,才將中間碼轉換成組合語言輸出。 中間碼是一種在計算機編程和編譯過程中使用的表示形式。它是源代碼和目標代碼之間的一個中間層,用於幫助將高級語言源代碼轉換為可執行的機器代碼。 **詞彙掃描器** 掃描器是用來將程式轉換成詞彙的程式,在實作上通常會被當作是一個單一的函數,當剖析器需要時,就會呼叫該函數。 ![](https://hackmd.io/_uploads/rJc8xfIL3.png) **c0語言的掃描器演算法** ![](https://hackmd.io/_uploads/BkTbVGII3.png) 接著利用不斷呼叫nextToken()函數的方法,不斷取得詞彙。 ![](https://hackmd.io/_uploads/rk_iNG8Uh.png) **剖析器** 剖析器的設計方法大致分為(遞迴下降法、LL法、運算子優先矩陣法、LR法) **甚麼是遞迴下降法** 是一種由上而下的剖析法,用於解析並分析上下文無關文法(Context-Free Grammar)所描述的語言。它通常用於編譯器和解釋器的構建過程中,比LL、LR等剖析法更為精簡。 **c0語言的掃描器演算法** ![](https://hackmd.io/_uploads/rkRsFM8U2.png) ![](https://hackmd.io/_uploads/SJg6KzIUh.png) ![](https://hackmd.io/_uploads/B1YQqG883.png) ![](https://hackmd.io/_uploads/SyeUqf8Ln.png) * 當遞迴下降演算法剖析程式時,會將剖析的節點按順序推入stack中,每比對一次規則,就會升成一個新的節點。 * 呼叫parseBaseList()時,會建立一個新節點,並推入stack中,等到要離開前,再利用popNode("BaseList")取回已經建立好的BaseList節點,此時該節點已經是一顆完整的樹,並附加到PROG節點下,等在回parseProg時,就會形成更大的樹。 ![](https://hackmd.io/_uploads/r1CU-7883.png) **語意分析** 將語法樹標註上節點狀態 ![](https://hackmd.io/_uploads/H18hu3U8h.png) 轉換過程中,必須檢查型態的相容問題 **中間碼產生** ![](https://hackmd.io/_uploads/H1X_1pUU2.png) FORO是起始標記,_FORO是結束標記,T0為臨時變數,且被當作是儲存計算中的結果,JEQ是條件跳躍指令,JMP是跳躍指令。 ![](https://hackmd.io/_uploads/SkSKJT883.png) **演算法** ![](https://hackmd.io/_uploads/S1657TUI3.png) ![](https://hackmd.io/_uploads/rkmn7p882.png) ![](https://hackmd.io/_uploads/rJ69UpI82.png) ![](https://hackmd.io/_uploads/Sk7nL6IL3.png) 此演算法單獨處理了FOR、STMT、COND、EXP等語法節點,也處理了id、number等詞彙規則的節點。 **組合語言的產生** ![](https://hackmd.io/_uploads/r1YFEkP83.png) ![](https://hackmd.io/_uploads/SkEthgPL3.png) ![](https://hackmd.io/_uploads/BkPcheDU3.png) ![](https://hackmd.io/_uploads/rk9CTePI3.png) ![](https://hackmd.io/_uploads/S1AJRgPLh.png) ![](https://hackmd.io/_uploads/r1alCew8h.png) **最佳化** ![](https://hackmd.io/_uploads/BJrg1ZvIh.png) ![](https://hackmd.io/_uploads/r1ASyZD83.png) ![](https://hackmd.io/_uploads/H1A2GZDU3.png) ![](https://hackmd.io/_uploads/HyMUJbwI3.png) **gcc編譯器** ![](https://hackmd.io/_uploads/ry_7mZP83.png) ![](https://hackmd.io/_uploads/HJP4XZDL3.png) **GCC編譯器的流程** ![](https://hackmd.io/_uploads/Hk5oQZPL3.png) ![](https://hackmd.io/_uploads/H1FCXWvL2.png)

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully