Language translators and IDEs
แนะนำใหม่
19:11
ระบบปฏิบัติการ
คุณไม่เคยเห็นมัน และคุณจะไม่มีวันเห็น — แต่มันก็อยู่ตรงนั้นเสมอ ด้านหลังแอปที่คุณเปิด ไฟล์ที่คุณบันทึก และการแตะหน้าจอทุกครั้ง มีสิ่งที่ไม่อาจมองเห็นได้…
บรรยายภาษาอังกฤษ · สลับคำบรรยายภาษาอังกฤษและภาษาจีนได้
ในบทเรียนนี้
| English | ความหมาย |
|---|---|
| compiler/kəmˈpaɪlə/ | คอมไพลเลอร์ |
| programmer | A person who writes and develops computer programs. |
| machine instructions | Commands in machine code that a processor can execute directly. |
| arithmetic/əˈrɪθmətɪk/ | Calculations with numbers, such as adding and subtracting. |
| source code/sɔːs kəʊd/ | ซอร์สโค้ด |
| translator/trænˈsleɪtə/ | ทรานส์เลเตอร์ |
| machine code/məˈʃiːn kəʊd/ | โค้ดเครื่อง |
| processor/ˈprəʊsesə/ | The component that executes instructions and performs the operations of a computer or similar system. |
| compiling | The process of translating a whole program before it runs. |
| interpreting | The process of translating and executing a program one statement at a time. |
| assembler/əˈsemblə/ | อสมบิลเลอร์ |
| assembly language/əˈsemblɪ ˈlæŋɡwɪdʒ/ | ภาษาอสมบิล |
| mnemonic instruction | An assembly language command that uses a short word for an operation. |
| labels/ˈleɪblz/ | Names used to mark positions in a program's code. |
| symbolic addresses | Names used to refer to memory locations instead of their actual addresses. |
| addresses | Numbers that identify specific locations in a computer's memory. |
| hardware/ˈhɑːdweə/ | The physical parts of a computer system that can be touched. |
| device drivers/dɪˈvaɪs ˈdraɪvəz/ | Programs that allow an operating system to control hardware devices. |
| embedded systems | Computers built into larger devices to perform specific tasks. |
| loops | Parts of a program that repeat instructions a number of times or until a condition is met. |
| high-level program | A program written in a language designed to be easier for people to understand. |
| object code/ˈɒbdʒekt kəʊd/ | ออบเจกต์โค้ด |
| executable/ɪɡˈzekjʊtəbl/ | ไฟล์ที่รันได้ |
| syntax errors | Mistakes that break the rules for writing code in a programming language. |
| run time/rʌn taɪm/ | The period during which a program is running on a computer. |
| operating system/ˈɒpəreɪtɪŋ ˈsɪstəm/ | System software that manages hardware resources and provides services for applications. |
| interpreter/ɪnˈtɜːprɪtə/ | อินเทอร์พรีเตอร์ |
| statement/ˈsteɪtmənt/ | A line of code that tells a program what to do. |
| execution speed | The rate at which a computer carries out a program's instructions. |
| portability | The ability of a program to run on different platforms. |
| platform/ˈplætfɔːm/ | The combination of processor and operating system on which a program runs. |
| debugging/ˈdiːbʌɡɪŋ/ | The process of finding and correcting errors in a program. |
| bytecode/ˈbaɪtkəʊd/ | 字节码 |
| portable/ˈpɔːtəbl/ | แบบพกพา |
| virtual machine/ˈvɜːtʃuːəl məˈʃiːn/ | เครื่องเสมือน |
| just-in-time compilation/dʒʌst ɪn taɪm ˌkɒmpɪˈleɪʃn/ | การคอมไพล์แบบทันที |
| native code | Machine code that can run directly on a particular processor. |
| console mode | A way of running a program using text input and output. |
| command line | A place where users type text commands to interact with a computer. |
| integrated development environment/ˈɪntɪɡreɪtɪd dɪˈveləpmənt enˈvaɪrənmənt/ | สภาพแวดล้อมการพัฒนาแบบบูรณาการ |
| context-sensitive prompts/ˈkɒntekst ˈsensɪtɪv prɒmpts/ | คำแนะนำที่ขึ้นกับบริบท |
| identifiers | Names chosen by programmers for parts of a program. |
| keywords/ˈkiːwɜːdz/ | Words with special meanings that are part of a programming language. |
| parameters/pəˈræmɪtəz/ | Values that specify a model or function, or named inputs that a subroutine receives. |
| auto-complete/ˈɔːtəʊ kəmˈpliːt/ | เติมอัตโนมัติ |
| dynamic syntax checks/daɪˈnæmɪk ˈsɪntæks tʃeks/ | การตรวจสอบไวยากรณ์แบบไดนามิก |
| prettyprint/ˈpretɪprɪnt/ | การจัดรูปแบบโค้ด |
| strings/strɪŋz/ | Sequences of characters used as text in a program. |
| comments/ˈkɒments/ | Explanatory text in source code or markup that does not execute as a program instruction. |
| indentation/ˌɪndenˈteɪʃn/ | Space placed at the start of a line to show structure, including code blocks in languages that use it syntactically. |
| expand and collapse | A feature that shows or hides sections of code. |
| block/blɒk/ | A group of statements treated as a single section of code. |
| breakpoints/ˈbreɪkpɔɪnts/ | จุดหยุด |
| single stepping/ˈsɪŋɡl ˈstepɪŋ/ | การดำเนินการทีละขั้นตอน |
| variables/ˈveərɪəblz/ | A quantity or named value that can change or take different values. |
| expressions | Combinations of values and operations that produce a value. |
| report window/rɪˈpɔːt ˈwɪndəʊ/ | หน้าต่างรายงาน |
| warnings | Messages that point out possible problems in a program. |
| function/ˈfʌŋkʃn/ | A mapping that assigns exactly one output to each allowed input. |
| logic error/ˈlɒdʒɪk ˈerə/ | A mistake in an algorithm or program that produces an incorrect result despite valid syntax. |
| run-time error messages | Messages that report errors occurring while a program is running. |
ไม่มีใครเชื่อ ότιคอมพิวเตอร์จะเขียนโปรแกรมตัวเองได้
- ในปี 1952 Grace Hopper สร้าง compiler ตัวแรก ซึ่งเป็นโปรแกรมที่แปลงProgramming notation ของนักพัฒนาให้เป็นคำสั่งเครื่อง "ไม่มีใครเชื่อเรื่องนั้น" เธอกล่าวในภายหลัง "ฉันมีcompiler ที่ทำงานได้ แต่ไม่มีใครกล้าสัมผัส มันบอกฉันว่าคอมพิวเตอร์ทำได้แค่เลขคณิตเท่านั้น"
- ภาษาที่คุณใช้ตั้งแต่ตอนนี้ล้วนตั้งอยู่บนแนวคิดนี้: คุณเขียน source code สำหรับมนุษย์ และตัวแปลจะผลิต machine code ที่โปรเซสเซอร์จะรัน
- มีตัวแปล 3 ประเภทและไฮบริดชื่อดัง 1 ตัว และการสอบต้องการให้คุณบอกว่าควรใช้ کدامเมื่อไร และทำไม
- บทเรียนนี้เกี่ยวกับตัวแปล ผลดี-ผลเสียระหว่างการคอมไพล์และการตีความ Java ที่ผสมผสานทั้งสองอย่าง และเครื่องมือต่างๆ ที่ IDE จัดเตรียมไว้รอบๆ它们
Source code, machine code และ Assembler
- โปรเซสเซอร์รันได้เฉพาะ machine code เท่านั้น ตัวแปลจะแปลงโปรแกรมที่เขียนโดยมนุษย์ให้เป็นมัน
- Assembler แปล assembly language เป็น machine code: คำสั่ง mnemonics แต่ละตัว,
LDD,ADD,JMP, จะกลายเป็นคำสั่ง machine code พอดี และป้ายชื่อ (labels) กับที่อยู่เชิงสัญลักษณ์จะถูกแทนที่ด้วยที่อยู่จริง - Assembly ถูกใช้ในกรณีที่นักพัฒนาต้องการควบคุมฮาร์ดแวร์โดยตรง: Device drivers, Embedded systems, Looms ภายในสุดของเกม
Match each translator to what it does.
ความยาก 2/5 · 140 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
Assembler: assembly→machine code; compiler: all-at-once to an executable; interpreter: line by line at run time.
ตัวแปลภาษา (Compiler)
- ตัวแปลภาษา ทำการแปลโปรแกรมระดับสูงทั้ง ทั้งหมด เป็นรหัสเครื่อง หรือ โค้ดเป้าหมาย (object code) ก่อนที่จะนำไปรัน会产生一个可执行文件,并在翻译结束时一次性报告所有语法错误。
- มันไม่ได้นำโปรแกรมไปรัน เมื่อโค้ดสะอาดแล้ว ไฟล์ที่สร้างได้จะรันโดยไม่ต้องมีตัวแปลภาษาติดตั้งอยู่ รันได้เท่าที่ต้องการ
- รันได้เร็ว เพราะไม่มีการแปลระหว่างรัน แต่รหัสเครื่องจะผูกติดกับโปรเซสเซอร์และระบบปฏิบัติการเฉพาะหนึ่งเท่านั้น
The compiler route: source to running program
Step through how a compiler works — translating the whole program once, before it runs. Contrast it with an interpreter, which translates and runs one line at a time.
A compiler differs from an interpreter because it:
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
A compiler translates all at once into an executable that runs without the compiler. An interpreter runs line by line.
Put the compiler route in order, from writing code to running it.
ความยาก 3/5 · 200 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
A compiler translates the whole program once into an executable; that file then runs without the compiler.
ตัวตีความ (Interpreter)
- ตัวตีความ จะแปล语句ของโปรแกรมระดับสูงทีละ statement และ ดำเนินการ ทันที ก่อนจะย้ายไปยังบรรทัดถัดไป
- ไม่产生ไฟล์ที่รันได้它将หยุดที่ข้อผิดพลาดแรก遇到的并报告它,包括行号,以便你修复后重新运行。
- ทั้งโค้ดต้นฉบับและตัวตีความต้องมีอยู่ทุกครั้งที่รันโปรแกรม และการรันแต่ละครั้งจะทำการแปลใหม่ ทำให้ Execution ช้าลง;แต่ source code เดียวกันสามารถรันได้ทุกที่ที่มีตัวตีความ

