diff options
Diffstat (limited to 'source/parse.cpp')
-rw-r--r-- | source/parse.cpp | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/source/parse.cpp b/source/parse.cpp index cebf702..6f68c84 100644 --- a/source/parse.cpp +++ b/source/parse.cpp @@ -22,31 +22,38 @@ #include <cctype> #include <cstdlib> -static void parseword(const char *start, const char *end) +[[nodiscard]] +static Error parseword(const char *start, const char *end) { + auto result = Error::none; + if (start != end) { if (auto word = find(start, end - start); word) { if (!word->immediate() && STATE) { comma((Cell)word->list); } else { - execute1(word); + result = execute1(word); } } else if (isdigit(*start)) { - *++SP = std::atoi(start); + push(std::atoi(start)); if (STATE) compileliteral(); } } + + return result; } -void parseSource() +[[nodiscard]] +static Error parseSource() { + auto result = Error::none; char *start = nullptr; char *end; char *s; - while (haskey()) { + while (result == Error::none && haskey()) { s = (char *)DICT[DIdxSource]; ++DICT[DIdxSource]; @@ -54,7 +61,7 @@ void parseSource() if (isspace(*s)) { if (start) { - parseword(start, end + 1); + result = parseword(start, end + 1); start = nullptr; } } else { @@ -69,16 +76,19 @@ void parseSource() // Parse the final word if it is non-empty. if (start) - parseword(start, s + 1); + result = parseword(start, s + 1); + + return result; } -void parse() +[[nodiscard]] +Error parse() { // Reset source buffer and try to fill it with getinput(). DICT[DIdxSource] = (Cell)&DICT[DIdxBegin]; DICT[DIdxSrcLen] = 0; getinput(); - parseSource(); + return parseSource(); } |