# mcf This is a toy compiler project named as mcf (making compiler is fun) aiming to make a compiler specialized for game development
Terms
:...
: this can be replaced in practice as a series of any symbols (tokens|expressions|statements) with at least one symbol.
TOKEN
: the highlighted and capitalized identifier represents a token
<Expression>
: the value between braces represents a expression
[Statement]
: the value between brackets represents a statement
{ ... }
: this represents that ...
is optional when parsing.
{ ... }+
: this represents that ...
must be there at least ONE or MORE.
{ ... }*
: this represents that ...
can be there NONE or MORE.
[prerequisite: TOKEN]
: this represents that TOKEN
must be required before parsing next symbol.
[expectnext: TOKEN]
: this represents that TOKEN
must be required for next symbol.
<Expression>
:<Identifier>
IDENTIFIER
<Literal>
LITERAL
<String>
STRING
<Prefix>
MINUS
<Expression>
BANG
<Expression>
AMPERSAND
<Expression>
<Group>
LPAREN
<Expression>
RPAREN
<Infix>
<Expression>
EQUAL
<Expression>
<Expression>
NOT_EQUAL
<Expression>
<Expression>
LT
<Expression>
<Expression>
GT
<Expression>
<Expression>
PLUS
<Expression>
<Expression>
MINUS
<Expression>
<Expression>
ASTERISK
<Expression>
<Expression>
SLASH
<Expression>
<Call>
<Expression>
LPAREN
{<Expression>
{COMMA
<Expression>
}* {COMMA
}} RPAREN
<Index>
<Expression>
LBRACKET
{<Expression>
} RBRACKET
<As>
<Expression>
KEYWORD_AS
<TypeSignature>
<Initializer>
LBRACE
<Expression>
{COMMA
<Expression>
}* {COMMA
} RBRACE
<INTERMEDIATE>
:<Variadic>
VARIADIC
<Identifier>
<TypeSignature>
KEYWORD_UNSIGNED
} <Identifier>
KEYWORD_UNSIGNED
} <Index>
<Identifier>
: identifier must be registered as type unless used for [Typedef]
<Index>
: for this index expression, the leftmost expression must be TYPE identifier, and the index value must be integer.
<VariableSignature>
<Identifier>
COLON
<TypeSignature>
<FunctionParams>
LPAREN
KEYWORD_VOID
RPAREN
LPAREN
<Variadic>
RPAREN
LPAREN
<VariableSignature>
{COMMA
<VariableSignature>
}* {COMMA
{<Variadic>
}} RPAREN
<FunctionSignature>
KEYWORD_FUNC
<Identifier>
<FunctionParams>
POINTING
KEYWORD_VOID
KEYWORD_FUNC
<Identifier>
<FunctionParams>
POINTING
<TypeSignature>
[Statement]
:[IncludeLibrary]
MACRO_INCLUDE
LT
KEYWORD_ASM
COMMA
STRING
GT
KEYWORD_LIB
: this represent that this will include a library file without any header.STRING
: this represent the path for the binary library file.[Typedef]
KEYWORD_TYPEDEF
<VariableSignature>
SEMICOLON`
<VariableSignature>
: represent a new type equivalent to source type with the size specified if any and/or the values specified if any.[Extern]
KEYWORD_EXTERN
<FunctionSignature>
SEMICOLON
<FunctionSignature>
: the function signature will be written as extern in the taget assembly.[Let]
KEYWORD_LET
<VariableSignature>
{ASSIGN
<Expression>
} SEMICOLON
{ASSIGN
<Expression>
} : if this phrase exist, the variable signature will be stored as data with initialized value; otherwise, it will be stored as bss.
[Block]
LBRACE
{[Statement]
}* RBRACE
{[Statement]
}*: scope must be pushed for these statements.
[Return]
KEYWORD_RETURN
<Expression>
SEMICOLON
<Expression>
: this expression must have value
[Func]
<FunctionSignature>
[Block]
<FunctionSignature>
: the signature is stored to code section.<Block>
: [Return]
is required at the end of statements if the signature has return type, and both type must be matched.[Main]
KEYWORD_MAIN
<FunctionParams>
POINTING
KEYWORD_VOID
[Block]
KEYWORD_MAIN
<FunctionParams>
POINTING
<TypeSignature>
[Block]
<FunctionParams>
: params are stored to bss section.<Block>
: [Return]
is required at the end of statements if the signature has return type, and both type must be matched.[Expression]
:<Expression>
SEMICOLON
<Expression>
: expressions like function call can be statement.
[Unused]
:KEYWORD_UNUSED
LPAREN
{<Identifier>
{COMMA
<Identifier>
}* {COMMA
}} RPAREN
{<Identifier>
{COMMA
<Identifier>
}* {COMMA
}}: variables passed will be checked as used.