Comparison of programming languages (syntax)


This article compares the syntax of many notable 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
  • TUTOR $$ note implicit multiply operator

    Statement delimitation

A language that supports the statement construct typically has rules for one or more of the following aspects:
  • Statement terminator marks the end of a statement
  • Statement separator demarcates the boundary between two statements; not needed for the last statement
  • Line continuation escapes a newline to continue a statement on the next line
Some languages define a special character as a terminator while some, called line-oriented, rely on the newline. Typically, a line-oriented language includes a line continuation feature whereas other languages have no need for line continuation since newline is treated like other whitespace. Some line-oriented languages provide a separator for use between statements on one line.
LanguageStatement delimitation
ABAPperiod separated
Adasemicolon terminated
ALGOLsemicolon separated
ALGOL 68semicolon and comma separated
APLnewline terminated, separated
AppleScriptnewline terminated
AutoHotkeynewline terminated
Awknewline or semicolon terminated
BASICnewline terminated, colon separated
Boonewline terminated
Csemicolon terminated, comma separated expressions
C++semicolon terminated, comma separated expressions
C#semicolon terminated
COBOLwhitespace separated, sometimes period separated, optionally separated with commas and semi-colons
Cobranewline terminated
CoffeeScriptnewline terminated
CSSsemicolon terminated
Dsemicolon terminated
Eiffelnewline terminated, semicolon separated
Erlangcolon separated, period terminated
F#newline terminated, semicolon
Fortrannewline terminated, semicolon separated
Forthsemicolons terminate word definitions; space terminates word use
GFA BASICnewline terminated
Gosemicolon separated
Haskellin do-notation: newline separated,
in do-notation with braces: semicolon separated
Javasemicolon terminated
JavaScriptsemicolon separated
Kotlinsemicolon separated
Luawhitespace separated
Mathematica a.k.a. Wolframsemicolon separated
MATLABnewline terminated, separated by semicolon or comma
MUMPS a.k.a. Mnewline terminates line-scope, the closest to a "statement" that M has, a space separates/terminates a command, allowing another command to follow
Nimnewline terminated
Object Pascal semicolon separated
Objective-Csemicolon terminated
OCamlsemicolon separated
Pascalsemicolon separated
Perlsemicolon separated
PHPsemicolon terminated
Pick Basicnewline terminated, semicolon separated
PowerShellnewline terminated, semicolon separated
Prologcomma separated, semicolon separated, period terminated
Pythonnewline terminated, semicolon separated
Rnewline terminated, semicolon separated
Rakusemicolon separated
Redwhitespace separated
Rubynewline terminated, semicolon separated
Rustsemicolon terminated, comma separates expressions
Scalanewline terminated, semicolon separator
Seed7semicolon separated
Simulasemicolon separated
S-Langsemicolon separated
Smalltalkperiod separated
Standard MLsemicolon separated
Swiftsemicolon separated
Tclnewline or semicolon terminated
V newline terminated, comma or semicolon separated
Visual Basicnewline terminated, colon separated
Visual Basic newline terminated, colon separated
Xojonewline terminated
Zigsemicolon terminated

Line continuation

Listed below are notable line-oriented languages that provide for line continuation. Unless otherwise noted the continuation marker must be the last text of the line.
;Ampersand
;Backslash
;Backtick
  • PowerShell
;Hyphen
  • SQL*Plus
;Underscore
  • AutoIt
  • Cobra
  • Visual Basic
  • Xojo
;Ellipsis
  • MATLAB: The ellipsis need not end the line, but text following it is ignored. It begins a comment that extends through the first subsequent newline. Contrast this with a line comment which extends until the next newline.
;Comma delimiter
  • Ruby: comment may follow delimiter
;Left bracket delimiter
;Operator symbol
  • Ruby: as last object of line; comment may follow operator
  • AutoHotkey: As the first character of continued line; any expression operators except ++ and --, and a comma or a period
