X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;ds=sidebyside;f=source%2Fprogramparser.cpp;h=393936624556df0a0c9fe5b2fef6a8576a1f5b0c;hb=ca52c492bd4f2fa1a1db3a85e50eaf7c43474830;hp=b607e1cfb8f063abfec2127b7c57247809677a81;hpb=9339ae44a89f295523b6c25681d87642767864c4;p=libs%2Fgl.git diff --git a/source/programparser.cpp b/source/programparser.cpp index b607e1cf..39393662 100644 --- a/source/programparser.cpp +++ b/source/programparser.cpp @@ -3,6 +3,8 @@ #include #include "programparser.h" +#undef interface + using namespace std; namespace Msp { @@ -110,7 +112,7 @@ void ProgramParser::parse_source() source_end = source.end(); current_line = 1; allow_preprocess = true; - while(RefPtr statement = parse_global_declaration()) + while(RefPtr statement = parse_global_declaration()) cur_stage->content.body.push_back(statement); } @@ -424,7 +426,7 @@ void ProgramParser::preprocess_stage() cur_stage = &module->stages.back(); } -RefPtr ProgramParser::parse_global_declaration() +RefPtr ProgramParser::parse_global_declaration() { allow_stage_change = true; string token = peek_token(); @@ -478,13 +480,15 @@ RefPtr ProgramParser::parse_global_declaration() throw runtime_error(format_syntax_error("a global declaration")); } -RefPtr ProgramParser::parse_statement() +RefPtr ProgramParser::parse_statement() { string token = peek_token(); if(token=="if") return parse_conditional(); else if(token=="for") - return parse_iteration(); + return parse_for(); + else if(token=="while") + return parse_while(); else if(token=="passthrough") return parse_passthrough(); else if(token=="return") @@ -518,7 +522,7 @@ RefPtr ProgramParser::parse_import() expect("import"); RefPtr import = new Import; - import->module = parse_token(); + import->module = expect_identifier(); expect(";"); return import; } @@ -843,7 +847,7 @@ RefPtr ProgramParser::parse_conditional() return cond; } -RefPtr ProgramParser::parse_iteration() +RefPtr ProgramParser::parse_for() { expect("for"); expect("("); @@ -873,6 +877,19 @@ RefPtr ProgramParser::parse_iteration() return loop; } +RefPtr ProgramParser::parse_while() +{ + expect("while"); + expect("("); + RefPtr loop = new Iteration; + loop->condition = parse_expression(); + expect(")"); + + parse_block(loop->body, false); + + return loop; +} + RefPtr ProgramParser::parse_passthrough() { expect("passthrough");