parrotcode: The compiler for Lua 5.1 | |
Contents | Language Implementations | Lua |
src/lua51.pir -- The compiler for Lua 5.1
This compiler extends HLLCompiler
(see runtime/parrot/library/Parrot/HLLCompiler.pir)
This compiler defines the following stages:
Used by languages/lua/luac.pir.
Some grammar routines are handly written in PIR.
See "Lua 5.1 Reference Manual", section 2.1 "Lexical Conventions", http://www.lua.org/manual/5.1/manual.html#2.1.
warning (message)
syntax_error (match, [message])
name
and break do else elseif
end false for function if
in local nil not or
repeat return then true until while
and
is a reserved word, but And
and AND
are two different, valid names. As a convention, names starting with an underscore followed by uppercase letters (such as _VERSION
) are reserved for internal global variables used by Lua.number
0x
. Examples of valid numerical constants are 3 3.0 3.1416 314.16e-2 0.31416E1 0xff 0x56
quoted_literal
'\a'
(bell), '\b'
(backspace), '\f'
(form feed), '\n'
(newline), '\r'
(carriage return), '\t'
(horizontal tab), '\v'
(vertical tab), '\\'
(backslash), '\"'
(quotation mark [double quote]), and '\''
(apostrophe [single quote]). Moreover, a backslash followed by a real newline results in a newline in the string. A character in a string may also be specified by its numerical value using the escape sequence \ddd
, where ddd is a sequence of up to three decimal digits. (Note that if a numerical escape is to be followed by a digit, it must be expressed using exactly three digits.) Strings in Lua may contain any 8-bit value, including embedded zeros, which can be specified as '\0'
.long_string
[[
, an opening long bracket of level 1 is written as [=[
, and so on. A closing long bracket is defined similarly; for instance, a closing long bracket of level 4 is written as ]====]
. A long string starts with an opening long bracket of any level and ends at the first closing long bracket of the same level. Literals in this bracketed form may run for several lines, do not interpret any escape sequences, and ignore long brackets of any other level. They may contain anything except a closing bracket of the proper level.'a'
is coded as 97, newline is coded as 10, and '1'
is coded as 49), the five literals below denote the same string: a = 'alo\n123"'
a = "alo\n123\""
a = '\97lo\10\04923"'
a = [[alo
123"]]
a = [==[
alo
123"]==]
long_comment
--
) anywhere outside a string. If the text immediately after --
is not an opening long bracket, the comment is a short comment, which runs until the end of the line. Otherwise, it is a long comment, which runs until the corresponding closing long bracket. Long comments are frequently used to disable code temporarily.internal_error
Klaas-Jan Stol <parrotcode@gmail.com>
Francois Perrad
|