platypus/PLATYPUS Grammar Specificat...

252 lines
5.9 KiB
Markdown
Raw 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
## NOTE: **This is incredibly incomplete and broken, I am simply writing this down and will fix it as I read along the informal language specification provided to me**
2017-02-10 21:29:07 +00:00
### 2.1 Input Elements and Tokens
2017-02-10 20:47:24 +00:00
```
2017-02-10 21:33:41 +00:00
<input character> ->
ASCII characters but not SEOF
2017-02-10 20:47:24 +00:00
2017-02-10 21:33:41 +00:00
<input> ->
<input elements> SEOF
2017-02-10 20:47:24 +00:00
2017-02-10 21:33:41 +00:00
<input elements> ->
<input element> | <input elements> <input element>
2017-02-10 20:47:24 +00:00
2017-02-10 21:33:41 +00:00
<token> ->
<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-02-10 20:47:24 +00:00
```
2017-02-10 21:33:41 +00:00
<white space> ->
ASCII SP character (space)
| ASCII HT character (horizontal tab)
| ASCII VT character (vertical tab)
| ASCII FF character (form feed)
| <line terminator>
<line terminator> ->
CR | LF | CR LF
2017-02-10 20:47:24 +00:00
```
2017-02-10 21:29:07 +00:00
### 2.3 Comments
2017-02-10 20:47:24 +00:00
```
2017-02-10 21:33:41 +00:00
<comment> ->
!< <opt_characters in line> <line terminator>
2017-02-10 20:47:24 +00:00
2017-02-10 21:33:41 +00:00
<characters in line> ->
<comment character> | <characters in line> <comment character>
2017-02-10 20:47:24 +00:00
2017-02-10 21:33:41 +00:00
<comment character> ->
<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-02-10 20:47:24 +00:00
```
2017-02-10 21:33:41 +00:00
<variable identifier> ->
<arithmetic variable identifier> | <string variable identifier>
<arithmetic identifier> ->
<letter> <opt_letters or digits>
2017-02-10 20:47:24 +00:00
2017-02-10 21:33:41 +00:00
<letters or digits> ->
<letter or digit> | <letters or digits> <letter or digit>
2017-02-10 20:47:24 +00:00
2017-02-10 21:33:41 +00:00
<letter> -> one of
[a-z][A-Z]
2017-02-10 20:47:24 +00:00
2017-02-10 21:33:41 +00:00
<letter or digit> -> one of
[a-z][A-Z][0-9]
2017-02-10 20:47:24 +00:00
2017-02-10 21:33:41 +00:00
<string variable identifier> ->
<arithmetic variable identifier>#
2017-02-10 20:47:24 +00:00
```
2017-02-10 21:29:07 +00:00
### 2.5 Keywords
2017-02-10 20:47:24 +00:00
```
2017-02-10 21:33:41 +00:00
<keyword> ->
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-02-10 20:47:24 +00:00
```
2017-02-10 21:33:41 +00:00
<integer literal> ->
<decimal integer literal> | <octal integer literal>
<decimal integer literal> ->
0 | <non-zero digit> <opt_digits>
<digits> ->
<digit> | <digits> <digit>
2017-02-10 20:47:24 +00:00
2017-02-10 21:33:41 +00:00
<digit> ->
0 | <non-zero digit>
2017-02-10 20:47:24 +00:00
2017-02-10 21:33:41 +00:00
<non-zero digit> -> one of
[1-9]
2017-02-10 20:47:24 +00:00
2017-02-10 21:33:41 +00:00
<octal integer literal> ->
0 <octal digit> <octal digits>
<octal digit> ->
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7
<octal digits> ->
<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-02-10 21:33:41 +00:00
<floating-point literal> ->
<decimal integer literal> . <opt_digits>
2017-02-10 21:29:07 +00:00
```
### 2.8 String Literals
```
2017-02-10 21:33:41 +00:00
<string literal> ->
"<opt_string characters>"
2017-02-10 21:29:07 +00:00
2017-02-10 21:33:41 +00:00
<string chacters> ->
<input character> | <string characters> <input character>
2017-02-10 21:29:07 +00:00
```
### 2.9 Separators
```
2017-02-10 21:33:41 +00:00
<separator> -> one of
( ) { } , ; " .
2017-02-10 21:29:07 +00:00
```
### 2.10 Operators
```
2017-02-10 21:33:41 +00:00
<operator> ->
<arithmetic operator> | <string concatenation operator>
| <relational operator> | <logical operator>
| <assignment operator>
<arithmetic operator> -> one of
+ - * /
2017-02-10 21:29:07 +00:00
2017-02-10 21:33:41 +00:00
<string concatenation operator> -> one of
> < == <>
2017-02-10 21:29:07 +00:00
2017-02-10 21:33:41 +00:00
<logical operator> ->
.AND. | .OR.
<assignment operator> ->
=
2017-02-10 21:29:07 +00:00
```
## 3. The PLATYPUS Syntatic Specification
### 3.1 PLATYPUS Program
```
2017-02-10 21:33:41 +00:00
<program> ->
PLATYPUS {<opt_statements>} SEOF
<statements> ->
<statement> | <statements> <statement>
2017-02-10 21:29:07 +00:00
```
### 3.2 Statements
```
2017-02-10 21:33:41 +00:00
<statement> ->
<assignment statement>
| <selection statement>
| <iteration statement>
| <input statement>
| <output statement>
2017-02-10 21:29:07 +00:00
```
### 3.3 Assignment Statement
```
2017-02-10 21:33:41 +00:00
<assignment statement> ->
<assignment expression>
2017-02-10 21:29:07 +00:00
2017-02-10 21:33:41 +00:00
<assignment expression> ->
AVID = <arithmetic expression>
| SVID = <string expression>
2017-02-10 21:29:07 +00:00
```
#### 3.2.2 Selection Statement (`if` statement)
```
2017-02-10 21:33:41 +00:00
<selection statement> ->
IF (<conditional expression>) THEN <statements>
ELSE {<opt_statements>};
2017-02-10 21:29:07 +00:00
```
#### 3.2.3 Iteration Statement (the loop statement)
```
2017-02-10 21:33:41 +00:00
<iteration statement> ->
<TBC>
2017-02-10 21:29:07 +00:00
```
#### 3.2.4 Input Statement
```
2017-02-10 21:33:41 +00:00
<input statement> ->
INPUT (<variable list>);
<variable list> ->
<variable identifier> | <variable list>,<variable identifier>
2017-02-10 21:29:07 +00:00
```
#### 3.2.5 Output Statement
```
2017-02-10 21:33:41 +00:00
<output statement> ->
<TBC>
2017-02-10 21:29:07 +00:00
```
### 3.3 Expressions
#### 3.3.1 Arithmetic Expressions
```
2017-02-10 21:33:41 +00:00
<arithmetic expression> ->
<unary arithmetic expression>
| <additive arithmetic expression>
<unary arithmetic expression> ->
- <primary arithmetic expression>
| + <primary arithmetic expression
<additive arithmetic expression> ->
<additive arithmetic expression> + <multiplicative arithmetic expression>
| <additive arithmetic expression> - <multiplicative arithmetic expression>
| <multiplicative arithmetic expression>
<multiplicative arithmetic expression> ->
<multiplicative arithmetic expression> * <primary arithmetic expression>
| <multiplicative arithmetic expression> / <primary arithmetic expression>
| <primary arithmetic expression>
<primary arithmetic expression> ->
<variable identifier>
| <floating-point literal>
| <integer literal>
| (<arithmetic expression>)
2017-02-10 21:29:07 +00:00
```
#### 3.3.2 String Expression
```
2017-02-10 21:33:41 +00:00
<string expression> ->
<primary string expression>
| <string expression> << <primary string expression>
2017-02-10 21:29:07 +00:00
2017-02-10 21:33:41 +00:00
<primary string expression> ->
<string variable identifier>
| <string literal>
2017-02-10 21:29:07 +00:00
```
#### 3.3.3 Conditional Expression
```
2017-02-10 21:33:41 +00:00
<conditional expression> ->
<logical OR expression>
2017-02-10 21:29:07 +00:00
2017-02-10 21:33:41 +00:00
<logical OR expression> ->
<TBC>
2017-02-10 21:29:07 +00:00
2017-02-10 21:33:41 +00:00
<logical AND expression> ->
<TBC>
2017-02-10 21:29:07 +00:00
```
#### 3.3.4 Relational Expression
```
2017-02-10 21:33:41 +00:00
<relational expression> ->
<primary a_relational expression> == <primary a_relational expression>
| <primary a_relational expression> <= <primary a_relational expression>
| <primary a_relational expression> > <primary a_relational expression>
| <primary a_relational expression> < <primary a_relational expression>
| <primary s_relational expression> == <primary s_relational expression>
| <primary s_relational expression> <= <primary s_relational expression>
| <primary s_relational expression> > <primary s_relational expression>
| <primary s_relational expression> < <primary s_relational expression>
<primary a_relational expression> ->
<floating-point literal>
| <integer literal>
| <variable identifier>
<primary s_relational expression> ->
<TBC>
2017-02-10 21:29:07 +00:00
```