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
- Lisp
)
- Fortran
*
- Forth
2 3 + 4 5 ** *
- TUTOR
$$ note implicit multiply operatorStatement delimitation
- 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
| Language | Statement delimitation |
| ABAP | period separated |
| Ada | semicolon terminated |
| ALGOL | semicolon separated |
| ALGOL 68 | semicolon and comma separated |
| APL | newline terminated, separated |
| AppleScript | newline terminated |
| AutoHotkey | newline terminated |
| Awk | newline or semicolon terminated |
| BASIC | newline terminated, colon separated |
| Boo | newline terminated |
| C | semicolon terminated, comma separated expressions |
| C++ | semicolon terminated, comma separated expressions |
| C# | semicolon terminated |
| COBOL | whitespace separated, sometimes period separated, optionally separated with commas and semi-colons |
| Cobra | newline terminated |
| CoffeeScript | newline terminated |
| CSS | semicolon terminated |
| D | semicolon terminated |
| Eiffel | newline terminated, semicolon separated |
| Erlang | colon separated, period terminated |
| F# | newline terminated, semicolon |
| Fortran | newline terminated, semicolon separated |
| Forth | semicolons terminate word definitions; space terminates word use |
| GFA BASIC | newline terminated |
| Go | semicolon separated |
| Haskell | in do-notation: newline separated, in do-notation with braces: semicolon separated |
| Java | semicolon terminated |
| JavaScript | semicolon separated |
| Kotlin | semicolon separated |
| Lua | whitespace separated |
| Mathematica a.k.a. Wolfram | semicolon separated |
| MATLAB | newline terminated, separated by semicolon or comma |
| MUMPS a.k.a. M | newline terminates line-scope, the closest to a "statement" that M has, a space separates/terminates a command, allowing another command to follow |
| Nim | newline terminated |
| Object Pascal | semicolon separated |
| Objective-C | semicolon terminated |
| OCaml | semicolon separated |
| Pascal | semicolon separated |
| Perl | semicolon separated |
| PHP | semicolon terminated |
| Pick Basic | newline terminated, semicolon separated |
| PowerShell | newline terminated, semicolon separated |
| Prolog | comma separated, semicolon separated, period terminated |
| Python | newline terminated, semicolon separated |
| R | newline terminated, semicolon separated |
| Raku | semicolon separated |
| Red | whitespace separated |
| Ruby | newline terminated, semicolon separated |
| Rust | semicolon terminated, comma separates expressions |
| Scala | newline terminated, semicolon separator |
| Seed7 | semicolon separated |
| Simula | semicolon separated |
| S-Lang | semicolon separated |
| Smalltalk | period separated |
| Standard ML | semicolon separated |
| Swift | semicolon separated |
| Tcl | newline or semicolon terminated |
| V | newline terminated, comma or semicolon separated |
| Visual Basic | newline terminated, colon separated |
| Visual Basic | newline terminated, colon separated |
| Xojo | newline terminated |
| Zig | semicolon 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
- bash and other Unix shells
- C preprocessor macros; used in conjunction with C, C++ and many other programming contexts
- Mathematica, Wolfram Language
- Python
- Ruby
- JavaScript – only within single- or double-quoted strings
- Vimscript as first character of continued line
- PowerShell
- SQL*Plus
- AutoIt
- Cobra
- Visual Basic
- Xojo
- 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.
- Ruby: comment may follow delimiter
- Batch file: starting a parenthetical block can allow line continuation
- Ruby: left parenthesis, left square bracket, or left curly bracket
- 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
- Turbo Assembler:
\ - m4:
dnl - TeX:
%
- 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.
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
-
addpathMATLAB - 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 programor#include programPick Basic -
include!;Rust -
load "filename"Ruby - Red
- Lua
-
require "filename";Perl, PHP - Ruby
- R
-
@import;Zig
-
#include filenameC -
import module;C++ -
# mod altname;Rust -
@import module;Objective-C -
<<nameMathematica, Wolfram Language - Prolog:
-
from module import *Python -
extern crate libname;orextern crate libname as altname;ormod modname;Rust -
libraryR: -
IMPORT moduleOberon -
import altname "package/name"Go: -
import package.module;orimport altname = package.module;D -
import Moduleorimport qualified Module as MHaskell -
import package.*Java, MATLAB, Kotlin -
import "modname";JavaScript -
import altname from "modname";JavaScript -
import packageorimport package._Scala -
import moduleSwift -
import moduleV -
import modulePython - Lua
- Ruby
-
use moduleFortran 90+ -
use module, only : identifierFortran 90+ -
use Module;Perl -
use Module qw;Perl -
use Package.''NameCobra -
uses unitPascal -
with packageAda -
@import;Zig
-
from module import ClassPython -
import package.classJava, MATLAB, kotlin -
import class from "modname";JavaScript -
import from "modname";JavaScript -
import from "modname";JavaScript -
import package.classScala -
import package.Scala -
import package._Scala -
use Namespace\ClassName;PHP -
use Namespace\ClassName as AliasName;PHP -
using namespace::subnamespace::Class;C++
-
from module import functionPython -
import package.module : symbol;D -
import package.module : altsymbolname = symbol;D -
import ModuleHaskell -
import function from "modname";JavaScript -
import from "modname";JavaScript -
import from "modname";JavaScript -
import package.functionMATLAB -
import package.class.functionScala -
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
-
use const Namespace\CONST_NAME;PHP
;Syntactic convenience
-
import package.*Java -
import package.classJava -
open moduleOCaml -
using namespace namespace::subnamespace;C++ -
use module::submodule::*;Rust
-
import module;C++ -
import altname "package/name"Go -
import altname from "modname";JavaScript -
import module''Python