Comparison of programming languages (syntax)


This comparison of programming languages compares the features of language syntax for over 50 computer programming languages.

Expressions

Programming language expressions can be broadly classified into four syntax structures:
;prefix notation
;infix notation
;suffix, postfix, or Reverse Polish notation
;math-like notation
Programming language statements typically have conventions for:
A statement separator is used to demarcate boundaries between two separate statements. A statement terminator is used to demarcate the end of an individual statement. Languages that interpret the end of line to be the end of a statement are called "line-oriented" languages.
"Line continuation" is a convention in line-oriented languages where the newline character could potentially be misinterpreted as a statement terminator. In such languages, it allows a single statement to span more than just one line.
LanguageStatement separator-terminatorSecondary separator
ABAPperiod separated-
Adasemicolon terminated-
ALGOLsemicolon separated-
ALGOL 68semicolon and comma separated-
APLnewline terminated separated
AppleScriptnewline terminated-
AutoHotkeynewline terminated-
BASICnewline terminatedcolon separated
Boonewline terminated-
Csemicolon terminates statementscomma separates expressions
C++semicolon terminates statementscomma separates expressions
C#semicolon terminated-
COBOLwhitespace separated, sometimes period separated, optionally separated with commas and semi-colons.
Cobranewline terminated-
CoffeeScriptnewline terminated-
CSSsemicolon separated-
Dsemicolon terminated-
Eiffelnewline terminatedsemicolon
Erlangcolon separated, period terminated-
F#newline terminatedsemicolon
Fortrannewline terminatedsemicolon
Forthsemicolons terminate word definitions-
GFA BASICnewline terminated-
Gosemicolon separated -
Haskell newline separated-
Haskell semicolon separated-
Javasemicolon terminated-
JavaScriptsemicolon separated -
Kotlinsemicolon separated -
Luawhitespace separated -
Mathematicasemicolon separated-
MATLABnewline terminatedsemicolon or comma
Object Pascal semicolon separated-
Objective-Csemicolon terminated-
OCamlsemicolon separated-
Pascalsemicolon separated-
Perlsemicolon separated-
PHPsemicolon terminated-
Pick Basicnewline terminatedsemicolon separated
PowerShellnewline terminatedsemicolon separated
Prologcomma separated, semicolon separated, period terminated -
Pythonnewline terminatedsemicolon
Rakusemicolon separated-
Redwhitespace separated-
Rubynewline terminatedsemicolon
Rustsemicolon terminates statementscomma separates expressions
Scalanewline terminated semicolon
Seed7semicolon separated -
Simulasemicolon separated-
S-Langsemicolon separated-
Smalltalkperiod separated-
Standard MLsemicolon separated-
Swiftsemicolon separated -
Visual Basicnewline terminatedcolon separated
Visual Basic.NETnewline terminatedcolon separated
Wolfram Languagesemicolon separated-
Xojonewline terminated-
LanguageStatement separator-terminatorSecondary separator

Line continuation

Line continuation is generally done as part of lexical analysis: a newline normally results in a token being added to the token stream, unless line continuation is detected.
;Whitespace – Languages that do not need continuations
;Ampersand as last character of line
;Backslash as last character of line
;Backtick as last character of line
;Hyphen as last character of line
;Underscore as last character of line
;Ellipsis
;Comma delimiter as last character of line
;Left bracket delimiter as last character of line
;Operator as last object of line
;Operator as first character of continued line
;Backslash as first character of continued line
;Some form of inline comment serves as line continuation
;Character position
; using normal quotes
To import a library is a way to read external, possibly compiled, routines, programs or packages. Imports can be classified by level and by syntax
;File import
;Package import
;Class import
;Procedure/function import
;Constant import
The above statements can also be classified by whether they are a syntactic convenience, or whether they are actually required to access the code.
;Syntactic convenience
;Required to access code
A block is a notation for a group of two or more statements, expressions or other units of code that are related in such a way as to comprise a whole.
;Braces :
;Parentheses
;Square brackets
;begin... end:
;do... end:
;do... done:
;do... end
;X... end :
;:
;:
;:
;Indentation
;Others
s can be classified by:
Inline comments are generally those that use a newline character to indicate the end of a comment, and an arbitrary delimiter or sequence of tokens to indicate the beginning of a comment.
Examples:
SymbolLanguages
CFortran I to Fortran 77
REMBASIC, Batch files
::Batch files, COMMAND.COM, cmd.exe
NB.J; from the common abbreviation Nota bene, the Latin for "note well".
APL; the mnemonic is the glyph resembles a desk lamp, and hence "illuminates" the foregoing.
#Bourne shell and other UNIX shells, Cobra, Perl, Python, Ruby, Seed7, Windows PowerShell, PHP, R, Make, Maple, Elixir, Nim
%TeX, Prolog, MATLAB, Erlang, S-Lang, Visual Prolog
//ActionScript, C, C++, C#, D, F#, Go, Java, JavaScript, Kotlin, Object Pascal, Objective-C, PHP, Rust, Scala, SASS, Swift, Xojo
'Monkey, Visual Basic, VBScript, Small Basic, Gambas, Xojo
!Fortran, Basic Plus, Inform, Pick Basic
;Assembly x86, AutoHotkey, AutoIt, Lisp, Common Lisp, Clojure, Rebol, Red, Scheme
--Euphoria, Haskell, SQL, Ada, AppleScript, Eiffel, Lua, VHDL, SGML, PureScript
*Assembler S/360, COBOL I to COBOL 85, PAW, Fortran IV to Fortran 77, Pick Basic
||Curl
"Vimscript, ABAP
\Forth
*>COBOL 90

Block comments

