comparison src/luan/interp/LuaParser.java @ 8:8896068e0a4b

finish operators git-svn-id: https://luan-java.googlecode.com/svn/trunk@9 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Wed, 21 Nov 2012 06:57:09 +0000
parents bca8fc5d928b
children 600676034a1a
comparison
equal deleted inserted replaced
7:bca8fc5d928b 8:8896068e0a4b
36 ); 36 );
37 } 37 }
38 38
39 Rule RelExpr() { 39 Rule RelExpr() {
40 return Sequence( 40 return Sequence(
41 ConcatExpr(),
42 ZeroOrMore(
43 FirstOf(
44 Sequence( "==", Spaces(), ConcatExpr(), push( new EqExpr((Expr)pop(1),(Expr)pop()) ) ),
45 Sequence( "~=", Spaces(), ConcatExpr(), push( new NotExpr(new EqExpr((Expr)pop(1),(Expr)pop())) ) ),
46 Sequence( "<=", Spaces(), ConcatExpr(), push( new LeExpr((Expr)pop(1),(Expr)pop()) ) ),
47 Sequence( ">=", Spaces(), ConcatExpr(), push( new LeExpr((Expr)pop(),(Expr)pop()) ) ),
48 Sequence( "<", Spaces(), ConcatExpr(), push( new LtExpr((Expr)pop(1),(Expr)pop()) ) ),
49 Sequence( ">", Spaces(), ConcatExpr(), push( new LtExpr((Expr)pop(),(Expr)pop()) ) )
50 )
51 )
52 );
53 }
54
55 Rule ConcatExpr() {
56 return Sequence(
41 SumExpr(), 57 SumExpr(),
42 ZeroOrMore( 58 Optional( "..", Spaces(), ConcatExpr(), push( new ConcatExpr((Expr)pop(1),(Expr)pop()) ) )
43 FirstOf(
44 Sequence( "==", Spaces(), SumExpr(), push( new EqExpr((Expr)pop(1),(Expr)pop()) ) ),
45 Sequence( "~=", Spaces(), SumExpr(), push( new NotExpr(new EqExpr((Expr)pop(1),(Expr)pop())) ) )
46 )
47 )
48 ); 59 );
49 } 60 }
50 61
51 Rule SumExpr() { 62 Rule SumExpr() {
52 return Sequence( 63 return Sequence(
73 ); 84 );
74 } 85 }
75 86
76 Rule UnaryExpr() { 87 Rule UnaryExpr() {
77 return FirstOf( 88 return FirstOf(
78 Sequence( '#', Spaces(), SingleExpr(), push( new LenExpr((Expr)pop()) ) ), 89 Sequence( '#', Spaces(), PowExpr(), push( new LenExpr((Expr)pop()) ) ),
79 Sequence( '-', Spaces(), SingleExpr(), push( new UnmExpr((Expr)pop()) ) ), 90 Sequence( '-', Spaces(), PowExpr(), push( new UnmExpr((Expr)pop()) ) ),
80 Sequence( "not", Spaces(), SingleExpr(), push( new NotExpr((Expr)pop()) ) ), 91 Sequence( "not", Spaces(), PowExpr(), push( new NotExpr((Expr)pop()) ) ),
81 SingleExpr() 92 PowExpr()
93 );
94 }
95
96 Rule PowExpr() {
97 return Sequence(
98 SingleExpr(),
99 Optional( '^', Spaces(), PowExpr(), push( new PowExpr((Expr)pop(1),(Expr)pop()) ) )
82 ); 100 );
83 } 101 }
84 102
85 Rule SingleExpr() { 103 Rule SingleExpr() {
86 return FirstOf( 104 return FirstOf(