forked from PuqiAR/Fig-TreeWalker
feat: implement for-loops with proper scope management
- Add support for C-style for loops: for (init; condition; increment) { body }
- Implement three-level scoping: loop context + per-iteration contexts
- Add semicolon disabler for increment statements using RAII guards
- Support break/continue/return control flow with scope validation
- Fix semicolon handling in parser for flexible for-loop syntax
This commit is contained in:
30
include/Ast/ForSt.hpp
Normal file
30
include/Ast/ForSt.hpp
Normal file
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#include <Ast/astBase.hpp>
|
||||
|
||||
namespace Fig::Ast
|
||||
{
|
||||
class ForSt final : public StatementAst
|
||||
{
|
||||
public:
|
||||
Statement initSt;
|
||||
Expression condition;
|
||||
Statement incrementSt;
|
||||
BlockStatement body;
|
||||
|
||||
ForSt()
|
||||
{
|
||||
type = AstType::ForSt;
|
||||
}
|
||||
ForSt(Statement _initSt, Expression _condition, Statement _incrementSt, BlockStatement _body) :
|
||||
initSt(std::move(_initSt)),
|
||||
condition(std::move(_condition)),
|
||||
incrementSt(std::move(_incrementSt)),
|
||||
body(std::move(_body))
|
||||
{
|
||||
type = AstType::ForSt;
|
||||
}
|
||||
};
|
||||
|
||||
using For = std::shared_ptr<ForSt>;
|
||||
};
|
||||
@@ -47,6 +47,7 @@ namespace Fig::Ast
|
||||
|
||||
VarAssignSt,
|
||||
WhileSt,
|
||||
ForSt,
|
||||
ReturnSt,
|
||||
BreakSt,
|
||||
ContinueSt,
|
||||
|
||||
Reference in New Issue
Block a user