;Some form of line comment serves as line continuation
  • Turbo Assembler: \
  • m4: dnl
  • TeX: %
;Character position
  • Fortran 77: A non-comment line is a continuation of the prior non-comment line if any non-space character appears in column 6. Comment lines cannot be continued.
  • COBOL: String constants may be continued by not ending the original string in a PICTURE clause with ', then inserting a - in column 7
  • TUTOR: Lines starting with a tab continue the prior command.
The C compiler concatenates adjacent string literals even if on separate lines, but this is not line continuation syntax as it works the same regardless of the kind of whitespace between the literals.

Consuming external software

Languages support a variety of ways to reference and consume other software in the syntax of the language. In some cases this is importing the exported functionality of a library, package or module but some mechanisms are simpler text file include operations.
Import can be classified by level and by syntax.
;File include
  • #include <filename> or #include "filename" C preprocessor used in conjunction with C and C++ and other development tools
;File import
  • addpath MATLAB
  • COBOL
  • or C++
  • :-include. Prolog
  • #include file="filename" ASP
  • #include <filename> or #include "filename" AutoHotkey, AutoIt
  • #import "filename" or #import <filename> Objective-C
  • Mathematica, Wolfram Language
  • Fortran
  • include "filename"; PHP
  • include program or #include program Pick Basic
  • include!; Rust
  • load "filename" Ruby
  • Red
  • Lua
  • require "filename"; Perl, PHP
  • Ruby
  • R
  • @import; Zig
;Package import
  • #include filename C
  • import module; C++
  • # mod altname; Rust
  • @import module; Objective-C
  • <<name Mathematica, Wolfram Language
  • Prolog:
  • from module import * Python
  • extern crate libname; or extern crate libname as altname; or mod modname; Rust
  • library R:
  • IMPORT module Oberon
  • import altname "package/name" Go:
  • import package.module; or import altname = package.module; D
  • import Module or import qualified Module as M Haskell
  • import package.* Java, MATLAB, Kotlin
  • import "modname"; JavaScript
  • import altname from "modname"; JavaScript
  • import package or import package._ Scala
  • import module Swift
  • import module V
  • import module Python
  • Lua
  • Ruby
  • use module Fortran 90+
  • use module, only : identifier Fortran 90+
  • use Module; Perl
  • use Module qw; Perl
  • use Package.''Name Cobra
  • uses unit Pascal
  • with package Ada
  • @import; Zig
;Class import
  • from module import Class Python
  • import package.class Java, MATLAB, kotlin
  • import class from "modname"; JavaScript
  • import from "modname"; JavaScript
  • import from "modname"; JavaScript
  • import package.class Scala
  • import package. Scala
  • import package._ Scala
  • use Namespace\ClassName; PHP
  • use Namespace\ClassName as AliasName; PHP
  • using namespace::subnamespace::Class; C++
;Procedure/function import
  • from module import function Python
  • import package.module : symbol; D
  • import package.module : altsymbolname = symbol; D
  • import Module Haskell
  • import function from "modname"; JavaScript
  • import from "modname"; JavaScript
  • import from "modname"; JavaScript
  • import package.function MATLAB
  • import package.class.function Scala
  • import package.class. Scala
  • Perl
  • use function Namespace\function_name; PHP
  • use Namespace\function_name as function_alias_name; PHP
  • using namespace::subnamespace::symbol; C++
  • use module::submodule::symbol; Rust
  • use module::submodule::; Rust
  • use module::submodule::symbol as altname; Rust
;Constant import
  • use const Namespace\CONST_NAME; PHP
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
  • import package.* Java
  • import package.class Java
  • open module OCaml
  • using namespace namespace::subnamespace; C++
  • use module::submodule::*; Rust
;Required to access code
  • import module;C++
  • import altname "package/name" Go
  • import altname from "modname";JavaScript
  • import module''Python