Robot Programming Language
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.
NOTATIONAL CONVENTIONS
Non-terminals are enclosed in angle brackets:
- Terminals are written as literal strings: "int"
- | denotes alternation
- { X } denotes zero or more repetitions
- [ X ] denotes an optional element
BNF defines syntax only. Semantic constraints are defined separately.
- LEXICAL STRUCTURE
2.1 Character Classes
::= "A" | ... | "Z" | "a" | ... | "z"
::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
::= "_"
2.2 Identifiers
::= { | | }
Rules:
- Case-sensitive
- MUST NOT begin with a digit
- MUST NOT match a reserved keyword
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.
- PROGRAM STRUCTURE
::= { } { }
Constraints:
- DECLARATIONS
4.1 Global Declaration
::=
4.2 Variable Declaration
::= "int" [ "=" ] ";"
Rules:
- Variables MUST be declared before use.
- Only type "int" is allowed for variables.
- FUNCTION DEFINITIONS
5.1 Main Function
::= "int" "main" "(" ")"
Constraints:
- MUST appear exactly once
- MUST have no parameters
- MUST return type int
5.2 User Function Definition
::= "(" [ ] ")"
::= "int" | "void"
5.3 Parameter List
::= { "," }
::= "int"
Rules:
- Only int parameters are allowed.
- Parameter names MUST be unique within the function.
- 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:
- Functions declared as int MUST return a value.
- Functions declared as void MUST NOT return a value.
- 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:
- Argument count MUST match parameter count.
- Argument types MUST match declared types.
- 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.
- STATIC SEMANTIC CONSTRAINTS
The following rules are mandatory and not enforced by BNF:
- Exactly one main function MUST exist.
- main MUST have signature: int main().
- All identifiers MUST be declared before use.
- No duplicate global variable names.
- No duplicate function names.
- Function return types MUST match return statements.
- No implicit type conversion is allowed.
- Only types int and void exist.
- Arrays are not supported.
- Pointers are not supported.
- Dynamic memory allocation is not supported.
- Recursion is allowed syntactically but execution limits are implementation-defined.
- UNDEFINED BEHAVIOR
The following produce undefined behavior:
- Division by zero
- Use of uninitialized variables
- Integer overflow beyond implementation limits
- Calling built-in functions with invalid parameter ranges
- Stack overflow due to deep recursion
End of Specification