comparison src/luan/interp/LuaParser.java @ 42:786699c78837

implement try-catch git-svn-id: https://luan-java.googlecode.com/svn/trunk@43 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Sun, 23 Dec 2012 06:36:56 +0000
parents e3624b7cd603
children 57054fa43189
comparison
equal deleted inserted replaced
41:c53dc854e6cc 42:786699c78837
221 FunctionStmt(), 221 FunctionStmt(),
222 LocalFunctionStmt(), 222 LocalFunctionStmt(),
223 BreakStmt(), 223 BreakStmt(),
224 GenericForStmt(), 224 GenericForStmt(),
225 NumericForStmt(), 225 NumericForStmt(),
226 TryStmt(),
226 DoStmt(), 227 DoStmt(),
227 WhileStmt(), 228 WhileStmt(),
228 RepeatStmt(), 229 RepeatStmt(),
229 IfStmt(), 230 IfStmt(),
230 SetStmt(), 231 SetStmt(),
310 Expr() 311 Expr()
311 ), 312 ),
312 addSymbol( (String)pop(3) ), // add "for" var to symbols 313 addSymbol( (String)pop(3) ), // add "for" var to symbols
313 Keyword("do"), LoopBlock(), Keyword("end"), 314 Keyword("do"), LoopBlock(), Keyword("end"),
314 push( new NumericForStmt( se(start.get()), symbolsSize()-1, expr(pop(3)), expr(pop(2)), expr(pop(1)), (Stmt)pop() ) ), 315 push( new NumericForStmt( se(start.get()), symbolsSize()-1, expr(pop(3)), expr(pop(2)), expr(pop(1)), (Stmt)pop() ) ),
316 popSymbols(1)
317 );
318 }
319
320 Rule TryStmt() {
321 return Sequence(
322 Keyword("try"), Block(),
323 Keyword("catch"), Name(), addSymbol( (String)pop() ),
324 Keyword("do"), Block(), Keyword("end"),
325 push( new TryStmt( (Stmt)pop(1), symbolsSize()-1, (Stmt)pop() ) ),
315 popSymbols(1) 326 popSymbols(1)
316 ); 327 );
317 } 328 }
318 329
319 Rule DoStmt() { 330 Rule DoStmt() {
825 } 836 }
826 837
827 static final Set<String> keywords = new HashSet<String>(Arrays.asList( 838 static final Set<String> keywords = new HashSet<String>(Arrays.asList(
828 "and", 839 "and",
829 "break", 840 "break",
841 "catch",
830 "do", 842 "do",
831 "else", 843 "else",
832 "elseif", 844 "elseif",
833 "end", 845 "end",
834 "false", 846 "false",
845 "return", 857 "return",
846 "step", 858 "step",
847 "then", 859 "then",
848 "to", 860 "to",
849 "true", 861 "true",
862 "try",
850 "until", 863 "until",
851 "while" 864 "while"
852 )); 865 ));
853 866
854 Rule LiteralExpr() { 867 Rule LiteralExpr() {