翻译一次后发布,或边用边翻译

When does an interpreter report an error?
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
An interpreter runs line by line, so it reports an error at the moment it reaches that line — handy during development.
An interpreter produces no stand-alone executable, so the interpreter itself must be installed to run the program.
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
An interpreter translates and runs line by line each time — there is no separate executable to ship, unlike a compiler.
优点和缺点,按评分方案列出
| Compiler | Interpreter | |
|---|---|---|
| ความเร็วในการรัน | เร็ว เพราะเป็นรหัสเครื่องอยู่แล้ว | ช้ากว่า เพราะต้องแปลในทุกครั้งที่รัน |
| สิ่งที่ผู้ใช้ต้องการ | ต้องมีแค่ไฟล์ที่รันได้;source code kept private | ต้องมีทั้ง source code และตัวตีความ |
| การหาข้อผิดพลาด | รายงานทั้งหมดพร้อมกันหลังการแปล | รายงานทีละบรรทัดตามจุดที่พัฒนา |
| การแก้ไขโค้ด | Recompile ทั้งหมด | แก้ไขและรันทันที |
| Portability | ใช้ได้กับ platform เดียว;ต้อง recompile ใหม่สำหรับแต่ละ platform | รันได้ทุกที่ที่มีตัวตีความ |

You should choose a compiler when:
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
Compiled executables are fast and stand-alone. Interpreters suit quick development and portable scripts.
Which points favour using an interpreter while developing a program? Select ทั้งหมด that apply.
ความยาก 2/5 · 140 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
Fast edit-run cycles and errors at their line are the interpreter's strengths. Run-time speed is the compiler's.
ตัวอย่างวิธีทำ: ใช้ Interpreter ขณะเขียน ใช้ Compiler เมื่อเสร็จสิ้น
- นักพัฒนาใช้ Interpreter ขณะเขียนโปรแกรม และใช้ Compiler เมื่อโปรแกรมเสร็จ อธิบายวิธีการใช้งานของแต่ละเครื่องมือ [4]
- ระหว่างการพัฒนา Interpreter จะรันโปรแกรมที่ยังเขียนไม่เสร็จทันที โดยไม่ต้องรอให้แปลครบถ้วน เมื่อเจอ error จะรายงานบรรทัด ทำให้ผู้พัฒนาสามารถแก้แล้วรันใหม่ได้ทันที:เป็น cycle การแก้ไข-รันที่รวดเร็ว ช่วยให้ง่ายต่อการ debug
- เมื่อโปรแกรมเสร็จสมบูรณ์ Compiler จะแปลโปรแกรมทั้งหมดให้เป็นไฟล์ที่รันได้ซึ่งรันได้เร็วกว่า ไม่ต้องมี translator บนคอมพิวเตอร์ของผู้ใช้ และรักษา source code ให้เป็นความลับ
- ได้คะแนน 2 สำหรับแต่ละเครื่องมือ:สิ่งที่มันทำได้ และเหตุผลที่เหมาะสมกับขั้นตอนนี้
Java: แปลบางส่วน ตีความบางส่วน
- Source ของ Java ถูก compile เป็น bytecode ซึ่งเป็นรูปแบบกลางที่กะทัดรัดและมี portability ไม่ใช่รหัสเครื่องของโปรเซสเซอร์จริงใดๆ
- Virtual machine หรือ JVM จะตีความ bytecode นั้นบนเครื่องwhatever ที่มันรันอยู่ หรือใช้ just-in-time compilation เพื่อเปลี่ยนส่วนที่ใช้หนักให้เป็น native code mientras el programa se ejecuta.
- Stage การ compile จะจับ syntax errors ได้ตั้งแต่ต้น;stage การ interpret อนุญาตให้ไฟล์ bytecode ไฟล์เดียวรันได้ทุกที่ที่มี JVM;Java ใน console mode หรือโปรแกรมข้อความที่รันจาก command line เป็นตัวอย่างในหลักสูตร

