Robot Programming Language

Complete Formal Specification (BNF)

Version 1.0

This document defines the complete formal syntax and static semantic rules of the Robot Programming Language.
The grammar is expressed using Backus–Naur Form (BNF) with minimal EBNF extensions.


  1. NOTATIONAL CONVENTIONS

  2. Non-terminals are enclosed in angle brackets:

  3. Terminals are written as literal strings: "int"
  4. | denotes alternation
  5. { X } denotes zero or more repetitions
  6. [ X ] denotes an optional element

BNF defines syntax only. Semantic constraints are defined separately.


  1. LEXICAL STRUCTURE

2.1 Character Classes

::= "A" | ... | "Z" | "a" | ... | "z"

::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"

::= "_"

2.2 Identifiers

::= { | | }

Rules:

2.3 Integer Literals

::= { }

Only unsigned decimal integers are supported.

2.4 Reserved Keywords

int void if else while return

Reserved keywords MUST NOT be used as identifiers.


  1. PROGRAM STRUCTURE

::= { } { }

Constraints:


  1. DECLARATIONS

4.1 Global Declaration

::=

4.2 Variable Declaration

::= "int" [ "=" ] ";"

Rules:


  1. FUNCTION DEFINITIONS

5.1 Main Function

::= "int" "main" "(" ")"

Constraints:

5.2 User Function Definition

::= "(" [ ] ")"

::= "int" | "void"

5.3 Parameter List

::= { "," }

::= "int"

Rules:


  1. STATEMENTS

::= | | | | |

6.1 Compound Statement

::= "{" { } "}"

6.2 Expression Statement

::= [ ] ";"

6.3 Selection Statement

::= "if" "(" ")" | "if" "(" ")" "else"

6.4 Iteration Statement

::= "while" "(" ")"

The language does not support "for" or "do-while".

6.5 Return Statement

::= "return" [ ] ";"

Rules:


  1. EXPRESSIONS

::=

7.1 Assignment

::= | "="

7.2 Logical OR

::= | "||"

7.3 Logical AND

::= | "&&"

7.4 Equality

::= | "==" | "!="

7.5 Relational

::= | "<" | ">" | "<=" | ">="

7.6 Additive

::= | "+" | "-"

7.7 Multiplicative

::= | "*" | "/" | "%"

7.8 Unary

::= | "!" | "-"

7.9 Primary

::= | | "(" ")" |

7.10 Function Call

::= "(" [ ] ")"

::= { "," }

Rules:


  1. BUILT-IN FUNCTION IDENTIFIERS

The following identifiers are reserved as runtime functions:

drive scan cannon loc_x loc_y damage speed rand

They follow normal grammar but are semantically defined by the runtime engine.


  1. STATIC SEMANTIC CONSTRAINTS

The following rules are mandatory and not enforced by BNF:

  1. Exactly one main function MUST exist.
  2. main MUST have signature: int main().
  3. All identifiers MUST be declared before use.
  4. No duplicate global variable names.
  5. No duplicate function names.
  6. Function return types MUST match return statements.
  7. No implicit type conversion is allowed.
  8. Only types int and void exist.
  9. Arrays are not supported.
  10. Pointers are not supported.
  11. Dynamic memory allocation is not supported.
  12. Recursion is allowed syntactically but execution limits are implementation-defined.

  1. UNDEFINED BEHAVIOR

The following produce undefined behavior:


End of Specification