platypus/PLATYPUS Grammar Specificat...

275 lines
6.7 KiB
Markdown
Raw Permalink Normal View History

2017-02-10 20:47:24 +00:00
# PLATYPUS Language Specification
2017-02-10 21:29:07 +00:00
## 2. Lexical Specification (INCOMPLETE)
2017-02-10 20:47:24 +00:00
2017-02-23 00:10:15 +00:00
## NOTE:
**This is incomplete, I am simply writing this down and will fix it as I read along the informal language specification provided to me
This does not follow standard BNF/EBNF syntax, I will rewrite it once I get all the definitions correct and complete.**
2017-02-10 20:47:24 +00:00
2017-02-10 21:29:07 +00:00
### 2.1 Input Elements and Tokens
``` bnf
<input character> ::=
2017-02-10 21:33:41 +00:00
ASCII characters but not SEOF
2017-02-10 20:47:24 +00:00
<input> ::=
2017-02-10 21:33:41 +00:00
<input elements> SEOF
2017-02-10 20:47:24 +00:00
<input elements> ::=
2017-02-10 21:33:41 +00:00
<input element> | <input elements> <input element>
2017-02-10 20:47:24 +00:00
<token> ::=
2017-02-10 21:33:41 +00:00
<variable identifier> | <keyword> | <floating-point literal>
| <integer literal> | <string literal> | <separator> | <operator>
2017-02-10 20:47:24 +00:00
```
2017-02-10 21:29:07 +00:00
### 2.2 White Space
2017-03-13 17:02:25 +00:00
``` bnf
<white space> ::=
2017-02-10 21:33:41 +00:00
ASCII SP character (space)
| ASCII HT character (horizontal tab)
| ASCII VT character (vertical tab)
| ASCII FF character (form feed)
| <line terminator>
<line terminator> ::=
2017-02-10 21:33:41 +00:00
CR | LF | CR LF
2017-02-10 20:47:24 +00:00
```
2017-02-10 21:29:07 +00:00
### 2.3 Comments
2017-03-13 17:02:25 +00:00
``` bnf
<comment> ::=
2017-02-10 21:33:41 +00:00
!< <opt_characters in line> <line terminator>
2017-02-10 20:47:24 +00:00
<characters in line> ::=
2017-02-10 21:33:41 +00:00
<comment character> | <characters in line> <comment character>
2017-02-10 20:47:24 +00:00
<comment character> ::=
2017-02-10 21:33:41 +00:00
<input character> but not <line terminator>
2017-02-10 20:47:24 +00:00
```
2017-02-10 21:29:07 +00:00
### 2.4 Variable Identifiers
2017-03-13 17:02:25 +00:00
``` bnf
<variable identifier> ::=
2017-02-10 21:33:41 +00:00
<arithmetic variable identifier> | <string variable identifier>
<arithmetic identifier> ::=
2017-02-10 21:33:41 +00:00
<letter> <opt_letters or digits>
2017-02-10 20:47:24 +00:00
<opt_letters or digits> ::=
ε | <letters or digits>
<letters or digits> ::=
2017-02-10 21:33:41 +00:00
<letter or digit> | <letters or digits> <letter or digit>
2017-02-10 20:47:24 +00:00
2017-03-13 23:14:01 +00:00
<letter> ::=
[a-z] | [A-Z]
2017-02-10 20:47:24 +00:00
2017-03-13 23:14:01 +00:00
<letter or digit> ::=
<letter> | <digit>
2017-02-10 20:47:24 +00:00
<string variable identifier> ::=
2017-02-10 21:33:41 +00:00
<arithmetic variable identifier>#
2017-02-10 20:47:24 +00:00
```
2017-02-10 21:29:07 +00:00
### 2.5 Keywords
2017-03-13 17:02:25 +00:00
``` bnf
<keyword> ::=
2017-02-10 21:33:41 +00:00
PLATYPUS | IF | THEN | ELSE | USING | REPEAT | INPUT | OUTPUT
2017-02-10 20:47:24 +00:00
```
2017-02-10 21:29:07 +00:00
### 2.6 Integer Literals
2017-03-13 17:02:25 +00:00
``` bnf
<integer literal> ::=
2017-02-10 21:33:41 +00:00
<decimal integer literal> | <octal integer literal>
<decimal integer literal> ::=
2017-02-10 21:33:41 +00:00
0 | <non-zero digit> <opt_digits>
<opt_digits> ::=
ε | <digits>
<digits> ::=
2017-02-10 21:33:41 +00:00
<digit> | <digits> <digit>
2017-02-10 20:47:24 +00:00
<digit> ::=
2017-02-10 21:33:41 +00:00
0 | <non-zero digit>
2017-02-10 20:47:24 +00:00
<non-zero digit> ::= one of
2017-02-21 20:08:32 +00:00
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
2017-02-10 20:47:24 +00:00
<octal integer literal> ::=
2017-02-10 21:33:41 +00:00
0 <octal digit> <octal digits>
<octal digit> ::=
2017-02-10 21:33:41 +00:00
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7
<octal digits> ::=
2017-02-10 21:33:41 +00:00
<octal digit> | <octal digits> <octal digit>
2017-02-10 20:47:24 +00:00
2017-02-10 21:29:07 +00:00
```
### 2.7 Floating-point Literals
2017-03-13 17:02:25 +00:00
``` bnf
<floating-point literal> ::=
2017-02-10 21:33:41 +00:00
<decimal integer literal> . <opt_digits>
2017-02-10 21:29:07 +00:00
```
### 2.8 String Literals
2017-03-13 17:02:25 +00:00
``` bnf
<opt_string literal> ::=
ε | <string literal>
2017-03-13 17:02:25 +00:00
<string literal> ::=
2017-02-10 21:33:41 +00:00
"<opt_string characters>"
2017-02-10 21:29:07 +00:00
<opt_string characters> ::=
ε | <string characters>
<string characters> ::=
2017-02-10 21:33:41 +00:00
<input character> | <string characters> <input character>
2017-02-10 21:29:07 +00:00
```
### 2.9 Separators
2017-03-13 17:02:25 +00:00
``` bnf
<separator> ::=
2017-02-21 20:08:32 +00:00
( | ) | { | } | , | ; | " |.
2017-02-10 21:29:07 +00:00
```
### 2.10 Operators
2017-03-13 17:02:25 +00:00
``` bnf
<operator> ::=
2017-02-10 21:33:41 +00:00
<arithmetic operator> | <string concatenation operator>
| <relational operator> | <logical operator>
| <assignment operator>
<arithmetic operator> ::=
2017-02-21 20:08:32 +00:00
+ | - | * | /
2017-02-10 21:29:07 +00:00
<string concatenation operator> ::=
2017-02-21 19:46:11 +00:00
<<
<relational operator> ::=
2017-02-21 20:08:32 +00:00
> | < | == | <>
2017-02-10 21:29:07 +00:00
<logical operator> ::=
2017-02-10 21:33:41 +00:00
.AND. | .OR.
<assignment operator> ::=
2017-02-10 21:33:41 +00:00
=
2017-02-10 21:29:07 +00:00
```
2017-02-23 00:10:15 +00:00
## 3. The PLATYPUS Syntactic Specification
2017-02-10 21:29:07 +00:00
### 3.1 PLATYPUS Program
2017-03-13 17:02:25 +00:00
``` bnf
<program> ::=
2017-02-10 21:33:41 +00:00
PLATYPUS {<opt_statements>} SEOF
<opt_statements> ::=
ε | <statements>
<statements> ::=
2017-02-10 21:33:41 +00:00
<statement> | <statements> <statement>
2017-02-10 21:29:07 +00:00
```
### 3.2 Statements
2017-03-13 17:02:25 +00:00
``` bnf
<statement> ::=
2017-02-10 21:33:41 +00:00
<assignment statement>
| <selection statement>
| <iteration statement>
| <input statement>
| <output statement>
2017-02-10 21:29:07 +00:00
```
### 3.3 Assignment Statement
2017-03-13 17:02:25 +00:00
``` bnf
<assignment statement> ::=
2017-02-23 00:18:48 +00:00
<assignment expression> ;
2017-02-10 21:29:07 +00:00
<assignment expression> ::=
2017-02-23 00:10:15 +00:00
<arithmetic variable identifier> = <arithmetic expression>
| <string variable identifier> = <string expression>
2017-02-10 21:29:07 +00:00
```
#### 3.2.2 Selection Statement (`if` statement)
2017-03-13 17:02:25 +00:00
``` bnf
<selection statement> ::=
2017-02-21 18:48:10 +00:00
IF (<conditional expression>) THEN <opt_statements>
2017-02-10 21:33:41 +00:00
ELSE {<opt_statements>};
2017-02-10 21:29:07 +00:00
```
#### 3.2.3 Iteration Statement (the loop statement)
2017-03-13 17:02:25 +00:00
``` bnf
<iteration statement> ::=
2017-02-21 18:48:10 +00:00
USING (<assignment expression> , <conditional expression>, <assignment expression>) REPEAT { <opt_statements> };
2017-02-10 21:29:07 +00:00
```
#### 3.2.4 Input Statement
2017-03-13 17:02:25 +00:00
``` bnf
<input statement> ::=
2017-02-10 21:33:41 +00:00
INPUT (<variable list>);
<opt_variable list> ::=
ε | <variable list>
<variable list> ::=
2017-02-10 21:33:41 +00:00
<variable identifier> | <variable list>,<variable identifier>
2017-02-10 21:29:07 +00:00
```
#### 3.2.5 Output Statement
2017-03-13 17:02:25 +00:00
``` bnf
<output statement> ::=
2017-02-21 18:48:10 +00:00
OUTPUT(<opt_variable list> | <opt_string literal>);
2017-02-10 21:29:07 +00:00
```
### 3.3 Expressions
#### 3.3.1 Arithmetic Expressions
2017-03-13 17:02:25 +00:00
``` bnf
<arithmetic expression> ::=
2017-02-10 21:33:41 +00:00
<unary arithmetic expression>
| <additive arithmetic expression>
<unary arithmetic expression> ::=
2017-02-10 21:33:41 +00:00
- <primary arithmetic expression>
| + <primary arithmetic expression
<additive arithmetic expression> ::=
2017-02-10 21:33:41 +00:00
<additive arithmetic expression> + <multiplicative arithmetic expression>
| <additive arithmetic expression> - <multiplicative arithmetic expression>
| <multiplicative arithmetic expression>
<multiplicative arithmetic expression> ::=
2017-02-10 21:33:41 +00:00
<multiplicative arithmetic expression> * <primary arithmetic expression>
| <multiplicative arithmetic expression> / <primary arithmetic expression>
| <primary arithmetic expression>
<primary arithmetic expression> ::=
2017-02-10 21:33:41 +00:00
<variable identifier>
| <floating-point literal>
| <integer literal>
| (<arithmetic expression>)
2017-02-10 21:29:07 +00:00
```
#### 3.3.2 String Expression
2017-03-13 17:02:25 +00:00
``` bnf
<string expression> ::=
2017-02-10 21:33:41 +00:00
<primary string expression>
| <string expression> << <primary string expression>
2017-02-10 21:29:07 +00:00
<primary string expression> ::=
2017-02-10 21:33:41 +00:00
<string variable identifier>
| <string literal>
2017-02-10 21:29:07 +00:00
```
#### 3.3.3 Conditional Expression
2017-03-13 17:02:25 +00:00
``` bnf
2017-02-23 00:18:48 +00:00
// BNF from C specification adapted to PLATYPUS
// source: https://cs.wmich.edu/~gupta/teaching/cs4850/sumII06/The%20syntax%20of%20C%20in%20Backus-Naur%20form.htm
<conditional expression> ::=
<logical OR expression>
<logical OR expression> ::=
<logical AND expression>
2017-02-23 00:10:15 +00:00
| <logical OR expression> .OR. <logical AND expression>
<logical AND expression> ::=
2017-02-21 19:29:51 +00:00
<relational expression>
| <logical AND expression> .AND. <relational expression>
// END BNF from C specification
2017-02-10 21:29:07 +00:00
```
#### 3.3.4 Relational Expression
2017-03-13 17:02:25 +00:00
``` bnf
<relational expression> ::=
<primary a_relational expression> <relational operator> <primary a_relational expression>
| <primary s_relational expression> <relational operator> <primary s_relational expression>
2017-02-10 21:33:41 +00:00
<primary a_relational expression> ::=
2017-02-10 21:33:41 +00:00
<floating-point literal>
| <integer literal>
| <variable identifier>
<primary s_relational expression> ::=
2017-02-23 00:10:15 +00:00
<string literal>
| <string variable identifier>
2017-02-10 21:29:07 +00:00
```