一次编写,到处运行:一个字节码文件,每个平台一个JVM

Java compiles to bytecode that runs on a JVM. The main benefit is:
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
Bytecode is platform-independent; any JVM can run it (with JIT giving near-native speed for hot code).
Java's compiler produces platform-independent ____, which a virtual machine then interprets.
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
Bytecode is an intermediate form: compiled once, then run by the JVM on any platform. That is what makes Java partially compiled and partially interpreted.
การ์ดนี้ได้รับการแก้ไขแล้ว จึงแสดงเป็นภาษาอังกฤษจนกว่าคำแปลจะได้รับการอัปเดต
Worked example: why compile to bytecode and then interpret?
- Explain why Java is compiled to bytecode rather than straight to machine code.
- A compiler produces machine code for a particular processor and operating system, so the program will not necessarily run on a machine with a different platform.
- Java's compiler targets a virtual machine instead, so the bytecode is identical everywhere. Each platform supplies its own JVM to interpret it.
- The cost is speed: interpreting bytecode is slower than running native code, which is why the JVM adds just-in-time compilation 即时编译 for the hot parts.
IDE และกลุ่มคุณสมบัติสี่ประเภท
- Environment สำหรับพัฒนาแบบบูรณาการ (IDE) คือแอปพลิเคชันเดียวสำหรับการเขียน แปล รัน และ debug โปรแกรม หลักสูตรแบ่งคุณสมบัติออกเป็นสี่กลุ่ม
- สำหรับการเขียนโค้ด: context-sensitive prompts จะเด้งขึ้นมาแสดง identifiers, keywords หรือ parameters ที่เหมาะสมกับจุดนั้น;auto-complete จะช่วยเติมชื่อให้
- สำหรับการตรวจจับข้อผิดพลาดเบื้องต้น: dynamic syntax checks จะขีดเส้นใต้ความผิดพลาดขณะพิมพ์ ก่อนการแปล;สำหรับการจัดรูปแบบ: prettyprint แสดง keywords, identifiers, strings และ comments ด้วยสีต่างๆ พร้อมการจัดย่อที่สม่ำเสมอ;expand and collapse ซ่อน body ของ block เพื่อให้เห็นโครงสร้างหลัก
- สำหรับการ debug: breakpoints จะหยุดโปรแกรมที่บรรทัดที่กำหนด;single stepping จะรันทีละบรรทัด;window แสดงค่าของ variables และ expressions;report window รายการข้อผิดพลาด คำเตือน และ output

