X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fprogramparser.cpp;h=c02adb325c25eaba6d4df7f31d9b8963506a5cd4;hp=3b87ea7b58b1a2a16c1a09d3cd6432c53009d73f;hb=ff85f90d33023d908c534b0bf5d9a65e9fc2cce2;hpb=f141ae14619bfbd51a7e6871c55edbdd17ac3417 diff --git a/source/programparser.cpp b/source/programparser.cpp index 3b87ea7b..c02adb32 100644 --- a/source/programparser.cpp +++ b/source/programparser.cpp @@ -484,7 +484,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 +845,7 @@ RefPtr ProgramParser::parse_conditional() return cond; } -RefPtr ProgramParser::parse_iteration() +RefPtr ProgramParser::parse_for() { expect("for"); expect("("); @@ -853,14 +855,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);