// comment
int main ()
{
for ( int i = 0 ; i < MAX ; i ++ )
printf ( "% d \ n " , i );
return 0 ;
}
Syntax highlighting - selection of syntactic text constructions using various colors , fonts and styles. Usually used to facilitate reading the source code of computer programs, improve visual perception. Syntax highlighting is an important feature of text editors , development environments , debuggers, and other software development tools. Syntax highlighting is also used when publishing source codes on the Internet and on paper.
Content
- 1 Principle
- 2 History
- 3 Examples
- 4 See also
- 5 notes
- 6 References
Principle
When syntax highlighting in the source code of programming languages are highlighted:
- language constructs;
- comments
- numeric and string data
More advanced syntax highlighting systems also highlight:
- variables
- parentheses
- standard language features
Many text editors and development environments also have the function of highlighting pair brackets under the cursor: when the text cursor approaches the bracket, both the bracket near which the cursor is located and the pair to it are highlighted.
Syntax highlighting, in addition to readability, also allows you to avoid syntax errors: incorrect spelling of language constructs, open quotes, etc. There may also be highlighting of obviously incorrect code: for example, unpaired brackets, or invalid characters outside the string data in quotation marks.
History
The Live Parsing Editor ( LEXX or LPEX ) on VM , written to digitize the Oxford Dictionary in 1985 , was one of the first syntax-highlighted editors [1] .
Examples
The following compares C code snippets :
| normal display | syntax highlighted |
|---|---|
/ * Hello World * /
#include <stdlib.h>
#include <stdio.h>
int main ()
{
printf ("Hello World \ n");
return 0;
}
| / * Hello World * /
#include <stdlib.h>
#include <stdio.h>
int main ()
{
printf ( "Hello World \ n " );
return 0 ;
}
|
And here is another example of syntactic highlighting: already in C ++ code :
// Create "window_count" Window objects:
const auto window_count = int { 10 };
auto windows = std :: array < std :: shared_ptr < Window > , max_window_count > {};
for ( auto i = int { 0 }; i < window_count ; ++ i ) {
windows [ i ] = std :: make_shared < Window > ();
}
In this example, the editor recognizes the keywords auto , const , int , and for ; comments at the beginning are also highlighted in a special way to distinguish from the current code.
See also
- Indentation style
- Colorer is a syntax highlighting library for source codes of programs in a text editor developed by Igor Russky.
- - Python syntax highlighting
- Scintilla is an open source editing component (including syntax highlighting) for Microsoft Windows and Linux with GTK +, developed by Neil Hodgson
- SynEdit - open source multiline editing component for Delphi, Kylix, C ++ Builder; development is no longer supported.
Notes
Links
- Code2HTML (English) . - Converter from source to HTML with highlighting. Date of treatment November 22, 2009. Archived February 12, 2012.
- syntaxhighlighter . - syntax highlighting code on a web page. Date of treatment November 22, 2009. Archived February 12, 2012.
- highlight.js . - Automatic syntax highlighting on web pages using JavaScript . Date of treatment November 22, 2009. Archived February 12, 2012.
- Features syntax highlighting for the Web . - Features syntax highlighting for the Web. Date of treatment December 1, 2010. Archived February 12, 2012.