diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2015-02-16 16:33:32 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2015-02-16 16:33:32 -0800 |
commit | fdd732fb4d7196b3b0ca094193d837243975ca9f (patch) | |
tree | 72f865bff8b816a0d349fcb7e84eff91f3eb5c5d | |
parent | 61c46db282f0539aba78375788e38848c3bbd8d1 (diff) | |
download | mu-fdd732fb4d7196b3b0ca094193d837243975ca9f.tar.gz |
766 - can recognize first word 'recipe'
-rw-r--r-- | cpp/002main.cc | 30 | ||||
-rw-r--r-- | cpp/002main.test.cc | 2 |
2 files changed, 31 insertions, 1 deletions
diff --git a/cpp/002main.cc b/cpp/002main.cc index c2baea50..cb0ed411 100644 --- a/cpp/002main.cc +++ b/cpp/002main.cc @@ -142,6 +142,36 @@ void setup_types() { } void compile(string form) { + istringstream in(form); + in >> std::noskipws; + if (next_word(in) != "recipe") + RAISE << "top-level forms must be of the form 'recipe _name_ [ _instruction_ ... ]'"; +} + +string next_word(istream& in) { + ostringstream out; + skip_whitespace(in); + slurp_word(in, out); +//? cout << out.str() << '\n'; //? 1 + return out.str(); +} + +void slurp_word(istream& in, ostream& out) { + char c; + while (in >> c) { +//? cout << c << '\n'; //? 1 + if (isspace(c)) { +//? cout << " space\n"; //? 1 + in.putback(c); + break; + } + out << c; + } +} + +void skip_whitespace(istream& in) { + while (isspace(in.peek()) && in.peek() != '\n') + in.get(); } diff --git a/cpp/002main.test.cc b/cpp/002main.test.cc index b622828b..1f77ab39 100644 --- a/cpp/002main.test.cc +++ b/cpp/002main.test.cc @@ -1,5 +1,5 @@ void test_literal() { - compile("function main [\n" + compile("recipe main [\n" " 1:integer <- copy 23:literal\n" "]\n"); run("main"); |