Skip to content

Commit 8af589a

Browse files
authored
Merge pull request #50 from javecs/feature/args
2つの引数を持つ関数を呼び出す機能を追加しました。
2 parents b0e2df9 + 7a73834 commit 8af589a

12 files changed

Lines changed: 173 additions & 117 deletions

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,19 @@
122122
[asin](https://docs.oracle.com/javase/jp/8/docs/api/java/lang/Math.html#asin-double-) | 指定された値の逆正弦(アーク・サイン)を返します。| asin(1) | 1.5707963267948966
123123
[acos](https://docs.oracle.com/javase/jp/8/docs/api/java/lang/Math.html#acos-double-) | 指定された値の逆余弦(アーク・コサイン)を返します。| acos(0) | 1.5707963267948966
124124
[atan](https://docs.oracle.com/javase/jp/8/docs/api/java/lang/Math.html#atan-double-) | 指定された値の逆正接(アーク・タンジェント)を返します。| atan(1) | 0.7853981633974483
125+
[atan2](https://docs.oracle.com/javase/jp/8/docs/api/java/lang/Math.html#atan2-double-double-) | 直交座標(x, y)から極座標(r, theta)への変換から得られる角度thetaを返します。| atan2(90, 15) | 1.4056476493802699
125126
[sinh](https://docs.oracle.com/javase/jp/8/docs/api/java/lang/Math.html#sinh-double-) | double値の双曲線正弦を返します。| sinh(1) | 1.1752011936438014
126127
[cosh](https://docs.oracle.com/javase/jp/8/docs/api/java/lang/Math.html#cosh-double-) | double値の双曲線余弦を返します。| cosh(1) | 1.543080634815244
127128
[tanh](https://docs.oracle.com/javase/jp/8/docs/api/java/lang/Math.html#tanh-double-) | double値の双曲線正接を返します。| tanh(1) | 0.7615941559557649
128129
[exp](https://docs.oracle.com/javase/jp/8/docs/api/java/lang/Math.html#exp-double-) | オイラー数eをdouble値で累乗した値を返します。| exp(1) | 2.718281828459045
129130
[log](https://docs.oracle.com/javase/jp/8/docs/api/java/lang/Math.html#log-double-) | 指定されたdouble値の自然対数(底はe)を返します。| log(2) | 0.6931471805599453
130131
[log10](https://docs.oracle.com/javase/jp/8/docs/api/java/lang/Math.html#log10-double-) | double値の10を底とする対数を返します。| log10(2) | 0.3010299956639812
131132
[sqrt](https://docs.oracle.com/javase/jp/8/docs/api/java/lang/Math.html#sqrt-double-) | double値の正しく丸めた正の平方根を返します。| sqrt(2) | 0.3010299956639812
133+
[hypot](https://docs.oracle.com/javase/jp/8/docs/api/java/lang/Math.html#hypot-double-double-) | sqrt(x2 +y2)を返します(途中でオーバーフローやアンダーフローは発生しない)。| hypot(3, 4) | 5
132134
[rad](https://docs.oracle.com/javase/jp/8/docs/api/java/lang/Math.html#toRadians-double-) | 度で計測した角度を、相当するラジアンに変換します。| rad(1) | 0.017453292519943295
133135
[deg](https://docs.oracle.com/javase/jp/8/docs/api/java/lang/Math.html#toDegrees-double-) | ラジアンで計測した角度を、相当する度に変換します。| deg(1) | 57.29577951308232
136+
[max](https://docs.oracle.com/javase/jp/8/docs/api/java/lang/Math.html#max-double-double-) | 2つのdouble値のうち大きいほうを返します。| max(e, pi) | 3.141592653589793
137+
[min](https://docs.oracle.com/javase/jp/8/docs/api/java/lang/Math.html#min-double-double-) | 2つのdouble値のうち小さいほうを返します。| min(e, pi) | 2.718281828459045
134138
135139
- 関数名の文字は、大文字と小文字を区別しません。
136140

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ plugins {
1616
}
1717

1818
group 'xyz.javecs.tools'
19-
version '0.1.10'
19+
version '0.1.11'
2020

2121
apply plugin: 'kotlin'
2222
apply plugin: 'antlr'

src/main/antlr/Expr.g4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ expr: <assoc=right> expr '^' expr # Pow
1111
| expr '%' expr # Mod
1212
| expr '+' expr # Add
1313
| expr '-' expr # Sub
14-
| ID '(' expr ')' # Function
14+
| ID '(' expr (',' expr)* ')' # Function
1515
| CONSTANT # Constant
1616
| NUMBER # Number
1717
| ID # Id

src/main/java/xyz/javecs/tools/expr/parser/Expr.tokens

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ T__5=6
77
T__6=7
88
T__7=8
99
T__8=9
10-
CONSTANT=10
11-
NUMBER=11
12-
ID=12
13-
WS=13
10+
T__9=10
11+
CONSTANT=11
12+
NUMBER=12
13+
ID=13
14+
WS=14
1415
'='=1
1516
'^'=2
1617
'+'=3
@@ -19,4 +20,5 @@ WS=13
1920
'/'=6
2021
'%'=7
2122
'('=8
22-
')'=9
23+
','=9
24+
')'=10

src/main/java/xyz/javecs/tools/expr/parser/ExprLexer.java

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class ExprLexer extends Lexer {
1818
new PredictionContextCache();
1919
public static final int
2020
T__0=1, T__1=2, T__2=3, T__3=4, T__4=5, T__5=6, T__6=7, T__7=8, T__8=9,
21-
CONSTANT=10, NUMBER=11, ID=12, WS=13;
21+
T__9=10, CONSTANT=11, NUMBER=12, ID=13, WS=14;
2222
public static String[] channelNames = {
2323
"DEFAULT_TOKEN_CHANNEL", "HIDDEN"
2424
};
@@ -29,14 +29,14 @@ public class ExprLexer extends Lexer {
2929

3030
public static final String[] ruleNames = {
3131
"T__0", "T__1", "T__2", "T__3", "T__4", "T__5", "T__6", "T__7", "T__8",
32-
"CONSTANT", "NUMBER", "ID", "WS"
32+
"T__9", "CONSTANT", "NUMBER", "ID", "WS"
3333
};
3434

3535
private static final String[] _LITERAL_NAMES = {
36-
null, "'='", "'^'", "'+'", "'-'", "'*'", "'/'", "'%'", "'('", "')'"
36+
null, "'='", "'^'", "'+'", "'-'", "'*'", "'/'", "'%'", "'('", "','", "')'"
3737
};
3838
private static final String[] _SYMBOLIC_NAMES = {
39-
null, null, null, null, null, null, null, null, null, null, "CONSTANT",
39+
null, null, null, null, null, null, null, null, null, null, null, "CONSTANT",
4040
"NUMBER", "ID", "WS"
4141
};
4242
public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES);
@@ -97,28 +97,29 @@ public ExprLexer(CharStream input) {
9797
public ATN getATN() { return _ATN; }
9898

9999
public static final String _serializedATN =
100-
"\3\u608b\ua72a\u8133\ub9ed\u417c\u3be7\u7786\u5964\2\17O\b\1\4\2\t\2\4"+
100+
"\3\u608b\ua72a\u8133\ub9ed\u417c\u3be7\u7786\u5964\2\20S\b\1\4\2\t\2\4"+
101101
"\3\t\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7\4\b\t\b\4\t\t\t\4\n\t\n\4\13\t"+
102-
"\13\4\f\t\f\4\r\t\r\4\16\t\16\3\2\3\2\3\3\3\3\3\4\3\4\3\5\3\5\3\6\3\6"+
103-
"\3\7\3\7\3\b\3\b\3\t\3\t\3\n\3\n\3\13\3\13\3\13\5\13\63\n\13\3\f\6\f\66"+
104-
"\n\f\r\f\16\f\67\3\f\3\f\6\f<\n\f\r\f\16\f=\5\f@\n\f\3\r\3\r\7\rD\n\r"+
105-
"\f\r\16\rG\13\r\3\16\6\16J\n\16\r\16\16\16K\3\16\3\16\2\2\17\3\3\5\4\7"+
106-
"\5\t\6\13\7\r\b\17\t\21\n\23\13\25\f\27\r\31\16\33\17\3\2\t\4\2RRrr\4"+
107-
"\2KKkk\4\2GGgg\3\2\62;\4\2C\\c|\5\2\62;C\\c|\5\2\13\f\17\17\"\"\2T\2\3"+
108-
"\3\2\2\2\2\5\3\2\2\2\2\7\3\2\2\2\2\t\3\2\2\2\2\13\3\2\2\2\2\r\3\2\2\2"+
109-
"\2\17\3\2\2\2\2\21\3\2\2\2\2\23\3\2\2\2\2\25\3\2\2\2\2\27\3\2\2\2\2\31"+
110-
"\3\2\2\2\2\33\3\2\2\2\3\35\3\2\2\2\5\37\3\2\2\2\7!\3\2\2\2\t#\3\2\2\2"+
111-
"\13%\3\2\2\2\r\'\3\2\2\2\17)\3\2\2\2\21+\3\2\2\2\23-\3\2\2\2\25\62\3\2"+
112-
"\2\2\27\65\3\2\2\2\31A\3\2\2\2\33I\3\2\2\2\35\36\7?\2\2\36\4\3\2\2\2\37"+
113-
" \7`\2\2 \6\3\2\2\2!\"\7-\2\2\"\b\3\2\2\2#$\7/\2\2$\n\3\2\2\2%&\7,\2\2"+
114-
"&\f\3\2\2\2\'(\7\61\2\2(\16\3\2\2\2)*\7\'\2\2*\20\3\2\2\2+,\7*\2\2,\22"+
115-
"\3\2\2\2-.\7+\2\2.\24\3\2\2\2/\60\t\2\2\2\60\63\t\3\2\2\61\63\t\4\2\2"+
116-
"\62/\3\2\2\2\62\61\3\2\2\2\63\26\3\2\2\2\64\66\t\5\2\2\65\64\3\2\2\2\66"+
117-
"\67\3\2\2\2\67\65\3\2\2\2\678\3\2\2\28?\3\2\2\29;\7\60\2\2:<\t\5\2\2;"+
118-
":\3\2\2\2<=\3\2\2\2=;\3\2\2\2=>\3\2\2\2>@\3\2\2\2?9\3\2\2\2?@\3\2\2\2"+
119-
"@\30\3\2\2\2AE\t\6\2\2BD\t\7\2\2CB\3\2\2\2DG\3\2\2\2EC\3\2\2\2EF\3\2\2"+
120-
"\2F\32\3\2\2\2GE\3\2\2\2HJ\t\b\2\2IH\3\2\2\2JK\3\2\2\2KI\3\2\2\2KL\3\2"+
121-
"\2\2LM\3\2\2\2MN\b\16\2\2N\34\3\2\2\2\t\2\62\67=?EK\3\b\2\2";
102+
"\13\4\f\t\f\4\r\t\r\4\16\t\16\4\17\t\17\3\2\3\2\3\3\3\3\3\4\3\4\3\5\3"+
103+
"\5\3\6\3\6\3\7\3\7\3\b\3\b\3\t\3\t\3\n\3\n\3\13\3\13\3\f\3\f\3\f\5\f\67"+
104+
"\n\f\3\r\6\r:\n\r\r\r\16\r;\3\r\3\r\6\r@\n\r\r\r\16\rA\5\rD\n\r\3\16\3"+
105+
"\16\7\16H\n\16\f\16\16\16K\13\16\3\17\6\17N\n\17\r\17\16\17O\3\17\3\17"+
106+
"\2\2\20\3\3\5\4\7\5\t\6\13\7\r\b\17\t\21\n\23\13\25\f\27\r\31\16\33\17"+
107+
"\35\20\3\2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b\2\2ML\3\2\2\2NO\3\2\2\2OM\3\2\2\2OP\3\2\2\2PQ\3\2\2"+
122+
"\2QR\b\17\2\2R\36\3\2\2\2\t\2\66;ACIO\3\b\2\2";
122123
public static final ATN _ATN =
123124
new ATNDeserializer().deserialize(_serializedATN.toCharArray());
124125
static {

src/main/java/xyz/javecs/tools/expr/parser/ExprLexer.tokens

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ T__5=6
77
T__6=7
88
T__7=8
99
T__8=9
10-
CONSTANT=10
11-
NUMBER=11
12-
ID=12
13-
WS=13
10+
T__9=10
11+
CONSTANT=11
12+
NUMBER=12
13+
ID=13
14+
WS=14
1415
'='=1
1516
'^'=2
1617
'+'=3
@@ -19,4 +20,5 @@ WS=13
1920
'/'=6
2021
'%'=7
2122
'('=8
22-
')'=9
23+
','=9
24+
')'=10

0 commit comments

Comments
 (0)