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.
Contents |
[edit] 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
[edit] Features
[edit] Summary of Language Features
Feature | Example | Reserved words |
---|---|---|
Scoping | scope { } | scope |
Classes | class Shape { } | class |
Value Sets | unique and multiple data type qualifiers | unique, multiple |
Demand driven evaluation | in out data type modifiers | in, out |
Roles | role parameter modifier | role, as |
Renaming inheritance | inherit Attribute as Name | inherit, as |
Function renaming | T Get() rename as Get% | rename, as |
Name sharing (value combination) | String GetAttributeNames() combine CommaCombine | combine |
Pointer inheritance (proxy classes) | CtrlTrade inherit proxy Trade | proxy |
Dynamic inheritance | CtrlTrade inherit dynamic Trade | dynamic |
Ranges and mappings | long[1..5] | |
Generics and type parameters | Sort(class T : Vector, class O : Order) | class |
services | service class IdGenerator { mutable long m_id; muted Id CreateId()} | service, mutable, muted |
Returning the result | result = 5 * 6 | result, return |
[edit] Precedence Grammar
[edit] Language Definition
A program is a statement.
<program> ::= <statement list>
[edit] 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.
<statement list> ::= <boolean expression list>
[edit] 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.
<expression> ::= <boolean expression> <expression> ::= <arithmetic expression> <expression> ::= <simple expression> <expression> ::= <type expression>
[edit] 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
The syntax is,
<boolean expression list> ::= <boolean expression> | <boolean expression> ";" <boolean expression list> <boolean expression> ::= <boolean term> | <boolean term> ("and" | "&&") <boolean expression> <boolean term> ::= <boolean factor> | <boolean term> ("or" | "||") <boolean term> <boolean factor> ::= <boolean constant> | <factor> | <block expression> | <Comparison Expression> | <declaration>
A boolean variable path must identify a variable symbol of type bool. A boolean function call must have a return type of bool.
[edit] Arithmetic Expression
A arithmetic expression is an expression that evaluates to a number or a class that implements the standard functions associated with operators,
Operator | Function name | Type |
---|---|---|
+ | add | (any, any) -> any |
- | minus | (any, any) -> any |
* | multiply | (any, any) -> any |
/ | divide | (any, any) -> any |
** | power | (any, any) -> any |
++ | inc | (any) -> any |
-- | dec | (any) -> any |
- binary operators +, -, *, /, **
- unary operators ++, --
- bracketed arithmetic expression.
- function call
- declaration
The syntax is,
<arithmetic expression> ::= <arithmetic term> | <arithmetic term> ("+" | "-") <arithmetic expression> <arithmetic term> ::= <arithmetic power> | <arithmetic term> ("*" | "/") <arithmetic term> <arithmetic power> ::= <arithmetic factor> | <arithmetic factor> ("**") <arithmetic power> <arithmetic factor> ::= <factor> | <arithmetic constant> <factor> ::= <variable path> | <function call> | <bracketed boolean expression> <arithmetic constant> ::= <number> | <boolean variable path> ::= <variable path> <boolean function call> ::= <function call> <bracketed boolean expression> ::= "(" <boolean expression> ")" <compound boolean expression> ::= "{" <boolean expression list> "}"
A boolean variable path must identify a variable symbol of type bool. A boolean function call must have a return type of bool.
[edit] Simple Expression
<simple expression> ::= <factor> | <string constant>
[edit] Factor
<factor> ::= <variable path> | <function call> | <bracketed boolean expression> <function call> ::= <variable path> "(" <actual parameter list> ")" <function call> ::= <variable path> "[" <actual parameter list> "]" <bracketed boolean expression> ::= "(" <boolean expression> ")"
[edit] 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
<comparison expression> ::= <expression> "=" <expression> | <ordered comparison expression> <ordered comparison expression> ::= <arithmetic expression> ("<"|">"|"<="|"=>") <arithmetic expression>
[edit] 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.
<variable path> ::= <variable name> | <variable name> "." <variable path> <variable name> ::= (<alpha> | "_") <variable name extension> <variable name extension> ::= | (<alpha> | "_" | <digit>) <variable name extension>
[edit] 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.
<block expression> ::= "{" <boolean expression list> "}"
[edit] 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
[edit] Pascal Style Declaration
A pascal declaration associates a name with a type expression.
<pascal style declaration> ::= <variable name list> ":" <type expression> <default definition> <default definition> ::= | "=" <expression> <variable name list> ::= <variable name> | <varable name> "," <variable name list>
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
[edit] Type expression
<type expression> ::= <function type> <type expression> ::= <class type> <type expression> ::= <mapping type> <type expression> ::= <set type> <type expression> ::= <enum type> <type expression> ::= <range type> <type expression> ::= <symple type> <type expression> ::= <type variable path> <type variable path> ::= <variable path>
[edit] 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.
<function signature> ::= <variable path> "(" <paramater list> ")" "->" <type expression> <function signature> ::= "function" <variable path> "(" <paramater list> ")" ":" <type expression> <function declaration> ::= <function forward type> <function body> <function body> ::= <block expression> | "{" <expression> "}"
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,
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,
[edit] Class Type
A class is a mathematical set, viewed as the properties of its elements.
<class forward type> ::= "class" <variable path> "(" <paramater list> ")" <class type> ::= <class forward type> <compound boolean expression>
[edit] 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
<mapping type> ::= <variable path> "[" <paramater list> "]" "->" <type expression> <mapping type> ::= "mapping" <variable path> "[" <paramater list> "]" ":" <type expression>
[edit] Set Type
<class forward declaration> ::= "set" <variable path> "(" <paramater list> ")"
[edit] Enum Type
An enum defines a set of constant values.
<enum declaration> ::= "enum" "{" <enum constant list> "}" <enum constant list> ::= <enum constant> | <enum constant> "," <enum constant list> <enum constant> ::= <name> | <name> "=" <signed integer>
[edit] Range Type
A range defines a set of contiguous values.
<range declaration> ::= <enum constant> ".." <enum constant> <range declaration> ::= <signed integer> ".." <signed integer>
[edit] Simple Type
<simple type> ::= "bool" | "int" | "integer" | "double" | "string" | "type"
</source>
Type | Description | Values |
---|---|---|
bool | Boolean/logical value | true, false |
int | Signed integer up to machine defined word limit 32/64/128 bit | 0, 1, -1, ... 2147483647, -2147483647 |
integer | Unlimited size signed integer | 0, 1, -1, 2, -2, ... |
double | Signed double precision floating point number | E.g 3.141592653. |
string | String of characters | E.g. "This is a string" |
type | A value describing a type | E.g. [int] -> int |
[edit] C style Declaration
[edit] Constant
[edit] Boolean Constant
<boolean constant> ::= "true" | "false"
[edit] Integer Constant
<scientific number> ::= <unsigned integer> | "-" <unsigned integer> <unsigned integer> ::= <digit> | <digit> <unsigned integer> <digit> :: "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
[edit] Real Constant
<fixed point> ::= <integer> | <integer> "." <unsigned integer> <integer> ::= <integer> | <fixed point> ("e" | "E") <integer>
[edit] String Constant
<string constant> ::= <quote> <char list> <quote> <char list> ::= | <char> <char list> <char> ::= <char other than quote> | "\" <quote> | "\n" | "\\"