diff options
| -rw-r--r-- | AGENTS/PITFALLS.md | 2 | ||||
| -rw-r--r-- | lib/Parser/ParserControlFlow.cc | 2 | ||||
| -rw-r--r-- | tests/i/while-do/case.json | 1 | ||||
| -rw-r--r-- | tests/i/while-do/expected.txt | 1 | ||||
| -rw-r--r-- | tests/i/while-do/notes.md | 3 | ||||
| -rw-r--r-- | tests/i/while-do/program.cps | 6 | ||||
| -rw-r--r-- | tests/iii/while-do-rejected/case.json | 8 | ||||
| -rw-r--r-- | tests/iii/while-do-rejected/notes.md | 3 | ||||
| -rw-r--r-- | tests/iii/while-do-rejected/program.cps | 3 |
9 files changed, 14 insertions, 15 deletions
diff --git a/AGENTS/PITFALLS.md b/AGENTS/PITFALLS.md index bae6bd3..ec5d034 100644 --- a/AGENTS/PITFALLS.md +++ b/AGENTS/PITFALLS.md @@ -119,4 +119,4 @@ NEW and class inheritance. Compiler fixtures now live in `tests/` (see TESTING.m Nightly CI runs the compiler suites, packaged EMBEDDED smoke checks and existing plugin tests. The initial standard conflicts and missing diagnostic locations are fixed on Linux. -WHILE uses the standard header without DO; old WHILE DO programs must be migrated. +WHILE accepts both the standard header without DO and the older WHILE DO form. diff --git a/lib/Parser/ParserControlFlow.cc b/lib/Parser/ParserControlFlow.cc index afa8bd8..1cbedcd 100644 --- a/lib/Parser/ParserControlFlow.cc +++ b/lib/Parser/ParserControlFlow.cc @@ -54,6 +54,8 @@ std::unique_ptr<StmtAST> Parser::ParseWhileStmt() { auto Cond = ParseExpression(); if (!Cond) return nullptr; + if (CurTok == tok_identifier && Lex.IdentifierStr == "DO") getNextToken(); + std::vector<std::unique_ptr<StmtAST>> Body = ParseBlock({tok_endwhile}); if (CurTok != tok_endwhile) { diff --git a/tests/i/while-do/case.json b/tests/i/while-do/case.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/tests/i/while-do/case.json @@ -0,0 +1 @@ +{} diff --git a/tests/i/while-do/expected.txt b/tests/i/while-do/expected.txt new file mode 100644 index 0000000..0cfbf08 --- /dev/null +++ b/tests/i/while-do/expected.txt @@ -0,0 +1 @@ +2 diff --git a/tests/i/while-do/notes.md b/tests/i/while-do/notes.md new file mode 100644 index 0000000..01e389c --- /dev/null +++ b/tests/i/while-do/notes.md @@ -0,0 +1,3 @@ +# while-do + +The legacy WHILE DO spelling and the standard WHILE spelling are both accepted. X advances from 0 through 1 to 2, then the loop stops. diff --git a/tests/i/while-do/program.cps b/tests/i/while-do/program.cps new file mode 100644 index 0000000..58d6319 --- /dev/null +++ b/tests/i/while-do/program.cps @@ -0,0 +1,6 @@ +DECLARE X : INTEGER +X <- 0 +WHILE X < 2 DO + X <- X + 1 +ENDWHILE +OUTPUT X diff --git a/tests/iii/while-do-rejected/case.json b/tests/iii/while-do-rejected/case.json deleted file mode 100644 index 9908d5e..0000000 --- a/tests/iii/while-do-rejected/case.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "errors": [ - { - "reason": "Expected\\ '<\\-'\\ after\\ identifier\\ 'DO'", - "line": 1 - } - ] -} diff --git a/tests/iii/while-do-rejected/notes.md b/tests/iii/while-do-rejected/notes.md deleted file mode 100644 index ed669b5..0000000 --- a/tests/iii/while-do-rejected/notes.md +++ /dev/null @@ -1,3 +0,0 @@ -# while-do-rejected - -The compiler must reject this program: Expected '<-' after identifier 'DO'. The diagnostic must identify line 1; compilation must preserve existing output. diff --git a/tests/iii/while-do-rejected/program.cps b/tests/iii/while-do-rejected/program.cps deleted file mode 100644 index b733e21..0000000 --- a/tests/iii/while-do-rejected/program.cps +++ /dev/null @@ -1,3 +0,0 @@ -WHILE FALSE DO - OUTPUT 1 -ENDWHILE |
