Révision | 01562859d7ed3aedc7724311e52bdd3c7e94c8cc (tree) |
---|---|
l'heure | 2015-11-09 06:13:04 |
Auteur | MirrgieRiana |
Commiter | MirrgieRiana |
fix: (test.libr).location; add: TNodesWS2.Variable
@@ -162,33 +162,10 @@ | ||
162 | 162 | |
163 | 163 | } |
164 | 164 | |
165 | - public static class TokenIdentifier extends TNodeBase implements IExpression | |
165 | + public static class TokenIdentifier extends TNodeBase | |
166 | 166 | { |
167 | 167 | |
168 | 168 | public Identifier node; |
169 | - public int index; | |
170 | - | |
171 | - @Override | |
172 | - public boolean validate(ArgumentsValidateWS2 argumentsValidate) | |
173 | - { | |
174 | - String name = node.string.string; | |
175 | - | |
176 | - Integer index2 = argumentsValidate.stackFrameRoot.getStackFrame().getVariableIndex(name); | |
177 | - if (index2 == null) { | |
178 | - argumentsValidate.addMessage(node.string, "未宣言の変数です: " + name); | |
179 | - return false; | |
180 | - } else { | |
181 | - index = index2; | |
182 | - } | |
183 | - | |
184 | - return true; | |
185 | - } | |
186 | - | |
187 | - @Override | |
188 | - public void calculate(ArgumentsInvokeWS2 argumentsInvoke, StructureComplex complex) | |
189 | - { | |
190 | - complex.set(argumentsInvoke.virtualMachine.stack.variables[index]); | |
191 | - } | |
192 | 169 | |
193 | 170 | } |
194 | 171 |
@@ -286,6 +263,37 @@ | ||
286 | 263 | |
287 | 264 | } |
288 | 265 | |
266 | + public static class Variable extends TNodeBase implements IExpression | |
267 | + { | |
268 | + | |
269 | + public TokenIdentifier token; | |
270 | + | |
271 | + public int index; | |
272 | + | |
273 | + @Override | |
274 | + public boolean validate(ArgumentsValidateWS2 argumentsValidate) | |
275 | + { | |
276 | + String name = token.node.string.string; | |
277 | + | |
278 | + Integer index2 = argumentsValidate.stackFrameRoot.getStackFrame().getVariableIndex(name); | |
279 | + if (index2 == null) { | |
280 | + argumentsValidate.addMessage(token.node.string, "未宣言の変数です: " + name); | |
281 | + return false; | |
282 | + } else { | |
283 | + index = index2; | |
284 | + } | |
285 | + | |
286 | + return true; | |
287 | + } | |
288 | + | |
289 | + @Override | |
290 | + public void calculate(ArgumentsInvokeWS2 argumentsInvoke, StructureComplex complex) | |
291 | + { | |
292 | + complex.set(argumentsInvoke.virtualMachine.stack.variables[index]); | |
293 | + } | |
294 | + | |
295 | + } | |
296 | + | |
289 | 297 | public static class LiteralNumeric extends TNodeBase implements IExpression |
290 | 298 | { |
291 | 299 |
@@ -1,86 +0,0 @@ | ||
1 | - | |
2 | -// ■トークン未満の構文素 | |
3 | -Comments := <strings>={ "[ \t\r\n]+" | |
4 | - | "//[^\r\n]*" | |
5 | - | "(?s)/\*.*?\*/" | |
6 | - } : <Comments>; | |
7 | -Identifier := <string>="[a-zA-Z_][a-zA-Z0-9_]*" : <Identifier>; | |
8 | -Sign := <string>="[+\-]" : <Sign>; | |
9 | -IntegerUnsigned := <string>="\d+" : <IntegerUnsigned>; | |
10 | -IntegerSigned := <sign>=?Sign <integer>=IntegerUnsigned : <IntegerSigned>; | |
11 | -Real := <significand>=IntegerSigned | |
12 | - <fraction>=?('.' <string>="\d*" : <Fraction>) | |
13 | - <exponent>=?("[eE]" <integer>=IntegerSigned : <Exponent>) : <Real>; | |
14 | -Imaginary := <real>=Real "[iI]" : <Imaginary>; | |
15 | - | |
16 | -// ■トークン | |
17 | -TokenIdentifier := Comments <node>=Identifier : <TokenIdentifier>; | |
18 | -TokenDecimal := Comments <node>=IntegerSigned : <TokenDecimal>; | |
19 | -TokenInteger := Comments <radix>=IntegerUnsigned 'x' <string>="[0-9a-zA-Z]+" : <TokenInteger>; | |
20 | -TokenReal := Comments <node>=Real : <TokenReal>; | |
21 | -TokenImaginary := Comments <node>=Imaginary : <TokenImaginary>; | |
22 | - | |
23 | -// ■因子 | |
24 | -LiteralNumeric := <token>=( TokenDecimal | |
25 | - | TokenInteger | |
26 | - | TokenReal | |
27 | - | TokenImaginary | |
28 | - ) : <LiteralNumeric>; | |
29 | -Bracket := Comments '(' <expression>=Expression Comments ')' : <Bracket>; | |
30 | - | |
31 | -// ■式 | |
32 | -Factor := ( TokenIdentifier | |
33 | - | LiteralNumeric | |
34 | - | Bracket | |
35 | - ); | |
36 | -ExpressionSingle := <operators>={ Comments <string>=( '-' | |
37 | - | '+' | |
38 | - | '~' | |
39 | - ) : <Operator> } | |
40 | - <expression>=Factor : <ExpressionSingle>; | |
41 | -ExpressionPow := <operations>=[ExpressionSingle, | |
42 | - Comments <string>=('^') : <Operator> | |
43 | - ] : <OperationsRight>; | |
44 | -ExpressionMul := <operations>=[ExpressionPow, | |
45 | - Comments <string>=('*' | '/') : <Operator> | |
46 | - ] : <Operations>; | |
47 | -ExpressionAdd := <operations>=[ExpressionMul, | |
48 | - Comments <string>=('+' | '-') : <Operator> | |
49 | - ] : <Operations>; | |
50 | -Expression := ExpressionAdd; | |
51 | - | |
52 | -// ■ルーチン | |
53 | -RoutineExpression := <expression>=Expression | |
54 | - Comments <token>=';' | |
55 | - : <RoutineExpression>; | |
56 | -RoutineAssignment := <identifier>=TokenIdentifier | |
57 | - Comments '=' | |
58 | - <expression>=Expression | |
59 | - Comments ';' | |
60 | - : <RoutineAssignment>; | |
61 | -RoutineDefinitionVariable := Comments 'var' | |
62 | - <identifier>=TokenIdentifier | |
63 | - Comments ';' | |
64 | - : <RoutineDefinitionVariable>; | |
65 | -RoutineDefinitionAndAssignmentVariable := Comments 'var' | |
66 | - <identifier>=TokenIdentifier | |
67 | - Comments '=' | |
68 | - <expression>=Expression | |
69 | - Comments ';' | |
70 | - : <RoutineDefinitionAndAssignmentVariable>; | |
71 | -Routine := ( RoutineExpression | |
72 | - | RoutineAssignment | |
73 | - | RoutineDefinitionVariable | |
74 | - | RoutineDefinitionAndAssignmentVariable | |
75 | - ); | |
76 | - | |
77 | -// ---------------------------------------------------------------------------------- | |
78 | - | |
79 | -// 0個以上のルーチン列 | |
80 | -Routines := <routines>={ Routine } : <Routines>; | |
81 | - | |
82 | -// ルーチン付き式 | |
83 | -ExpressionRoutined := <routines>=Routines <expression>=Expression : <ExpressionRoutined>; | |
84 | - | |
85 | -// ソースコード | |
86 | -root := <routines>=Routines Comments "$" : <Root>; |
@@ -0,0 +1,87 @@ | ||
1 | + | |
2 | +// ■トークン未満の構文素 | |
3 | +Comments := <strings>={ "[ \t\r\n]+" | |
4 | + | "//[^\r\n]*" | |
5 | + | "(?s)/\*.*?\*/" | |
6 | + } : <Comments>; | |
7 | +Identifier := <string>="[a-zA-Z_][a-zA-Z0-9_]*" : <Identifier>; | |
8 | +Sign := <string>="[+\-]" : <Sign>; | |
9 | +IntegerUnsigned := <string>="\d+" : <IntegerUnsigned>; | |
10 | +IntegerSigned := <sign>=?Sign <integer>=IntegerUnsigned : <IntegerSigned>; | |
11 | +Real := <significand>=IntegerSigned | |
12 | + <fraction>=?('.' <string>="\d*" : <Fraction>) | |
13 | + <exponent>=?("[eE]" <integer>=IntegerSigned : <Exponent>) : <Real>; | |
14 | +Imaginary := <real>=Real "[iI]" : <Imaginary>; | |
15 | + | |
16 | +// ■トークン | |
17 | +TokenIdentifier := Comments <node>=Identifier : <TokenIdentifier>; | |
18 | +TokenDecimal := Comments <node>=IntegerSigned : <TokenDecimal>; | |
19 | +TokenInteger := Comments <radix>=IntegerUnsigned 'x' <string>="[0-9a-zA-Z]+" : <TokenInteger>; | |
20 | +TokenReal := Comments <node>=Real : <TokenReal>; | |
21 | +TokenImaginary := Comments <node>=Imaginary : <TokenImaginary>; | |
22 | + | |
23 | +// ■因子 | |
24 | +Variable := <token>=TokenIdentifier : <Variable>; | |
25 | +LiteralNumeric := <token>=( TokenDecimal | |
26 | + | TokenInteger | |
27 | + | TokenReal | |
28 | + | TokenImaginary | |
29 | + ) : <LiteralNumeric>; | |
30 | +Bracket := Comments '(' <expression>=Expression Comments ')' : <Bracket>; | |
31 | + | |
32 | +// ■式 | |
33 | +Factor := ( Variable | |
34 | + | LiteralNumeric | |
35 | + | Bracket | |
36 | + ); | |
37 | +ExpressionSingle := <operators>={ Comments <string>=( '-' | |
38 | + | '+' | |
39 | + | '~' | |
40 | + ) : <Operator> } | |
41 | + <expression>=Factor : <ExpressionSingle>; | |
42 | +ExpressionPow := <operations>=[ExpressionSingle, | |
43 | + Comments <string>=('^') : <Operator> | |
44 | + ] : <OperationsRight>; | |
45 | +ExpressionMul := <operations>=[ExpressionPow, | |
46 | + Comments <string>=('*' | '/') : <Operator> | |
47 | + ] : <Operations>; | |
48 | +ExpressionAdd := <operations>=[ExpressionMul, | |
49 | + Comments <string>=('+' | '-') : <Operator> | |
50 | + ] : <Operations>; | |
51 | +Expression := ExpressionAdd; | |
52 | + | |
53 | +// ■ルーチン | |
54 | +RoutineExpression := <expression>=Expression | |
55 | + Comments <token>=';' | |
56 | + : <RoutineExpression>; | |
57 | +RoutineAssignment := <identifier>=TokenIdentifier | |
58 | + Comments '=' | |
59 | + <expression>=Expression | |
60 | + Comments ';' | |
61 | + : <RoutineAssignment>; | |
62 | +RoutineDefinitionVariable := Comments 'var' | |
63 | + <identifier>=TokenIdentifier | |
64 | + Comments ';' | |
65 | + : <RoutineDefinitionVariable>; | |
66 | +RoutineDefinitionAndAssignmentVariable := Comments 'var' | |
67 | + <identifier>=TokenIdentifier | |
68 | + Comments '=' | |
69 | + <expression>=Expression | |
70 | + Comments ';' | |
71 | + : <RoutineDefinitionAndAssignmentVariable>; | |
72 | +Routine := ( RoutineExpression | |
73 | + | RoutineAssignment | |
74 | + | RoutineDefinitionVariable | |
75 | + | RoutineDefinitionAndAssignmentVariable | |
76 | + ); | |
77 | + | |
78 | +// ---------------------------------------------------------------------------------- | |
79 | + | |
80 | +// 0個以上のルーチン列 | |
81 | +Routines := <routines>={ Routine } : <Routines>; | |
82 | + | |
83 | +// ルーチン付き式 | |
84 | +ExpressionRoutined := <routines>=Routines <expression>=Expression : <ExpressionRoutined>; | |
85 | + | |
86 | +// ソースコード | |
87 | +root := <routines>=Routines Comments "$" : <Root>; |