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 (* (+ 2 3) (expt 4 5)) infix notation Fortran (2 + 3) * (4 ** 5) suffix, postfix, or Reverse Polish notation Forth 2 3 + 4 5 ** * math-like notation TUTOR (2 + 3)(45) $$ 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.
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 Fortran 90, Fortran 95, Fortran 2003, Fortran 2008 Backslash bash and other Unix shells C preprocessor macros; used in conjunction with C, C++ and many other programming contexts Crystal Mathematica, Wolfram Language Python Ruby JavaScript – only within single- or double-quoted strings Vimscript as first character of continued line Backtick PowerShell Hyphen SQL*Plus Underscore AutoIt Cobra Visual Basic Xojo Ellipsis (three dots) MATLAB: The ellipsis need not end the line, but text following it is ignored. It begins a comment that extends through (including) 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 Batch file: starting a parenthetical block can allow line continuation Ruby: left parenthesis, left square bracket, or left curly bracket 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 (same position as the * for comment is used.) TUTOR: Lines starting with a tab (after any indentation required by the context) 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 (module, package, class, procedure,...) and by syntax (directive name, attributes,...).
File include #include <filename> or #include "filename" – C preprocessor used in conjunction with C and C++ and other development tools
File import addpath(directory) – MATLAB COPY filename. – COBOL import <filename>; or import "filename"; – C++ :-include("filename"). – Prolog #include file="filename" – ASP #include <filename> or #include "filename" – AutoHotkey, AutoIt #import "filename" or #import <filename> – Objective-C Import["filename"] – Mathematica, Wolfram Language include 'filename' – Fortran include "filename"; – PHP include [filename] program or #include [filename] program – Pick Basic include!("filename"); – Rust load "filename" – Ruby load %filename – Red require('filename') – Lua require "filename"; – Perl, PHP require "filename" – Ruby, Crystal source(""filename"") – R @import("filename"); – Zig
Package import #include filename – C import module; – C++ #[path = "filename"] mod altname; – Rust @import module; – Objective-C <<name – Mathematica, Wolfram Language :-use_module(module). – Prolog: from module import * – Python extern crate libname; – or extern crate libname as altname; or mod modname; – Rust library("package") – 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 (Vlang) import module – Python require('modname') – Lua require "shard" – Crystal require "gem" – Ruby use module – Fortran 90+ use module, only : identifier – Fortran 90+ use Module; – Perl use Module qw(import options); – Perl use Package.Name – Cobra uses unit – Pascal with package – Ada @import("pkgname"); – Zig
… excerpt ends here. Continue reading the full article.
