Commit ca58f49a authored by Jiawen Lyu's avatar Jiawen Lyu

fonction with one param and without instructions

parent 3d3f24ff
token literal names:
null
'pour'
'fin'
'rends'
'fin'
':'
'repete'
'['
......@@ -23,8 +23,6 @@ null
'"'
'si'
'tantque'
'('
')'
'*'
'/'
'+'
......@@ -37,6 +35,8 @@ null
'=='
'hasard'
'cos'
'('
')'
'sin'
'loop'
null
......@@ -102,4 +102,4 @@ expr
atn:
[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
[3, 24715, 42794, 33075, 47597, 16764, 15335, 30598, 22884, 3, 46, 144, 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, 5, 2, 21, 10, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 3, 3, 3, 6, 3, 29, 10, 3, 13, 3, 14, 3, 30, 3, 4, 7, 4, 34, 10, 4, 12, 4, 14, 4, 37, 11, 4, 3, 4, 3, 4, 3, 5, 6, 5, 42, 10, 5, 13, 5, 14, 5, 43, 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, 88, 10, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 5, 6, 96, 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, 3, 7, 3, 7, 3, 7, 7, 7, 122, 10, 7, 12, 7, 14, 7, 125, 11, 7, 3, 7, 5, 7, 128, 10, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 7, 7, 139, 10, 7, 12, 7, 14, 7, 142, 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, 168, 2, 14, 3, 2, 2, 2, 4, 28, 3, 2, 2, 2, 6, 35, 3, 2, 2, 2, 8, 41, 3, 2, 2, 2, 10, 95, 3, 2, 2, 2, 12, 127, 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, 20, 3, 2, 2, 2, 19, 21, 5, 8, 5, 2, 20, 19, 3, 2, 2, 2, 20, 21, 3, 2, 2, 2, 21, 22, 3, 2, 2, 2, 22, 23, 7, 4, 2, 2, 23, 24, 5, 12, 7, 2, 24, 25, 7, 5, 2, 2, 25, 3, 3, 2, 2, 2, 26, 27, 7, 6, 2, 2, 27, 29, 7, 43, 2, 2, 28, 26, 3, 2, 2, 2, 29, 30, 3, 2, 2, 2, 30, 28, 3, 2, 2, 2, 30, 31, 3, 2, 2, 2, 31, 5, 3, 2, 2, 2, 32, 34, 5, 2, 2, 2, 33, 32, 3, 2, 2, 2, 34, 37, 3, 2, 2, 2, 35, 33, 3, 2, 2, 2, 35, 36, 3, 2, 2, 2, 36, 38, 3, 2, 2, 2, 37, 35, 3, 2, 2, 2, 38, 39, 5, 8, 5, 2, 39, 7, 3, 2, 2, 2, 40, 42, 5, 10, 6, 2, 41, 40, 3, 2, 2, 2, 42, 43, 3, 2, 2, 2, 43, 41, 3, 2, 2, 2, 43, 44, 3, 2, 2, 2, 44, 9, 3, 2, 2, 2, 45, 46, 7, 7, 2, 2, 46, 47, 5, 12, 7, 2, 47, 48, 7, 8, 2, 2, 48, 49, 5, 8, 5, 2, 49, 50, 7, 9, 2, 2, 50, 96, 3, 2, 2, 2, 51, 52, 7, 10, 2, 2, 52, 96, 5, 12, 7, 2, 53, 54, 7, 11, 2, 2, 54, 96, 5, 12, 7, 2, 55, 56, 7, 12, 2, 2, 56, 96, 5, 12, 7, 2, 57, 58, 7, 13, 2, 2, 58, 96, 5, 12, 7, 2, 59, 60, 7, 14, 2, 2, 60, 96, 5, 12, 7, 2, 61, 62, 7, 15, 2, 2, 62, 96, 5, 12, 7, 2, 63, 96, 7, 16, 2, 2, 64, 96, 7, 17, 2, 2, 65, 66, 7, 18, 2, 2, 66, 67, 7, 8, 2, 2, 67, 68, 5, 12, 7, 2, 68, 69, 7, 19, 2, 2, 69, 70, 5, 12, 7, 2, 70, 71, 7, 9, 2, 2, 71, 96, 3, 2, 2, 2, 72, 96, 7, 20, 2, 2, 73, 96, 7, 21, 2, 2, 74, 75, 7, 22, 2, 2, 75, 76, 7, 23, 2, 2, 76, 77, 7, 43, 2, 2, 77, 96, 5, 12, 7, 2, 78, 79, 7, 24, 2, 2, 79, 80, 5, 12, 7, 2, 80, 81, 7, 8, 2, 2, 81, 82, 5, 8, 5, 2, 82, 87, 7, 9, 2, 2, 83, 84, 7, 8, 2, 2, 84, 85, 5, 8, 5, 2, 85, 86, 7, 9, 2, 2, 86, 88, 3, 2, 2, 2, 87, 83, 3, 2, 2, 2, 87, 88, 3, 2, 2, 2, 88, 96, 3, 2, 2, 2, 89, 90, 7, 25, 2, 2, 90, 91, 5, 12, 7, 2, 91, 92, 7, 8, 2, 2, 92, 93, 5, 8, 5, 2, 93, 94, 7, 9, 2, 2, 94, 96, 3, 2, 2, 2, 95, 45, 3, 2, 2, 2, 95, 51, 3, 2, 2, 2, 95, 53, 3, 2, 2, 2, 95, 55, 3, 2, 2, 2, 95, 57, 3, 2, 2, 2, 95, 59, 3, 2, 2, 2, 95, 61, 3, 2, 2, 2, 95, 63, 3, 2, 2, 2, 95, 64, 3, 2, 2, 2, 95, 65, 3, 2, 2, 2, 95, 72, 3, 2, 2, 2, 95, 73, 3, 2, 2, 2, 95, 74, 3, 2, 2, 2, 95, 78, 3, 2, 2, 2, 95, 89, 3, 2, 2, 2, 96, 11, 3, 2, 2, 2, 97, 98, 8, 7, 1, 2, 98, 99, 7, 36, 2, 2, 99, 128, 5, 12, 7, 2, 100, 101, 7, 37, 2, 2, 101, 102, 7, 38, 2, 2, 102, 103, 5, 12, 7, 2, 103, 104, 7, 39, 2, 2, 104, 128, 3, 2, 2, 2, 105, 106, 7, 40, 2, 2, 106, 107, 7, 38, 2, 2, 107, 108, 5, 12, 7, 2, 108, 109, 7, 39, 2, 2, 109, 128, 3, 2, 2, 2, 110, 128, 7, 42, 2, 2, 111, 128, 7, 41, 2, 2, 112, 113, 7, 6, 2, 2, 113, 128, 7, 43, 2, 2, 114, 115, 7, 38, 2, 2, 115, 116, 5, 12, 7, 2, 116, 117, 7, 39, 2, 2, 117, 128, 3, 2, 2, 2, 118, 119, 7, 43, 2, 2, 119, 123, 7, 38, 2, 2, 120, 122, 5, 12, 7, 2, 121, 120, 3, 2, 2, 2, 122, 125, 3, 2, 2, 2, 123, 121, 3, 2, 2, 2, 123, 124, 3, 2, 2, 2, 124, 126, 3, 2, 2, 2, 125, 123, 3, 2, 2, 2, 126, 128, 7, 39, 2, 2, 127, 97, 3, 2, 2, 2, 127, 100, 3, 2, 2, 2, 127, 105, 3, 2, 2, 2, 127, 110, 3, 2, 2, 2, 127, 111, 3, 2, 2, 2, 127, 112, 3, 2, 2, 2, 127, 114, 3, 2, 2, 2, 127, 118, 3, 2, 2, 2, 128, 140, 3, 2, 2, 2, 129, 130, 12, 13, 2, 2, 130, 131, 9, 2, 2, 2, 131, 139, 5, 12, 7, 14, 132, 133, 12, 12, 2, 2, 133, 134, 9, 3, 2, 2, 134, 139, 5, 12, 7, 13, 135, 136, 12, 11, 2, 2, 136, 137, 9, 4, 2, 2, 137, 139, 5, 12, 7, 12, 138, 129, 3, 2, 2, 2, 138, 132, 3, 2, 2, 2, 138, 135, 3, 2, 2, 2, 139, 142, 3, 2, 2, 2, 140, 138, 3, 2, 2, 2, 140, 141, 3, 2, 2, 2, 141, 13, 3, 2, 2, 2, 142, 140, 3, 2, 2, 2, 13, 17, 20, 30, 35, 43, 87, 95, 123, 127, 138, 140]
\ No newline at end of file
......@@ -43,8 +43,8 @@ WS=42
COMMENT1=43
COMMENT2=44
'pour'=1
'fin'=2
'rends'=3
'rends'=2
'fin'=3
':'=4
'repete'=5
'['=6
......@@ -65,19 +65,19 @@ COMMENT2=44
'"'=21
'si'=22
'tantque'=23
'('=24
')'=25
'*'=26
'/'=27
'+'=28
'-'=29
'>'=30
'<'=31
'<='=32
'>='=33
'!='=34
'=='=35
'hasard'=36
'cos'=37
'*'=24
'/'=25
'+'=26
'-'=27
'>'=28
'<'=29
'<='=30
'>='=31
'!='=32
'=='=33
'hasard'=34
'cos'=35
'('=36
')'=37
'sin'=38
'loop'=39
This diff is collapsed.
......@@ -43,8 +43,8 @@ WS=42
COMMENT1=43
COMMENT2=44
'pour'=1
'fin'=2
'rends'=3
'rends'=2
'fin'=3
':'=4
'repete'=5
'['=6
......@@ -65,19 +65,19 @@ COMMENT2=44
'"'=21
'si'=22
'tantque'=23
'('=24
')'=25
'*'=26
'/'=27
'+'=28
'-'=29
'>'=30
'<'=31
'<='=32
'>='=33
'!='=34
'=='=35
'hasard'=36
'cos'=37
'*'=24
'/'=25
'+'=26
'-'=27
'>'=28
'<'=29
'<='=30
'>='=31
'!='=32
'=='=33
'hasard'=34
'cos'=35
'('=36
')'=37
'sin'=38
'loop'=39
......@@ -58,6 +58,7 @@ expr:
| 'loop' # loop
| ':'VAR # appelle
| '(' expr ')' # parenthese
| VAR '(' (expr)* ')' # executeFonction
;
......
package logoparsing;
public class Fonction {
private String nomFonction;
private TableSymboles tableSymbLocale;
private LogoParser.Liste_instructionsContext listeInstructions;
private LogoParser.ExprContext result;
public Fonction(String n, TableSymboles t, LogoParser.Liste_instructionsContext l) {
this.nomFonction = n;
this.tableSymbLocale = t;
this.listeInstructions = l;
}
public String getNomFonction() {
return nomFonction;
}
public void setNomFonction(String nomFonction) {
this.nomFonction = nomFonction;
}
public TableSymboles getTableSymbLocale() {
return tableSymbLocale;
}
public void setTableSymbLocale(TableSymboles tableSymbLocale) {
this.tableSymbLocale = tableSymbLocale;
}
public LogoParser.Liste_instructionsContext getListeInstructions() {
return listeInstructions;
}
public void setListeInstructions(LogoParser.Liste_instructionsContext listeInstructions) {
this.listeInstructions = listeInstructions;
}
public LogoParser.ExprContext getResult() {
return result;
}
public void setResult(LogoParser.ExprContext result) {
this.result = result;
}
}
This diff is collapsed.
......@@ -337,6 +337,18 @@ public class LogoBaseListener implements LogoListener {
* <p>The default implementation does nothing.</p>
*/
@Override public void exitParenthese(LogoParser.ParentheseContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterExecuteFonction(LogoParser.ExecuteFonctionContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitExecuteFonction(LogoParser.ExecuteFonctionContext ctx) { }
/**
* {@inheritDoc}
*
......
......@@ -202,6 +202,13 @@ public class LogoBaseVisitor<T> extends AbstractParseTreeVisitor<T> implements L
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitParenthese(LogoParser.ParentheseContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitExecuteFonction(LogoParser.ExecuteFonctionContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
......
......@@ -327,6 +327,18 @@ public interface LogoListener extends ParseTreeListener {
* @param ctx the parse tree
*/
void exitParenthese(LogoParser.ParentheseContext ctx);
/**
* Enter a parse tree produced by the {@code executeFonction}
* labeled alternative in {@link LogoParser#expr}.
* @param ctx the parse tree
*/
void enterExecuteFonction(LogoParser.ExecuteFonctionContext ctx);
/**
* Exit a parse tree produced by the {@code executeFonction}
* labeled alternative in {@link LogoParser#expr}.
* @param ctx the parse tree
*/
void exitExecuteFonction(LogoParser.ExecuteFonctionContext ctx);
/**
* Enter a parse tree produced by the {@code sum}
* labeled alternative in {@link LogoParser#expr}.
......
This diff is collapsed.
......@@ -46,6 +46,7 @@ public class LogoTreeVisitor extends LogoBaseVisitor<Integer> {
TableSymboles tableSymbGlobale;
//用来保存VAR和其对应的Procedure
Map<String, Procedure> tableProcedures;
Map<String, Fonction> tableFonctions;
// 用来保留两位小数
DecimalFormat df = new DecimalFormat("#.00");
......@@ -56,6 +57,7 @@ public class LogoTreeVisitor extends LogoBaseVisitor<Integer> {
this.tableSymbGlobale = new TableSymboles();
this.pileExecution = new Stack<>();
this.tableProcedures = new HashMap<>();
this.tableFonctions = new HashMap<>();
pileExecution.push(tableSymbGlobale);
}
......@@ -214,9 +216,74 @@ public class LogoTreeVisitor extends LogoBaseVisitor<Integer> {
return 0;
}
// @Override
// public Integer visitProcedure(LogoParser.ProcedureContext ctx) {
// String nomProcedure = ctx.VAR().getText();
// //创建一个作用域,然后推入执行栈中,方便参数列表把记住所有的参数名
// TableSymboles currentTableSymboles = new TableSymboles();
// pileExecution.push(currentTableSymboles);
//
// Liste_instructionsContext listeInstructions = ctx.liste_instructions();
// //通过执行栈存储参数列表
// Integer createListeParamsSuccess;
// if (ctx.liste_parametres() != null) {
// //如果有参数传进来
// createListeParamsSuccess = visit(ctx.liste_parametres());
// } else {
// //如果没有参数
// createListeParamsSuccess = 0;
// }
//
// //获取到参数名之后,创建相应的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();
//
// //通过名字从tableProcedures拿到过程
// 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(index);
// tableSymbolesLocale.creerVar(nomParam, exprValue);
// index++;
// } else return -1;//在调用函数的时候参数的个数和申明函数时不一样
// }
// pileExecution.push(tableSymbolesLocale);
//
// //开始执行语句
// int doesSuccess = visit(listeInstructions);
// if (doesSuccess == 0) {
// pileExecution.pop();
// return 0;
// } else return -2;
//
// }
@Override
public Integer visitProcedure(LogoParser.ProcedureContext ctx) {
String nomProcedure = ctx.VAR().getText();
public Integer visitFonction(LogoParser.FonctionContext ctx) {
String nomFonction = ctx.VAR().getText();
//创建一个作用域,然后推入执行栈中,方便参数列表把记住所有的参数名
TableSymboles currentTableSymboles = new TableSymboles();
pileExecution.push(currentTableSymboles);
......@@ -224,35 +291,37 @@ public class LogoTreeVisitor extends LogoBaseVisitor<Integer> {
Liste_instructionsContext listeInstructions = ctx.liste_instructions();
//通过执行栈存储参数列表
Integer createListeParamsSuccess;
if(ctx.liste_parametres() != null) {
if (ctx.liste_parametres() != null) {
//如果有参数传进来
createListeParamsSuccess = visit(ctx.liste_parametres());
}else {
} else {
//如果没有参数
createListeParamsSuccess = 0;
}
//获取到参数名之后,创建相应的procedure实例
//获取到参数名之后,创建相应的fonction实例
currentTableSymboles = pileExecution.pop();
if (createListeParamsSuccess == 0) {
Procedure newProcedure = new Procedure(nomProcedure, currentTableSymboles, listeInstructions);
tableProcedures.put(nomProcedure, newProcedure);
Fonction newFonction = new Fonction(nomFonction, currentTableSymboles, listeInstructions);
newFonction.setResult(ctx.expr());
tableFonctions.put(nomFonction, newFonction);
return 0;
} else return -1;
}
@Override
public Integer visitExecuteProcedure(LogoParser.ExecuteProcedureContext ctx) {
public Integer visitExecuteFonction(LogoParser.ExecuteFonctionContext ctx) {
//拿到过程的名字
String nomProcedure = ctx.VAR().getText();
String nomFonction = ctx.VAR().getText();
//通过名字从tableProcedures拿到过程
Procedure currentProcedure = tableProcedures.get(nomProcedure);
Liste_instructionsContext listeInstructions = currentProcedure.getListeInstructions();
Fonction currentFonction = tableFonctions.get(nomFonction);
LogoParser.ExprContext result = currentFonction.getResult();
Liste_instructionsContext listeInstructions = currentFonction.getListeInstructions();
//在执行过程的时候需要把作用域推入执行栈
TableSymboles tableSymbolesLocale = currentProcedure.getTableSymbLocale();
TableSymboles tableSymbolesLocale = currentFonction.getTableSymbLocale();
List<String> nomsParams = tableSymbolesLocale.getListeNomsParams();
List<LogoParser.ExprContext> listeParamsValues = ctx.expr();
......@@ -260,7 +329,7 @@ public class LogoTreeVisitor extends LogoBaseVisitor<Integer> {
//给符号表中的参数赋值
for (LogoParser.ExprContext currentExpr : listeParamsValues) {
if(index < nomsParams.size()) {
if (index < nomsParams.size()) {
Binome expr = evaluateExpr(currentExpr);
Double exprValue = expr._2;
String nomParam = nomsParams.get(index);
......@@ -271,12 +340,22 @@ public class LogoTreeVisitor extends LogoBaseVisitor<Integer> {
pileExecution.push(tableSymbolesLocale);
//开始执行语句
int doesSuccess = visit(listeInstructions);
if(doesSuccess == 0) {
if(listeInstructions != null){
int doesSuccess = visit(listeInstructions);
if (doesSuccess == 0) {
Binome resultBinome = evaluateExpr(result);
if (resultBinome._1 == 0) setExprValue(ctx, resultBinome._2);
else return -3;//无法给返回值赋值
pileExecution.pop();
return 0;
} else return -2;//函数的指令集执行错误
}else {
Binome resultBinome = evaluateExpr(result);
if (resultBinome._1 == 0) setExprValue(ctx, resultBinome._2);
else return -3;//无法给返回值赋值
pileExecution.pop();
return 0;
}
else return -2;
}
......
......@@ -198,6 +198,13 @@ public interface LogoVisitor<T> extends ParseTreeVisitor<T> {
* @return the visitor result
*/
T visitParenthese(LogoParser.ParentheseContext ctx);
/**
* Visit a parse tree produced by the {@code executeFonction}
* labeled alternative in {@link LogoParser#expr}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitExecuteFonction(LogoParser.ExecuteFonctionContext ctx);
/**
* Visit a parse tree produced by the {@code sum}
* labeled alternative in {@link LogoParser#expr}.
......
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