Mercurial Hosting > luan
comparison src/luan/impl/LuanParser.java @ 1091:20d5968e65cc
add end_do, end_for, end_function, end_if, end_while
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 02 Jan 2017 21:28:30 -0700 |
parents | 894786a03d22 |
children | a656fa45e315 |
comparison
equal
deleted
inserted
replaced
1090:616761e0b9f6 | 1091:20d5968e65cc |
---|---|
508 stmt.addAll( makeLocalSetStmt(names,fnExp) ); | 508 stmt.addAll( makeLocalSetStmt(names,fnExp) ); |
509 stmt.add( "if( " ); | 509 stmt.add( "if( " ); |
510 stmt.addAll( nameVar(names.get(0)).exp() ); | 510 stmt.addAll( nameVar(names.get(0)).exp() ); |
511 stmt.add( "==null ) break; " ); | 511 stmt.add( "==null ) break; " ); |
512 Stmts loop = RequiredLoopBlock(); | 512 Stmts loop = RequiredLoopBlock(); |
513 RequiredKeyword("end"); | 513 RequiredEnd("end_for"); |
514 stmt.addAll( loop ); | 514 stmt.addAll( loop ); |
515 stmt.add( "} " ); | 515 stmt.add( "} " ); |
516 popSymbols( symbolsSize() - stackStart ); | 516 popSymbols( symbolsSize() - stackStart ); |
517 return parser.success(stmt); | 517 return parser.success(stmt); |
518 } | 518 } |
520 private Stmts DoStmt() throws ParseException { | 520 private Stmts DoStmt() throws ParseException { |
521 parser.begin(); | 521 parser.begin(); |
522 if( !Keyword("do") ) | 522 if( !Keyword("do") ) |
523 return parser.failure(null); | 523 return parser.failure(null); |
524 Stmts stmt = RequiredBlock(); | 524 Stmts stmt = RequiredBlock(); |
525 RequiredKeyword("end"); | 525 RequiredEnd("end_do"); |
526 return parser.success(stmt); | 526 return parser.success(stmt); |
527 } | 527 } |
528 | 528 |
529 private Stmts LocalStmt() throws ParseException { | 529 private Stmts LocalStmt() throws ParseException { |
530 parser.begin(); | 530 parser.begin(); |
589 if( !Keyword("while") ) | 589 if( !Keyword("while") ) |
590 return parser.failure(null); | 590 return parser.failure(null); |
591 Expr cnd = RequiredExpr(In.NOTHING).single(); | 591 Expr cnd = RequiredExpr(In.NOTHING).single(); |
592 RequiredKeyword("do"); | 592 RequiredKeyword("do"); |
593 Stmts loop = RequiredLoopBlock(); | 593 Stmts loop = RequiredLoopBlock(); |
594 RequiredKeyword("end"); | 594 RequiredEnd("end_while"); |
595 Stmts stmt = new Stmts(); | 595 Stmts stmt = new Stmts(); |
596 stmt.add( "while( Luan.checkBoolean(" ); | 596 stmt.add( "while( Luan.checkBoolean(" ); |
597 stmt.addAll( cnd ); | 597 stmt.addAll( cnd ); |
598 stmt.add( ") ) { " ); | 598 stmt.add( ") ) { " ); |
599 stmt.addAll( loop ); | 599 stmt.addAll( loop ); |
659 if( !block.hasReturn ) | 659 if( !block.hasReturn ) |
660 hasReturn = false; | 660 hasReturn = false; |
661 } else { | 661 } else { |
662 hasReturn = false; | 662 hasReturn = false; |
663 } | 663 } |
664 RequiredKeyword("end"); | 664 RequiredEnd("end_if"); |
665 stmt.add( "} " ); | 665 stmt.add( "} " ); |
666 stmt.hasReturn = hasReturn; | 666 stmt.hasReturn = hasReturn; |
667 return parser.success( stmt ); | 667 return parser.success( stmt ); |
668 } | 668 } |
669 | 669 |
1109 Spaces(); | 1109 Spaces(); |
1110 Stmts block = RequiredBlock(); | 1110 Stmts block = RequiredBlock(); |
1111 stmt.addAll( block ); | 1111 stmt.addAll( block ); |
1112 stmt.hasReturn = block.hasReturn; | 1112 stmt.hasReturn = block.hasReturn; |
1113 Expr fnDef = newFnExp(stmt,name); | 1113 Expr fnDef = newFnExp(stmt,name); |
1114 RequiredKeyword("end"); | 1114 RequiredEnd("end_function"); |
1115 frame = frame.parent; | 1115 frame = frame.parent; |
1116 return parser.success(fnDef); | 1116 return parser.success(fnDef); |
1117 } | 1117 } |
1118 | 1118 |
1119 private Expr VarArgs() throws ParseException { | 1119 private Expr VarArgs() throws ParseException { |
1456 private void RequiredMatch(String s) throws ParseException { | 1456 private void RequiredMatch(String s) throws ParseException { |
1457 if( !parser.match(s) ) | 1457 if( !parser.match(s) ) |
1458 throw parser.exception("'"+s+"' expected"); | 1458 throw parser.exception("'"+s+"' expected"); |
1459 } | 1459 } |
1460 | 1460 |
1461 private void RequiredEnd(String keyword) throws ParseException { | |
1462 if( !Keyword("end") && !Keyword(keyword) ) | |
1463 throw parser.exception("'"+keyword+"' or 'end' expected"); | |
1464 } | |
1465 | |
1461 private void RequiredKeyword(String keyword) throws ParseException { | 1466 private void RequiredKeyword(String keyword) throws ParseException { |
1462 if( !Keyword(keyword) ) | 1467 if( !Keyword(keyword) ) |
1463 throw parser.exception("'"+keyword+"' expected"); | 1468 throw parser.exception("'"+keyword+"' expected"); |
1464 } | 1469 } |
1465 | 1470 |
1476 "break", | 1481 "break", |
1477 "do", | 1482 "do", |
1478 "else", | 1483 "else", |
1479 "elseif", | 1484 "elseif", |
1480 "end", | 1485 "end", |
1486 "end_do", | |
1487 "end_for", | |
1488 "end_function", | |
1489 "end_if", | |
1490 "end_while", | |
1481 "false", | 1491 "false", |
1482 "for", | 1492 "for", |
1483 "function", | 1493 "function", |
1484 "goto", | 1494 "goto", |
1485 "if", | 1495 "if", |