|
1 | 1 | grammata
|
2 | 2 | ========
|
3 | 3 |
|
4 |
| -**grammata** is a simple script language interpreted and run as a monadic structure. |
5 |
| -In future it will support polyparadigmatic features such as functional expressions and logical knowledge bases and queries to use them. |
| 4 | +**grammata** is a simple script language interpreted and run on a monadic virtual machine. |
| 5 | +It supports polyparadigmatic features such as |
| 6 | + * imperative procedures and functions |
| 7 | + * functional expressions |
| 8 | + * logical knowledge bases and queries to use them |
6 | 9 |
|
7 | 10 | Syntax
|
8 | 11 | ------
|
9 | 12 |
|
10 |
| -Every *program* has the stucture `program { <DECLARAION>* <STATEMENT>* }`, |
11 |
| -whereas |
12 |
| -* **`DECLARATION`** is |
13 |
| - * an uninitialized variable `var <ID>;`. |
14 |
| - * a number initialized variable `var <ID> := <NUMBER>;`. |
15 |
| - * a function initialized variable `var <ID> := func ( <PARAM>* ) { <DECLARATION>* <STATEMENT>* };`. |
16 |
| - |
17 |
| -* **`STATEMENT`** is |
18 |
| - * an assignment `<ID> := <NUMBER>;` |
19 |
| - * a for loop `for( <COUNTER> ; <END> ; <STEP> ) { <STATEMENT>* }`, whereas |
20 |
| - * **`COUNTER`** is the `ID` of the counter variable. |
21 |
| - * the value of the `EXPRESSION` **`END`** must be less (if `STEP` < 0) or greater (if `STEP` >= 0) than `COUNTER` to continue the loop. |
22 |
| - * the value of the `EXPRESSION` **`STEP`** is added to the counter variable after every iteration. |
23 |
| - * a while loop `while ( <COND> ) { <STATEMENT>* };` runs till the `EXPRESSION` `COND` is less then 0. |
24 |
| - * a do while loop `do { <STATEMENT>* } while ( <COND> );` runs till the `EXPRESSION` `COND` is less then 0. The body will be executed at least once. |
25 |
| - * a one armed if `if ( <COND> ) then { <STATEMENT>* };`. The then block will be executed if the `EXPRESSION` `COND` is greater or equal to 0. |
26 |
| - * a two armed if `if ( <COND> ) then { <STATEMENT>* } else { <STATEMENT>* };`. The then block will be executed if the `EXPRESSION` `COND` is greater or equal to 0, the else block otherwise. |
27 |
| - * a return `return <TORETURN>`, which will either print the result of the program or return a value to the calling function; however, the value of the `EXPRESSION` `TORETURN` is returned. |
28 |
| -* **`ID`** is an identifier beginning with a lower or uppercase letter and consisting of lower and uppercase letters and ciphers. |
29 |
| -* **`NUMBER`** is a number literal, consisting of two blocks of ciphers seprated by a `.` (`123.456`) or one block of ciphers (`123`). |
30 |
| -* a **`PARAM`** has the form `var <ID>` separated by `,`. |
31 |
| -* an **`EXPRESSION`** is |
32 |
| - * an identifiers `ID`. |
33 |
| - * a constants `NUMBER`. |
34 |
| - * a binary operations `<EXPRESSION> ° <EXPRESSION>` whereas `°` is |
35 |
| - * an addition `+`. |
36 |
| - * a subtraction `-`. |
37 |
| - * a multiplication `*`. |
38 |
| - * a division `/`. |
39 |
| - * an integer division `div`. |
40 |
| - * a modulo operation `%` (returns integer values). |
41 |
| - * a comparisons `<`, `>`, `<=`, `>=`, `==` and `!=` which yield `0` if as `false` and `1` as `true`. |
42 |
| - * a logical and `&&`. |
43 |
| - * a logical or `||`. |
44 |
| - * a unary |
45 |
| - * `- <EXPRESSION>`. |
46 |
| - * `not <EXPRESSION>`. |
47 |
| - * a function applications `<ID>( <ARG>* )` whereas `ARG` is an `EXPRESSION`. |
48 |
| - |
49 |
| -`<PARAM>*` and `<ARG>*` are separated by `,`. |
50 |
| - |
51 |
| -Comments are |
52 |
| -* single line comments initialized with `##`. |
53 |
| -* multi line comments surrounded by `# ... #`. |
| 13 | +### Grammata Programs |
| 14 | +``` |
| 15 | +PROGRAM ::= program {A..Z}{a..z|A..Z|0..9} { with DECL* }? begin SUBPRG+ end |
| 16 | +DECL ::= var IDENT { := EXPRESSION }? ; |
| 17 | +IDENT ::= {a..z}{ 0..9 | A..Z | a..z }* |
| 18 | +SUBPRG ::= FUNCTIONAL |
| 19 | + | IMPERATIVE |
| 20 | + | QUERY |
| 21 | + | BASE |
| 22 | +``` |
| 23 | +### General arithmetical expressions |
| 24 | +``` |
| 25 | +EXPRESSION ::= DISJ { || DISJ}* |
| 26 | +DISJ ::= CONJ { && CONJ}* |
| 27 | +CONJ ::= COMP {{ == | != | <= | >= | < | > } COMP}* |
| 28 | +COMP ::= SUM {{ + | - } SUM}* |
| 29 | +SUM ::= FAC {{ * | / } FAC}* |
| 30 | +FAC ::= ( EXPRESSION ) |
| 31 | + | { - | ! } EXPRESSION |
| 32 | + | IDENT{(EXPRESSION { , EXPRESSION}*)}? |
| 33 | + | PARAM_VALUE |
| 34 | +``` |
| 35 | +### Functional |
| 36 | +``` |
| 37 | +FUNCTIONAL ::= lambda IDENT ( IDENT* ) is LAMBDA end |
| 38 | +LAMBDA ::= ARITH ARITH* |
| 39 | +ARITH ::= DISJ {|| DISJ}* |
| 40 | +DISJ ::= KONJ {&& KONJ}* |
| 41 | +KONJ ::= COMP {{ == | != | <= | >= | < | > } COMP}* |
| 42 | +COMP ::= SUM {{+ | -} SUM}* |
| 43 | +SUM ::= SIMPLE {{ * | / } SIMPLE}* |
| 44 | +SIMPLE ::= \ LOG+ . LAMBDA |
| 45 | + | if LAMBDA then LAMBDA else LAMBDA end |
| 46 | + | let DEF* in LAMBDA end |
| 47 | + | ( LAMBDA ) |
| 48 | + | LOG |
| 49 | + | VALUE |
| 50 | + | IDENT[( LAMBDA [, LAMBDA]* )] |
| 51 | +DEF ::= LOG := LAMBDA ; |
| 52 | +LOG ::= $IDENT |
| 53 | +``` |
| 54 | +### Imperative |
| 55 | +``` |
| 56 | +IMPERATIVE ::= { func | proc } IDENT ( {IDENT { , IDENT }*}? ) { with DECL+ }? does STMT* end |
| 57 | +STMT ::= for IDENT { from EXPRESSION }? to EXPRESSION { in EXPRESSION }? do STMT* end |
| 58 | + | while EXPRESSION to STMT* end |
| 59 | + | do STMT* while EXPRESSION end |
| 60 | + | if EXPRESSION then STMT* else STMT* end |
| 61 | + | call IDENT({ EXPRESSION { , EXPRESSION }*}?) ; |
| 62 | + | IDENT := EXPRESSION ; |
| 63 | + | return EXPRESSION ; |
| 64 | + | exit ; |
| 65 | + | backtrack ; |
| 66 | +``` |
| 67 | +### Logical |
| 68 | +``` |
| 69 | +QUERY ::= query ( { IDENT { , IDENT}*}? ) { asks IDENT* } { for IDENT } ?- CLAUSE end |
| 70 | +CLAUSE ::= DISJ { ; DISJ}* |
| 71 | +DISJ ::= CONJ { , CONJ}* |
| 72 | +CONJ ::= - CLAUSE |
| 73 | + | ( CLAUSE ) |
| 74 | + | GOAL |
| 75 | +GOAL ::= TERM :=: TERM |
| 76 | + | IDENT{( TERM { , TERM }*)}? |
| 77 | +TERM ::= VALUE |
| 78 | + | {A..Z}{a..z|A..Z|0..9}* |
| 79 | + | EXPRESSION |
| 80 | +BASE ::= base IDENT says RULE+ end |
| 81 | +RULE ::= GOAL { :- CLAUSE}? . |
| 82 | +``` |
54 | 83 |
|
55 | 84 | Examples
|
56 | 85 | --------
|
|
0 commit comments