Block comments are generally those that use a delimiter to indicate the beginning of a comment, and another delimiter to indicate the end of a comment. In this context, whitespace and newline characters are not counted as delimiters.
Examples:
SymbolLanguages
comment ~ ;ALGOL 60, SIMULA
¢ ~ ¢,
# ~ #, co ~ co,
comment ~ comment
ALGOL 68
/* ~ */ActionScript, AutoHotkey, C, C++, C#, D, Go, Java, JavaScript, kotlin, Objective-C, PHP, PL/I, Prolog, Rexx, Rust, Scala, SAS, SASS, SQL, Swift, Visual Prolog, CSS
#cs ~ #ceAutoIt
/+ ~ +/D
/# ~ #/Cobra
<# ~ #>Powershell
<!-- ~ -->HTML, XML
=begin ~ =cutPerl
#`Raku
=begin ~ =endRuby
# ~ #, #stop ~ EOF,
#iffalse ~ #endif, #ifntrue ~ #endif,
#if false ~ #endif, #if !true ~ #endif
S-Lang
Haskell
Delphi, ML, Mathematica, Object Pascal, Pascal, Seed7, Applescript, OCaml, Standard ML, Maple, Newspeak, F#
Delphi, Object Pascal, Pascal, Red
Nunjucks, Twig
Mustache, Handlebars
Handlebars
|# ~ #|Curl
%MATLAB
#| ~ |#Lisp, Scheme, Racket.
##Nim
-- ~ ,
--=],
--=...=]
Lua
" ~ "Smalltalk
Clojure

Unique variants

;Fortran
;COBOL
;Cobra
;Curl
;Lua
;Perl
;PHP
;Python
;Raku
;Ruby
;S-Lang
;Scheme and Racket
;ABAP
ABAP supports two different kinds of comments. If the first character of a line, including indentation, is an asterisk the whole line is considered as a comment, while a single double quote begins an in-line commet which acts until the end of the line. ABAP comments are not possible between the statements EXEC SQL and ENDEXEC because Native SQL has other usages for these characters. In the most SQL dialects the double dash can be used instead.
;Esoteric languages
There is a wide variety of syntax styles for declaring comments in source code.
BlockComment in italics is used here to indicate block comment style.
InlineComment in italics is used here to indicate inline comment style.
LanguageIn-line commentBlock comment
Ada, Eiffel, Euphoria, Occam, SPARK, ANSI SQL, and VHDL-- InlineComment
ALGOL 60comment BlockComment;
ALGOL 68¢ BlockComment ¢
comment BlockComment comment
co BlockComment co
# BlockComment #
£ BlockComment £
APLInlineComment
AppleScript-- InlineComment
Assembly language ; InlineComment one example
AutoHotkey; InlineComment/* BlockComment */
AWK, Bash, Bourne shell, C shell, Maple, R, Tcl, and Windows PowerShell# InlineComment<# BlockComment #>
BASIC :'InlineComment
REM InlineComment
C, CHILL, PL/I, and REXX/* BlockComment */
C, C++, Go, Swift and JavaScript// InlineComment/* BlockComment */
C#// InlineComment
/// InlineComment
/* BlockComment */
/** BlockComment */
COBOL I to COBOL 85 * InlineComment
COBOL 2002*> InlineComment
Curl|| InlineComment|# BlockComment #|
|foo# BlockComment #|
Cobra# InlineComment/# BlockComment #/
D// InlineComment
/// Documentation InlineComment
/* BlockComment */
/** Documentation BlockComment */
/+ BlockComment +/
/++ Documentation BlockComment +/
DCL$! InlineComment
ECMAScript // InlineComment/* BlockComment */
Forth\ InlineComment
stack comment convention
FORTRAN I to FORTRAN 77C InlineComment
Fortran 90! InlineComment
Haskell-- InlineComment
Java// InlineComment/* BlockComment */
/** BlockComment */
Lisp and Scheme; InlineComment#| BlockComment |#
Lua-- InlineComment --]
Maple# InlineComment
Mathematica
Matlab% InlineComment%
Note: Both percent–bracket symbols must be the only non-whitespace characters on their respective lines.
Nim# InlineComment ##
Object Pascal // InlineComment
OCaml
Pascal, Modula-2, Modula-3, Oberon, and ML:
Perl and Ruby# InlineComment =begin
BlockComment
=cut

__END__
Comments after end of code
PHP# InlineComment
// InlineComment
/* BlockComment */
/** Documentation BlockComment */
PILOTR:InlineComment
PLZ/SYS! BlockComment !
PL/SQL and TSQL-- InlineComment/* BlockComment */
Prolog% InlineComment/* BlockComment */
Python# InlineComment BlockComment
""" BlockComment """

Raku# InlineComment #`
=comment
This comment paragraph goes until the next POD directive
or the first blank line.
Red; InlineComment
Rust// InlineComment
/// InlineComment
//! InlineComment
/* BlockComment */
/** BlockComment */
/*! BlockComment */
SAS* BlockComment;
/* BlockComment */
Seed7# InlineComment
Simulacomment BlockComment;
! BlockComment;
Smalltalk"BlockComment"
Smarty
Standard ML
TeX, LaTeX, PostScript, Erlang, Elixir and S-Lang% InlineComment
Texinfo@c InlineComment
@comment InlineComment
TUTOR* InlineComment
command $$ InlineComment
Visual Basic' InlineComment
Rem InlineComment
Visual Basic.NET' InlineComment
' InlineComment
Rem
InlineComment
Visual Prolog% InlineComment/* BlockComment */
Wolfram Language
Xojo' InlineComment
//
InlineComment
rem
InlineComment''