stringtranslate.com

Comparison of programming languages (syntax)

This comparison of programming languages compares the features of language syntax (format) 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

Statements

When a programming languages has statements, they typically have conventions for:

A statement separator demarcates the boundary between two separate statements. A statement terminator defines 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.

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 (as three periods–not one special character)
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
[End and Begin] using normal quotes

Libraries

To import a library is a way to read external, possibly compiled, routines, programs or packages. Imports can be classified by level (module, package, class, procedure,...) and by syntax (directive name, attributes,...)

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 (allowing things to be referred to by a shorter name, but they can still be referred to by some fully qualified name without import), or whether they are actually required to access the code (without which it is impossible to access the code, even with fully qualified names).

Syntactic convenience
Required to access code

Blocks

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 (a.k.a. curly brackets) { ... }
Parentheses ( ... )
Square brackets [ ... ]
begin ... end
do ... end
do ... done
do ... end
X ... end (e.g. if ... end):
(begin ...)
(progn ...)
(do ...)
Indentation
Others

Comments

Comments can be classified by:

Inline comments

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:

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. In the examples, the symbol ~ represents the comment; and, the symbols surrounding it are understood by the interpreters/compilers as the delimiters.

Examples:

Unique variants

Fortran
COBOL
Cobra
Curl
Lua
Perl
PHP
Python
Elixir
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 comment 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

Comment comparison

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.

See also

References

  1. ^ a b For multiple statements on one line
  2. ^ Three different kinds of clauses, each separates phrases and the units differently:
      1. serial-clause using go-on-token (viz. semicolon): begin a; b; c end – units are executed in order.
      2. collateral-clause using and-also-token (viz. ","): begin a, b, c end – order of execution is to be optimised by the compiler.
      3. parallel-clause using and-also-token (viz. ","): par begin a, b, c end – units must be run in parallel threads.
  3. ^ semicolon – result of receding statement hidden, comma – result displayed
  4. ^ a b From the R Language Definition, section 3.2 Control structures: "A semicolon always indicates the end of a statement while a new line may indicate the end of a statement. If the current statement is not syntactically complete new lines are simply ignored by the evaluator."
  5. ^ Bash Reference Manual, 3.1.2.1 Escape Character
  6. ^ Python Documentation, 2. Lexical analysis: 2.1.5. Explicit line joining
  7. ^ "Mathworks.com". Archived from the original on 7 February 2010.
  8. ^ "Parenthesis/Brackets - Windows CMD - SS64.com". ss64.com.
  9. ^ "Scripts - Definition & Usage | AutoHotkey".
  10. ^ For an M-file (MATLAB source) to be accessible by name, its parent directory must be in the search path (or current directory).
  11. ^ a b c "Verbose Syntax - F# | Microsoft Learn". Microsoft Learn. 5 November 2021. Retrieved 17 November 2022.
  12. ^ "Nim Manual". nim-lang.org.
  13. ^ a b "Mathworks.com". Archived from the original on 21 November 2013. Retrieved 25 June 2013.
  14. ^ "Algol68_revised_report-AB.pdf on PDF pp. 61–62, original document pp. 121–122" (PDF). Retrieved 27 May 2014.
  15. ^ "HTML Version of the Algol68 Revised Report AB". Archived from the original on 17 March 2013. Retrieved 27 May 2014.
  16. ^ a b "DLang.org, Lexical". Retrieved 27 May 2014.
  17. ^ "AutoItScript.com Keyword Reference, #comments-start". Retrieved 27 May 2014.
  18. ^ "slang-2.2.4/src/slprepr.c – line 43 to 113". Retrieved 28 May 2014.
  19. ^ "Punctuation · The Julia Language".
  20. ^ "Nim Manual". nim-lang.org.
  21. ^ "Python tip: You can use multi-line strings as multi-line comments", 11 September 2011, Guido van Rossum
  22. ^ "Writing Documentation — Elixir v1.12.3". Retrieved 28 July 2023.
  23. ^ "Perl 6 Documentation (Syntax)". docs.perl6.org. Comments. Retrieved 5 April 2017.
  24. ^ "Using the FPP Preprocessor". Archived from the original on 18 November 2022. Retrieved 18 November 2022.
  25. ^ "Perl 6 POD Comments". 25 May 2023.
  26. ^ "Perl 6 POD (Abbreviated Blocks)". 25 May 2023.

Notes

  1. ^ Visual Basic .NET does not support traditional multi-line comments, but they can be emulated through compiler directives.
  2. ^ a b While C# supports traditional block comments /* ... */, compiler directives can be used to mimic them just as in VB.NET.
  3. ^ a b The line continuation character _ can be used to extend a single-line comment to the next line without needing to type ' or REM again. This can be done up to 24 times in a row.
  4. ^ Fortran does not support traditional block comments, but some compilers support preprocessor directives in the style of C/C++, allowing a programmer to emulate multi-line comments.[24]