Commit fc9c62a3 authored by Jiawen Lyu's avatar Jiawen Lyu

procedure with only one param

parent 7a26e397
......@@ -23,6 +23,8 @@ null
'"'
'si'
'tantque'
'('
')'
'*'
'/'
'+'
......@@ -35,8 +37,6 @@ null
'=='
'hasard'
'cos'
'('
')'
'sin'
'loop'
null
......@@ -102,4 +102,4 @@ expr
atn:
[3, 24715, 42794, 33075, 47597, 16764, 15335, 30598, 22884, 3, 46, 145, 4, 2, 9, 2, 4, 3, 9, 3, 4, 4, 9, 4, 4, 5, 9, 5, 4, 6, 9, 6, 4, 7, 9, 7, 3, 2, 3, 2, 3, 2, 5, 2, 18, 10, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 5, 2, 26, 10, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 5, 2, 34, 10, 2, 3, 3, 3, 3, 6, 3, 38, 10, 3, 13, 3, 14, 3, 39, 3, 4, 5, 4, 43, 10, 4, 3, 4, 3, 4, 3, 5, 6, 5, 48, 10, 5, 13, 5, 14, 5, 49, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 5, 6, 94, 10, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 5, 6, 104, 10, 6, 5, 6, 106, 10, 6, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 5, 7, 129, 10, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 7, 7, 140, 10, 7, 12, 7, 14, 7, 143, 11, 7, 3, 7, 2, 3, 12, 8, 2, 4, 6, 8, 10, 12, 2, 5, 3, 2, 26, 27, 3, 2, 28, 29, 3, 2, 30, 35, 2, 170, 2, 33, 3, 2, 2, 2, 4, 37, 3, 2, 2, 2, 6, 42, 3, 2, 2, 2, 8, 47, 3, 2, 2, 2, 10, 105, 3, 2, 2, 2, 12, 128, 3, 2, 2, 2, 14, 15, 7, 3, 2, 2, 15, 17, 7, 43, 2, 2, 16, 18, 5, 4, 3, 2, 17, 16, 3, 2, 2, 2, 17, 18, 3, 2, 2, 2, 18, 19, 3, 2, 2, 2, 19, 20, 5, 8, 5, 2, 20, 21, 7, 4, 2, 2, 21, 34, 3, 2, 2, 2, 22, 23, 7, 3, 2, 2, 23, 25, 7, 43, 2, 2, 24, 26, 5, 4, 3, 2, 25, 24, 3, 2, 2, 2, 25, 26, 3, 2, 2, 2, 26, 27, 3, 2, 2, 2, 27, 28, 5, 8, 5, 2, 28, 29, 7, 5, 2, 2, 29, 30, 7, 6, 2, 2, 30, 31, 7, 43, 2, 2, 31, 32, 7, 4, 2, 2, 32, 34, 3, 2, 2, 2, 33, 14, 3, 2, 2, 2, 33, 22, 3, 2, 2, 2, 34, 3, 3, 2, 2, 2, 35, 36, 7, 6, 2, 2, 36, 38, 7, 43, 2, 2, 37, 35, 3, 2, 2, 2, 38, 39, 3, 2, 2, 2, 39, 37, 3, 2, 2, 2, 39, 40, 3, 2, 2, 2, 40, 5, 3, 2, 2, 2, 41, 43, 5, 2, 2, 2, 42, 41, 3, 2, 2, 2, 42, 43, 3, 2, 2, 2, 43, 44, 3, 2, 2, 2, 44, 45, 5, 8, 5, 2, 45, 7, 3, 2, 2, 2, 46, 48, 5, 10, 6, 2, 47, 46, 3, 2, 2, 2, 48, 49, 3, 2, 2, 2, 49, 47, 3, 2, 2, 2, 49, 50, 3, 2, 2, 2, 50, 9, 3, 2, 2, 2, 51, 52, 7, 7, 2, 2, 52, 53, 5, 12, 7, 2, 53, 54, 7, 8, 2, 2, 54, 55, 5, 8, 5, 2, 55, 56, 7, 9, 2, 2, 56, 106, 3, 2, 2, 2, 57, 58, 7, 10, 2, 2, 58, 106, 5, 12, 7, 2, 59, 60, 7, 11, 2, 2, 60, 106, 5, 12, 7, 2, 61, 62, 7, 12, 2, 2, 62, 106, 5, 12, 7, 2, 63, 64, 7, 13, 2, 2, 64, 106, 5, 12, 7, 2, 65, 66, 7, 14, 2, 2, 66, 106, 5, 12, 7, 2, 67, 68, 7, 15, 2, 2, 68, 106, 5, 12, 7, 2, 69, 106, 7, 16, 2, 2, 70, 106, 7, 17, 2, 2, 71, 72, 7, 18, 2, 2, 72, 73, 7, 8, 2, 2, 73, 74, 5, 12, 7, 2, 74, 75, 7, 19, 2, 2, 75, 76, 5, 12, 7, 2, 76, 77, 7, 9, 2, 2, 77, 106, 3, 2, 2, 2, 78, 106, 7, 20, 2, 2, 79, 106, 7, 21, 2, 2, 80, 81, 7, 22, 2, 2, 81, 82, 7, 23, 2, 2, 82, 83, 7, 43, 2, 2, 83, 106, 5, 12, 7, 2, 84, 85, 7, 24, 2, 2, 85, 86, 5, 12, 7, 2, 86, 87, 7, 8, 2, 2, 87, 88, 5, 8, 5, 2, 88, 93, 7, 9, 2, 2, 89, 90, 7, 8, 2, 2, 90, 91, 5, 8, 5, 2, 91, 92, 7, 9, 2, 2, 92, 94, 3, 2, 2, 2, 93, 89, 3, 2, 2, 2, 93, 94, 3, 2, 2, 2, 94, 106, 3, 2, 2, 2, 95, 96, 7, 25, 2, 2, 96, 97, 5, 12, 7, 2, 97, 98, 7, 8, 2, 2, 98, 99, 5, 8, 5, 2, 99, 100, 7, 9, 2, 2, 100, 106, 3, 2, 2, 2, 101, 103, 7, 43, 2, 2, 102, 104, 5, 4, 3, 2, 103, 102, 3, 2, 2, 2, 103, 104, 3, 2, 2, 2, 104, 106, 3, 2, 2, 2, 105, 51, 3, 2, 2, 2, 105, 57, 3, 2, 2, 2, 105, 59, 3, 2, 2, 2, 105, 61, 3, 2, 2, 2, 105, 63, 3, 2, 2, 2, 105, 65, 3, 2, 2, 2, 105, 67, 3, 2, 2, 2, 105, 69, 3, 2, 2, 2, 105, 70, 3, 2, 2, 2, 105, 71, 3, 2, 2, 2, 105, 78, 3, 2, 2, 2, 105, 79, 3, 2, 2, 2, 105, 80, 3, 2, 2, 2, 105, 84, 3, 2, 2, 2, 105, 95, 3, 2, 2, 2, 105, 101, 3, 2, 2, 2, 106, 11, 3, 2, 2, 2, 107, 108, 8, 7, 1, 2, 108, 109, 7, 36, 2, 2, 109, 129, 5, 12, 7, 2, 110, 111, 7, 37, 2, 2, 111, 112, 7, 38, 2, 2, 112, 113, 5, 12, 7, 2, 113, 114, 7, 39, 2, 2, 114, 129, 3, 2, 2, 2, 115, 116, 7, 40, 2, 2, 116, 117, 7, 38, 2, 2, 117, 118, 5, 12, 7, 2, 118, 119, 7, 39, 2, 2, 119, 129, 3, 2, 2, 2, 120, 129, 7, 42, 2, 2, 121, 129, 7, 41, 2, 2, 122, 123, 7, 6, 2, 2, 123, 129, 7, 43, 2, 2, 124, 125, 7, 38, 2, 2, 125, 126, 5, 12, 7, 2, 126, 127, 7, 39, 2, 2, 127, 129, 3, 2, 2, 2, 128, 107, 3, 2, 2, 2, 128, 110, 3, 2, 2, 2, 128, 115, 3, 2, 2, 2, 128, 120, 3, 2, 2, 2, 128, 121, 3, 2, 2, 2, 128, 122, 3, 2, 2, 2, 128, 124, 3, 2, 2, 2, 129, 141, 3, 2, 2, 2, 130, 131, 12, 12, 2, 2, 131, 132, 9, 2, 2, 2, 132, 140, 5, 12, 7, 13, 133, 134, 12, 11, 2, 2, 134, 135, 9, 3, 2, 2, 135, 140, 5, 12, 7, 12, 136, 137, 12, 10, 2, 2, 137, 138, 9, 4, 2, 2, 138, 140, 5, 12, 7, 11, 139, 130, 3, 2, 2, 2, 139, 133, 3, 2, 2, 2, 139, 136, 3, 2, 2, 2, 140, 143, 3, 2, 2, 2, 141, 139, 3, 2, 2, 2, 141, 142, 3, 2, 2, 2, 142, 13, 3, 2, 2, 2, 143, 141, 3, 2, 2, 2, 14, 17, 25, 33, 39, 42, 49, 93, 103, 105, 128, 139, 141]
\ No newline at end of file
[3, 24715, 42794, 33075, 47597, 16764, 15335, 30598, 22884, 3, 46, 154, 4, 2, 9, 2, 4, 3, 9, 3, 4, 4, 9, 4, 4, 5, 9, 5, 4, 6, 9, 6, 4, 7, 9, 7, 3, 2, 3, 2, 3, 2, 5, 2, 18, 10, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 5, 2, 26, 10, 2, 3, 2, 5, 2, 29, 10, 2, 3, 2, 3, 2, 3, 2, 3, 2, 5, 2, 35, 10, 2, 3, 3, 3, 3, 6, 3, 39, 10, 3, 13, 3, 14, 3, 40, 3, 4, 7, 4, 44, 10, 4, 12, 4, 14, 4, 47, 11, 4, 3, 4, 3, 4, 3, 5, 6, 5, 52, 10, 5, 13, 5, 14, 5, 53, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 5, 6, 98, 10, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 7, 6, 109, 10, 6, 12, 6, 14, 6, 112, 11, 6, 3, 6, 5, 6, 115, 10, 6, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 5, 7, 138, 10, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 7, 7, 149, 10, 7, 12, 7, 14, 7, 152, 11, 7, 3, 7, 2, 3, 12, 8, 2, 4, 6, 8, 10, 12, 2, 5, 3, 2, 28, 29, 3, 2, 30, 31, 3, 2, 32, 37, 2, 180, 2, 34, 3, 2, 2, 2, 4, 38, 3, 2, 2, 2, 6, 45, 3, 2, 2, 2, 8, 51, 3, 2, 2, 2, 10, 114, 3, 2, 2, 2, 12, 137, 3, 2, 2, 2, 14, 15, 7, 3, 2, 2, 15, 17, 7, 43, 2, 2, 16, 18, 5, 4, 3, 2, 17, 16, 3, 2, 2, 2, 17, 18, 3, 2, 2, 2, 18, 19, 3, 2, 2, 2, 19, 20, 5, 8, 5, 2, 20, 21, 7, 4, 2, 2, 21, 35, 3, 2, 2, 2, 22, 23, 7, 3, 2, 2, 23, 25, 7, 43, 2, 2, 24, 26, 5, 4, 3, 2, 25, 24, 3, 2, 2, 2, 25, 26, 3, 2, 2, 2, 26, 28, 3, 2, 2, 2, 27, 29, 5, 8, 5, 2, 28, 27, 3, 2, 2, 2, 28, 29, 3, 2, 2, 2, 29, 30, 3, 2, 2, 2, 30, 31, 7, 5, 2, 2, 31, 32, 5, 12, 7, 2, 32, 33, 7, 4, 2, 2, 33, 35, 3, 2, 2, 2, 34, 14, 3, 2, 2, 2, 34, 22, 3, 2, 2, 2, 35, 3, 3, 2, 2, 2, 36, 37, 7, 6, 2, 2, 37, 39, 7, 43, 2, 2, 38, 36, 3, 2, 2, 2, 39, 40, 3, 2, 2, 2, 40, 38, 3, 2, 2, 2, 40, 41, 3, 2, 2, 2, 41, 5, 3, 2, 2, 2, 42, 44, 5, 2, 2, 2, 43, 42, 3, 2, 2, 2, 44, 47, 3, 2, 2, 2, 45, 43, 3, 2, 2, 2, 45, 46, 3, 2, 2, 2, 46, 48, 3, 2, 2, 2, 47, 45, 3, 2, 2, 2, 48, 49, 5, 8, 5, 2, 49, 7, 3, 2, 2, 2, 50, 52, 5, 10, 6, 2, 51, 50, 3, 2, 2, 2, 52, 53, 3, 2, 2, 2, 53, 51, 3, 2, 2, 2, 53, 54, 3, 2, 2, 2, 54, 9, 3, 2, 2, 2, 55, 56, 7, 7, 2, 2, 56, 57, 5, 12, 7, 2, 57, 58, 7, 8, 2, 2, 58, 59, 5, 8, 5, 2, 59, 60, 7, 9, 2, 2, 60, 115, 3, 2, 2, 2, 61, 62, 7, 10, 2, 2, 62, 115, 5, 12, 7, 2, 63, 64, 7, 11, 2, 2, 64, 115, 5, 12, 7, 2, 65, 66, 7, 12, 2, 2, 66, 115, 5, 12, 7, 2, 67, 68, 7, 13, 2, 2, 68, 115, 5, 12, 7, 2, 69, 70, 7, 14, 2, 2, 70, 115, 5, 12, 7, 2, 71, 72, 7, 15, 2, 2, 72, 115, 5, 12, 7, 2, 73, 115, 7, 16, 2, 2, 74, 115, 7, 17, 2, 2, 75, 76, 7, 18, 2, 2, 76, 77, 7, 8, 2, 2, 77, 78, 5, 12, 7, 2, 78, 79, 7, 19, 2, 2, 79, 80, 5, 12, 7, 2, 80, 81, 7, 9, 2, 2, 81, 115, 3, 2, 2, 2, 82, 115, 7, 20, 2, 2, 83, 115, 7, 21, 2, 2, 84, 85, 7, 22, 2, 2, 85, 86, 7, 23, 2, 2, 86, 87, 7, 43, 2, 2, 87, 115, 5, 12, 7, 2, 88, 89, 7, 24, 2, 2, 89, 90, 5, 12, 7, 2, 90, 91, 7, 8, 2, 2, 91, 92, 5, 8, 5, 2, 92, 97, 7, 9, 2, 2, 93, 94, 7, 8, 2, 2, 94, 95, 5, 8, 5, 2, 95, 96, 7, 9, 2, 2, 96, 98, 3, 2, 2, 2, 97, 93, 3, 2, 2, 2, 97, 98, 3, 2, 2, 2, 98, 115, 3, 2, 2, 2, 99, 100, 7, 25, 2, 2, 100, 101, 5, 12, 7, 2, 101, 102, 7, 8, 2, 2, 102, 103, 5, 8, 5, 2, 103, 104, 7, 9, 2, 2, 104, 115, 3, 2, 2, 2, 105, 106, 7, 43, 2, 2, 106, 110, 7, 26, 2, 2, 107, 109, 5, 12, 7, 2, 108, 107, 3, 2, 2, 2, 109, 112, 3, 2, 2, 2, 110, 108, 3, 2, 2, 2, 110, 111, 3, 2, 2, 2, 111, 113, 3, 2, 2, 2, 112, 110, 3, 2, 2, 2, 113, 115, 7, 27, 2, 2, 114, 55, 3, 2, 2, 2, 114, 61, 3, 2, 2, 2, 114, 63, 3, 2, 2, 2, 114, 65, 3, 2, 2, 2, 114, 67, 3, 2, 2, 2, 114, 69, 3, 2, 2, 2, 114, 71, 3, 2, 2, 2, 114, 73, 3, 2, 2, 2, 114, 74, 3, 2, 2, 2, 114, 75, 3, 2, 2, 2, 114, 82, 3, 2, 2, 2, 114, 83, 3, 2, 2, 2, 114, 84, 3, 2, 2, 2, 114, 88, 3, 2, 2, 2, 114, 99, 3, 2, 2, 2, 114, 105, 3, 2, 2, 2, 115, 11, 3, 2, 2, 2, 116, 117, 8, 7, 1, 2, 117, 118, 7, 38, 2, 2, 118, 138, 5, 12, 7, 2, 119, 120, 7, 39, 2, 2, 120, 121, 7, 26, 2, 2, 121, 122, 5, 12, 7, 2, 122, 123, 7, 27, 2, 2, 123, 138, 3, 2, 2, 2, 124, 125, 7, 40, 2, 2, 125, 126, 7, 26, 2, 2, 126, 127, 5, 12, 7, 2, 127, 128, 7, 27, 2, 2, 128, 138, 3, 2, 2, 2, 129, 138, 7, 42, 2, 2, 130, 138, 7, 41, 2, 2, 131, 132, 7, 6, 2, 2, 132, 138, 7, 43, 2, 2, 133, 134, 7, 26, 2, 2, 134, 135, 5, 12, 7, 2, 135, 136, 7, 27, 2, 2, 136, 138, 3, 2, 2, 2, 137, 116, 3, 2, 2, 2, 137, 119, 3, 2, 2, 2, 137, 124, 3, 2, 2, 2, 137, 129, 3, 2, 2, 2, 137, 130, 3, 2, 2, 2, 137, 131, 3, 2, 2, 2, 137, 133, 3, 2, 2, 2, 138, 150, 3, 2, 2, 2, 139, 140, 12, 12, 2, 2, 140, 141, 9, 2, 2, 2, 141, 149, 5, 12, 7, 13, 142, 143, 12, 11, 2, 2, 143, 144, 9, 3, 2, 2, 144, 149, 5, 12, 7, 12, 145, 146, 12, 10, 2, 2, 146, 147, 9, 4, 2, 2, 147, 149, 5, 12, 7, 11, 148, 139, 3, 2, 2, 2, 148, 142, 3, 2, 2, 2, 148, 145, 3, 2, 2, 2, 149, 152, 3, 2, 2, 2, 150, 148, 3, 2, 2, 2, 150, 151, 3, 2, 2, 2, 151, 13, 3, 2, 2, 2, 152, 150, 3, 2, 2, 2, 15, 17, 25, 28, 34, 40, 45, 53, 97, 110, 114, 137, 148, 150]
\ No newline at end of file
......@@ -65,19 +65,19 @@ COMMENT2=44
'"'=21
'si'=22
'tantque'=23
'*'=24
'/'=25
'+'=26
'-'=27
'>'=28
'<'=29
'<='=30
'>='=31
'!='=32
'=='=33
'hasard'=34
'cos'=35
'('=36
')'=37
'('=24
')'=25
'*'=26
'/'=27
'+'=28
'-'=29
'>'=30
'<'=31
'<='=32
'>='=33
'!='=34
'=='=35
'hasard'=36
'cos'=37
'sin'=38
'loop'=39
This diff is collapsed.
......@@ -65,19 +65,19 @@ COMMENT2=44
'"'=21
'si'=22
'tantque'=23
'*'=24
'/'=25
'+'=26
'-'=27
'>'=28
'<'=29
'<='=30
'>='=31
'!='=32
'=='=33
'hasard'=34
'cos'=35
'('=36
')'=37
'('=24
')'=25
'*'=26
'/'=27
'+'=28
'-'=29
'>'=30
'<'=31
'<='=32
'>='=33
'!='=34
'=='=35
'hasard'=36
'cos'=37
'sin'=38
'loop'=39
......@@ -37,6 +37,7 @@ import logoparsing.LogoParser.SumContext;
import logoparsing.LogoParser.TantqueContext;
import logoparsing.LogoParser.TdContext;
import logoparsing.LogoParser.TgContext;
import org.antlr.v4.runtime.tree.TerminalNode;
public class LogoTreeVisitor extends LogoBaseVisitor<Integer> {
Traceur traceur;
......@@ -202,9 +203,9 @@ public class LogoTreeVisitor extends LogoBaseVisitor<Integer> {
@Override
public Integer visitListe_parametres(LogoParser.Liste_parametresContext ctx) {
List<ParseTree> listChildren = ctx.children;
List<TerminalNode> listChildren = ctx.VAR();
TableSymboles currentTableSymboles = pileExecution.pop();
for (ParseTree child : listChildren) {
for (TerminalNode child : listChildren) {
String currentNomParam = child.getText();
currentTableSymboles.creerVar(currentNomParam, null);
currentTableSymboles.addNomParam(currentNomParam);
......@@ -217,30 +218,60 @@ public class LogoTreeVisitor extends LogoBaseVisitor<Integer> {
public Integer visitProcedure(LogoParser.ProcedureContext ctx) {
String nomProcedure = ctx.VAR().getText();
Integer createListeParamsSuccess;
//创建一个作用域,然后推入执行栈中,方便参数列表把记住所有的参数名
TableSymboles currentTableSymboles = new TableSymboles();
pileExecution.push(currentTableSymboles);
Liste_instructionsContext listeInstructions = ctx.liste_instructions();
//通过执行栈存储参数列表
createListeParamsSuccess = visit(ctx.liste_parametres());
//获取到参数名之后,创建相应的procedure实例
currentTableSymboles = pileExecution.pop();
if (createListeParamsSuccess == 0) {
Procedure newProcedure = new Procedure(nomProcedure, currentTableSymboles, listeInstructions);
tableProcedures.put(nomProcedure, newProcedure);
return 0;
} else return -1;
}
@Override
public Integer visitExecuteProcedure(LogoParser.ExecuteProcedureContext ctx) {
//拿到过程的名字
String nomProcedure = ctx.VAR().getText();
Procedure currentProcedure = tableProcedures.get(nomProcedure);
Liste_instructionsContext listeInstructions = currentProcedure.getListeInstructions();
//在执行过程的时候需要把作用域推入执行栈
TableSymboles tableSymbolesLocale = currentProcedure.getTableSymbLocale();
List<String> nomsParams = tableSymbolesLocale.getListeNomsParams();
List<LogoParser.ExprContext> listeParamsValues = ctx.expr();
int index = 0;
//给符号表中的参数赋值
for (LogoParser.ExprContext currentExpr : listeParamsValues) {
if(index < nomsParams.size()) {
Binome expr = evaluateExpr(currentExpr);
Double exprValue = expr._2;
String nomParam = nomsParams.get(0);
tableSymbolesLocale.creerVar(nomParam, exprValue);
index++;
} else return -1;//在调用函数的时候参数的个数和申明函数时不一样
}
return 0;
pileExecution.push(tableSymbolesLocale);
//开始执行语句
int doesSuccess = visit(listeInstructions);
if(doesSuccess == 0) {
pileExecution.pop();
return 0;
}
else return -2;
}
@Override
......@@ -441,22 +472,39 @@ public class LogoTreeVisitor extends LogoBaseVisitor<Integer> {
@Override
public Integer visitAffecter(AffecterContext ctx) {
//先把作用域从执行栈里取出
TableSymboles currentTableSymboles;
if (!pileExecution.empty()) {
currentTableSymboles = pileExecution.pop();
} else {
System.out.println("执行栈为空");
return -1;
}
// 访问var下的子结点,并返回是否执行成功
Binome value = evaluateExpr(ctx.expr());
if (value._1 == 0) {
String nomVar = ctx.VAR().getText();
tableSymbGlobale.creerVar(nomVar, value._2);
currentTableSymboles.creerVar(nomVar, value._2);
log.setValue("Bien affecter la variable " + nomVar + " avec " + value._2);
log.setValue("\n");
}
pileExecution.push(currentTableSymboles);
return 0;
}
@Override
public Integer visitAppelle(AppelleContext ctx) {
String varText = ctx.VAR().getText();
setExprValue(ctx, tableSymbGlobale.getValeur(varText));
TableSymboles currentTableSymboles;
if (!pileExecution.empty()) {
currentTableSymboles = pileExecution.pop();
} else {
System.out.println("执行栈为空");
return -1;
}
setExprValue(ctx, currentTableSymboles.getValeur(varText));
pileExecution.push(currentTableSymboles);
return 0;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment