Lexical Specifications
- Keywords
array,if,then,else,while,for,to,do,let,in,end,of,break,nil,function,var,type,importandprimitive- Object-related keywords
The keywords
class,extends,methodandneware reserved for object-related constructions. They are valid keywords when the object extension of the language is enabled, and reserved words if this extension is disabled (i.e. they cannot be used as identifiers in object-less syntax).- Symbols
,,:,;,(,),[,],{,},.,+,-,*,/,=,<>,<,<=,>,>=,&,|, and:=- White characters
Space and tabulations are the only white space characters supported. Both count as a single character when tracking locations.
- End-of-line
End of lines are
\n\r,\r\n,\rand\n, freely intermixed.- Strings
The strings are ANSI-C strings: enclosed by
", with support for the following escapes:\a,\b,\f,\n,\r,\t,\vControl characters.
\numThe character which code is
numin octal. Valid character codes belong to an extended (8-bit) ASCII set, i.e. values between0and255in decimal (0and377in octal).numis composed of exactly three octal characters, and any invalid value is a lexical error.\xnumThe character which code is
numin hexadecimal (upper case or lower case or mixed).numis composed of exactly two hexadecimal characters. Likewise, expected values belong to an extended (i.e. 8-bit) ASCII set.\\A single backslash.
\"A double quote.
\characterIf no rule above applies, this is an error.
All the other characters are plain characters and are to be included in the string. In particular, multi-line strings are allowed.
- Comments
Like C comments, but can be nested:
/* Comment /* Nested comment */ Comment */
- Identifiers
Identifiers start with a letter, followed by any number of alphanumeric characters plus the underscore. Identifiers are case sensitive. Moreover, the special
_mainstring is also accepted as a valid identifier.id = letter { letter | digit | "_" } | "_main" ;
- Numbers
There are only integers in Tiger, i.e. values between
0and \(2^{31} - 1\) =2147483647. More explanations can be found in TC-1/2-Lexer FAQ.integer = digit { digit } ;
- Invalid characters
Any other character is invalid.