Мельница данных   (23.09.2017)
Формальная грамматика
Goal: MethodBody | Expression;

MethodBody: [ConstantDeclaration] [VariableDeclaration] CompoundStatement ";";

ConstantDeclaration: "const" Ident ":" DomainSpecification ";" 
  [{Ident ":" DomainSpecification ";"}];

VariableDeclaration: "var" DomainDefinition [{DomainDefinition}];

DomainDefinition: Ident ":" DomainSpecification ";";

DomainSpecification: IntegerDomainDefinition
  | StringDomainDefinition
  | FloatDomainDefinition
  | DateDomainDefinition
  | TimeDomainDefinition
  | DateTimeDomainDefinition
  | BooleanDomainDefinition
  | BlobDomainDefinition
  | EnumerationDomainDefinition
  | Ident;

IntegerDomainDefinition: "integer";
StringDomainDefinition: "string" "[" Number "]";
FloatDomainDefinition: "float" ["(" Number ["." Number] ")"];
DateDomainDefinition: "date";
TimeDomainDefinition: "time";
DateTimeDomainDefinition: "datetime";
BooleanDomainDefinition: "boolean";
BlobDomainDefinition: "blob" | "clob";
EnumerationDomainDefinition: "(" Ident {"," Ident} ")";

CompoundStatement: "begin" Statement [{";" Statement}] "end";

Statement:
  | CompoundStatement
  | AssignmentStatement
  | InheritedStatement
  | CallStatement
  | IfStatement
  | CaseStatement
  | ForStatement
  | WhileStatement
  | RepeatStatement
  | TryFinallyStatement
  | TryExceptStatement
  | RaiseStatement
  | ForEachStatement
  | ExitStatement;

AssignmentStatement:  Qualifier ":=" Expression;

CallStatement: Qualifier;

InheritedStatement: "inherited";

IfStatement: "if" Expression "then" Statement ["else" Statement];

CaseStatement: "case" Expression "of" {CaseBranch} ["else" Statement ";"] "end";

CaseBranch: CaseLabel [{',' CaseLabel}] ":" Statement ";";

CaseLabel: Number | Ident;

ForStatement: "for" Ident ":=" Expression ("to"|"downto") 
  Expression "do" Statement;

WhileStatement: "while" Expression "do" Statement;

RepeatStatement: "repeat" Statement [{";" Statement}] "until" Expression;

TryFinallyStatement: "try" Statement [{";" Statement}] "finally" 
  Statement [{";" Statement}] "end";

TryExceptStatement: "try" Statement [{";" Statement}] "except" 
  Statement [{";" Statement}] "end";

RaiseStatement: "raise" [Expression];

ForEachStatement: "for" "each" Ident "of" Ident ["with" Expression] 
  ["by" Expression] "do" Statement;

ExitStatement: "exit";

Expression: ComparedExpression [{RelationOperation Expression}];

ComparedExpression: Addon [{AdditionOperaton ComparedExpression}];

Addon: Factor [{MultiplicativeOperation Addon}];

Factor: "(" Expression ")"
  | "not" Expression
  | Number ["." Number]
  | StringConstant
  | Qualifier
  | "nil"
  | "True"
  | "False"
  | "(" Expression "is" Ident ")"
  | "any" Aggregate
  | "count" Aggregate
  | "sum" Aggregate
  | "max" Aggregate
  | "min" Aggregate;

Aggregate: "(" Ident ["." Ident] ["with" Expression] ")";

Qualifier: QualifierPart [{"." QualifierPart}];

QualifierPart: Ident ["(" Expression [{", " Expression}] ")"]
  | "self"
  | "(" Qualifier "as" Ident ")";

RelationOperation: "<"
  | ">"
  | "<="
  | ">="
  | "="
  | "<>";

AdditionOperaton: "+"
  | "-"
  | "or";

MultiplicativeOperation: "*"
  | "/"
  | "div"
  | "and";