Version 27 (modified by archibald, 8 years ago) (diff)

--

(1) Namespaces

(1.1) Data Types

(2) Types

(3) Enums

(4) Signals

(5) Singletons

(6) Classes

(7) Expression Syntax

This is just an area in which I'm exploring a simple expression syntax ...
I hope to determine which logic for expression is simply lexical, which goes in grammar, which in type system / checking. Add to this ideas of lexical hints, syntax hints, type hints and better error recovery etc etc etc

Here's an example of a simple syntax

operators := ( "+" | "-" | "*" | "/" | "%" | ":=" );
expression := 
  ( identifier
  | constant
  | operator /* monadic */ expression 
      ( operator /* diadic */ expression )
  | "(" expression ")"
  );

The above syntax should let you have any operator as either monadic or diadic ... and has no implicit precedence (ie the brackets are required to produce the precedence)

This doesn't take into account whether an identifer is or isn't mutable ... and takes no account of contants not being mutable.

What does all this this mean?

Well if we don't mind having expressions like

3 := fred + (2 * -15) + *thing

Then it's accepable.

Some improvement

OK, well if we sp;it the operators into monadic, diadic or both then hat might help things somewhat.

infixMonadics := ( "-" | "!" | "++" | "--" );

infixDiadics := ( "+" | "-" | "*" | "/" | "%" | ":=" | "==" );

infixTriadic := "?";

postfixMonadics := ( "++" | "--" );

typename := lexicalIdent [nameSpaceEnvironmentTypeCheck(LEX)];

bracedMonadic :=
  "«" typename "»"; // CASTING

expression := 
  ( identifier
  | constant
  | ( infixMonadics expression
    | bracedMonadic "(" expression ")"
    | expression
    )
    ( postfixMonadics )
    ( ( inFixDiadics expression
      | infixTriadic expression ":" expression 
      | expression 
      ) )
  | "(" expression ")"
  );

which gives us the ability to specify a subset of monadic, diadic operators (infix notation) and a set of monadic braced expressions (apparently single parameter functions).

This would show up the following errors in the syntax and not in the type checking

freddy / * burt // ERROR at *, as * is not a monadic infix operator
arthur := «bool»(tom == 21) ? 1*2*dick : harry  // and triadics

This assumes that each data element ( variable/attribute ) has a number of descriptive values that can be compared ( to determine applicability ) to an operation.

  • identifier the name
  • type the type it represents
  • organisation the overlying set organisation
  • mutability whether the value can be modified or not

eg ... fred has been declared as a part of the "fruitbat" namespace, it's an integer it's a solitary integer and is immutable with the value 3 thus :

  • variable (fruitbat:fred:int:single:imm:3)

so the "++" postfix operator will not be able to operate on it as it's immutable.

(7.1) What about identifiers (Expression Syntax) ?