Mercurial Hosting > luan
comparison src/luan/impl/LuanParser.java @ 1681:6061be2cd84b
minor
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Fri, 03 Jun 2022 09:17:21 -0600 |
parents | 9ef19f5ea973 |
children | 842a0e0fd8c5 |
comparison
equal
deleted
inserted
replaced
1680:9ef19f5ea973 | 1681:6061be2cd84b |
---|---|
1010 private boolean Minus() { | 1010 private boolean Minus() { |
1011 parser.begin(); | 1011 parser.begin(); |
1012 return parser.match('-') && !parser.match('-') ? parser.success() : parser.failure(); | 1012 return parser.match('-') && !parser.match('-') ? parser.success() : parser.failure(); |
1013 } | 1013 } |
1014 | 1014 |
1015 private Expr TermExpr(Expr exp,String op) throws ParseException { | |
1016 Spaces(); | |
1017 exp = exp.single(); | |
1018 Expr exp2 = required(UnaryExpr()).single(); | |
1019 Expr newExp = new Expr(Val.SINGLE,false); | |
1020 newExp.add( "LuanImpl." + op + "(luan," ); | |
1021 newExp.addAll( exp ); | |
1022 newExp.add( "," ); | |
1023 newExp.addAll( exp2 ); | |
1024 newExp.add( ")" ); | |
1025 return newExp; | |
1026 } | |
1027 | |
1015 private Expr TermExpr() throws ParseException { | 1028 private Expr TermExpr() throws ParseException { |
1016 parser.begin(); | 1029 parser.begin(); |
1017 Expr exp = UnaryExpr(); | 1030 Expr exp = UnaryExpr(); |
1018 if( exp==null ) | 1031 if( exp==null ) |
1019 return parser.failure(null); | 1032 return parser.failure(null); |
1020 while(true) { | 1033 while(true) { |
1021 if( parser.match('*') ) { | 1034 if( parser.match('*') ) { |
1022 Spaces(); | 1035 exp = TermExpr(exp,"mul"); |
1023 exp = exp.single(); | |
1024 Expr exp2 = required(UnaryExpr()).single(); | |
1025 Expr newExp = new Expr(Val.SINGLE,false); | |
1026 newExp.add( "LuanImpl.mul(luan," ); | |
1027 newExp.addAll( exp ); | |
1028 newExp.add( "," ); | |
1029 newExp.addAll( exp2 ); | |
1030 newExp.add( ")" ); | |
1031 exp = newExp; | |
1032 } else if( parser.match('/') ) { | 1036 } else if( parser.match('/') ) { |
1033 if( parser.match('/') ) { | 1037 if( parser.match('/') ) { |
1034 Spaces(); | 1038 exp = TermExpr(exp,"idiv"); |
1035 exp = exp.single(); | |
1036 Expr exp2 = required(UnaryExpr()).single(); | |
1037 Expr newExp = new Expr(Val.SINGLE,false); | |
1038 newExp.add( "LuanImpl.idiv(luan," ); | |
1039 newExp.addAll( exp ); | |
1040 newExp.add( "," ); | |
1041 newExp.addAll( exp2 ); | |
1042 newExp.add( ")" ); | |
1043 exp = newExp; | |
1044 } else { | 1039 } else { |
1045 Spaces(); | 1040 exp = TermExpr(exp,"div"); |
1046 exp = exp.single(); | |
1047 Expr exp2 = required(UnaryExpr()).single(); | |
1048 Expr newExp = new Expr(Val.SINGLE,false); | |
1049 newExp.add( "LuanImpl.div(luan," ); | |
1050 newExp.addAll( exp ); | |
1051 newExp.add( "," ); | |
1052 newExp.addAll( exp2 ); | |
1053 newExp.add( ")" ); | |
1054 exp = newExp; | |
1055 } | 1041 } |
1056 } else if( Mod() ) { | 1042 } else if( Mod() ) { |
1057 Spaces(); | 1043 exp = TermExpr(exp,"mod"); |
1058 exp = exp.single(); | |
1059 Expr exp2 = required(UnaryExpr()).single(); | |
1060 Expr newExp = new Expr(Val.SINGLE,false); | |
1061 newExp.add( "LuanImpl.mod(luan," ); | |
1062 newExp.addAll( exp ); | |
1063 newExp.add( "," ); | |
1064 newExp.addAll( exp2 ); | |
1065 newExp.add( ")" ); | |
1066 exp = newExp; | |
1067 } else | 1044 } else |
1068 break; | 1045 break; |
1069 } | 1046 } |
1070 return parser.success(exp); | 1047 return parser.success(exp); |
1071 } | 1048 } |