X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fprogramparser.cpp;h=4f08b97718d26afe4ab1b41b60af3ee5f737d70b;hp=b3a226fc98c55d2d9ceed2f39e9e498b4c68a71a;hb=d901696935a6bf9fdad6ac8abe65ffab79bd297d;hpb=11520b2b95f4242b3ca4d2d3d14a0f2b5c1623f1 diff --git a/source/programparser.cpp b/source/programparser.cpp index b3a226fc..4f08b977 100644 --- a/source/programparser.cpp +++ b/source/programparser.cpp @@ -3,6 +3,8 @@ #include #include "programparser.h" +#undef interface + using namespace std; namespace Msp { @@ -263,7 +265,7 @@ void ProgramParser::skip_comment_and_whitespace() { if(*iter=='/') comment = 0; - else + else if(*iter!='*') comment = 3; } @@ -315,7 +317,7 @@ bool ProgramParser::is_interface_qualifier(const string &token) bool ProgramParser::is_sampling_qualifier(const string &token) { - return token=="centroid"; + return (token=="centroid" || token=="sample"); } bool ProgramParser::is_interpolation_qualifier(const string &token) @@ -484,7 +486,9 @@ RefPtr ProgramParser::parse_statement() 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") @@ -843,7 +847,7 @@ RefPtr ProgramParser::parse_conditional() return cond; } -RefPtr ProgramParser::parse_iteration() +RefPtr ProgramParser::parse_for() { expect("for"); expect("("); @@ -853,14 +857,32 @@ RefPtr ProgramParser::parse_iteration() loop->init_statement = parse_statement(); else { - RefPtr expr = new ExpressionStatement; - expr->expression = parse_expression(); + if(token!=";") + { + RefPtr expr = new ExpressionStatement; + expr->expression = parse_expression(); + loop->init_statement = expr; + } expect(";"); - loop->init_statement = expr; } - loop->condition = parse_expression(); + if(peek_token()!=";") + loop->condition = parse_expression(); expect(";"); - loop->loop_expression = parse_expression(); + if(peek_token()!=")") + loop->loop_expression = parse_expression(); + expect(")"); + + parse_block(loop->body, false); + + return loop; +} + +RefPtr ProgramParser::parse_while() +{ + expect("while"); + expect("("); + RefPtr loop = new Iteration; + loop->condition = parse_expression(); expect(")"); parse_block(loop->body, false);