1 \documentclass{article}
5 \usepackage[utf8]{inputenc}
6 \usepackage[parfill]{parskip}
12 %%% GEOMETRY FOR DOCUMENT
15 %%% HEADERS/FOOTERS APPEARANCE
16 \usepackage{fancyhdr} % This should be set AFTER setting up the page geometry
17 \pagestyle{fancy} % options: empty , plain , fancy
18 \renewcommand{\headrulewidth}{0pt} % customise the layout...
19 \lhead{}\chead{}\rhead{}
20 \lfoot{}\cfoot{\thepage}\rfoot{}
22 %%% SECTION TITLE APPEARANCE
23 \allsectionsfont{\sffamily\mdseries\upshape} % (See the fntguide.pdf for font help)
26 \usepackage[nottoc,notlof,notlot]{tocbibind} % Put the bibliography in the ToC
27 \usepackage[titles,subfigure]{tocloft} % Alter the style of the Table of Contents
28 \renewcommand{\cftsecfont}{\rmfamily\mdseries\upshape}
29 \renewcommand{\cftsecpagefont}{\rmfamily\mdseries\upshape} % No bold!
31 %%% listing language definitions
32 %%% BNF for now, QuakeC will be later
33 \definecolor{keyword1}{RGB}{0,102,153}
34 \definecolor{keyword2}{RGB}{0,153,102}
35 \definecolor{keyword3}{RGB}{0,153,255}
36 \definecolor{comment}{RGB}{204,0,0}
37 \definecolor{function}{RGB}{153,102,255}
38 \definecolor{digit}{RGB}{255,0,0}
39 \definecolor{string}{RGB}{255,0,204}
40 \definecolor{rule}{RGB}{192,192,192}
41 \definecolor{back}{RGB}{250,250,250}
43 \lstdefinelanguage{bnf}{
44 keywordstyle={\color{keyword2}\bfseries},
46 otherkeywords={::=,|},
47 morecomment=[s][\color{comment}]{(*}{*)},
48 stringstyle=\color{string},
52 showstringspaces=false,
54 rulecolor=\color{rule},
55 backgroundcolor=\color{back}
58 %% Title Information %%
59 \title{The GMQCC QuakeC Programming Language}
70 This document specifies the form and establishes the interpretation of programs written in
71 the GMQCC QuakeC programming language variant (refereed simply as QuakeC throughout this
72 document). It specifies:
74 \item the representation of QuakeC programs;
75 \item the syntax and constraints of the QuakeC language;
76 \item the semantic rules for interpreting QuakeC programs;
77 \item the representation of input data to be processes by QuakeC programs;
78 \item the representation of output data produced by QuakeC programs;
79 \item the restrictions and limits imposed by a conforming implementation of QuakeC.
81 This document does not specify
83 \item the mechanism by which QuakeC programs are transformed for use by a data-
85 \item the mechanism by which QuakeC programs are invoked for use by a data-processing
87 \item the mechanism by which input data are transformed for use by a QuakeC program;
88 \item the size or complexity of a program and its data that will exceed the capacity
89 of any specific data-processing system or the capacity of a particular
90 execution environment;
91 \item all minimal requirements of a data-processing system that is capable of
92 supporting a conforming implementation.
95 %% Table Of Contents %%
102 \raggedright % No weird TEX spacing on lines to fill page
104 %% -> Terms, definitions, and symbols %%
105 \section{Terms, definitions, and symbols}
106 \subsection*{argument}
107 Expression in the comma-separated list bounded by the parentheses in a function call
108 expression, or a sequence of preprocessing tokens in the comma-separated list bounded
109 by the parentheses in a function-like macro invocation.
111 \subsection*{behavior}
112 External appearance or action
114 \subsection*{implementation-defined behavior}
115 Unspecified behavior where each implementation documents how the choice is made.
117 \subsection*{undefined behavior}
118 Behavior, upon use of a non-portable or erroneous program construct or of erroneous data,
119 for which this document imposes no actual requirements.
121 \subsection*{unspecified behavior}
122 Use of an unspecified value, or other behavior where this document provides two or more
123 possibilities and imposes no further requirements on which is chosen in any instance.
125 \subsection*{constraint}
126 Restriction, either syntactic or semantic, by which the exposition of language elements
127 is to be interpreted.
129 \subsection*{diagnostic message}
130 Message belonging to an implementation-defined subset of the implementation's message
134 Region of data storage in the execution environment, the contents of which can represent
137 \subsection*{parameter}
138 Object declare as part of a function declaration or definition that acquires a value on
139 entry to the function, or an identifier from the comma-separated list bounded by the
140 parentheses immediately following the macro name in a function-like macro definition.
142 \subsection*{recommended practice}
143 Specification that is strongly recommended as being in keeping with the intent of this
144 document, but that may be impractical for some implementations.
147 Precise meaning of the contents of an object when interpreted as having a specific type.
149 \subsection*{implementation-defined value}
150 Unspecified value where each implementation documents how the choice is made.
152 \subsection*{unspecified value}
153 Valid value of the relevant type where this document imposes no requirements on which
154 value is chosen in any instance.
157 \section{Conformance}
158 In this document, "shall" is to be interpreted as a requirement on an implementation
159 or on a program; conversely, "shall not" is to be interpreted as a prohibition. \\
160 If a "shall" or "shall not" requirement that appears outside of a constraint is violated,
161 the behavior is undefined. Undefined behavior is otherwise indicated in this document by
162 the words "undefined behavior" or by the omission of any explicit definition of behavior.
163 There is no difference in emphasis among these three; they all describe "behavior that is
167 \section{Environment}
168 An implementation that translates QuakeC source files and executes QuakeC programs in two
169 data processing-system environments, which will be called the translation environment and
170 the execution environment in this document. Their characteristics define and constrain the
171 results of executing QuakeC programs constructed according to the syntactic and semantic
172 rules for conforming implementations.
173 \subsection{Conceptual models}
174 \subsubsection{Translation environment}
175 \paragraph*{Translation steps}
176 The precedence among the syntax rules of translation is specified by the following steps
178 \item Physical source file characters are mapped, in an implementation-defined manner,
179 to the source character set (introducing new-line characters for end-of-line
180 indicators) if necessary. Trigraph and digraph sequences are replaced by their
181 corresponding single-character internal representations.
182 \item The source file is decomposed into preprocessing tokens and sequences of white-
183 space characters (including comments). A source file shall not end in a partial
184 preprocessing token or in a partial comment. Each comment is replaced by one
185 space character. New-line characters are retained. Whether each nonempty
186 sequences of white-space characters other than new-line is retained or replaced
187 by one space character is implementation-defined.
188 \item Preprocessing directives are executed, macro invocations are expanded
189 recursively. A \#include preprocessing directive causes the named header or
190 source file to be processes from step one through step three, recursively. All
191 preprocessing directives are then deleted.
192 \item Each source character set member and escape sequence in character constants and
193 string literals is converted to the corresponding member of the execution
194 character set; if there is no corresponding member, it is converted to an
195 implementation-defined member other than the null character.
196 \item Adjacent string literal tokens are concatenated.
197 \item White-space characters seperating tokens are no longer significant. Each
198 preprocessing token is converted into a token. The resulting tokens are then
199 syntactically and semantically analyzed and translated.
201 \subparagraph*{Footnotes}
202 Implementations shall behave as if these separate steps occur, even though many are likely
203 to be folded together in practice. Source files need not be stored as file, nor need there
204 be any one-to-one correspondence between these items and any external representation. The
205 description is conceptual only, and does not specify any particular implementation.
207 \paragraph*{Diagnostics}
208 A conforming implementation shall produce at least on diagnostic message(identified in an
209 implementation-defined manner) if a source file contains a violation of any syntax rule or
210 constraint, even if the behavior is also explicitly specified as undefined or
211 implementation-defined. Diagnostic messages need not be produced in other circumstances.
213 %% ->-> Execution environments %%
214 \subsubsection{Execution environments}
215 Two execution environments are defined
219 \subsection{Notation}
220 The syntax notation used in this document is that of a BNF specification. A set of
221 derivation rules, often written as:
222 \begin{lstlisting}[language=bnf]
223 symbol ::= expression
225 Where symbol is a nonterminal, and the expression consists of one or more sequences of
226 symbols; more sequences are separated by a vertical bar \textbar, indicating a choice,
227 the whole being a possible substitution for the symbol on the left. Symbols that never
228 appear on the left side are terminals.
230 This document defines language syntax throughout it's way at defining language
231 constructs If you're interested in a summary of the language syntax, one is given in
235 \subsection{Concepts}
236 %% ->-> Scopes of identifiers %%
237 \subsubsection{Scopes of identifiers}
238 An identifier can denote an object; a function, or enumeration; a label name; a macro
239 name; or a macro parameter. The same identifier can denote difference items at different
240 point in the program. A member of an enumeration is called an enumeration constant.
241 Macro names and macro parameters are not considered further here, because prior to the
242 semantic phase of program translation any occurrences of macro names in the source file
243 are replaced by the preprocessing token sequences that constitute their macro definitions.
246 For each different item that an identifier designates, the identifier is visible (i.e,
247 can be used) only within a region of program text called its scope. Different items
248 designated by the same identifier either have different scopes, or are in different name
249 spaces. There are four kinds of scopes: function, file, block and function prototype.
250 (A function prototype is a declaration of a function that declares the types of its
254 A label name is the only kind of identifier that has function scope. It can be used (in
255 a goto statement) anywhere in the function in which it appears, and is declared
256 implicitly by its syntactic appearance (prefixed by a : and a statement).
259 Every other identifier has scope determined by the placement of its declaration (in a
260 declarator or type specifier). If the declarator or types specifier that declares the
261 identifier appears outside any block or list of parameters, the identifier has file
262 scope, which terminates at the end of the file. If the declartor or type specifier that
263 declares the identifier appears inside a block or within the list of parameter
264 declarations in a function definition, the identifier has block scope, which terminates
265 at the end of the associated block. If the declarator or type specifier that declares
266 the identifier appears within the list of parameter declarations in a function prototype
267 (not part of a function definition), the identifier has function prototype scope, which
268 terminates at the end of the function declarator. If an identifier designates two
269 different items in the same name space, the scopes might overlap. If so, the scope of
270 one item (the inner scope) will be a strict subset of the scope of the other item (the
271 outer scope). Within the inner scope, the identifier designates the item declared in the
272 inner scope; the item declared in the outer scope is hidden (and not visible) within
276 Unless explicitly stated otherwise, where this document uses the term "identifier" to
277 refer to some item (as opposed to the syntactic construct), it refers to the item in the
278 relevant name space whose declaration is visible at the point the identifier occurs.
281 Two identifiers have the same scope it and only if their scopes terminate at the same
285 Each enumeration constant has scope that begins just after the appearance of its defining
286 enumerator in an enumerator list. Any other identifier has scope that begins just after
287 the completion of its declarator.
289 %% ->-> Name spaces of identifiers %%
290 \subsubsection{Name spaces of identifiers}
291 If more than one declaration of a particular identifier is visible at any point in a
292 source file, the syntactic context disambiguates uses that refer to different items.
293 Thus, there are separate name spaces for various categories of identifiers, as follows:
296 \item Label names (disambiguated by the syntax of the lbvel declaration and use);
297 \item Enumerations (disambiguated by following the keyword enum);
298 \item All other identifiers, called ordinary identifiers (declared in ordinary
299 declarators or as enumeration constants).
303 \subsubsection{Types}
304 The meaning of a value stored in an object returned by a function is determined by the
305 type of the expression used to access it. (An identifier declared to be an object is the simplest
306 such expression; the type is specified in the declaration of the identifier.) Types are
307 partitioned into object types (types that fully describe objects), function types(types
308 that describe functions), and incomplete types(types that describe objects but lack
312 An object declared type bool is large enough to store the values 0 and 1.
315 An object declared type float is a real type; An object declared type vector is a
316 comprised set of three floats that respectively represent the \underline{x,y,z}
317 components of a three-dimensional vector.
320 An enumeration comprises a set of named integer constant values. Each distinct
321 enumeration constitutes a different enumerated type.
324 Enumeration types and float are collectively called arithmetic types. Each arithmetic
325 type belongs to one type domain.
328 The void type comprises an empty set of values; it is an incomplete type that cannot be
332 A number of derived types can be constructed from the object, function and incomplete
337 \item An array type describes a contiguously allocated nonempty set of objects with a
338 particular object types, called the element type. Array types are characterized
339 by their element type and by the number of elements in the array. An array type
340 is said to be derived from its element type, and if its element is type T, the
341 array type is sometimes called "array of T". The construction of an array type
342 from an element type is called "array type derivation".
343 \item A function type described a function with a specified return type. A function
344 type is characterized by its return type and the number and types of its
345 parameters. A function type is said to be derived from its return type, and if
346 its return type is T, the function type is sometimes called "function returning
347 T". The construction of a function type from a return type is called "function
353 Arithmetic types are collectively called scalar types. Arrays and vectors are
354 collectively called aggregate types.
357 An array of unknown size is an incomplete type. It is completed, for an identifier of
358 that byte, by specifying the size in a later declaration. Arrays are required to have
362 A type is characterized by its type category, which is either the outermost derivation
363 of a derived type (as noted above in the construction of derived types), or the type
364 itself if the type consists of no derived types.
367 Any type so far mentioned is an unqualified type. Each unqualified type has several
368 qualified version of its type, corresponding to the combinations of one, two, or all
369 two of const and volatile qualifiers. The qualified or unqualified versions of a type
370 are distinct types that belong to the same type category and have the same representation.
371 A derived type is not qualified by the qualifiers (if any) of the type from which it
375 %% ->-> Compatible types and composite type %%
376 \subsubsection{Compatible types and composite type}
377 Two types have compatible type if their types are the same.
380 All declarations that refer to the same object or function shall have compatible type;
381 otherwise the behavior is undefined.
384 A composite type can be constructed from two types that are compatible; it is a type that
385 is compatible with both of the two types and satisfies the following conditions:
387 \item If one type is an array, the composite type is an array of that size.
388 \item If only one type is a function type with a parameter type list(a function
389 prototype), the composite type is a function prototype with the parameter type
391 \item If both types are function types with parameter type lists, the type of each
392 parameter in the composite parameter type list is the composite type of the
393 corresponding parameters.
395 These rules apply recursively to types from which the twp types are derived.
399 \subsection{Conversions}
400 Several operators convert operand values from one type to another automatically. This
401 sub-clause specified the result required from such an implicit conversion.
404 Conversion from an operand value to a compatible type causes no change to the value or
408 %% ->->Aritmetic operands %%
409 \subsubsection{Arithmetic operands}
410 \paragraph*{Boolean type}
411 When any scalar value is converted to bool, the result is 0 if the value compares equal
412 to 0; otherwise the result is 1.
414 %% ->->Other operands %%
415 \subsubsection{Other operands}
416 \paragraph{Lvalues, arrays and function designators}
417 An lvalue is an expression with an object type or an incomplete type other than void;
418 if an lvalue does not designate an object when it is evaluated, the behavior is undefined.
419 When an object is said to have a particular type, the type is specified by the lvalue
420 used to designate the object. A modifiable lvalue is an lvalue that does not have an
421 array type, does not have an incomplete type, does not have a const-qualified type.
424 Except when it is the operand of the unary \& operator, the ++ operator, the -- operator,
425 or the left operand of the . operator or an assignment operator, an lvalue that does not
426 have array type is converted to the value stored in the designated object (and is no
427 longer an lvalue). If the lvalue has qualified type, the value has the unqualified
428 version of the type of the lvalue; otherwise, the value has the type of the lvalue. If
429 the lvalue has an incomplete type and does not have array type, the behavior is undefined.
432 A function designator is an expression that has function type.
436 The (nonexistent) value of a void expression (an expression that has type void) shall not
437 be used in any way, and implicit conversions (except to void) shall not be applied to
438 such an expression. If an expression of any other type is evaluated as a void expression
439 , its value or designator is discarded. (A void expression is only evaluated for its
443 \subsection{Lexical elements}
445 \begin{lstlisting}[language=bnf]
446 token ::= keyword | identifier
447 | constant | string-literal
450 preprocessing-token := header-name | identifier
451 | pp-number | string-literal
454 \paragraph*{Constraints}
455 Each preprocessing token that is converted to a token shall have the lexical form of a
456 keyword, an identifier, a constant, a string literal, or a punctuator.
458 \paragraph*{Semantics}
462 \subsubsection{Keywords}
464 \begin{lstlisting}[language=bnf]
465 keyword ::= enum | break
477 \paragraph*{Semantics}
478 The above tokens (case sensitive) are reserved (in translation step seven and eight) for
479 use as keywords, and shall not be used otherwise.
481 %% ->->Identifiers %%
482 \subsubsection{Identifiers}
484 \begin{lstlisting}[language=bnf]
485 identifier ::= nondigit
486 | identifier nondigit
489 nondigit ::= _ | a | b | c | d | e | f | g | h | i
490 | j | k | l | m | n | o | p | q | r | s
491 | t | u | v | w | x | y | z | A | B | C
492 | D | E | F | G | H | I | J | K | L | M
493 | N | P | Q | R | S | T | U | V | W | X
496 digit ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
500 \subsubsection{Constants}
501 \begin{lstlisting}[language=bnf]
502 constant ::= integer-constant
504 | enumeration-constant
508 integer-constant ::= decimal-constant
510 | hexadecimal-constant
512 decimal-constant ::= nonzero-digit
513 | decimal-constant digit
516 | octal-constant octal-digit
518 hexadecimal-constant ::= hexdecimal-prefix
523 hexadecimal-prefix: ::= 0x | 0X
525 nonzero-digit ::= 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8
528 octal-digit ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7
530 hexadecimal-digit ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7
531 | 8 | 9 | a | b | c | d | e | f
532 | A | B | C | D | E | F
535 %% ->-> String literals %%
536 \subsubsection{String literals}
537 \begin{lstlisting}[language=bnf]
538 string-literal := " s-char-sequence "
540 s-char-sequence := s-char
541 | s-char-sequence s-char
543 s-char := ` | ! | @ | # | $ | % | ^ | & | *
544 | ( | ) | _ | - | + | = | { | } | [
545 | ] | | | : | ; | ' | < | , | > | .
546 | ? | / | 1 | 2 | 3 | 4 | 5 | 6 | 7
547 | 8 | 9 | 0 | q | w | e | r | t | y
548 | u | i | o | p | a | s | d | f | g
549 | h | j | k | l | z | x | c | v | b
550 | n | m | Q | W | E | R | T | Y | U
551 | I | O | P | A | S | D | F | G | |
552 | H | J | K | L | Z | X | C | V | B
555 \paragraph*{Description}
556 A character string literal is a sequence of zero or more characters enclosed in
557 double-quotes, as in "xyz".
560 The same considerations apply to each element of the sequence in a character string
561 literal as if it where an integer character constant, except that the single-quote
562 ' is representable either by itself or by the escape sequence \textbackslash', but
563 the double-quote " shall be represented by the escape sequence \textbackslash".
565 \paragraph*{Semantics}
566 In translation stage six, the character sequences specified by any sequence of adjacent
567 character string literal tokens are concatenated into a single character sequence.
569 %% ->-> Punctuators %%
570 \subsubsection{Punctuators}
573 A punctuator is a symbol that has independent syntactic and semantic significance.
574 Depending on context, it may specify an operation to be performed (which in turn
575 may yield a value or a function designator, produce a side effect, or some combination
576 thereof) in which case it is known as an operator (other forms of operator also exist
577 in some contexts). An operand is an item on which an operator acts.
580 TODO: Trigraphs \& Digraphs
582 \subsubsection{Header names}
584 \subsubsection{Preprocessing numbers}
586 \subsubsection{Comments}
587 Except within a character constant, a string literal, or a comment, the characters /*
588 introduce a comment. The contents of such a comment are examined only to identify
589 characters and to find the characters /* that terminate it.
592 Except within a character constant, a string literal, or a comment, the characters //
593 introduce a comment that includes all characters up to, but not including, the next
594 new-line character. The contents of such a comment are examined only to identify
595 characters and to find the terminating new-line characters.
599 \subsection{Expressions}
600 An expression is a sequence of operators and operands that specifies computation of a
601 value, or that designates an object or function, or that generates side effects, or that
602 performs a combination thereof.
605 Between the previous and next sequence point an object shall have its stored value
606 modified at most once by the evaluation of an expression. Furthermore, the prior value
607 shall be read only to determine the value to be stored.
610 The grouping of operators and operands is indicated by the syntax. Except as specified
611 later (for the function call (), \&\&, \textbar\textbar ?:, and comma operators), the
612 order of evaluation of sub-expressions and the order in which side effects take place
613 are both unspecified.
616 Some operators (the unary \textasciitilde operator, and the binary operators \textless
617 \textless, \textgreater\textgreater, \&, \^, and \textbar, collectively describe bitwise
618 operators) are required to have operands that are either integer, or floating point with
619 zero points of decimal precision.
622 If an exceptional condition occurs during the evaluation of an expression (that is, if
623 the result is not mathematically defined or not in the range or representable values for
624 its type), the behavior is undefined.
626 %% ->-> Primary expressions %%
627 \subsubsection{Primary expressions}
629 \begin{lstlisting}[language=bnf]
630 primary-expression := identifier
635 \paragraph*{Semantics}
636 An identifier is a primary expression, provided it has been declared as designating an
637 object(in which case it is an lvalye) or a function(in which case it is a function
641 A constant is a primary expression. Its type depends on its form and value.
644 A string literal is a primary expression. It is an lvalue.
647 A parenthesized expression is a primary expression. Its type and value identical to
648 those of the unparenthesized expression. It is an lvalue, a function designator, or a
649 void expression if the unparenthesized expression is, respectively, an lvalue, a
650 function designator, or a void expression.
652 \bibliographystyle{abbrv}