Symbolic Logic:Programming:Programming Language

A language is needed to include the new features.
 * Renaming inheritance
 * Roles
 * Services
 * Mappings
 * Preconditions
 * Characteristics

The least important part of a language is its syntax. The underlying logic and features are what is important. The use of text to enter and edit programs seems anachronistic now when a GUI is used for entering of data for most applications.

However a textual representation of a progam is still needed.

Transformations
This document describes how text in the language describes the internal model of the program. There are 3 transformations required for this


 * Syntax Analysis
 * Scope Transformation
 * Role Transformation

Language Definition
A program is a statement.

Statement
A statement is a boolean expression that when evaluated must equal true.

If a statement does not evaluate to true, the program is inconsistent, and a paradox has been found.

Expression
An expression is any type of expression that represents a value, or a type,
 * Boolean expression - evaluates to bool
 * Arithmetic expression - evaluates to any number type, or class where appropriate operators are defined.
 * Type expression - Type expressions must be evaluated in the Type Resolution Metaphase.

Boolean Expression
A boolean expression is an expression that evaluates to true or false. A boolean expression may be formed out of,


 * binary boolean operators and/or
 * unary boolean operator not
 * bracketed boolean expression.
 * compound boolean expression - An expression in which declarations are local.
 * comparison operators on expressions - < = >
 * boolean function call
 * declaration

Note that the statement separator ";" is equivalent to the "and" condition, but has a different operator precedence. Also note that a declaration is regarded as an expression that evaluates to true or false.

A declaration states the existence of a variable, within a compound boolean expression, and its membership of a set. For example, {bool x; x = a or b; x and c} means
 * $$\exists x \in bool ((x=a \or b) \and x \and c) $$

The syntax is,

A boolean variable path must identify a variable symbol of type bool. A boolean function call must have a return type of bool.

Arithmetic Expression
A arithmetic expression is an expression that evaluates to a number or a class that implements the standard functions associated with operators,


 * binary operators +, -, *, /, **
 * unary operators ++, --
 * bracketed arithmetic expression.
 * function call
 * declaration

The syntax is,

A boolean variable path must identify a variable symbol of type bool. A boolean function call must have a return type of bool.

Comparison Expression
Any values may be compared for eqquality. The built in types other than "type" may be compared for order. In addition classes may be compared for equality, if they implement the Compare method.

Compare : [any, any] -> int

Variable
A variable path identifies a variable symbol, using the scope rules. A variable symbol is a placeholder for a value. Each variable symbol must evaluate to the same value.

Blocks and Local Variables
A block expression defines the scope of any variables declared in declarations within it. A variable path is mapped to a variable symbol by scope rules. The same variable path refers to a different variable symbol outside the scope of the variable declaration.

Declaration
A declaration associates a variable name with a variable symbol within a scope. It declares the existence of the variable symbol, and defines the type to which it belongs. A type is more general that a set in that it includes functions as well as sets.

The variable identifies the variable symbol within the scope. Outside the scope the same variable name a different The scope is defined by the inner-most enclosing bracketed

Two declaration syntaxes are supported,
 * Pascal style.
 * C, C++, Java style

Pascal Style Declaration
A pascal declaration associates a name with a type expression.

Example variables, n : integer x : double = 6.55 name : string = "Bob"

Example forward declaration Simple : class Complex : class (T : type = float) fact : (n : integer) -> integer

Example declaration with body fact : (n : integer) -> integer { if n = 1 then 1 else fact(n-1) } Simple : class { } Complex : class (T : type = float) { ... }

Example type declaration T : type = [n : int] -> int

Function Type
A function is an implementation of mapping from set of input parameter values to an output value by a rule.

A function has a signature which consists of its name and the types of its parameters. A function signature with a function body is a function declaration.

If the function body is a compound statement declared like,

f : (p : P) -> { c(result) } where,
 * f is the function name
 * p : P represents the formal parameters
 * c(result) represents the block expression, including the result

Then this is equivalent in mathematics to,


 * $$ \forall p \in P \ ( f(p) = result \and c(result) ) $$

If the function body is an expression then,

f : (p : P ) -> { c } where,
 * f is the function name
 * p : P represents the formal parameters
 * c represents the expression

Then this is equivalent in mathematics to,


 * $$ \forall p \in P \ ( f(p) = c ) $$

Class Type
A class is a mathematical set, viewed as the properties of its elements.

Mapping Declaration
A mapping declaration represents a mapping which is recorded by individual values stored for each set of function input parameter values. This differs from a function where the mapping is represented by a rule which describes how the result is calculated from the input values.

The mapping will be implemented using an array, if the range of values is not too great,
 * boolean
 * enum
 * range of values

Otherwise the mapping will be implemented using one of the sparse data lookup strategies,
 * Tree
 * Hash table

Enum Type
An enum defines a set of constant values.

Range Type
A range defines a set of contiguous values.

Links

 * Symbolic Logic:Programming
 * Intelligence and Reasoning