-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparseit_test.lua
1900 lines (1765 loc) · 80.3 KB
/
parseit_test.lua
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
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env lua
-- Unit tests for parseit.lua
-- Glenn G. Chappell
-- 23 Feb 2018
-- Updated 28 Feb 2018
parseit = require "parseit" -- Import parseit module
-- *********************************************
-- * YOU MAY WISH TO CHANGE THE FOLLOWING LINE *
-- *********************************************
EXIT_ON_FIRST_FAILURE = true
-- If EXIT_ON_FIRST_FAILURE is true, then this program exits after the
-- first failing test. If it is false, then this program executes all
-- tests, reporting success/failure for each.
-- *********************************************************************
-- Testing Package
-- *********************************************************************
tester = {}
tester.countTests = 0
tester.countPasses = 0
function tester.test(self, success, testName)
self.countTests = self.countTests+1
io.write(" Test: " .. testName .. " - ")
if success then
self.countPasses = self.countPasses+1
io.write("passed")
else
io.write("********** FAILED **********")
end
io.write("\n")
end
function tester.allPassed(self)
return self.countPasses == self.countTests
end
-- *********************************************************************
-- Utility Functions
-- *********************************************************************
function fail_exit()
if EXIT_ON_FIRST_FAILURE then
io.write("*******************************\n")
-- Terminate program
os.exit(1)
end
end
-- printTable
-- Given a table, prints it in (roughly) Lua literal notation. If
-- parameter is not a table, prints <not a table>.
function printTable(t)
-- out
-- Print parameter, surrounded by double quotes if it is a string,
-- or simply an indication of its type, if it is not number, string,
-- or boolean.
local function out(p)
if type(p) == "number" then
io.write(p)
elseif type(p) == "string" then
io.write('"'..p..'"')
elseif type(p) == "boolean" then
if p then
io.write("true")
else
io.write("false")
end
else
io.write('<'..type(p)..'>')
end
end
if type(t) ~= "table" then
io.write("<not a table>")
end
io.write("{ ")
local first = true -- First iteration of loop?
for k, v in pairs(t) do
if first then
first = false
else
io.write(", ")
end
io.write("[")
out(k)
io.write("]=")
out(v)
end
io.write(" }")
end
-- printArray
-- Given a table, prints it in (roughly) Lua literal notation for an
-- array. If parameter is not a table, prints <not a table>.
function printArray(t)
-- out
-- Print parameter, surrounded by double quotes if it is a string.
local function out(p)
if type(p) == "string" then io.write('"') end
io.write(p)
if type(p) == "string" then io.write('"') end
end
if type(t) ~= "table" then
io.write("<not a table>")
end
io.write("{ ")
local first = true -- First iteration of loop?
for k, v in ipairs(t) do
if first then
first = false
else
io.write(", ")
end
out(v)
end
io.write(" }")
end
-- tableEq
-- Compare equality of two tables.
-- Uses "==" on table values. Returns false if either of t1 or t2 is not
-- a table.
function tableEq(t1, t2)
-- Both params are tables?
local type1, type2 = type(t1), type(t2)
if type1 ~= "table" or type2 ~= "table" then
return false
end
-- Get number of keys in t1 & check values in t1, t2 are equal
local t1numkeys = 0
for k, v in pairs(t1) do
t1numkeys = t1numkeys + 1
if t2[k] ~= v then
return false
end
end
-- Check number of keys in t1, t2 same
local t2numkeys = 0
for k, v in pairs(t2) do
t2numkeys = t2numkeys + 1
end
return t1numkeys == t2numkeys
end
-- *********************************************************************
-- Definitions for This Test Program
-- *********************************************************************
-- Symbolic Constants for AST
-- Names differ from those in assignment, to avoid interference.
local STMTxLIST = 1
local INPUTxSTMT = 2
local PRINTxSTMT = 3
local FUNCxSTMT = 4
local CALLxFUNC = 5
local IFxSTMT = 6
local WHILExSTMT = 7
local ASSNxSTMT = 8
local CRxOUT = 9
local STRLITxOUT = 10
local BINxOP = 11
local UNxOP = 12
local NUMLITxVAL = 13
local BOOLLITxVAL = 14
local SIMPLExVAR = 15
local ARRAYxVAR = 16
-- String forms of symbolic constants
symbolNames = {
[1]="STMT_LIST",
[2]="INPUT_STMT",
[3]="PRINT_STMT",
[4]="FUNC_STMT",
[5]="CALL_FUNC",
[6]="IF_STMT",
[7]="WHILE_STMT",
[8]="ASSN_STMT",
[9]="CR_OUT",
[10]="STRLIT_OUT",
[11]="BIN_OP",
[12]="UN_OP",
[13]="NUMLIT_VAL",
[14]="BOOLLIT_VAL",
[15]="SIMPLE_VAR",
[16]="ARRAY_VAR",
}
-- writeAST_parseit
-- Write an AST, in (roughly) Lua form, with numbers replaced by the
-- symbolic constants used in parseit.
-- A table is assumed to represent an array.
-- See the Assignment 4 description for the AST Specification.
function writeAST_parseit(x)
if type(x) == "number" then
local name = symbolNames[x]
if name == nil then
io.write("<ERROR: Unknown constant: "..x..">")
else
io.write(name)
end
elseif type(x) == "string" then
io.write('"'..x..'"')
elseif type(x) == "boolean" then
if x then
io.write("true")
else
io.write("false")
end
elseif type(x) == "table" then
local first = true
io.write("{")
for k = 1, #x do -- ipairs is problematic
if not first then
io.write(", ")
end
writeAST_parseit(x[k])
first = false
end
io.write("}")
elseif type(x) == "nil" then
io.write("nil")
else
io.write("<ERROR: "..type(x)..">")
end
end
-- astEq
-- Checks equality of two ASTs, represented as in the Assignment 4
-- description. Returns true if equal, false otherwise.
function astEq(ast1, ast2)
if type(ast1) ~= type(ast2) then
return false
end
if type(ast1) ~= "table" then
return ast1 == ast2
end
if #ast1 ~= #ast2 then
return false
end
for k = 1, #ast1 do -- ipairs is problematic
if not astEq(ast1[k], ast2[k]) then
return false
end
end
return true
end
-- bool2Str
-- Given boolean, return string representing it: "true" or "false".
function bool2Str(b)
if b then
return "true"
else
return "false"
end
end
-- checkParse
-- Given tester object, input string ("program"), expected output values
-- from parser (good, AST), and string giving the name of the test. Do
-- test & print result. If test fails and EXIT_ON_FIRST_FAILURE is true,
-- then print detailed results and exit program.
function checkParse(t, prog,
expectedGood, expectedDone, expectedAST,
testName)
local actualGood, actualDone, actualAST = parseit.parse(prog)
local sameGood = (expectedGood == actualGood)
local sameDone = (expectedDone == actualDone)
local sameAST = true
if sameGood and expectedGood and sameDone and expectedDone then
sameAST = astEq(expectedAST, actualAST)
end
local success = sameGood and sameDone and sameAST
t:test(success, testName)
if success or not EXIT_ON_FIRST_FAILURE then
return
end
io.write("\n")
io.write("Input for the last test above:\n")
io.write('"'..prog..'"\n')
io.write("\n")
io.write("Expected parser 'good' return value: ")
io.write(bool2Str(expectedGood).."\n")
io.write("Actual parser 'good' return value: ")
io.write(bool2Str(actualGood).."\n")
io.write("Expected parser 'done' return value: ")
io.write(bool2Str(expectedDone).."\n")
io.write("Actual parser 'done' return value: ")
io.write(bool2Str(actualDone).."\n")
if not sameAST then
io.write("\n")
io.write("Expected AST:\n")
writeAST_parseit(expectedAST)
io.write("\n")
io.write("\n")
io.write("Returned AST:\n")
writeAST_parseit(actualAST)
io.write("\n")
end
io.write("\n")
fail_exit()
end
-- *********************************************************************
-- Test Suite Functions
-- *********************************************************************
function test_simple(t)
io.write("Test Suite: simple cases\n")
checkParse(t, "", true, true, {STMTxLIST},
"Empty program")
checkParse(t, "end", true, false, nil,
"Bad program: Keyword only #1")
checkParse(t, "elseif", true, false, nil,
"Bad program: Keyword only #2")
checkParse(t, "else", true, false, nil,
"Bad program: Keyword only #3")
checkParse(t, "bc", false, true, nil,
"Bad program: Identifier only")
checkParse(t, "123", true, false, nil,
"Bad program: NumericLiteral only")
checkParse(t, "'xyz'", true, false, nil,
"Bad program: StringLiteral only #1")
checkParse(t, '"xyz"', true, false, nil,
"Bad program: StringLiteral only #2")
checkParse(t, "<=", true, false, nil,
"Bad program: Operator only")
checkParse(t, "{", true, false, nil,
"Bad program: Punctuation only")
checkParse(t, "\a", true, false, nil,
"Bad program: Malformed only #1")
checkParse(t, "'", true, false, nil,
"bad program: malformed only #2")
end
function test_call_stmt(t)
io.write("Test Suite: call statements\n")
checkParse(t, "call s", true, true,
{STMTxLIST,{CALLxFUNC,"s"}},
"Call statement #1")
checkParse(t, "call sssssssssssssssssssssssssssssssss", true, true,
{STMTxLIST,{CALLxFUNC,"sssssssssssssssssssssssssssssssss"}},
"Call statement #2")
checkParse(t, "call sss call ttt", true, true,
{STMTxLIST,{CALLxFUNC,"sss"},{CALLxFUNC,"ttt"}},
"Two call statements")
checkParse(t, "call call sss", false, false, nil,
"Bad call statement: extra call")
checkParse(t, "call sss sss", false, true, nil,
"Bad call statement: extra name")
checkParse(t, "call (sss)", false, false, nil,
"Bad call statement: parentheses around name")
end
function test_input_stmt(t)
io.write("Test Suite: input statements\n")
checkParse(t, "input x", true, true,
{STMTxLIST,{INPUTxSTMT,{SIMPLExVAR,"x"}}},
"Input statement: simple")
checkParse(t, "input x[1]", true, true,
{STMTxLIST,{INPUTxSTMT,{ARRAYxVAR,"x",
{NUMLITxVAL,"1"}}}},
"Input statement: array ref")
checkParse(t, "input x[(a==b[c[d]])+e[3e7%5]]", true, true,
{STMTxLIST,{INPUTxSTMT,{ARRAYxVAR,"x",{{BINxOP,"+"},
{{BINxOP,"=="},{SIMPLExVAR,"a"},{ARRAYxVAR,"b",{ARRAYxVAR,
"c",{SIMPLExVAR,"d"}}}},{ARRAYxVAR,"e",
{{BINxOP,"%"},{NUMLITxVAL,"3e7"},{NUMLITxVAL,"5"}}}}}}},
"Input statement, complex array ref")
checkParse(t, "input", false, true, nil,
"Bad input statement: no lvalue")
checkParse(t, "input a b", false, true, nil,
"Bad input statement: two lvalues")
checkParse(t, "input end", false, false, nil,
"Bad input statement: keyword")
checkParse(t, "input (x)", false, false, nil,
"Bad input statement: var in parens")
checkParse(t, "input (x[1])", false, false, nil,
"Bad input statement: array ref in parens")
end
function test_print_stmt_no_expr(t)
io.write("Test Suite: print statements - no expressions\n")
checkParse(t, "print 'abc'", true, true,
{STMTxLIST,{PRINTxSTMT,{STRLITxOUT,"'abc'"}}},
"Print statement: StringLiteral")
checkParse(t, "print cr", true, true,
{STMTxLIST,{PRINTxSTMT,{CRxOUT}}},
"Print statement: cr")
checkParse(t, "print cr; cr", true, true,
{STMTxLIST,{PRINTxSTMT,{CRxOUT},{CRxOUT}}},
"Print statement: 2 cr")
checkParse(t, "print cr; cr; cr; cr; cr", true, true,
{STMTxLIST,{PRINTxSTMT,{CRxOUT},{CRxOUT},{CRxOUT},{CRxOUT},
{CRxOUT}}},
"Print statement: many cr")
checkParse(t, "print 'a'; cr; 'b'; cr", true, true,
{STMTxLIST,{PRINTxSTMT,{STRLITxOUT,"'a'"},{CRxOUT},{STRLITxOUT,
"'b'"},{CRxOUT}}},
"Print statement: StringLiterals & CRs")
checkParse(t, "print", false, true, nil,
"Bad print statement: empty")
checkParse(t, "print end", false, false, nil,
"Bad print statement: keyword #1")
checkParse(t, "print print", false, false, nil,
"Bad print statement: keyword #2")
checkParse(t, "print ;", false, false, nil,
"Bad print statement: print semicolon")
checkParse(t, "; cr", true, false, nil,
"Bad print statement: (no print) semicolon cr")
checkParse(t, "print cr end", true, false, nil,
"Bad print statement: print cr followed by end")
checkParse(t, "cr", true, false, nil,
"Bad program: (no print) cr only")
checkParse(t, "print cr; cr; cr; cr;", false, true, nil,
"Bad print statement: end with semicolon")
checkParse(t, "print cr;; cr", false, false, nil,
"Bad print statement: 2 semicolon")
end
function test_func_stmt_no_expr(t)
io.write("Test Suite: function definitions - no expressions\n")
checkParse(t, "func s end", true, true,
{STMTxLIST,{FUNCxSTMT,"s",{STMTxLIST}}},
"Function definition: empty body")
checkParse(t, "func end", false, false, nil,
"Bad function definition: missing name")
checkParse(t, "func &s end", false, false, nil,
"Bad function definition: ampersand before name")
checkParse(t, "func s() end", false, false, nil,
"Bad function definition: C-style parameter list")
checkParse(t, "func s end end", true, false, nil,
"Bad function definition: extra end")
checkParse(t, "func s s end", false, false, nil,
"Bad function definition: extra name")
checkParse(t, "func (s) end", false, false, nil,
"Bad function definition: name in parentheses")
checkParse(t, "func s print cr end", true, true,
{STMTxLIST,{FUNCxSTMT,"s",{STMTxLIST,{PRINTxSTMT,{CRxOUT}}}}},
"Function definition: 1-statement body #1")
checkParse(t, "func s print 'x' end", true, true,
{STMTxLIST,{FUNCxSTMT,"s",{STMTxLIST,{PRINTxSTMT,
{STRLITxOUT,"'x'"}}}}},
"Function definition: 1-statment body #2")
checkParse(t, "func s input x call y end", true, true,
{STMTxLIST,{FUNCxSTMT,"s",{STMTxLIST,{INPUTxSTMT,
{SIMPLExVAR,"x"}},{CALLxFUNC,"y"}}}},
"Function definition: 2-statment body")
checkParse(t, "func sss print cr print cr print cr end", true, true,
{STMTxLIST,{FUNCxSTMT,"sss",{STMTxLIST,{PRINTxSTMT,{CRxOUT}},
{PRINTxSTMT,{CRxOUT}},{PRINTxSTMT,{CRxOUT}}}}},
"Function definition: longer body")
checkParse(t, "func s func t func u print cr end end func v print "
.."cr end end", true, true,
{STMTxLIST,{FUNCxSTMT,"s",{STMTxLIST,{FUNCxSTMT,"t",{STMTxLIST,
{FUNCxSTMT,"u",{STMTxLIST,{PRINTxSTMT,{CRxOUT}}}}}},{FUNCxSTMT,
"v",{STMTxLIST,{PRINTxSTMT,{CRxOUT}}}}}}},
"Function definition: nested function definitions")
end
function test_while_stmt_simple_expr(t)
io.write("Test Suite: while statements - simple expressions only\n")
checkParse(t, "while 1 print cr end", true, true,
{STMTxLIST,{WHILExSTMT,{NUMLITxVAL,"1"},{STMTxLIST,{PRINTxSTMT,
{CRxOUT}}}}},
"While statement: simple")
checkParse(t, "while 2 print cr print cr print cr print cr print "
.."cr print cr print cr print cr print cr print cr end", true,
true,
{STMTxLIST,{WHILExSTMT,{NUMLITxVAL,"2"},{STMTxLIST,{PRINTxSTMT,
{CRxOUT}},{PRINTxSTMT,{CRxOUT}},{PRINTxSTMT,{CRxOUT}},
{PRINTxSTMT,{CRxOUT}},{PRINTxSTMT,{CRxOUT}},{PRINTxSTMT,
{CRxOUT}},{PRINTxSTMT,{CRxOUT}},{PRINTxSTMT,{CRxOUT}},
{PRINTxSTMT,{CRxOUT}},{PRINTxSTMT,{CRxOUT}}}}},
"While statement: longer statement list")
checkParse(t, "while 3 end", true, true,
{STMTxLIST,{WHILExSTMT,{NUMLITxVAL,"3"},{STMTxLIST}}},
"While statement: empty statement list")
checkParse(t, "while 1 while 2 while 3 while 4 while 5 while 6 "
.."while 7 print cr end end end end end end end", true, true,
{STMTxLIST,{WHILExSTMT,{NUMLITxVAL,"1"},{STMTxLIST,{WHILExSTMT,
{NUMLITxVAL,"2"},{STMTxLIST,{WHILExSTMT,{NUMLITxVAL,"3"},
{STMTxLIST,{WHILExSTMT,{NUMLITxVAL,"4"},{STMTxLIST,{WHILExSTMT,
{NUMLITxVAL,"5"},{STMTxLIST,{WHILExSTMT,{NUMLITxVAL,"6"},
{STMTxLIST,{WHILExSTMT,{NUMLITxVAL,"7"},{STMTxLIST,{PRINTxSTMT,
{CRxOUT}}}}}}}}}}}}}}}}},
"While statement: nested")
checkParse(t, "while print cr end", false, false, nil,
"Bad while statement: no expr")
checkParse(t, "while 1 print cr", false, true, nil,
"Bad while statement: no end")
checkParse(t, "while 1 print cr else print cr end ",
false, false, nil,
"Bad while statement: has else")
checkParse(t, "while 1 print cr end end", true, false, nil,
"Bad while statement: followed by end")
end
function test_if_stmt_simple_expr(t)
io.write("Test Suite: if statements - simple expressions only\n")
checkParse(t, "if 1 print cr end", true, true,
{STMTxLIST,{IFxSTMT,{NUMLITxVAL,"1"},{STMTxLIST,{PRINTxSTMT,
{CRxOUT}}}}},
"If statement: simple")
checkParse(t, "if 2 end", true, true,
{STMTxLIST,{IFxSTMT,{NUMLITxVAL,"2"},{STMTxLIST}}},
"If statement: empty statement list")
checkParse(t, "if 3 print cr else print cr print cr end", true,
true,
{STMTxLIST,{IFxSTMT,{NUMLITxVAL,"3"},{STMTxLIST,{PRINTxSTMT,
{CRxOUT}}},{STMTxLIST,{PRINTxSTMT,{CRxOUT}},{PRINTxSTMT,
{CRxOUT}}}}},
"If statement: else")
checkParse(t, "if 4 print cr elseif 5 print cr print cr else print "
.."cr print cr print cr end", true, true,
{STMTxLIST,{IFxSTMT,{NUMLITxVAL,"4"},{STMTxLIST,{PRINTxSTMT,
{CRxOUT}}},{NUMLITxVAL,"5"},{STMTxLIST,{PRINTxSTMT,{CRxOUT}},
{PRINTxSTMT,{CRxOUT}}},{STMTxLIST,{PRINTxSTMT,{CRxOUT}},
{PRINTxSTMT,{CRxOUT}},{PRINTxSTMT,{CRxOUT}}}}},
"If statement: elseif, else")
checkParse(t, "if a print cr elseif b print cr print cr elseif c "
.."print cr print cr print cr elseif d print cr print cr print "
.."cr print cr elseif e print cr print cr print cr print cr "
.."print cr else print cr print cr print cr print cr print cr "
.."print cr end", true, true,
{STMTxLIST,{IFxSTMT,{SIMPLExVAR,"a"},{STMTxLIST,{PRINTxSTMT,
{CRxOUT}}},{SIMPLExVAR,"b"},{STMTxLIST,{PRINTxSTMT,{CRxOUT}},
{PRINTxSTMT,{CRxOUT}}},{SIMPLExVAR,"c"},{STMTxLIST,{PRINTxSTMT,
{CRxOUT}},{PRINTxSTMT,{CRxOUT}},{PRINTxSTMT,{CRxOUT}}},
{SIMPLExVAR,"d"},{STMTxLIST,{PRINTxSTMT,{CRxOUT}},{PRINTxSTMT,
{CRxOUT}},{PRINTxSTMT,{CRxOUT}},{PRINTxSTMT,{CRxOUT}}},
{SIMPLExVAR,"e"},{STMTxLIST,{PRINTxSTMT,{CRxOUT}},{PRINTxSTMT,
{CRxOUT}},{PRINTxSTMT,{CRxOUT}},{PRINTxSTMT,{CRxOUT}},
{PRINTxSTMT,{CRxOUT}}},{STMTxLIST,{PRINTxSTMT,{CRxOUT}},
{PRINTxSTMT,{CRxOUT}},{PRINTxSTMT,{CRxOUT}},{PRINTxSTMT,
{CRxOUT}},{PRINTxSTMT,{CRxOUT}},{PRINTxSTMT,{CRxOUT}}}}},
"If statement: multiple elseif, else")
checkParse(t, "if 1 print cr elseif 2 print cr print cr elseif 3 "
.."print cr print cr print cr elseif 4 print cr print cr print "
.."cr print cr elseif 5 print cr print cr print cr print cr "
.."print cr end", true, true,
{STMTxLIST,{IFxSTMT,{NUMLITxVAL,"1"},{STMTxLIST,{PRINTxSTMT,
{CRxOUT}}},{NUMLITxVAL,"2"},{STMTxLIST,{PRINTxSTMT,{CRxOUT}},
{PRINTxSTMT,{CRxOUT}}},{NUMLITxVAL,"3"},{STMTxLIST,{PRINTxSTMT,
{CRxOUT}},{PRINTxSTMT,{CRxOUT}},{PRINTxSTMT,{CRxOUT}}},
{NUMLITxVAL,"4"},{STMTxLIST,{PRINTxSTMT,{CRxOUT}},{PRINTxSTMT,
{CRxOUT}},{PRINTxSTMT,{CRxOUT}},{PRINTxSTMT,{CRxOUT}}},
{NUMLITxVAL,"5"},{STMTxLIST,{PRINTxSTMT,{CRxOUT}},{PRINTxSTMT,
{CRxOUT}},{PRINTxSTMT,{CRxOUT}},{PRINTxSTMT,{CRxOUT}},
{PRINTxSTMT,{CRxOUT}}}}},
"If statement: multiple elseif, no else")
checkParse(t, "if 1 elseif 2 elseif 3 elseif 4 elseif 5 else end",
true, true,
{STMTxLIST,{IFxSTMT,{NUMLITxVAL,"1"},{STMTxLIST},{NUMLITxVAL,"2"},
{STMTxLIST},{NUMLITxVAL,"3"},{STMTxLIST},{NUMLITxVAL,"4"},
{STMTxLIST},{NUMLITxVAL,"5"},{STMTxLIST},{STMTxLIST}}},
"If statement: multiple elseif, else, empty statement lists")
checkParse(t, "if 1 if 2 print cr else print cr end elseif 3 if 4 "
.."print cr else print cr end else if 5 print cr else print cr "
.."end end", true, true,
{STMTxLIST,{IFxSTMT,{NUMLITxVAL,"1"},{STMTxLIST,{IFxSTMT,
{NUMLITxVAL,"2"},{STMTxLIST,{PRINTxSTMT,{CRxOUT}}},{STMTxLIST,
{PRINTxSTMT,{CRxOUT}}}}},{NUMLITxVAL,"3"},{STMTxLIST,{IFxSTMT,
{NUMLITxVAL,"4"},{STMTxLIST,{PRINTxSTMT,{CRxOUT}}},{STMTxLIST,
{PRINTxSTMT,{CRxOUT}}}}},{STMTxLIST,{IFxSTMT,{NUMLITxVAL,"5"},
{STMTxLIST,{PRINTxSTMT,{CRxOUT}}},{STMTxLIST,{PRINTxSTMT,
{CRxOUT}}}}}}},
"If statement: nested #1")
checkParse(t, "if 1 if 2 if 3 if 4 if 5 if 6 if 7 print cr end end "
.."end end end end end", true, true,
{STMTxLIST,{IFxSTMT,{NUMLITxVAL,"1"},{STMTxLIST,{IFxSTMT,
{NUMLITxVAL,"2"},{STMTxLIST,{IFxSTMT,{NUMLITxVAL,"3"},
{STMTxLIST,{IFxSTMT,{NUMLITxVAL,"4"},{STMTxLIST,{IFxSTMT,
{NUMLITxVAL,"5"},{STMTxLIST,{IFxSTMT,{NUMLITxVAL,"6"},
{STMTxLIST,{IFxSTMT,{NUMLITxVAL,"7"},{STMTxLIST,{PRINTxSTMT,
{CRxOUT}}}}}}}}}}}}}}}}},
"If statement: nested #2")
checkParse(t, "while 1 if 2 while 3 end elseif 4 while 5 if 6 end "
.."end elseif 7 while 8 end else while 9 end end end", true, true,
{STMTxLIST,{WHILExSTMT,{NUMLITxVAL,"1"},{STMTxLIST,{IFxSTMT,
{NUMLITxVAL,"2"},{STMTxLIST,{WHILExSTMT,{NUMLITxVAL,"3"},
{STMTxLIST}}},{NUMLITxVAL,"4"},{STMTxLIST,{WHILExSTMT,
{NUMLITxVAL,"5"},{STMTxLIST,{IFxSTMT,{NUMLITxVAL,"6"},
{STMTxLIST}}}}},{NUMLITxVAL,"7"},{STMTxLIST,{WHILExSTMT,
{NUMLITxVAL,"8"},{STMTxLIST}}},{STMTxLIST,{WHILExSTMT,
{NUMLITxVAL,"9"},{STMTxLIST}}}}}}},
"While statement: nested while & if")
checkParse(t, "if cr end", false, false, nil,
"Bad if statement: no expr")
checkParse(t, "if a print cr", false, true, nil,
"Bad if statement: no end")
checkParse(t, "if a b cr end", false, false, nil,
"Bad if statement: 2 expressions")
checkParse(t, "if a cr else cr elseif b cr", false, false, nil,
"Bad if statement: else before elseif")
checkParse(t, "if a print cr end end", true, false, nil,
"Bad if statement: followed by end")
end
function test_assn_stmt_simple_expr(t)
io.write("Test Suite: assignment statements - simple expressions\n")
checkParse(t, "abc=123", true, true,
{STMTxLIST,{ASSNxSTMT,{SIMPLExVAR,"abc"},{NUMLITxVAL,"123"}}},
"Assignment statement: NumericLiteral")
checkParse(t, "abc=xyz", true, true,
{STMTxLIST,{ASSNxSTMT,{SIMPLExVAR, "abc"},{SIMPLExVAR,"xyz"}}},
"Assignment statement: identifier")
checkParse(t, "abc[1]=xyz", true, true,
{STMTxLIST,{ASSNxSTMT,{ARRAYxVAR,"abc",{NUMLITxVAL,"1"}},
{SIMPLExVAR,"xyz"}}},
"Assignment statement: array ref = ...")
checkParse(t, "abc=true", true, true,
{STMTxLIST,{ASSNxSTMT,{SIMPLExVAR, "abc"},{BOOLLITxVAL,"true"}}},
"Assignment statement: boolean literal Keyword: true")
checkParse(t, "abc=false", true, true,
{STMTxLIST,{ASSNxSTMT,{SIMPLExVAR, "abc"},{BOOLLITxVAL,"false"}}},
"Assignment statement: boolean literal Keyword: false")
checkParse(t, "=123", true, false, nil,
"Bad assignment statement: missing LHS")
checkParse(t, "123=123", true, false, nil,
"Bad assignment statement: LHS is NumericLiteral")
checkParse(t, "end=123", true, false, nil,
"Bad assignment statement: LHS is Keyword")
checkParse(t, "abc 123", false, false, nil,
"Bad assignment statement: missing assignment op")
checkParse(t, "abc == 123", false, false, nil,
"Bad assignment statement: assignment op replaced by equality")
checkParse(t, "abc =", false, true, nil,
"Bad assignment statement: RHS is empty")
checkParse(t, "abc=end", false, false, nil,
"Bad assignment statement: RHS is Keyword")
checkParse(t, "abc=1 2", true, false, nil,
"Bad assignment statement: RHS is two NumericLiterals")
checkParse(t, "abc=1 end", true, false, nil,
"Bad assignment statement: followed by end")
end
function test_expr_simple(t)
io.write("Test Suite: simple expressions\n")
checkParse(t, "x=true", true, true,
{STMTxLIST,{ASSNxSTMT,{SIMPLExVAR,"x"},{BOOLLITxVAL,"true"}}},
"Simple expression: true")
checkParse(t, "x=false", true, true,
{STMTxLIST,{ASSNxSTMT,{SIMPLExVAR,"x"},{BOOLLITxVAL,"false"}}},
"Simple expression: true")
checkParse(t, "x=call foo", true, true,
{STMTxLIST,{ASSNxSTMT,{SIMPLExVAR,"x"},{CALLxFUNC,"foo"}}},
"Simple expression: call")
checkParse(t, "x=call", false, true, nil,
"Bad expression: call without name")
checkParse(t, "x=1&&2", true, true,
{STMTxLIST,{ASSNxSTMT,{SIMPLExVAR,"x"},{{BINxOP,"&&"},
{NUMLITxVAL,"1"},{NUMLITxVAL,"2"}}}},
"Simple expression: &&")
checkParse(t, "x=1||2", true, true,
{STMTxLIST,{ASSNxSTMT,{SIMPLExVAR,"x"},{{BINxOP,"||"},
{NUMLITxVAL,"1"},{NUMLITxVAL,"2"}}}},
"Simple expression: ||")
checkParse(t, "x=1 + 2", true, true,
{STMTxLIST,{ASSNxSTMT,{SIMPLExVAR,"x"},{{BINxOP,"+"},
{NUMLITxVAL,"1"},{NUMLITxVAL,"2"}}}},
"Simple expression: binary + (numbers with space)")
checkParse(t, "x=1+2", true, true,
{STMTxLIST,{ASSNxSTMT,{SIMPLExVAR,"x"},{{BINxOP,"+"},
{NUMLITxVAL,"1"},{NUMLITxVAL,"2"}}}},
"Simple expression: binary + (numbers without space)")
checkParse(t, "x=a+2", true, true,
{STMTxLIST,{ASSNxSTMT,{SIMPLExVAR,"x"},{{BINxOP,"+"},
{SIMPLExVAR,"a"},{NUMLITxVAL,"2"}}}},
"Simple expression: binary + (var+number)")
checkParse(t, "x=1+b", true, true,
{STMTxLIST,{ASSNxSTMT,{SIMPLExVAR,"x"},{{BINxOP,"+"},
{NUMLITxVAL,"1"},{SIMPLExVAR,"b"}}}},
"Simple expression: binary + (number+var)")
checkParse(t, "x=a+b", true, true,
{STMTxLIST,{ASSNxSTMT,{SIMPLExVAR,"x"},{{BINxOP,"+"},
{SIMPLExVAR,"a"},{SIMPLExVAR,"b"}}}},
"Simple expression: binary + (vars)")
checkParse(t, "x=1+", false, true, nil,
"Bad expression: end with +")
checkParse(t, "x=1 - 2", true, true,
{STMTxLIST,{ASSNxSTMT,{SIMPLExVAR,"x"},{{BINxOP,"-"},
{NUMLITxVAL,"1"},{NUMLITxVAL,"2"}}}},
"Simple expression: binary - (numbers with space)")
checkParse(t, "x=1-2", true, true,
{STMTxLIST,{ASSNxSTMT,{SIMPLExVAR,"x"},{{BINxOP,"-"},
{NUMLITxVAL,"1"},{NUMLITxVAL,"2"}}}},
"Simple expression: binary - (numbers without space)")
checkParse(t, "x=1-", false, true, nil,
"Bad expression: end with -")
checkParse(t, "x=1*2", true, true,
{STMTxLIST,{ASSNxSTMT,{SIMPLExVAR,"x"},{{BINxOP,"*"},
{NUMLITxVAL,"1"},{NUMLITxVAL,"2"}}}},
"Simple expression: * (numbers)")
checkParse(t, "x=a*2", true, true,
{STMTxLIST,{ASSNxSTMT,{SIMPLExVAR,"x"},{{BINxOP,"*"},
{SIMPLExVAR,"a"},{NUMLITxVAL,"2"}}}},
"Simple expression: * (var*number)")
checkParse(t, "x=1*b", true, true,
{STMTxLIST,{ASSNxSTMT,{SIMPLExVAR,"x"},{{BINxOP,"*"},
{NUMLITxVAL,"1"},{SIMPLExVAR,"b"}}}},
"Simple expression: * (number*var)")
checkParse(t, "x=a*b", true, true,
{STMTxLIST,{ASSNxSTMT,{SIMPLExVAR,"x"},{{BINxOP,"*"},
{SIMPLExVAR,"a"},{SIMPLExVAR,"b"}}}},
"Simple expression: * (vars)")
checkParse(t, "x=1*", false, true, nil,
"Bad expression: end with *")
checkParse(t, "x=1/2", true, true,
{STMTxLIST,{ASSNxSTMT,{SIMPLExVAR,"x"},{{BINxOP,"/"},
{NUMLITxVAL,"1"},{NUMLITxVAL,"2"}}}},
"Simple expression: /")
checkParse(t, "x=1/", false, true, nil,
"Bad expression: end with /")
checkParse(t, "x=1%2", true, true,
{STMTxLIST,{ASSNxSTMT,{SIMPLExVAR,"x"},{{BINxOP,"%"},
{NUMLITxVAL,"1"},{NUMLITxVAL,"2"}}}},
"Simple expression: % #1")
checkParse(t, "x=1%true", true, true,
{STMTxLIST,{ASSNxSTMT,{SIMPLExVAR,"x"},{{BINxOP,"%"},
{NUMLITxVAL,"1"},{BOOLLITxVAL,"true"}}}},
"Simple expression: % #2")
checkParse(t, "x=1%false", true, true,
{STMTxLIST,{ASSNxSTMT,{SIMPLExVAR,"x"},{{BINxOP,"%"},
{NUMLITxVAL,"1"},{BOOLLITxVAL,"false"}}}},
"Simple expression: % #3")
checkParse(t, "x=1%", false, true, nil,
"Bad expression: end with %")
checkParse(t, "x=1==2", true, true,
{STMTxLIST,{ASSNxSTMT,{SIMPLExVAR,"x"},{{BINxOP,"=="},
{NUMLITxVAL,"1"},{NUMLITxVAL,"2"}}}},
"Simple expression: == (numbers)")
checkParse(t, "x=a==2", true, true,
{STMTxLIST,{ASSNxSTMT,{SIMPLExVAR,"x"},{{BINxOP,"=="},
{SIMPLExVAR,"a"},{NUMLITxVAL,"2"}}}},
"Simple expression: == (var==number)")
checkParse(t, "x=1==b", true, true,
{STMTxLIST,{ASSNxSTMT,{SIMPLExVAR,"x"},{{BINxOP,"=="},
{NUMLITxVAL,"1"},{SIMPLExVAR,"b"}}}},
"Simple expression: == (number==var)")
checkParse(t, "x=a==b", true, true,
{STMTxLIST,{ASSNxSTMT,{SIMPLExVAR,"x"},{{BINxOP,"=="},
{SIMPLExVAR,"a"},{SIMPLExVAR,"b"}}}},
"Simple expression: == (vars)")
checkParse(t, "x=1==", false, true, nil,
"Bad expression: end with ==")
checkParse(t, "x=1!=2", true, true,
{STMTxLIST,{ASSNxSTMT,{SIMPLExVAR,"x"},{{BINxOP,"!="},
{NUMLITxVAL,"1"},{NUMLITxVAL,"2"}}}},
"Simple expression: !=")
checkParse(t, "x=1!=", false, true, nil,
"Bad expression: end with !=")
checkParse(t, "x=1<2", true, true,
{STMTxLIST,{ASSNxSTMT,{SIMPLExVAR,"x"},{{BINxOP,"<"},
{NUMLITxVAL,"1"},{NUMLITxVAL,"2"}}}},
"Simple expression: <")
checkParse(t, "x=1<", false, true, nil,
"Bad expression: end with <")
checkParse(t, "x=1<=2", true, true,
{STMTxLIST,{ASSNxSTMT,{SIMPLExVAR,"x"},{{BINxOP,"<="},
{NUMLITxVAL,"1"},{NUMLITxVAL,"2"}}}},
"Simple expression: <=")
checkParse(t, "x=1<=", false, true, nil,
"Bad expression: end with <=")
checkParse(t, "x=1>2", true, true,
{STMTxLIST,{ASSNxSTMT,{SIMPLExVAR,"x"},{{BINxOP,">"},
{NUMLITxVAL,"1"},{NUMLITxVAL,"2"}}}},
"Simple expression: >")
checkParse(t, "x=1>", false, true, nil,
"Bad expression: end with >")
checkParse(t, "x=1>=2", true, true,
{STMTxLIST,{ASSNxSTMT,{SIMPLExVAR,"x"},{{BINxOP,">="},
{NUMLITxVAL,"1"},{NUMLITxVAL,"2"}}}},
"Simple expression: >=")
checkParse(t, "x=+a", true, true,
{STMTxLIST,{ASSNxSTMT,{SIMPLExVAR,"x"},{{UNxOP,"+"},{SIMPLExVAR,
"a"}}}},
"Simple expression: unary +")
checkParse(t, "x=-a", true, true,
{STMTxLIST,{ASSNxSTMT,{SIMPLExVAR,"x"},{{UNxOP,"-"},{SIMPLExVAR,
"a"}}}},
"Simple expression: unary -")
checkParse(t, "x=1>=", false, true, nil,
"Bad expression: end with >=")
checkParse(t, "x=(1)", true, true,
{STMTxLIST,{ASSNxSTMT,{SIMPLExVAR,"x"},{NUMLITxVAL,"1"}}},
"Simple expression: parens (number)")
checkParse(t, "x=(a)", true, true,
{STMTxLIST,{ASSNxSTMT,{SIMPLExVAR,"x"},{SIMPLExVAR,"a"}}},
"Simple expression: parens (var)")
checkParse(t, "x=a[1]", true, true,
{STMTxLIST,{ASSNxSTMT,{SIMPLExVAR,"x"},{ARRAYxVAR,"a",
{NUMLITxVAL,"1"}}}},
"Simple expression: array ref")
checkParse(t, "x=(1", false, true, nil,
"Bad expression: no closing paren")
checkParse(t, "x=()", false, false, nil,
"Bad expression: empty parens")
checkParse(t, "x=a[1", false, true, nil,
"Bad expression: no closing bracket")
checkParse(t, "x=a 1]", true, false, nil,
"Bad expression: no opening bracket")
checkParse(t, "x=a[]", false, false, nil,
"Bad expression: empty brackets")
checkParse(t, "x=(x)", true, true,
{STMTxLIST,{ASSNxSTMT,{SIMPLExVAR,"x"},{SIMPLExVAR,"x"}}},
"Simple expression: var in parens on RHS")
checkParse(t, "(x)=x", true, false, nil,
"Bad expression: var in parens on LHS")
checkParse(t, "x[1]=(x[1])", true, true,
{STMTxLIST,{ASSNxSTMT,{ARRAYxVAR,"x",{NUMLITxVAL,"1"}},
{ARRAYxVAR,"x",{NUMLITxVAL,"1"}}}},
"Simple expression: array ref in parens on RHS")
checkParse(t, "(x[1])=x[1]", true, false, nil,
"Bad expression: array ref in parens on LHS")
checkParse(t, "x=call call f", false, false, nil,
"Bad expression: consecutive call keywords")
checkParse(t, "x=call 3", false, false, nil,
"Bad expression: call number")
checkParse(t, "x=call true", false, false, nil,
"Bad expression: call boolean")
checkParse(t, "x=call (x)", false, false, nil,
"Bad expression: call with parentheses")
end
function test_print_stmt_with_expr(t)
io.write("Test Suite: print statements - with expressions\n")
checkParse(t, "print x", true, true,
{STMTxLIST,{PRINTxSTMT,{SIMPLExVAR,"x"}}},
"print statement: variable")
checkParse(t, "print a+x[b*(c==d-f)]%g<=h", true, true,
{STMTxLIST,{PRINTxSTMT,{{BINxOP,"<="},{{BINxOP,"+"},{SIMPLExVAR,
"a"},{{BINxOP,"%"},{ARRAYxVAR,"x",{{BINxOP,"*"},{SIMPLExVAR,
"b"},{{BINxOP,"=="},{SIMPLExVAR,"c"},{{BINxOP,"-"},{SIMPLExVAR,
"d"},{SIMPLExVAR,"f"}}}}},{SIMPLExVAR,"g"}}},{SIMPLExVAR,
"h"}}}},
"print statement: expression")
checkParse(t, "print 1 end", true, false, nil,
"bad print statement: print 1 followed by end")
end
function test_func_stmt_with_expr(t)
io.write("Test Suite: function declarations - with expressions\n")
checkParse(t, "func q print abc+3 end", true, true,
{STMTxLIST,{FUNCxSTMT,"q",{STMTxLIST,{PRINTxSTMT,{{BINxOP,"+"},
{SIMPLExVAR,"abc"},{NUMLITxVAL,"3"}}}}}},
"func declaration: with print expr")
checkParse(t, "func qq print a+x[b*(c==d-f)]%g<=h end", true, true,
{STMTxLIST,{FUNCxSTMT,"qq",{STMTxLIST,{PRINTxSTMT,{{BINxOP,"<="},
{{BINxOP,"+"},{SIMPLExVAR,"a"},{{BINxOP,"%"},{ARRAYxVAR,"x",
{{BINxOP,"*"},{SIMPLExVAR,"b"},{{BINxOP,"=="},{SIMPLExVAR,"c"},
{{BINxOP,"-"},{SIMPLExVAR,"d"},{SIMPLExVAR,"f"}}}}},{SIMPLExVAR,
"g"}}},{SIMPLExVAR,"h"}}}}}},
"function declaration: complex expression")
end
function test_expr_prec_assoc(t)
io.write("Test Suite: expressions - precedence & associativity\n")
checkParse(t, "x=1&&2&&3&&4&&5", true, true,
{STMTxLIST,{ASSNxSTMT,{SIMPLExVAR,"x"},{{BINxOP,"&&"},{{BINxOP,
"&&"},{{BINxOP, "&&"},{{BINxOP,"&&"},{NUMLITxVAL,"1"},
{NUMLITxVAL,"2"}},{NUMLITxVAL,"3"}},{NUMLITxVAL,"4"}},
{NUMLITxVAL,"5"}}}},
"Operator && is left-associative")
checkParse(t, "x=1||2||3||4||5", true, true,
{STMTxLIST,{ASSNxSTMT,{SIMPLExVAR,"x"},{{BINxOP,"||"},{{BINxOP,
"||"},{{BINxOP, "||"},{{BINxOP,"||"},{NUMLITxVAL,"1"},
{NUMLITxVAL,"2"}},{NUMLITxVAL,"3"}},{NUMLITxVAL,"4"}},
{NUMLITxVAL,"5"}}}},
"Operator || is left-associative")
checkParse(t, "x=1+2+3+4+5", true, true,
{STMTxLIST,{ASSNxSTMT,{SIMPLExVAR,"x"},{{BINxOP,"+"},{{BINxOP,
"+"},{{BINxOP, "+"},{{BINxOP,"+"},{NUMLITxVAL,"1"},{NUMLITxVAL,
"2"}},{NUMLITxVAL,"3"}},{NUMLITxVAL,"4"}},{NUMLITxVAL,"5"}}}},
"Binary operator + is left-associative")
checkParse(t, "x=1-2-3-4-5", true, true,
{STMTxLIST,{ASSNxSTMT,{SIMPLExVAR,"x"},{{BINxOP,"-"},{{BINxOP,
"-"},{{BINxOP, "-"},{{BINxOP,"-"},{NUMLITxVAL,"1"},{NUMLITxVAL,
"2"}},{NUMLITxVAL,"3"}},{NUMLITxVAL,"4"}},{NUMLITxVAL,"5"}}}},
"Binary operator - is left-associative")
checkParse(t, "x=1*2*3*4*5", true, true,
{STMTxLIST,{ASSNxSTMT,{SIMPLExVAR,"x"},{{BINxOP,"*"},{{BINxOP,
"*"},{{BINxOP, "*"},{{BINxOP,"*"},{NUMLITxVAL,"1"},{NUMLITxVAL,
"2"}},{NUMLITxVAL,"3"}},{NUMLITxVAL,"4"}},{NUMLITxVAL,"5"}}}},
"Operator * is left-associative")
checkParse(t, "x=1/2/3/4/5", true, true,
{STMTxLIST,{ASSNxSTMT,{SIMPLExVAR,"x"},{{BINxOP,"/"},{{BINxOP,
"/"},{{BINxOP, "/"},{{BINxOP,"/"},{NUMLITxVAL,"1"},{NUMLITxVAL,
"2"}},{NUMLITxVAL,"3"}},{NUMLITxVAL,"4"}},{NUMLITxVAL,"5"}}}},
"Operator / is left-associative")
checkParse(t, "x=1%2%3%4%5", true, true,
{STMTxLIST,{ASSNxSTMT,{SIMPLExVAR,"x"},{{BINxOP,"%"},{{BINxOP,
"%"},{{BINxOP, "%"},{{BINxOP,"%"},{NUMLITxVAL,"1"},{NUMLITxVAL,
"2"}},{NUMLITxVAL,"3"}},{NUMLITxVAL,"4"}},{NUMLITxVAL,"5"}}}},
"Operator % is left-associative")
checkParse(t, "x=1==2==3==4==5", true, true,
{STMTxLIST,{ASSNxSTMT,{SIMPLExVAR,"x"},{{BINxOP,"=="},{{BINxOP,
"=="},{{BINxOP, "=="},{{BINxOP,"=="},{NUMLITxVAL,"1"},
{NUMLITxVAL,"2"}},{NUMLITxVAL,"3"}},{NUMLITxVAL,"4"}},
{NUMLITxVAL,"5"}}}},
"Operator == is left-associative")
checkParse(t, "x=1!=2!=3!=4!=5", true, true,
{STMTxLIST,{ASSNxSTMT,{SIMPLExVAR,"x"},{{BINxOP,"!="},{{BINxOP,
"!="},{{BINxOP, "!="},{{BINxOP,"!="},{NUMLITxVAL,"1"},
{NUMLITxVAL,"2"}},{NUMLITxVAL,"3"}},{NUMLITxVAL,"4"}},
{NUMLITxVAL,"5"}}}},
"Operator != is left-associative")
checkParse(t, "x=1<2<3<4<5", true, true,
{STMTxLIST,{ASSNxSTMT,{SIMPLExVAR,"x"},{{BINxOP,"<"},{{BINxOP,
"<"},{{BINxOP, "<"},{{BINxOP,"<"},{NUMLITxVAL,"1"},{NUMLITxVAL,
"2"}},{NUMLITxVAL,"3"}},{NUMLITxVAL,"4"}},{NUMLITxVAL,"5"}}}},
"Operator < is left-associative")
checkParse(t, "x=1<=2<=3<=4<=5", true, true,
{STMTxLIST,{ASSNxSTMT,{SIMPLExVAR,"x"},{{BINxOP,"<="},{{BINxOP,
"<="},{{BINxOP, "<="},{{BINxOP,"<="},{NUMLITxVAL,"1"},
{NUMLITxVAL,"2"}},{NUMLITxVAL,"3"}},{NUMLITxVAL,"4"}},
{NUMLITxVAL,"5"}}}},
"Operator <= is left-associative")
checkParse(t, "x=1>2>3>4>5", true, true,
{STMTxLIST,{ASSNxSTMT,{SIMPLExVAR,"x"},{{BINxOP,">"},{{BINxOP,
">"},{{BINxOP, ">"},{{BINxOP,">"},{NUMLITxVAL,"1"},{NUMLITxVAL,
"2"}},{NUMLITxVAL,"3"}},{NUMLITxVAL,"4"}},{NUMLITxVAL,"5"}}}},
"Operator > is left-associative")
checkParse(t, "x=1>=2>=3>=4>=5", true, true,
{STMTxLIST,{ASSNxSTMT,{SIMPLExVAR,"x"},{{BINxOP,">="},{{BINxOP,
">="},{{BINxOP, ">="},{{BINxOP,">="},{NUMLITxVAL,"1"},
{NUMLITxVAL,"2"}},{NUMLITxVAL,"3"}},{NUMLITxVAL,"4"}},
{NUMLITxVAL,"5"}}}},
"Operator >= is left-associative")
checkParse(t, "x=!!!!a", true, true,
{STMTxLIST,{ASSNxSTMT,{SIMPLExVAR,"x"},{{UNxOP,"!"},{{UNxOP,"!"},
{{UNxOP,"!"},{{UNxOP,"!"},{SIMPLExVAR,"a"}}}}}}},
"Operator ! is right-associative")
checkParse(t, "x=++++a", true, true,
{STMTxLIST,{ASSNxSTMT,{SIMPLExVAR,"x"},{{UNxOP,"+"},{{UNxOP,"+"},