From 0c0eee435482df5e58634cf7d26e3016bba4cf12 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Tue, 17 Feb 2015 13:28:28 -0800 Subject: 772 --- cpp/002main.cc | 12 +++++++++++- cpp/002main.test.cc | 15 +++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/cpp/002main.cc b/cpp/002main.cc index 0eaea16a..ec03cf45 100644 --- a/cpp/002main.cc +++ b/cpp/002main.cc @@ -165,7 +165,9 @@ void setup_types() { } void setup_recipes() { - Recipe.clear(); Recipe_number.clear(); Next_recipe_number = 1; + Recipe.clear(); Recipe_number.clear(); + Recipe_number["idle"] = 0; + Next_recipe_number = 1; Recipe_number["copy"] = Next_recipe_number++; //? dbg << "AAA " << Recipe_number["copy"] << '\n'; //? 1 } @@ -220,6 +222,14 @@ bool next_instruction(istream& in, instruction* curr) { //? cout << '\n'; //? 1 //? return true; //? 1 + if (words.size() == 1 && *(words[0].end()-1) == ':') { + curr->is_label = true; + words[0].erase(words[0].end()-1); + curr->label = words[0]; + trace("parse") << "label: " << curr->label; + return !in.eof(); + } + vector::iterator p = words.begin(); if (find(words.begin(), words.end(), "<-") != words.end()) { //? cout << "instruction yields products\n"; //? 1 diff --git a/cpp/002main.test.cc b/cpp/002main.test.cc index 52db64bb..cc14762a 100644 --- a/cpp/002main.test.cc +++ b/cpp/002main.test.cc @@ -21,6 +21,21 @@ void test_parse() { CHECK_EQ(i->products[0].properties.size(), 0); } +void test_parse_label() { + compile("recipe main [\n" + " foo:\n" + "]\n"); + cout << '\n'; DUMP("parse"); + CHECK(Recipe_number.find("main") != Recipe_number.end()); + recipe r = Recipe[Recipe_number["main"]]; + vector::iterator i = r.step.begin(); + CHECK_EQ(i->is_label, true); + CHECK_EQ(i->label, string("foo")); + CHECK_EQ(i->operation, 0); + CHECK_EQ(i->ingredients.size(), 0); + CHECK_EQ(i->products.size(), 0); +} + void test_parse2() { compile("recipe main [\n" " 1:integer, 2:integer <- copy 23:literal\n" -- cgit 1.4.1-2-gfad0