Coding, error detection, presentation, debugging

Which feature is part of an IDE's debugger?
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
A debugger lets you set breakpoints, step through code line by line, and inspect variable values.
Match each IDE feature to its syllabus group.
ความยาก 2/5 · 140 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
Coding, initial error detection, presentation, debugging: the four groups the syllabus names, one feature each here.
ตัวอย่างวิธีทำ: หา bug ใน Calculate()
- 函数
Calculate()返回了意外值。描述IDE的调试功能如何帮助找出原因。 [4] - ตั้ง breakpoint ที่บรรทัดแรกของ
Calculate()เพื่อให้โปรแกรมหยุดที่นั่นแทนที่จะรันผ่าน - ใช้ Single-step ผ่านฟังก์ชันทีละบรรทัด หลังแต่ละ step อ่านค่าของ variables และของ expression ที่คุณตั้งค่าให้ IDE monitor เปรียบเทียบกับค่าที่คุณคาดหวัง
- บรรทัดแรกหลังจากที่ค่าผิดคือจุดที่มี logic error. The report window แสดงข้อความ runtime error และ output ระหว่างทาง

หยุดชั่วคราว, ข้ามขั้นตอน, ตรวจสอบ

Put the steps of finding a logic error with a debugger in order.
ความยาก 3/5 · 200 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
Pause, step, inspect, compare, locate. Each is one of the debugging features the syllabus lists.
คะแนนที่หลุดหายไป
- คอมไพเลอร์ ไม่รัน โปรแกรม แต่จะแปลทั้งส่วนแล้วสร้างไฟล์ที่รันได้
- อินเทอร์เตอร์จะหยุดที่ ข้อผิดพลาดแรก; คอมไพเลอร์จะแสดงข้อผิดพลาด ทั้งหมด อย่าสลับกัน
- คำว่า "เร็วขึ้น" ต้องใช้คู่กับ "during run time", และคำว่า "พกพาได้" ต้องใช้คู่กับ "ซอร์สโค้ดเดียวกันรันได้ทุกที่ที่มีอินเทอร์เตอร์"
- จัดกลุ่มคุณสมบัติของ IDE เข้าเป็น สี่กลุ่ม ตามหลักสูตร: จุดหยุดชั่วคราวคือระบบดีบัก, การจัดรูปแบบข้อความคือการนำเสนอ, การเรียกคำแนะนำแบบเฉพาะบริบทคือการเขียนโค้ด บายต์โค้ด ไม่ใช่ โค้ดเครื่อง
คุณเข้าใจแล้ว
- แอสเซมเบลเลอร์: คำสั่งแอสเซมบลีหนึ่งคำสั่ง ↔ คำสั่งโค้ดเครื่องหนึ่งคำสั่ง · คอมไพเลอร์: ทั้งโปรแกรมทั้งหมด ก่อนรัน, ไฟล์ที่รันได้, แสดงข้อผิดพลาดทั้งหมด · อินเทอร์เตอร์: คำสั่งทีละบรรทัด, รันทันที, หยุดที่ข้อผิดพลาดแรก, ไม่มีไฟล์ที่รันได้
- ใช้คอมไพเลอร์เพื่อความเร็ว การกระจายและการรักษาความลับของซอร์สโค้ด; ใช้อินเทอร์เตอร์เพื่อรอบการทำงานแก้ไข-รันที่รวดเร็ว ความสามารถในการพกพา และการใช้งานสำหรับผู้เริ่มต้น
- Java编译成 portable bytecode ที่ JVM จะทำ インเทอร์ปหรือ JIT-compile:部分组成 compile,部分组成 интерпретация
- คุณสมบัติของ IDE ในสี่กลุ่ม: การเขียนโค้ด (การแนะนำแบบเฉพาะบริบท), การตรวจจับข้อผิดพลาดเบื้องต้น (การตรวจสอบไวยากรณ์แบบไดนามิก), การนำเสนอ (การจัดรูปแบบข้อความ, ขยายและหด), การดีบัก (จุดหยุดชั่วคราว, การข้ามขั้นตอน, ตัวแปร, หน้าต่างรายงาน)
เกิดปัญหาอะไรขึ้น? เฉพาะทีมเว็บไซต์เท่านั้นที่เห็นข้อมูลนี้