parser: Add continue & break
This commit is contained in:
parent
1a7b240cb0
commit
4172071dba
@ -67,9 +67,9 @@ AnalysisResult analyze(Node &ast, Memory &memory) {
|
|||||||
} else if (holds_alternative<double>(token.data)) {
|
} else if (holds_alternative<double>(token.data)) {
|
||||||
return Type::Double;
|
return Type::Double;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
throw exception();
|
throw exception();
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case TokenType::Identifier: {
|
case TokenType::Identifier: {
|
||||||
string identifier = get<string>(token.data);
|
string identifier = get<string>(token.data);
|
||||||
|
|
||||||
@ -77,9 +77,12 @@ AnalysisResult analyze(Node &ast, Memory &memory) {
|
|||||||
throw RuntimeError("Unknown identifier \""+identifier+"\"", token.pos);
|
throw RuntimeError("Unknown identifier \""+identifier+"\"", token.pos);
|
||||||
|
|
||||||
return memory.get(identifier).type;
|
return memory.get(identifier).type;
|
||||||
}
|
|
||||||
throw exception();
|
throw exception();
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
case TokenType::Break:
|
||||||
|
case TokenType::Continue:
|
||||||
|
return {};
|
||||||
default:
|
default:
|
||||||
throw exception();
|
throw exception();
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,8 @@ Statement ->
|
|||||||
| If (Expr) Instruction Else Instruction
|
| If (Expr) Instruction Else Instruction
|
||||||
| While (Expr) Instruction
|
| While (Expr) Instruction
|
||||||
| For (Expr | ExprStatement; Expr; Expr) Instruction
|
| For (Expr | ExprStatement; Expr; Expr) Instruction
|
||||||
|
| Continue ;
|
||||||
|
| Break ;
|
||||||
|
|
||||||
ExprStatement ->
|
ExprStatement ->
|
||||||
| Type ParIdentifier = Expr // AssignedDeclaration
|
| Type ParIdentifier = Expr // AssignedDeclaration
|
||||||
|
@ -163,6 +163,20 @@ ParseReturn parse_statement(vector<Token> tokens) {
|
|||||||
throw ParseException();
|
throw ParseException();
|
||||||
|
|
||||||
switch (tokens.back().type) {
|
switch (tokens.back().type) {
|
||||||
|
case TokenType::Break:
|
||||||
|
case TokenType::Continue: {
|
||||||
|
Token token = tokens.back();
|
||||||
|
tokens.pop_back();
|
||||||
|
|
||||||
|
if (tokens.back().type != TokenType::Semicolon)
|
||||||
|
throw SyntaxError("Expected ';'", tokens.back().pos);
|
||||||
|
|
||||||
|
tokens.pop_back();
|
||||||
|
return {
|
||||||
|
.node=token,
|
||||||
|
.tokens=tokens
|
||||||
|
};
|
||||||
|
}
|
||||||
case TokenType::While:
|
case TokenType::While:
|
||||||
case TokenType::If: {
|
case TokenType::If: {
|
||||||
CodePosition pos = tokens.back().pos;
|
CodePosition pos = tokens.back().pos;
|
||||||
|
Loading…
Reference in New Issue
Block a user