Start converting UBNF (ugly BNF) into BNF
This commit is contained in:
parent
6b6d084096
commit
cd18b51176
|
@ -7,147 +7,147 @@
|
||||||
This does not follow standard BNF/EBNF syntax, I will rewrite it once I get all the definitions correct and complete.**
|
This does not follow standard BNF/EBNF syntax, I will rewrite it once I get all the definitions correct and complete.**
|
||||||
|
|
||||||
### 2.1 Input Elements and Tokens
|
### 2.1 Input Elements and Tokens
|
||||||
```
|
``` bnf
|
||||||
<input character> ->
|
<input character> ::=
|
||||||
ASCII characters but not SEOF
|
ASCII characters but not SEOF
|
||||||
|
|
||||||
<input> ->
|
<input> ::=
|
||||||
<input elements> SEOF
|
<input elements> SEOF
|
||||||
|
|
||||||
<input elements> ->
|
<input elements> ::=
|
||||||
<input element> | <input elements> <input element>
|
<input element> | <input elements> <input element>
|
||||||
|
|
||||||
<token> ->
|
<token> ::=
|
||||||
<variable identifier> | <keyword> | <floating-point literal>
|
<variable identifier> | <keyword> | <floating-point literal>
|
||||||
| <integer literal> | <string literal> | <separator> | <operator>
|
| <integer literal> | <string literal> | <separator> | <operator>
|
||||||
```
|
```
|
||||||
### 2.2 White Space
|
### 2.2 White Space
|
||||||
```
|
```
|
||||||
<white space> ->
|
<white space> ::=
|
||||||
ASCII SP character (space)
|
ASCII SP character (space)
|
||||||
| ASCII HT character (horizontal tab)
|
| ASCII HT character (horizontal tab)
|
||||||
| ASCII VT character (vertical tab)
|
| ASCII VT character (vertical tab)
|
||||||
| ASCII FF character (form feed)
|
| ASCII FF character (form feed)
|
||||||
| <line terminator>
|
| <line terminator>
|
||||||
|
|
||||||
<line terminator> ->
|
<line terminator> ::=
|
||||||
CR | LF | CR LF
|
CR | LF | CR LF
|
||||||
```
|
```
|
||||||
### 2.3 Comments
|
### 2.3 Comments
|
||||||
```
|
```
|
||||||
<comment> ->
|
<comment> ::=
|
||||||
!< <opt_characters in line> <line terminator>
|
!< <opt_characters in line> <line terminator>
|
||||||
|
|
||||||
<characters in line> ->
|
<characters in line> ::=
|
||||||
<comment character> | <characters in line> <comment character>
|
<comment character> | <characters in line> <comment character>
|
||||||
|
|
||||||
<comment character> ->
|
<comment character> ::=
|
||||||
<input character> but not <line terminator>
|
<input character> but not <line terminator>
|
||||||
```
|
```
|
||||||
### 2.4 Variable Identifiers
|
### 2.4 Variable Identifiers
|
||||||
```
|
```
|
||||||
<variable identifier> ->
|
<variable identifier> ::=
|
||||||
<arithmetic variable identifier> | <string variable identifier>
|
<arithmetic variable identifier> | <string variable identifier>
|
||||||
|
|
||||||
<arithmetic identifier> ->
|
<arithmetic identifier> ::=
|
||||||
<letter> <opt_letters or digits>
|
<letter> <opt_letters or digits>
|
||||||
|
|
||||||
<letters or digits> ->
|
<letters or digits> ::=
|
||||||
<letter or digit> | <letters or digits> <letter or digit>
|
<letter or digit> | <letters or digits> <letter or digit>
|
||||||
|
|
||||||
<letter> -> one of
|
<letter> ::= one of
|
||||||
[a-z][A-Z]
|
[a-z][A-Z]
|
||||||
|
|
||||||
<letter or digit> -> one of
|
<letter or digit> ::= one of
|
||||||
[a-z][A-Z][0-9]
|
[a-z][A-Z][0-9]
|
||||||
|
|
||||||
<string variable identifier> ->
|
<string variable identifier> ::=
|
||||||
<arithmetic variable identifier>#
|
<arithmetic variable identifier>#
|
||||||
```
|
```
|
||||||
### 2.5 Keywords
|
### 2.5 Keywords
|
||||||
```
|
```
|
||||||
<keyword> ->
|
<keyword> ::=
|
||||||
PLATYPUS | IF | THEN | ELSE | USING | REPEAT | INPUT | OUTPUT
|
PLATYPUS | IF | THEN | ELSE | USING | REPEAT | INPUT | OUTPUT
|
||||||
```
|
```
|
||||||
### 2.6 Integer Literals
|
### 2.6 Integer Literals
|
||||||
```
|
```
|
||||||
<integer literal> ->
|
<integer literal> ::=
|
||||||
<decimal integer literal> | <octal integer literal>
|
<decimal integer literal> | <octal integer literal>
|
||||||
|
|
||||||
<decimal integer literal> ->
|
<decimal integer literal> ::=
|
||||||
0 | <non-zero digit> <opt_digits>
|
0 | <non-zero digit> <opt_digits>
|
||||||
|
|
||||||
<digits> ->
|
<digits> ::=
|
||||||
<digit> | <digits> <digit>
|
<digit> | <digits> <digit>
|
||||||
|
|
||||||
<digit> ->
|
<digit> ::=
|
||||||
0 | <non-zero digit>
|
0 | <non-zero digit>
|
||||||
|
|
||||||
<non-zero digit> -> one of
|
<non-zero digit> ::= one of
|
||||||
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
|
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
|
||||||
|
|
||||||
<octal integer literal> ->
|
<octal integer literal> ::=
|
||||||
0 <octal digit> <octal digits>
|
0 <octal digit> <octal digits>
|
||||||
|
|
||||||
<octal digit> ->
|
<octal digit> ::=
|
||||||
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7
|
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7
|
||||||
|
|
||||||
<octal digits> ->
|
<octal digits> ::=
|
||||||
<octal digit> | <octal digits> <octal digit>
|
<octal digit> | <octal digits> <octal digit>
|
||||||
|
|
||||||
```
|
```
|
||||||
### 2.7 Floating-point Literals
|
### 2.7 Floating-point Literals
|
||||||
```
|
```
|
||||||
<floating-point literal> ->
|
<floating-point literal> ::=
|
||||||
<decimal integer literal> . <opt_digits>
|
<decimal integer literal> . <opt_digits>
|
||||||
```
|
```
|
||||||
### 2.8 String Literals
|
### 2.8 String Literals
|
||||||
```
|
```
|
||||||
<string literal> ->
|
<string literal> ::=
|
||||||
"<opt_string characters>"
|
"<opt_string characters>"
|
||||||
|
|
||||||
<string chacters> ->
|
<string chacters> ::=
|
||||||
<input character> | <string characters> <input character>
|
<input character> | <string characters> <input character>
|
||||||
```
|
```
|
||||||
### 2.9 Separators
|
### 2.9 Separators
|
||||||
```
|
```
|
||||||
<separator> ->
|
<separator> ::=
|
||||||
( | ) | { | } | , | ; | " |.
|
( | ) | { | } | , | ; | " |.
|
||||||
```
|
```
|
||||||
### 2.10 Operators
|
### 2.10 Operators
|
||||||
```
|
```
|
||||||
<operator> ->
|
<operator> ::=
|
||||||
<arithmetic operator> | <string concatenation operator>
|
<arithmetic operator> | <string concatenation operator>
|
||||||
| <relational operator> | <logical operator>
|
| <relational operator> | <logical operator>
|
||||||
| <assignment operator>
|
| <assignment operator>
|
||||||
|
|
||||||
<arithmetic operator> ->
|
<arithmetic operator> ::=
|
||||||
+ | - | * | /
|
+ | - | * | /
|
||||||
|
|
||||||
<string concatenation operator> ->
|
<string concatenation operator> ::=
|
||||||
<<
|
<<
|
||||||
|
|
||||||
<relational operator> ->
|
<relational operator> ::=
|
||||||
> | < | == | <>
|
> | < | == | <>
|
||||||
|
|
||||||
<logical operator> ->
|
<logical operator> ::=
|
||||||
.AND. | .OR.
|
.AND. | .OR.
|
||||||
|
|
||||||
<assignment operator> ->
|
<assignment operator> ::=
|
||||||
=
|
=
|
||||||
```
|
```
|
||||||
## 3. The PLATYPUS Syntactic Specification
|
## 3. The PLATYPUS Syntactic Specification
|
||||||
### 3.1 PLATYPUS Program
|
### 3.1 PLATYPUS Program
|
||||||
```
|
```
|
||||||
<program> ->
|
<program> ::=
|
||||||
PLATYPUS {<opt_statements>} SEOF
|
PLATYPUS {<opt_statements>} SEOF
|
||||||
|
|
||||||
<statements> ->
|
<statements> ::=
|
||||||
<statement> | <statements> <statement>
|
<statement> | <statements> <statement>
|
||||||
```
|
```
|
||||||
### 3.2 Statements
|
### 3.2 Statements
|
||||||
```
|
```
|
||||||
<statement> ->
|
<statement> ::=
|
||||||
<assignment statement>
|
<assignment statement>
|
||||||
| <selection statement>
|
| <selection statement>
|
||||||
| <iteration statement>
|
| <iteration statement>
|
||||||
|
@ -156,59 +156,59 @@ This does not follow standard BNF/EBNF syntax, I will rewrite it once I get all
|
||||||
```
|
```
|
||||||
### 3.3 Assignment Statement
|
### 3.3 Assignment Statement
|
||||||
```
|
```
|
||||||
<assignment statement> ->
|
<assignment statement> ::=
|
||||||
<assignment expression> ;
|
<assignment expression> ;
|
||||||
|
|
||||||
<assignment expression> ->
|
<assignment expression> ::=
|
||||||
<arithmetic variable identifier> = <arithmetic expression>
|
<arithmetic variable identifier> = <arithmetic expression>
|
||||||
| <string variable identifier> = <string expression>
|
| <string variable identifier> = <string expression>
|
||||||
```
|
```
|
||||||
#### 3.2.2 Selection Statement (`if` statement)
|
#### 3.2.2 Selection Statement (`if` statement)
|
||||||
```
|
```
|
||||||
<selection statement> ->
|
<selection statement> ::=
|
||||||
IF (<conditional expression>) THEN <opt_statements>
|
IF (<conditional expression>) THEN <opt_statements>
|
||||||
ELSE {<opt_statements>};
|
ELSE {<opt_statements>};
|
||||||
```
|
```
|
||||||
#### 3.2.3 Iteration Statement (the loop statement)
|
#### 3.2.3 Iteration Statement (the loop statement)
|
||||||
```
|
```
|
||||||
<iteration statement> ->
|
<iteration statement> ::=
|
||||||
USING (<assignment expression> , <conditional expression>, <assignment expression>) REPEAT { <opt_statements> };
|
USING (<assignment expression> , <conditional expression>, <assignment expression>) REPEAT { <opt_statements> };
|
||||||
```
|
```
|
||||||
#### 3.2.4 Input Statement
|
#### 3.2.4 Input Statement
|
||||||
```
|
```
|
||||||
<input statement> ->
|
<input statement> ::=
|
||||||
INPUT (<variable list>);
|
INPUT (<variable list>);
|
||||||
|
|
||||||
<variable list> ->
|
<variable list> ::=
|
||||||
<variable identifier> | <variable list>,<variable identifier>
|
<variable identifier> | <variable list>,<variable identifier>
|
||||||
```
|
```
|
||||||
#### 3.2.5 Output Statement
|
#### 3.2.5 Output Statement
|
||||||
```
|
```
|
||||||
<output statement> ->
|
<output statement> ::=
|
||||||
OUTPUT(<opt_variable list> | <opt_string literal>);
|
OUTPUT(<opt_variable list> | <opt_string literal>);
|
||||||
```
|
```
|
||||||
### 3.3 Expressions
|
### 3.3 Expressions
|
||||||
#### 3.3.1 Arithmetic Expressions
|
#### 3.3.1 Arithmetic Expressions
|
||||||
```
|
```
|
||||||
<arithmetic expression> ->
|
<arithmetic expression> ::=
|
||||||
<unary arithmetic expression>
|
<unary arithmetic expression>
|
||||||
| <additive arithmetic expression>
|
| <additive arithmetic expression>
|
||||||
|
|
||||||
<unary arithmetic expression> ->
|
<unary arithmetic expression> ::=
|
||||||
- <primary arithmetic expression>
|
- <primary arithmetic expression>
|
||||||
| + <primary arithmetic expression
|
| + <primary arithmetic expression
|
||||||
|
|
||||||
<additive arithmetic expression> ->
|
<additive arithmetic expression> ::=
|
||||||
<additive arithmetic expression> + <multiplicative arithmetic expression>
|
<additive arithmetic expression> + <multiplicative arithmetic expression>
|
||||||
| <additive arithmetic expression> - <multiplicative arithmetic expression>
|
| <additive arithmetic expression> - <multiplicative arithmetic expression>
|
||||||
| <multiplicative arithmetic expression>
|
| <multiplicative arithmetic expression>
|
||||||
|
|
||||||
<multiplicative arithmetic expression> ->
|
<multiplicative arithmetic expression> ::=
|
||||||
<multiplicative arithmetic expression> * <primary arithmetic expression>
|
<multiplicative arithmetic expression> * <primary arithmetic expression>
|
||||||
| <multiplicative arithmetic expression> / <primary arithmetic expression>
|
| <multiplicative arithmetic expression> / <primary arithmetic expression>
|
||||||
| <primary arithmetic expression>
|
| <primary arithmetic expression>
|
||||||
|
|
||||||
<primary arithmetic expression> ->
|
<primary arithmetic expression> ::=
|
||||||
<variable identifier>
|
<variable identifier>
|
||||||
| <floating-point literal>
|
| <floating-point literal>
|
||||||
| <integer literal>
|
| <integer literal>
|
||||||
|
@ -216,11 +216,11 @@ This does not follow standard BNF/EBNF syntax, I will rewrite it once I get all
|
||||||
```
|
```
|
||||||
#### 3.3.2 String Expression
|
#### 3.3.2 String Expression
|
||||||
```
|
```
|
||||||
<string expression> ->
|
<string expression> ::=
|
||||||
<primary string expression>
|
<primary string expression>
|
||||||
| <string expression> << <primary string expression>
|
| <string expression> << <primary string expression>
|
||||||
|
|
||||||
<primary string expression> ->
|
<primary string expression> ::=
|
||||||
<string variable identifier>
|
<string variable identifier>
|
||||||
| <string literal>
|
| <string literal>
|
||||||
```
|
```
|
||||||
|
@ -228,30 +228,30 @@ This does not follow standard BNF/EBNF syntax, I will rewrite it once I get all
|
||||||
```
|
```
|
||||||
// BNF from C specification adapted to PLATYPUS
|
// 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
|
// source: https://cs.wmich.edu/~gupta/teaching/cs4850/sumII06/The%20syntax%20of%20C%20in%20Backus-Naur%20form.htm
|
||||||
<conditional expression> ->
|
<conditional expression> ::=
|
||||||
<logical OR expression>
|
<logical OR expression>
|
||||||
|
|
||||||
<logical OR expression> ->
|
<logical OR expression> ::=
|
||||||
<logical AND expression>
|
<logical AND expression>
|
||||||
| <logical OR expression> .OR. <logical AND expression>
|
| <logical OR expression> .OR. <logical AND expression>
|
||||||
|
|
||||||
<logical AND expression> ->
|
<logical AND expression> ::=
|
||||||
<relational expression>
|
<relational expression>
|
||||||
| <logical AND expression> .AND. <relational expression>
|
| <logical AND expression> .AND. <relational expression>
|
||||||
// END BNF from C specification
|
// END BNF from C specification
|
||||||
```
|
```
|
||||||
#### 3.3.4 Relational Expression
|
#### 3.3.4 Relational Expression
|
||||||
```
|
```
|
||||||
<relational expression> ->
|
<relational expression> ::=
|
||||||
<primary a_relational expression> <relational operator> <primary a_relational expression>
|
<primary a_relational expression> <relational operator> <primary a_relational expression>
|
||||||
| <primary s_relational expression> <relational operator> <primary s_relational expression>
|
| <primary s_relational expression> <relational operator> <primary s_relational expression>
|
||||||
|
|
||||||
<primary a_relational expression> ->
|
<primary a_relational expression> ::=
|
||||||
<floating-point literal>
|
<floating-point literal>
|
||||||
| <integer literal>
|
| <integer literal>
|
||||||
| <variable identifier>
|
| <variable identifier>
|
||||||
|
|
||||||
<primary s_relational expression> ->
|
<primary s_relational expression> ::=
|
||||||
<string literal>
|
<string literal>
|
||||||
| <string variable identifier>
|
| <string variable identifier>
|
||||||
```
|
```
|
Loading…
Reference in New Issue