Chapter 22.2
This commit is contained in:
parent
df1985ae84
commit
42a7e26292
1 changed files with 16 additions and 0 deletions
|
@ -149,6 +149,10 @@ static void endCompiler() {
|
|||
#endif
|
||||
}
|
||||
|
||||
static void beginScope() { current->scopeDepth++; }
|
||||
|
||||
static void endScope() { current->scopeDepth--; }
|
||||
|
||||
static void expression();
|
||||
static void statement();
|
||||
static void declaration();
|
||||
|
@ -217,6 +221,14 @@ static void literal(bool canAssign) {
|
|||
|
||||
static void expression() { parsePrecedence(PREC_ASSIGNMENT); }
|
||||
|
||||
static void block() {
|
||||
while (!check(TOKEN_RIGHT_BRACE) && !check(TOKEN_EOF)) {
|
||||
declaration();
|
||||
}
|
||||
|
||||
consume(TOKEN_RIGHT_BRACE, "Expect '}' after block.");
|
||||
}
|
||||
|
||||
static void varDeclaration() {
|
||||
uint8_t global = parseVariable("Expect variable name.");
|
||||
|
||||
|
@ -280,6 +292,10 @@ static void declaration() {
|
|||
static void statement() {
|
||||
if (match(TOKEN_PRINT)) {
|
||||
printStatement();
|
||||
} else if (match(TOKEN_LEFT_BRACE)) {
|
||||
beginScope();
|
||||
block();
|
||||
endScope();
|
||||
} else {
|
||||
expressionStatement();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue