語法高亮(英語:Syntax highlighting,台湾作語法突顯,又称语法加亮),是指根據術語(關鍵字)類別來顯示不同的顏色与字體以增强可读性的一种编辑器特性。
这种功能可改善人对编辑器中内容(通常为源代碼)的可讀性,進而降低因出现誤讀或誤寫而出现错误的几率。
下面是一例C++的語法突顯范例:
// Allocate all the windows for (int i = 0; i < max; i++) { pWins[i] = new Window(); }
在這個範例中,編輯器辨認出關鍵字為for,int和new,并辨認出變數的名字i,pWins和max,相應地將它們以高亮颜色顯示,註解则以灰色(或異於關鍵字的颜色)顯示,以避免與程式碼相混淆。
下面是一个關於Python的例子:
#Allocate all the windows for i in range(1, 11): print(i)
基本上现代专业的代碼編輯器都支援語法突顯功能,並且支援重新定義語法突顯功能。亦有不少常规文本编辑器支持这种功能。
这是一篇關於電腦程式語言的小作品。你可以通过编辑或修订扩充其内容。 |
This article uses material from the Wikipedia 中文 article 語法突顯, which is released under the Creative Commons Attribution-ShareAlike 3.0 license ("CC BY-SA 3.0"); additional terms may apply (view authors). 除非另有声明,本网站内容采用CC BY-SA 4.0授权。 Images, videos and audio are available under their respective licenses.
®Wikipedia is a registered trademark of the Wiki Foundation, Inc. Wiki 中文 (DUHOCTRUNGQUOC.VN) is an independent company and has no affiliation with Wiki Foundation.