GTA3script Specification
- Introduction
- 1. Scope -
- 2. Terms and Definitions -
- 3. General Principles +
- 2. Terms and Definitions +
- 3. General Principles @@ -172,12 +172,12 @@
diff --git a/core.html b/core.html index 9ac8e83..15f64f0 100644 --- a/core.html +++ b/core.html @@ -52,7 +52,7 @@
The language specified by this document is thus a subset of the language accepted by the in-house compiler. Any source code translated by an implementation of this should be able to be translated by the original compiler. The reverse is not true. A known list of differences is presented in Appendix D.
+The language specified by this document is thus a subset of the language accepted by the in-house compiler. Any source code translated by an implementation of this should be able to be translated by the original compiler. The reverse is not true. A known list of differences is presented in Appendix D.
For the purposes of this document, the terms and definitions given in [ISO/IEC 2382:2015] and the following apply.
@@ -380,10 +380,10 @@A conforming implementation must be able to translate and correctly execute, within its resource limits, any program which does not violate the rules in this document.
Section 4 through 10 describes the GTA3script programming language. That description includes detailed syntactic specifications in a form detailed in 3.3. For convenience, Appendix A repeats all such syntactic specifications.
+Section 4 through 10 describes the GTA3script programming language. That description includes detailed syntactic specifications in a form detailed in 3.3. For convenience, Appendix A repeats all such syntactic specifications.
Appendix B describes a regular grammar suitable for scanning the language.
+Appendix B describes a regular grammar suitable for scanning the language.
Appendix C describes ambiguities present in the language grammar and resolutions for them.
Appendix D describes problematic elements in the in-house compiler that this specification choose not to follow.
+Appendix D describes problematic elements in the in-house compiler that this specification choose not to follow.
Along this document there are several footnotes explaining or clarifying some decisions. Often these footnotes exposes the reason for changes in the language compared to the in-house compiler. These footnotes are purely informative and are not an integral part of this document.
Some changes demand more details than a footnote permits. These are marked with the footnote [1] and further details are presented in Appendix D.
+Some changes demand more details than a footnote permits. These are marked with the footnote [1] and further details are presented in Appendix D.
main_script_file := {statement} ;
@@ -1814,7 +1814,7 @@ main_extension_file := {statement} ;
@@ -1831,7 +1831,7 @@ subscript_file := 'MISSION_START' eol @@ -1860,7 +1860,7 @@-
10.4. Mission Script Files
+10.4. Mission Script Files
mission_script_file := subscript_file ;@@ -2437,13 +2437,179 @@
Appendix A: Grammar Summary
--TODO
+++# The GTA3script Grammar (informative) + +ascii_char := ascii_printable | ascii_control ; +ascii_printable := /* printable ASCII characters */ ; +ascii_control := '\n' | '\t' | '\r' ; + +whitespace := ' ' | '\t' | '(' | ')' | ',' ; + +newline := ['\r'] `\n` ; + +graph_char := ascii_printable - (whitespace | '"') ; +token_char := graph_char - ('+' | '-' | '*' | '/' | '=' | '<' | '>') ; + +sep := whitespace {whitespace} ; +eol := newline | EOF ; + +comment := line_comment | block_comment ; +line_comment := '//' {ascii_char} eol ; +block_comment := '/*' {block_comment | ascii_char} '*/' ; + +command_name := token_char {token_char} ; +command := command_name { sep argument } ; + +argument := integer + | floating + | identifier + | string_literal ; + +digit := '0'..'9' ; +integer := ['-'] digit {digit} ; + +floating_form1 := '.' digit { digit | '.' | 'F' } ; +floating_form2 := digit { digit } ('.' | 'F') { digit | '.' | 'F' } ; +floating := ['-'] (floating_form1 | floating_form2) ; + +identifier := ('$' | 'A'..'Z') {token_char} ; + +string_literal := '"' { ascii_char - (newline | '"') } '"' ; + +variable_char := token_char - ('[' | ']') ; +variable_name := ('$' | 'A'..'Z') {variable_char} ; + +subscript := '[' (variable_name | integer) ']' ; +variable := variable_name [ subscript ] ; + +binop := '+' | '-' | '*' | '/' | '+@' | '-@' ; +asop := '=' | '=#' | '+=' | '-=' | '*=' | '/=' | '+=@' | '-=@' ; +unop := '--' | '++' ; + +expr_assign_abs := identifier {whitespace} '=' {whitespace} 'ABS' {whitespace} argument ; +expr_assign_binary := identifier {whitespace} asop {whitespace} argument ; +expr_assign_ternary := identifier {whitespace} '=' {whitespace} argument {whitespace} binop {whitespace} argument ; +expr_assign_unary := (unop {whitespace} identifier) + | (identifier {whitespace} unop) ; + +assignment_expression := expr_assign_unary + | expr_assign_binary + | expr_assign_ternary + | expr_assign_abs ; + +relop := '=' | '<' | '>' | '>=' | '<=' ; +conditional_expression := argument {whitespace} relop {whitespace} argument ; + +statement := labeled_statement + | embedded_statement ; + +label_def := identifier ':' ; +label_prefix := label_def sep ; + +labeled_statement := label_prefix embedded_statement + | label_def empty_statement ; + +empty_statement := eol ; + +embedded_statement := empty_statement + | command_statement + | expression_statement + | scope_statement + | var_statement + | if_statement + | ifnot_statement + | if_goto_statement + | ifnot_goto_statement + | while_statement + | whilenot_statement + | repeat_statement + | require_statement ; + +command_statement := command eol ; + +expression_statement := assignment_expression eol + | conditional_expression eol ; + +scope_statement := '{' eol + {statement} + [label_prefix] '}' eol ; + +command_var_name := 'VAR_INT' + | 'LVAR_INT' + | 'VAR_FLOAT' + | 'LVAR_FLOAT' + | 'VAR_TEXT_LABEL' + | 'LVAR_TEXT_LABEL' ; +command_var_param := sep variable ; + +var_statement := command_var_name command_var_param {command_var_param} eol ; + +conditional_element := ['NOT' sep] (command | conditional_expression) ; + +and_conditional_stmt := 'AND' sep conditional_element eol ; +or_conditional_stmt := 'OR' sep conditional_element eol ; + +conditional_list := conditional_element eol + ({and_conditional_stmt} | {or_conditional_stmt}) ; + +if_statement := 'IF' sep conditional_list + {statement} + [[label_prefix] 'ELSE' eol + {statement}] + [label_prefix] 'ENDIF' eol ; + +ifnot_statement := 'IFNOT' sep conditional_list + {statement} + [[label_prefix] 'ELSE' eol + {statement}] + [label_prefix] 'ENDIF' eol ; + +if_goto_statement := 'IF' sep conditional_element sep 'GOTO' sep identifier eol ; + +ifnot_goto_statement := 'IFNOT' sep conditional_element sep 'GOTO' sep identifier eol ; + +while_statement := 'WHILE' sep conditional_list + {statement} + [label_prefix] 'ENDWHILE' eol ; + +whilenot_statement := 'WHILENOT' sep conditional_list + {statement} + [label_prefix] 'ENDWHILE' eol ; + +repeat_statement := 'REPEAT' sep integer sep identifier eol + {statement} + [label_prefix] 'ENDREPEAT' eol ; + +filename := {graph_char} '.SC' ; + +require_statement := command_gosub_file + | command_launch_mission + | command_load_and_launch_mission ; + +command_gosub_file := 'GOSUB_FILE' sep identifier sep filename eol ; + +command_launch_mission := 'LAUNCH_MISSION' sep filename eol ; + +command_load_and_launch_mission := 'LOAD_AND_LAUNCH_MISSION' sep filename eol ; + +main_script_file := {statement} ; + +main_extension_file := {statement} ; + +subscript_file := 'MISSION_START' eol + {statement} + [label_prefix] 'MISSION_END' eol + {statement} ; + +mission_script_file := subscript_file ;+-Appendix B: Regular Lexical Grammar
+Appendix B: Regular Lexical Grammar
@@ -2532,7 +2698,7 @@Appendix C: Ambiguity
Not only the language, but the grammar presented in this document is ambiguous. Here are all the instances of ambiguity, which is the correct derivation, and suggestions to avoid users getting trapped in them.
-C.1. IF GOTO
+C.1. IF GOTO
-C.2. Ternary Minus One
+C.2. Ternary Minus One
-The token stream produced by the regular lexical grammar in Appendix B should solve this issue naturally.
+The token stream produced by the regular lexical grammar in Appendix B should solve this issue naturally.
-Appendix D: How to MISS2
+Appendix D: How to MISS2
The leaked script compiler is full of bugs. It was written for in-house use, so it’s meant to work and recognize at least the intended language. The problem is, the language is too inconsistent in this buggy superset. After constantly trying to make those bugs part of this specification, I strongly believe we shouldn’t. For the conservative, the following is a list of known things miss2 accepts that this specification does not.
@@ -2864,8 +3030,7 @@References
-TODO should we fix the floating point literals (e.g. '1.9.2')? I think there are DMA scripts that need this. -TODO list of special command names (user cannot write these, include AND/OR/NOT) +
TODO list of special command names (user cannot write these, include AND/OR/NOT) TODO label semantics of start new script (GTA3 allows label: {}) TODO SAN ANDREAS ALLOWS IDENTIFIERS TO BEGIN WITH UNDERSCORES TODO remember GTASA INPUT_OPT does not accept text label vars at all (not at runtime level) @@ -2893,7 +3058,7 @@
References
-1. For consistency we have simplified this feature. Please refer to Appendix D for details on how the in-house compiler behaves. +1. For consistency we have simplified this feature. Please refer to Appendix D for details on how the in-house compiler behaves.