-
Notifications
You must be signed in to change notification settings - Fork 2
/
Grammar.txt
564 lines (432 loc) · 22 KB
/
Grammar.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
## RegExpressions
Space= \x0020;
Tab=\x0009;
CR= \x000D;
LF= \x000A;
Ws=(Space|Tab)+;
NewLine=(CR | LF);
QuotationPuncts = "‘" | "’" ;
%
WordWithoutSpace = (^("‘’+-=*\_^؛(){}$" \x000D \x000A ) | "’’" | "‘‘" ) +;
Word = WordWithoutSpace (Ws+ WordWithoutSpace)*;
%
Word = (^("‘’+-=*\_^؛(){}$ " \x000D \x000A ) | "’’" | "‘‘" ) +;
QuotedText=QuotationPuncts (^"‘’" |"’’"|"‘‘") QuotationPuncts;
IntegralMathDirective = "تكامل" ;
DoubleIntegralMathDirective ="تكامل_ثنائي" ;
TripleIntegralMathDirective = "تكامل_ثلاثي" ;
ClosedIntegralMathDirective = "تكامل_مغلق" ;
LineBarnchMathDirective = "عديد_الأسطر" ;
MultiLineMathDirective = "الأسطر" ;
MirrorMathDirective = "انعكاس";
RootMathDirective = "جذر" ;
FactorialMathDirective = "مضروب" ;
SumMathDirective = "مج" ;
##!
##RegExpression Actions
Word
$
{
tok.LexVal = new char[lexEnd - lexStart];
int insertionPos = 0;
for (int i = lexStart; i < lexEnd; i++)
{
tok.LexVal[insertionPos] = this.lexData[i];
if ((this.lexData[i] != '‘' || i + 1 >= lexEnd - 1 || this.lexData[i + 1] != '‘') && (this.lexData[i] != '’' || i + 1 >= lexEnd - 1 || this.lexData[i + 1] != '’'))
{
insertionPos++;
}
}
if (insertionPos < lexEnd - lexStart)
{
char[] newData = new char[insertionPos];
Array.Copy(tok.LexVal, 0, newData, 0, insertionPos);
tok.LexVal = newData;
}
return tok;
}
$
QuotedText
$
{
tok.LexVal = new char[lexEnd - lexStart - 2];
int insertionPos = 0;
for (int i = lexStart + 1; i < lexEnd - 1; i++)
{
tok.LexVal[insertionPos] = this.lexData[i];
if ((this.lexData[i] != '‘' || i + 1 >= lexEnd - 1 || this.lexData[i + 1] != '‘') && (this.lexData[i] != '’' || i + 1 >= lexEnd - 1 || this.lexData[i + 1] != '’'))
{
insertionPos++;
}
}
if (insertionPos < lexEnd - lexStart - 2)
{
char[] newData = new char[insertionPos];
Array.Copy(tok.LexVal, 0, newData, 0, insertionPos);
tok.LexVal = newData;
}
return tok;
}
$
Ws
$$
NewLine
$$
IntegralMathDirective
DoubleIntegralMathDirective
TripleIntegralMathDirective
ClosedIntegralMathDirective
LineBarnchMathDirective
MultiLineMathDirective
MirrorMathDirective
RootMathDirective
FactorialMathDirective
SumMathDirective
Error
$
env.ReportError(tok.LineNo,ERROR_TYPE.LEXICAL,"خطأ نصى!!");
$
##!
## Productions
Goal = Equations;
$
var stmts = new MultiLineStatement();
stmts.Statements = Equations.StmtList;
env.Equations=stmts;
$
Equations=Equations Equation;
$
Equations.StmtList = Equations_1.StmtList;
Equations.StmtList.Add(Equation.Value);
$
Equations=Equation;
>Equations.StmtList:List<SequenceStatement>;
$
Equations.StmtList=new List<SequenceStatement>();
Equations.StmtList.Add(Equation.Value);
$
Equation = Expressions "؛" ;
>Equation.Value:SequenceStatement;
$
SequenceStatement statement = new SequenceStatement
{
Statements = Expressions.Value
};
Equation.Value = statement;
$
Expression = Expression "_" Expression "^" Expression ;
$
LeftDoubleScript script = new LeftDoubleScript {
BaseStatement = Expression_1.Value,
SubStatement = Expression_2.Value,
SuperStatement = Expression_3.Value
};
Expression.Value = script;
$
Expression = Expression "_" Expression;
$
LeftSubScript script = new LeftSubScript {
BaseStatement = Expression_1.Value,
SubStatement = Expression_2.Value
};
Expression.Value = script;
$
Expression = Expression "^" Expression;
$
LeftSuperScript script = new LeftSuperScript {
BaseStatement = Expression_1.Value,
SuperStatement = Expression_2.Value
};
Expression.Value = script;
$
Expression = Expression "__" Expression "^^" Expression ;
$
OverDownScript script = new OverDownScript {
BaseStatement = Expression_1.Value,
SubStatement = Expression_2.Value,
SuperStatement = Expression_3.Value
};
Expression.Value = script;
$
Expression = Expression "__" Expression;
$
DownScript script = new DownScript {
BaseStatement = Expression_1.Value,
SubStatement = Expression_2.Value
};
Expression.Value = script;
$
Expression = Expression "^^" Expression;
$
OverScript script = new OverScript {
BaseStatement = Expression_1.Value,
SuperStatement = Expression_2.Value
};
Expression.Value = script;
$
Expression = Expression "___" Expression "^^^" Expression ;
$
RightDoubleScript script = new RightDoubleScript {
BaseStatement = Expression_1.Value,
SubStatement = Expression_2.Value,
SuperStatement = Expression_3.Value
};
Expression.Value = script;
$
Expression = Expression "___" Expression;
$
RightSubScript script = new RightSubScript {
BaseStatement = Expression_1.Value,
SubStatement = Expression_2.Value
};
Expression.Value = script;
$
Expression = Expression "^^^" Expression;
$
RightSuperScript script = new RightSuperScript {
BaseStatement = Expression_1.Value,
SuperStatement = Expression_2.Value
};
Expression.Value = script;
$
Expression= "$" LineBarnchMathDirective "{" Expressions "}";
$
LineBranchStatement statement = new LineBranchStatement {
Statements = Expressions.Value
};
Expression.Value = statement;
$
Expression= "$" MultiLineMathDirective "{" Equations "}";
$
MultiLineStatement statement = new MultiLineStatement {
Statements = Equations.StmtList
};
Expression.Value = statement;
$
Expression = "$" MirrorMathDirective "{" MathTextContent "}";
$
MirrorStatement statement = new MirrorStatement {
Text = MathTextContent.Value
};
Expression.Value = statement;
$
Expression ="(" Expressions ")" ;
$
TextStatement txtStmt1=new TextStatement();
txtStmt1.Text="(";
TextStatement txtStmt2=new TextStatement();
txtStmt2.Text=")";
SequenceStatement stmt=new SequenceStatement();
stmt.Statements.Add(txtStmt1);
foreach (Statement s in Expressions.Value)
{
stmt.Statements.Add(s);
}
stmt.Statements.Add(txtStmt2);
Expression.Value=stmt;
$
Expression ="{" Expressions "}" ;
$
SequenceStatement stmt=new SequenceStatement();
stmt.Statements=Expressions.Value;
Expression.Value=stmt;
$
% \x005c is the \ character %
Expression = Expression "\" Expression ;
$
Division stmt=new Division();
stmt.Numerator=Expression_1.Value;
stmt.Denominator=Expression_2.Value;
Expression.Value=stmt;
$
Expression = "$" RootMathDirective "{" Expressions "}" ;
$
Root root = new Root();
SequenceStatement statement = new SequenceStatement();
statement.Statements=Expressions.Value;
root.RootStatement = statement;
Expression.Value = root;
$
Expression = "$" RootMathDirective "{" Expressions "}" "{" Expressions "}" ;
$
Root root = new Root();
SequenceStatement power = new SequenceStatement{
Statements = Expressions_1.Value
};
root.Power = power;
SequenceStatement stmts = new SequenceStatement {
Statements = Expressions_1.Value
};
root.RootStatement = stmts;
Expression.Value = root;
$
Expression = "$" IntegralMathDirective;
$
Expression.Value = new IntegralStatement();
$
Expression = "$" DoubleIntegralMathDirective;
$
Expression.Value = new DoubleIntegralStatement();
$
Expression = "$" TripleIntegralMathDirective;
$
Expression.Value = new TripleIntegralStatement();
$
Expression = "$" ClosedIntegralMathDirective;
$
Expression.Value = new ClosedIntegralStatement();
$
Expression = "$" SumMathDirective;
$
Expression.Value = new SummationStatement();
$
Expression = "$" FactorialMathDirective "{" Expressions "}";
$
FactorialStatement stmt = new FactorialStatement();
SequenceStatement stmts = new SequenceStatement {
Statements = Expressions.Value
};
stmt.Content = stmts;
Expression.Value = stmt;
$
Expression = "&" ;
$
Expression.Value = new AlignStatement();
$
Expression = MathTextContent ;
>Expression.Value:Statement;
$
TextStatement stmt=new TextStatement();
Expression.Value=stmt;
stmt.Text=MathTextContent.Value;
$
Expressions = Expressions "+" Expressions ;
$
TextStatement item = new TextStatement {
Text = "+"
};
Expressions_1.Value.Add(item);
foreach (Statement s in Expressions_2.Value)
{
Expressions_1.Value.Add(s);
}
Expressions.Value = Expressions_1.Value;
$
Expressions = Expressions "-" Expressions ;
$
TextStatement item = new TextStatement {
Text = "-"
};
Expressions_1.Value.Add(item);
foreach (Statement s in Expressions_2.Value)
{
Expressions_1.Value.Add(s);
}
Expressions.Value = Expressions_1.Value;
$
Expressions = Expressions "*" Expressions ;
$
TextStatement item = new TextStatement {
Text = "*"
};
Expressions_1.Value.Add(item);
foreach (Statement s in Expressions_2.Value)
{
Expressions_1.Value.Add(s);
}
Expressions.Value = Expressions_1.Value;
$
Expressions = "-" Expressions ;
$
TextStatement item = new TextStatement {
Text = "-"
};
Expressions.Value = new List<Statement>();
Expressions.Value.Add(item);
foreach (Statement s in Expressions_1.Value)
{
Expressions.Value.Add(s);
}
$
Expressions = Expressions "=" Expressions ;
$
TextStatement item = new TextStatement {
Text = "="
};
Expressions_1.Value.Add(item);
foreach (Statement statement2 in Expressions_2.Value)
{
Expressions_1.Value.Add(statement2);
}
Expressions.Value = Expressions_1.Value;
$
Expressions = Expressions Expression ;
$
Expressions.Value = Expressions_1.Value;
Expressions.Value.Add(Expression.Value);
$
Expressions=Expression;
>Expressions.Value:List<Statement>;
$
List<Statement> list = new List<Statement>();
Expressions.Value = list;
Expressions.Value.Add(Expression.Value);
$
MathTextContent= Word;
>MathTextContent.Value:string;
$
string str = new string(Word.LexVal);
str = str.Trim(new char[] { ' ', '\r', '\n' });
MathTextContent.Value = str;
$
MathTextContent= QuotedText;
$
MathTextContent.Value=new string(QuotedText.LexVal);
$
##!
## Error Handling
Goal = Error ;
$
this.env.ReportError(Error.LineNo, ERROR_TYPE.SYNTAX, "’" + new string(Error.LexVal) + "’ : كلمة غير متوقعة");
this.env.FatalErrorFlag = true;
$
Equation= Expressions;
$
this.env.ReportWarning(this.tok.LineNo, ERROR_TYPE.SYNTAX, "هل نسيت فصلة منقوطة فى نهاية النص الرياضى؟ ");
SequenceStatement statement = new SequenceStatement {
Statements = Expressions.Value
};
Equation.Value = statement;
if (!this.env.FatalErrorFlag)
{
this.env.ErrorFlag = false;
}
$
MathTextContent = "$" Word;
$
this.env.ReportWarning(_0.LineNo, ERROR_TYPE.SYNTAX, "’" + new string(Word.LexVal) + "’ : يجب أن يكون موجها رياضيا");
MathTextContent.Value = "\$" + new string(Word.LexVal);
if (!this.env.FatalErrorFlag)
{
this.env.ErrorFlag = false;
}
$
##!
## Settings
#Prec "$";
#Prec "=";
#Prec "(",")";
#Prec "+" ;
#Prec "-" ;
#Prec "*" ;
#Prec "\" ;
#Prec "_" ,"__","___", "^","^^","^^^";
#Prec "&";
#Left "\", "$";
#Right "^" ,"_";
##!
##Head Code
$
using MathEditor;
$
##!