pora na 300+

This commit is contained in:
bronku 2025-11-30 11:41:42 +01:00
parent 878dfe74e0
commit a2fb31ab5a
5 changed files with 27 additions and 5 deletions

View file

@ -67,6 +67,22 @@ struct Pass : Stmt
}
};
struct Break : Stmt
{
std::string dump(int indent = 0) const override
{
return indent_str(indent) + "Break";
}
};
struct Continue : Stmt
{
std::string dump(int indent = 0) const override
{
return indent_str(indent) + "Continue";
}
};
// #todo elif
struct If : Stmt
{

View file

@ -50,6 +50,8 @@ else { return yy::parser::token::TOK_KW_ELSE; }
elif { return yy::parser::token::TOK_KW_ELIF; }
class { return yy::parser::token::TOK_KW_CLASS; }
while { return yy::parser::token::TOK_KW_WHILE; }
break { return yy::parser::token::TOK_KW_BREAK; }
continue { return yy::parser::token::TOK_KW_CONTINUE; }
\=\= { return yy::parser::token::TOK_EQ; }
\!\= { return yy::parser::token::TOK_NE; }

View file

@ -32,7 +32,7 @@
%left KW_OR
%left KW_AND
%right KW_NOT // unary logical NOT
%token KW_DEF KW_IF KW_RETURN KW_FOR KW_IN KW_PASS KW_ELSE KW_ELIF KW_CLASS KW_WHILE
%token KW_DEF KW_IF KW_RETURN KW_FOR KW_IN KW_PASS KW_ELSE KW_ELIF KW_CLASS KW_WHILE KW_BREAK KW_CONTINUE
%token L_PAREN R_PAREN L_BRACKET R_BRACKET L_BRACE R_BRACE
%token DOT COLON SEMICOLON COMMA
@ -100,6 +100,12 @@ stmt:
| KW_PASS NEWLINE {
$$ = std::make_unique<Pass>();
}
| KW_BREAK NEWLINE {
$$ = std::make_unique<Break>();
}
| KW_CONTINUE NEWLINE {
$$ = std::make_unique<Continue>();
}
| KW_WHILE expr COLON NEWLINE INDENT stmt_list DEDENT {
$$ = std::make_unique<While>(std::move($2), std::move($6));
}