完善了ptml的g4语法描述文件,重新生成对应的解析文件,创建CST遍历代码(待实现)

This commit is contained in:
2193177243@qq.com 2023-10-07 08:42:04 +08:00
parent b15c9d575c
commit 005558e29c
10 changed files with 268 additions and 156 deletions

View File

@ -1,13 +1,13 @@
sequence:
select:
CoffeeCupFound
FindCoffeeCup
cond CoffeeCupFound()
act FindCoffeeCup()
select:
CoffeeCupGrasped
GraspCoffeeCup
cond CoffeeCupGrasped()
act GraspCoffeeCup()
select:
DestinationAReached
ReachDestinationA
cond DestinationAReached()
act ReachDestinationA()
select:
CoffeeCupPlaced
PlaceCoffeeCup
cond CoffeeCupPlaced()
act PlaceCoffeeCup()

17
ptml/btAPI.py Normal file
View File

@ -0,0 +1,17 @@
import py_trees as bt
class BTAPI():
"""
"""
def __init__(self) -> None:
self.string = None
def newTree(self) -> bt.trees.BehaviourTree:
"""_summary_
Returns:
bt.trees.BehaviourTree: _description_
"""

View File

@ -2,7 +2,7 @@ grammar ptml;
tree : internal_node ':' (action_sign|tree)+ EOF;
internal_node : 'sequence' | 'selector' | 'parallel' Integer | 'decorator' ;
action_sign : 'act' Names '(' action_parm? ')';
action_sign : ('act'|'cond') Names '(' action_parm? ')';
action_parm : (var_decls|Integer|Float|boolean) (',' (var_decls|Integer|Float|boolean))* ;
var_decls : var_type Names ;
var_type : 'int' | 'float' | 'bool' | 'string' ;
@ -12,8 +12,6 @@ Names : [a-zA-Z_][a-zA-Z_0-9]* ;
Integer : '-'?[1-9][0-9]* | '0' ;
Float : [0-9]+'.'[0-9]* | '.'[0-9]+ ;
// comments
LINE_COMMENT : '//' .*? '\r'?'\n' -> skip ;
// useless

View File

@ -6,6 +6,7 @@ null
'parallel'
'decorator'
'act'
'cond'
'('
')'
','
@ -38,6 +39,7 @@ null
null
null
null
null
Names
Integer
Float
@ -55,4 +57,4 @@ boolean
atn:
[4, 1, 20, 65, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 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, 8, 3, 10, 3, 12, 3, 56, 9, 3, 1, 4, 1, 4, 1, 4, 1, 5, 1, 5, 1, 6, 1, 6, 1, 6, 0, 0, 7, 0, 2, 4, 6, 8, 10, 12, 0, 3, 1, 0, 6, 7, 1, 0, 11, 14, 1, 0, 15, 16, 70, 0, 14, 1, 0, 0, 0, 2, 29, 1, 0, 0, 0, 4, 31, 1, 0, 0, 0, 6, 43, 1, 0, 0, 0, 8, 57, 1, 0, 0, 0, 10, 60, 1, 0, 0, 0, 12, 62, 1, 0, 0, 0, 14, 15, 3, 2, 1, 0, 15, 18, 5, 1, 0, 0, 16, 19, 3, 4, 2, 0, 17, 19, 3, 0, 0, 0, 18, 16, 1, 0, 0, 0, 18, 17, 1, 0, 0, 0, 19, 20, 1, 0, 0, 0, 20, 18, 1, 0, 0, 0, 20, 21, 1, 0, 0, 0, 21, 22, 1, 0, 0, 0, 22, 23, 5, 0, 0, 1, 23, 1, 1, 0, 0, 0, 24, 30, 5, 2, 0, 0, 25, 30, 5, 3, 0, 0, 26, 27, 5, 4, 0, 0, 27, 30, 5, 18, 0, 0, 28, 30, 5, 5, 0, 0, 29, 24, 1, 0, 0, 0, 29, 25, 1, 0, 0, 0, 29, 26, 1, 0, 0, 0, 29, 28, 1, 0, 0, 0, 30, 3, 1, 0, 0, 0, 31, 32, 7, 0, 0, 0, 32, 33, 5, 17, 0, 0, 33, 35, 5, 8, 0, 0, 34, 36, 3, 6, 3, 0, 35, 34, 1, 0, 0, 0, 35, 36, 1, 0, 0, 0, 36, 37, 1, 0, 0, 0, 37, 38, 5, 9, 0, 0, 38, 5, 1, 0, 0, 0, 39, 44, 3, 8, 4, 0, 40, 44, 5, 18, 0, 0, 41, 44, 5, 19, 0, 0, 42, 44, 3, 12, 6, 0, 43, 39, 1, 0, 0, 0, 43, 40, 1, 0, 0, 0, 43, 41, 1, 0, 0, 0, 43, 42, 1, 0, 0, 0, 44, 54, 1, 0, 0, 0, 45, 50, 5, 10, 0, 0, 46, 51, 3, 8, 4, 0, 47, 51, 5, 18, 0, 0, 48, 51, 5, 19, 0, 0, 49, 51, 3, 12, 6, 0, 50, 46, 1, 0, 0, 0, 50, 47, 1, 0, 0, 0, 50, 48, 1, 0, 0, 0, 50, 49, 1, 0, 0, 0, 51, 53, 1, 0, 0, 0, 52, 45, 1, 0, 0, 0, 53, 56, 1, 0, 0, 0, 54, 52, 1, 0, 0, 0, 54, 55, 1, 0, 0, 0, 55, 7, 1, 0, 0, 0, 56, 54, 1, 0, 0, 0, 57, 58, 3, 10, 5, 0, 58, 59, 5, 17, 0, 0, 59, 9, 1, 0, 0, 0, 60, 61, 7, 1, 0, 0, 61, 11, 1, 0, 0, 0, 62, 63, 7, 2, 0, 0, 63, 13, 1, 0, 0, 0, 7, 18, 20, 29, 35, 43, 50, 54]

View File

@ -13,23 +13,25 @@ T__11=12
T__12=13
T__13=14
T__14=15
Names=16
Integer=17
Float=18
LINE_COMMENT=19
WS=20
T__15=16
Names=17
Integer=18
Float=19
LINE_COMMENT=20
WS=21
':'=1
'sequence'=2
'selector'=3
'parallel'=4
'decorator'=5
'act'=6
'('=7
')'=8
','=9
'int'=10
'float'=11
'bool'=12
'string'=13
'True'=14
'False'=15
'cond'=7
'('=8
')'=9
','=10
'int'=11
'float'=12
'bool'=13
'string'=14
'True'=15
'False'=16

File diff suppressed because one or more lines are too long

View File

@ -10,72 +10,75 @@ else:
def serializedATN():
return [
4,0,20,186,6,-1,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,
4,0,21,193,6,-1,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,
2,6,7,6,2,7,7,7,2,8,7,8,2,9,7,9,2,10,7,10,2,11,7,11,2,12,7,12,2,
13,7,13,2,14,7,14,2,15,7,15,2,16,7,16,2,17,7,17,2,18,7,18,2,19,7,
19,1,0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,1,2,1,2,1,2,1,
2,1,2,1,2,1,2,1,2,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,4,1,4,1,
4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,5,1,5,1,5,1,5,1,6,1,6,1,7,1,7,1,
8,1,8,1,9,1,9,1,9,1,9,1,10,1,10,1,10,1,10,1,10,1,10,1,11,1,11,1,
11,1,11,1,11,1,12,1,12,1,12,1,12,1,12,1,12,1,12,1,13,1,13,1,13,1,
13,1,13,1,14,1,14,1,14,1,14,1,14,1,14,1,15,1,15,5,15,126,8,15,10,
15,12,15,129,9,15,1,16,3,16,132,8,16,1,16,1,16,5,16,136,8,16,10,
16,12,16,139,9,16,1,16,3,16,142,8,16,1,17,4,17,145,8,17,11,17,12,
17,146,1,17,1,17,5,17,151,8,17,10,17,12,17,154,9,17,1,17,1,17,4,
17,158,8,17,11,17,12,17,159,3,17,162,8,17,1,18,1,18,1,18,1,18,5,
18,168,8,18,10,18,12,18,171,9,18,1,18,3,18,174,8,18,1,18,1,18,1,
18,1,18,1,19,4,19,181,8,19,11,19,12,19,182,1,19,1,19,1,169,0,20,
1,1,3,2,5,3,7,4,9,5,11,6,13,7,15,8,17,9,19,10,21,11,23,12,25,13,
27,14,29,15,31,16,33,17,35,18,37,19,39,20,1,0,5,3,0,65,90,95,95,
97,122,4,0,48,57,65,90,95,95,97,122,1,0,49,57,1,0,48,57,3,0,9,10,
12,13,32,32,196,0,1,1,0,0,0,0,3,1,0,0,0,0,5,1,0,0,0,0,7,1,0,0,0,
0,9,1,0,0,0,0,11,1,0,0,0,0,13,1,0,0,0,0,15,1,0,0,0,0,17,1,0,0,0,
0,19,1,0,0,0,0,21,1,0,0,0,0,23,1,0,0,0,0,25,1,0,0,0,0,27,1,0,0,0,
0,29,1,0,0,0,0,31,1,0,0,0,0,33,1,0,0,0,0,35,1,0,0,0,0,37,1,0,0,0,
0,39,1,0,0,0,1,41,1,0,0,0,3,43,1,0,0,0,5,52,1,0,0,0,7,61,1,0,0,0,
9,70,1,0,0,0,11,80,1,0,0,0,13,84,1,0,0,0,15,86,1,0,0,0,17,88,1,0,
0,0,19,90,1,0,0,0,21,94,1,0,0,0,23,100,1,0,0,0,25,105,1,0,0,0,27,
112,1,0,0,0,29,117,1,0,0,0,31,123,1,0,0,0,33,141,1,0,0,0,35,161,
1,0,0,0,37,163,1,0,0,0,39,180,1,0,0,0,41,42,5,58,0,0,42,2,1,0,0,
0,43,44,5,115,0,0,44,45,5,101,0,0,45,46,5,113,0,0,46,47,5,117,0,
0,47,48,5,101,0,0,48,49,5,110,0,0,49,50,5,99,0,0,50,51,5,101,0,0,
51,4,1,0,0,0,52,53,5,115,0,0,53,54,5,101,0,0,54,55,5,108,0,0,55,
56,5,101,0,0,56,57,5,99,0,0,57,58,5,116,0,0,58,59,5,111,0,0,59,60,
5,114,0,0,60,6,1,0,0,0,61,62,5,112,0,0,62,63,5,97,0,0,63,64,5,114,
0,0,64,65,5,97,0,0,65,66,5,108,0,0,66,67,5,108,0,0,67,68,5,101,0,
0,68,69,5,108,0,0,69,8,1,0,0,0,70,71,5,100,0,0,71,72,5,101,0,0,72,
73,5,99,0,0,73,74,5,111,0,0,74,75,5,114,0,0,75,76,5,97,0,0,76,77,
5,116,0,0,77,78,5,111,0,0,78,79,5,114,0,0,79,10,1,0,0,0,80,81,5,
97,0,0,81,82,5,99,0,0,82,83,5,116,0,0,83,12,1,0,0,0,84,85,5,40,0,
0,85,14,1,0,0,0,86,87,5,41,0,0,87,16,1,0,0,0,88,89,5,44,0,0,89,18,
1,0,0,0,90,91,5,105,0,0,91,92,5,110,0,0,92,93,5,116,0,0,93,20,1,
0,0,0,94,95,5,102,0,0,95,96,5,108,0,0,96,97,5,111,0,0,97,98,5,97,
0,0,98,99,5,116,0,0,99,22,1,0,0,0,100,101,5,98,0,0,101,102,5,111,
0,0,102,103,5,111,0,0,103,104,5,108,0,0,104,24,1,0,0,0,105,106,5,
115,0,0,106,107,5,116,0,0,107,108,5,114,0,0,108,109,5,105,0,0,109,
110,5,110,0,0,110,111,5,103,0,0,111,26,1,0,0,0,112,113,5,84,0,0,
113,114,5,114,0,0,114,115,5,117,0,0,115,116,5,101,0,0,116,28,1,0,
0,0,117,118,5,70,0,0,118,119,5,97,0,0,119,120,5,108,0,0,120,121,
5,115,0,0,121,122,5,101,0,0,122,30,1,0,0,0,123,127,7,0,0,0,124,126,
7,1,0,0,125,124,1,0,0,0,126,129,1,0,0,0,127,125,1,0,0,0,127,128,
1,0,0,0,128,32,1,0,0,0,129,127,1,0,0,0,130,132,5,45,0,0,131,130,
1,0,0,0,131,132,1,0,0,0,132,133,1,0,0,0,133,137,7,2,0,0,134,136,
7,3,0,0,135,134,1,0,0,0,136,139,1,0,0,0,137,135,1,0,0,0,137,138,
1,0,0,0,138,142,1,0,0,0,139,137,1,0,0,0,140,142,5,48,0,0,141,131,
1,0,0,0,141,140,1,0,0,0,142,34,1,0,0,0,143,145,7,3,0,0,144,143,1,
0,0,0,145,146,1,0,0,0,146,144,1,0,0,0,146,147,1,0,0,0,147,148,1,
0,0,0,148,152,5,46,0,0,149,151,7,3,0,0,150,149,1,0,0,0,151,154,1,
0,0,0,152,150,1,0,0,0,152,153,1,0,0,0,153,162,1,0,0,0,154,152,1,
0,0,0,155,157,5,46,0,0,156,158,7,3,0,0,157,156,1,0,0,0,158,159,1,
0,0,0,159,157,1,0,0,0,159,160,1,0,0,0,160,162,1,0,0,0,161,144,1,
0,0,0,161,155,1,0,0,0,162,36,1,0,0,0,163,164,5,47,0,0,164,165,5,
47,0,0,165,169,1,0,0,0,166,168,9,0,0,0,167,166,1,0,0,0,168,171,1,
0,0,0,169,170,1,0,0,0,169,167,1,0,0,0,170,173,1,0,0,0,171,169,1,
0,0,0,172,174,5,13,0,0,173,172,1,0,0,0,173,174,1,0,0,0,174,175,1,
0,0,0,175,176,5,10,0,0,176,177,1,0,0,0,177,178,6,18,0,0,178,38,1,
0,0,0,179,181,7,4,0,0,180,179,1,0,0,0,181,182,1,0,0,0,182,180,1,
0,0,0,182,183,1,0,0,0,183,184,1,0,0,0,184,185,6,19,0,0,185,40,1,
0,0,0,12,0,127,131,137,141,146,152,159,161,169,173,182,1,6,0,0
19,2,20,7,20,1,0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,1,2,
1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,
1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,5,1,5,1,5,1,5,1,6,1,6,
1,6,1,6,1,6,1,7,1,7,1,8,1,8,1,9,1,9,1,10,1,10,1,10,1,10,1,11,1,11,
1,11,1,11,1,11,1,11,1,12,1,12,1,12,1,12,1,12,1,13,1,13,1,13,1,13,
1,13,1,13,1,13,1,14,1,14,1,14,1,14,1,14,1,15,1,15,1,15,1,15,1,15,
1,15,1,16,1,16,5,16,133,8,16,10,16,12,16,136,9,16,1,17,3,17,139,
8,17,1,17,1,17,5,17,143,8,17,10,17,12,17,146,9,17,1,17,3,17,149,
8,17,1,18,4,18,152,8,18,11,18,12,18,153,1,18,1,18,5,18,158,8,18,
10,18,12,18,161,9,18,1,18,1,18,4,18,165,8,18,11,18,12,18,166,3,18,
169,8,18,1,19,1,19,1,19,1,19,5,19,175,8,19,10,19,12,19,178,9,19,
1,19,3,19,181,8,19,1,19,1,19,1,19,1,19,1,20,4,20,188,8,20,11,20,
12,20,189,1,20,1,20,1,176,0,21,1,1,3,2,5,3,7,4,9,5,11,6,13,7,15,
8,17,9,19,10,21,11,23,12,25,13,27,14,29,15,31,16,33,17,35,18,37,
19,39,20,41,21,1,0,5,3,0,65,90,95,95,97,122,4,0,48,57,65,90,95,95,
97,122,1,0,49,57,1,0,48,57,3,0,9,10,12,13,32,32,203,0,1,1,0,0,0,
0,3,1,0,0,0,0,5,1,0,0,0,0,7,1,0,0,0,0,9,1,0,0,0,0,11,1,0,0,0,0,13,
1,0,0,0,0,15,1,0,0,0,0,17,1,0,0,0,0,19,1,0,0,0,0,21,1,0,0,0,0,23,
1,0,0,0,0,25,1,0,0,0,0,27,1,0,0,0,0,29,1,0,0,0,0,31,1,0,0,0,0,33,
1,0,0,0,0,35,1,0,0,0,0,37,1,0,0,0,0,39,1,0,0,0,0,41,1,0,0,0,1,43,
1,0,0,0,3,45,1,0,0,0,5,54,1,0,0,0,7,63,1,0,0,0,9,72,1,0,0,0,11,82,
1,0,0,0,13,86,1,0,0,0,15,91,1,0,0,0,17,93,1,0,0,0,19,95,1,0,0,0,
21,97,1,0,0,0,23,101,1,0,0,0,25,107,1,0,0,0,27,112,1,0,0,0,29,119,
1,0,0,0,31,124,1,0,0,0,33,130,1,0,0,0,35,148,1,0,0,0,37,168,1,0,
0,0,39,170,1,0,0,0,41,187,1,0,0,0,43,44,5,58,0,0,44,2,1,0,0,0,45,
46,5,115,0,0,46,47,5,101,0,0,47,48,5,113,0,0,48,49,5,117,0,0,49,
50,5,101,0,0,50,51,5,110,0,0,51,52,5,99,0,0,52,53,5,101,0,0,53,4,
1,0,0,0,54,55,5,115,0,0,55,56,5,101,0,0,56,57,5,108,0,0,57,58,5,
101,0,0,58,59,5,99,0,0,59,60,5,116,0,0,60,61,5,111,0,0,61,62,5,114,
0,0,62,6,1,0,0,0,63,64,5,112,0,0,64,65,5,97,0,0,65,66,5,114,0,0,
66,67,5,97,0,0,67,68,5,108,0,0,68,69,5,108,0,0,69,70,5,101,0,0,70,
71,5,108,0,0,71,8,1,0,0,0,72,73,5,100,0,0,73,74,5,101,0,0,74,75,
5,99,0,0,75,76,5,111,0,0,76,77,5,114,0,0,77,78,5,97,0,0,78,79,5,
116,0,0,79,80,5,111,0,0,80,81,5,114,0,0,81,10,1,0,0,0,82,83,5,97,
0,0,83,84,5,99,0,0,84,85,5,116,0,0,85,12,1,0,0,0,86,87,5,99,0,0,
87,88,5,111,0,0,88,89,5,110,0,0,89,90,5,100,0,0,90,14,1,0,0,0,91,
92,5,40,0,0,92,16,1,0,0,0,93,94,5,41,0,0,94,18,1,0,0,0,95,96,5,44,
0,0,96,20,1,0,0,0,97,98,5,105,0,0,98,99,5,110,0,0,99,100,5,116,0,
0,100,22,1,0,0,0,101,102,5,102,0,0,102,103,5,108,0,0,103,104,5,111,
0,0,104,105,5,97,0,0,105,106,5,116,0,0,106,24,1,0,0,0,107,108,5,
98,0,0,108,109,5,111,0,0,109,110,5,111,0,0,110,111,5,108,0,0,111,
26,1,0,0,0,112,113,5,115,0,0,113,114,5,116,0,0,114,115,5,114,0,0,
115,116,5,105,0,0,116,117,5,110,0,0,117,118,5,103,0,0,118,28,1,0,
0,0,119,120,5,84,0,0,120,121,5,114,0,0,121,122,5,117,0,0,122,123,
5,101,0,0,123,30,1,0,0,0,124,125,5,70,0,0,125,126,5,97,0,0,126,127,
5,108,0,0,127,128,5,115,0,0,128,129,5,101,0,0,129,32,1,0,0,0,130,
134,7,0,0,0,131,133,7,1,0,0,132,131,1,0,0,0,133,136,1,0,0,0,134,
132,1,0,0,0,134,135,1,0,0,0,135,34,1,0,0,0,136,134,1,0,0,0,137,139,
5,45,0,0,138,137,1,0,0,0,138,139,1,0,0,0,139,140,1,0,0,0,140,144,
7,2,0,0,141,143,7,3,0,0,142,141,1,0,0,0,143,146,1,0,0,0,144,142,
1,0,0,0,144,145,1,0,0,0,145,149,1,0,0,0,146,144,1,0,0,0,147,149,
5,48,0,0,148,138,1,0,0,0,148,147,1,0,0,0,149,36,1,0,0,0,150,152,
7,3,0,0,151,150,1,0,0,0,152,153,1,0,0,0,153,151,1,0,0,0,153,154,
1,0,0,0,154,155,1,0,0,0,155,159,5,46,0,0,156,158,7,3,0,0,157,156,
1,0,0,0,158,161,1,0,0,0,159,157,1,0,0,0,159,160,1,0,0,0,160,169,
1,0,0,0,161,159,1,0,0,0,162,164,5,46,0,0,163,165,7,3,0,0,164,163,
1,0,0,0,165,166,1,0,0,0,166,164,1,0,0,0,166,167,1,0,0,0,167,169,
1,0,0,0,168,151,1,0,0,0,168,162,1,0,0,0,169,38,1,0,0,0,170,171,5,
47,0,0,171,172,5,47,0,0,172,176,1,0,0,0,173,175,9,0,0,0,174,173,
1,0,0,0,175,178,1,0,0,0,176,177,1,0,0,0,176,174,1,0,0,0,177,180,
1,0,0,0,178,176,1,0,0,0,179,181,5,13,0,0,180,179,1,0,0,0,180,181,
1,0,0,0,181,182,1,0,0,0,182,183,5,10,0,0,183,184,1,0,0,0,184,185,
6,19,0,0,185,40,1,0,0,0,186,188,7,4,0,0,187,186,1,0,0,0,188,189,
1,0,0,0,189,187,1,0,0,0,189,190,1,0,0,0,190,191,1,0,0,0,191,192,
6,20,0,0,192,42,1,0,0,0,12,0,134,138,144,148,153,159,166,168,176,
180,189,1,6,0,0
]
class ptmlLexer(Lexer):
@ -99,11 +102,12 @@ class ptmlLexer(Lexer):
T__12 = 13
T__13 = 14
T__14 = 15
Names = 16
Integer = 17
Float = 18
LINE_COMMENT = 19
WS = 20
T__15 = 16
Names = 17
Integer = 18
Float = 19
LINE_COMMENT = 20
WS = 21
channelNames = [ u"DEFAULT_TOKEN_CHANNEL", u"HIDDEN" ]
@ -111,15 +115,15 @@ class ptmlLexer(Lexer):
literalNames = [ "<INVALID>",
"':'", "'sequence'", "'selector'", "'parallel'", "'decorator'",
"'act'", "'('", "')'", "','", "'int'", "'float'", "'bool'",
"'string'", "'True'", "'False'" ]
"'act'", "'cond'", "'('", "')'", "','", "'int'", "'float'",
"'bool'", "'string'", "'True'", "'False'" ]
symbolicNames = [ "<INVALID>",
"Names", "Integer", "Float", "LINE_COMMENT", "WS" ]
ruleNames = [ "T__0", "T__1", "T__2", "T__3", "T__4", "T__5", "T__6",
"T__7", "T__8", "T__9", "T__10", "T__11", "T__12", "T__13",
"T__14", "Names", "Integer", "Float", "LINE_COMMENT",
"T__14", "T__15", "Names", "Integer", "Float", "LINE_COMMENT",
"WS" ]
grammarFileName = "ptml.g4"

View File

@ -13,23 +13,25 @@ T__11=12
T__12=13
T__13=14
T__14=15
Names=16
Integer=17
Float=18
LINE_COMMENT=19
WS=20
T__15=16
Names=17
Integer=18
Float=19
LINE_COMMENT=20
WS=21
':'=1
'sequence'=2
'selector'=3
'parallel'=4
'decorator'=5
'act'=6
'('=7
')'=8
','=9
'int'=10
'float'=11
'bool'=12
'string'=13
'True'=14
'False'=15
'cond'=7
'('=8
')'=9
','=10
'int'=11
'float'=12
'bool'=13
'string'=14
'True'=15
'False'=16

View File

@ -10,27 +10,27 @@ else:
def serializedATN():
return [
4,1,20,65,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,2,6,7,
4,1,21,65,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,2,6,7,
6,1,0,1,0,1,0,1,0,4,0,19,8,0,11,0,12,0,20,1,0,1,0,1,1,1,1,1,1,1,
1,1,1,3,1,30,8,1,1,2,1,2,1,2,1,2,3,2,36,8,2,1,2,1,2,1,3,1,3,1,3,
1,3,3,3,44,8,3,1,3,1,3,1,3,1,3,1,3,3,3,51,8,3,5,3,53,8,3,10,3,12,
3,56,9,3,1,4,1,4,1,4,1,5,1,5,1,6,1,6,1,6,0,0,7,0,2,4,6,8,10,12,0,
2,1,0,10,13,1,0,14,15,70,0,14,1,0,0,0,2,29,1,0,0,0,4,31,1,0,0,0,
6,43,1,0,0,0,8,57,1,0,0,0,10,60,1,0,0,0,12,62,1,0,0,0,14,15,3,2,
1,0,15,18,5,1,0,0,16,19,3,4,2,0,17,19,3,0,0,0,18,16,1,0,0,0,18,17,
1,0,0,0,19,20,1,0,0,0,20,18,1,0,0,0,20,21,1,0,0,0,21,22,1,0,0,0,
22,23,5,0,0,1,23,1,1,0,0,0,24,30,5,2,0,0,25,30,5,3,0,0,26,27,5,4,
0,0,27,30,5,17,0,0,28,30,5,5,0,0,29,24,1,0,0,0,29,25,1,0,0,0,29,
26,1,0,0,0,29,28,1,0,0,0,30,3,1,0,0,0,31,32,5,6,0,0,32,33,5,16,0,
0,33,35,5,7,0,0,34,36,3,6,3,0,35,34,1,0,0,0,35,36,1,0,0,0,36,37,
1,0,0,0,37,38,5,8,0,0,38,5,1,0,0,0,39,44,3,8,4,0,40,44,5,17,0,0,
41,44,5,18,0,0,42,44,3,12,6,0,43,39,1,0,0,0,43,40,1,0,0,0,43,41,
1,0,0,0,43,42,1,0,0,0,44,54,1,0,0,0,45,50,5,9,0,0,46,51,3,8,4,0,
47,51,5,17,0,0,48,51,5,18,0,0,49,51,3,12,6,0,50,46,1,0,0,0,50,47,
1,0,0,0,50,48,1,0,0,0,50,49,1,0,0,0,51,53,1,0,0,0,52,45,1,0,0,0,
53,56,1,0,0,0,54,52,1,0,0,0,54,55,1,0,0,0,55,7,1,0,0,0,56,54,1,0,
0,0,57,58,3,10,5,0,58,59,5,16,0,0,59,9,1,0,0,0,60,61,7,0,0,0,61,
11,1,0,0,0,62,63,7,1,0,0,63,13,1,0,0,0,7,18,20,29,35,43,50,54
3,1,0,6,7,1,0,11,14,1,0,15,16,70,0,14,1,0,0,0,2,29,1,0,0,0,4,31,
1,0,0,0,6,43,1,0,0,0,8,57,1,0,0,0,10,60,1,0,0,0,12,62,1,0,0,0,14,
15,3,2,1,0,15,18,5,1,0,0,16,19,3,4,2,0,17,19,3,0,0,0,18,16,1,0,0,
0,18,17,1,0,0,0,19,20,1,0,0,0,20,18,1,0,0,0,20,21,1,0,0,0,21,22,
1,0,0,0,22,23,5,0,0,1,23,1,1,0,0,0,24,30,5,2,0,0,25,30,5,3,0,0,26,
27,5,4,0,0,27,30,5,18,0,0,28,30,5,5,0,0,29,24,1,0,0,0,29,25,1,0,
0,0,29,26,1,0,0,0,29,28,1,0,0,0,30,3,1,0,0,0,31,32,7,0,0,0,32,33,
5,17,0,0,33,35,5,8,0,0,34,36,3,6,3,0,35,34,1,0,0,0,35,36,1,0,0,0,
36,37,1,0,0,0,37,38,5,9,0,0,38,5,1,0,0,0,39,44,3,8,4,0,40,44,5,18,
0,0,41,44,5,19,0,0,42,44,3,12,6,0,43,39,1,0,0,0,43,40,1,0,0,0,43,
41,1,0,0,0,43,42,1,0,0,0,44,54,1,0,0,0,45,50,5,10,0,0,46,51,3,8,
4,0,47,51,5,18,0,0,48,51,5,19,0,0,49,51,3,12,6,0,50,46,1,0,0,0,50,
47,1,0,0,0,50,48,1,0,0,0,50,49,1,0,0,0,51,53,1,0,0,0,52,45,1,0,0,
0,53,56,1,0,0,0,54,52,1,0,0,0,54,55,1,0,0,0,55,7,1,0,0,0,56,54,1,
0,0,0,57,58,3,10,5,0,58,59,5,17,0,0,59,9,1,0,0,0,60,61,7,1,0,0,61,
11,1,0,0,0,62,63,7,2,0,0,63,13,1,0,0,0,7,18,20,29,35,43,50,54
]
class ptmlParser ( Parser ):
@ -44,14 +44,16 @@ class ptmlParser ( Parser ):
sharedContextCache = PredictionContextCache()
literalNames = [ "<INVALID>", "':'", "'sequence'", "'selector'", "'parallel'",
"'decorator'", "'act'", "'('", "')'", "','", "'int'",
"'float'", "'bool'", "'string'", "'True'", "'False'" ]
"'decorator'", "'act'", "'cond'", "'('", "')'", "','",
"'int'", "'float'", "'bool'", "'string'", "'True'",
"'False'" ]
symbolicNames = [ "<INVALID>", "<INVALID>", "<INVALID>", "<INVALID>",
"<INVALID>", "<INVALID>", "<INVALID>", "<INVALID>",
"<INVALID>", "<INVALID>", "<INVALID>", "<INVALID>",
"<INVALID>", "<INVALID>", "<INVALID>", "<INVALID>",
"Names", "Integer", "Float", "LINE_COMMENT", "WS" ]
"<INVALID>", "Names", "Integer", "Float", "LINE_COMMENT",
"WS" ]
RULE_tree = 0
RULE_internal_node = 1
@ -80,11 +82,12 @@ class ptmlParser ( Parser ):
T__12=13
T__13=14
T__14=15
Names=16
Integer=17
Float=18
LINE_COMMENT=19
WS=20
T__15=16
Names=17
Integer=18
Float=19
LINE_COMMENT=20
WS=21
def __init__(self, input:TokenStream, output:TextIO = sys.stdout):
super().__init__(input, output)
@ -155,7 +158,7 @@ class ptmlParser ( Parser ):
self.state = 18
self._errHandler.sync(self)
token = self._input.LA(1)
if token in [6]:
if token in [6, 7]:
self.state = 16
self.action_sign()
pass
@ -169,7 +172,7 @@ class ptmlParser ( Parser ):
self.state = 20
self._errHandler.sync(self)
_la = self._input.LA(1)
if not ((((_la) & ~0x3f) == 0 and ((1 << _la) & 124) != 0)):
if not ((((_la) & ~0x3f) == 0 and ((1 << _la) & 252) != 0)):
break
self.state = 22
@ -285,21 +288,26 @@ class ptmlParser ( Parser ):
try:
self.enterOuterAlt(localctx, 1)
self.state = 31
self.match(ptmlParser.T__5)
_la = self._input.LA(1)
if not(_la==6 or _la==7):
self._errHandler.recoverInline(self)
else:
self._errHandler.reportMatch(self)
self.consume()
self.state = 32
self.match(ptmlParser.Names)
self.state = 33
self.match(ptmlParser.T__6)
self.match(ptmlParser.T__7)
self.state = 35
self._errHandler.sync(self)
_la = self._input.LA(1)
if (((_la) & ~0x3f) == 0 and ((1 << _la) & 457728) != 0):
if (((_la) & ~0x3f) == 0 and ((1 << _la) & 915456) != 0):
self.state = 34
self.action_parm()
self.state = 37
self.match(ptmlParser.T__7)
self.match(ptmlParser.T__8)
except RecognitionException as re:
localctx.exception = re
self._errHandler.reportError(self, re)
@ -366,19 +374,19 @@ class ptmlParser ( Parser ):
self.state = 43
self._errHandler.sync(self)
token = self._input.LA(1)
if token in [10, 11, 12, 13]:
if token in [11, 12, 13, 14]:
self.state = 39
self.var_decls()
pass
elif token in [17]:
elif token in [18]:
self.state = 40
self.match(ptmlParser.Integer)
pass
elif token in [18]:
elif token in [19]:
self.state = 41
self.match(ptmlParser.Float)
pass
elif token in [14, 15]:
elif token in [15, 16]:
self.state = 42
self.boolean()
pass
@ -388,25 +396,25 @@ class ptmlParser ( Parser ):
self.state = 54
self._errHandler.sync(self)
_la = self._input.LA(1)
while _la==9:
while _la==10:
self.state = 45
self.match(ptmlParser.T__8)
self.match(ptmlParser.T__9)
self.state = 50
self._errHandler.sync(self)
token = self._input.LA(1)
if token in [10, 11, 12, 13]:
if token in [11, 12, 13, 14]:
self.state = 46
self.var_decls()
pass
elif token in [17]:
elif token in [18]:
self.state = 47
self.match(ptmlParser.Integer)
pass
elif token in [18]:
elif token in [19]:
self.state = 48
self.match(ptmlParser.Float)
pass
elif token in [14, 15]:
elif token in [15, 16]:
self.state = 49
self.boolean()
pass
@ -504,7 +512,7 @@ class ptmlParser ( Parser ):
self.enterOuterAlt(localctx, 1)
self.state = 60
_la = self._input.LA(1)
if not((((_la) & ~0x3f) == 0 and ((1 << _la) & 15360) != 0)):
if not((((_la) & ~0x3f) == 0 and ((1 << _la) & 30720) != 0)):
self._errHandler.recoverInline(self)
else:
self._errHandler.reportMatch(self)
@ -549,7 +557,7 @@ class ptmlParser ( Parser ):
self.enterOuterAlt(localctx, 1)
self.state = 62
_la = self._input.LA(1)
if not(_la==14 or _la==15):
if not(_la==15 or _la==16):
self._errHandler.recoverInline(self)
else:
self._errHandler.reportMatch(self)

76
ptml/ptmlTranslator.py Normal file
View File

@ -0,0 +1,76 @@
from antlr4 import *
from .ptmlListener import ptmlListener
from .ptmlParser import ptmlParser
class ptmlTranslator(ptmlListener):
"""Translate the ptml language to BT.
Args:
ptmlListener (_type_): _description_
"""
def __init__(self) -> None:
super().__init__()
# Enter a parse tree produced by ptmlParser#tree.
def enterTree(self, ctx:ptmlParser.TreeContext):
pass
# Exit a parse tree produced by ptmlParser#tree.
def exitTree(self, ctx:ptmlParser.TreeContext):
pass
# Enter a parse tree produced by ptmlParser#internal_node.
def enterInternal_node(self, ctx:ptmlParser.Internal_nodeContext):
pass
# Exit a parse tree produced by ptmlParser#internal_node.
def exitInternal_node(self, ctx:ptmlParser.Internal_nodeContext):
pass
# Enter a parse tree produced by ptmlParser#action_sign.
def enterAction_sign(self, ctx:ptmlParser.Action_signContext):
pass
# Exit a parse tree produced by ptmlParser#action_sign.
def exitAction_sign(self, ctx:ptmlParser.Action_signContext):
pass
# Enter a parse tree produced by ptmlParser#action_parm.
def enterAction_parm(self, ctx:ptmlParser.Action_parmContext):
pass
# Exit a parse tree produced by ptmlParser#action_parm.
def exitAction_parm(self, ctx:ptmlParser.Action_parmContext):
pass
# Enter a parse tree produced by ptmlParser#var_decls.
def enterVar_decls(self, ctx:ptmlParser.Var_declsContext):
pass
# Exit a parse tree produced by ptmlParser#var_decls.
def exitVar_decls(self, ctx:ptmlParser.Var_declsContext):
pass
# Enter a parse tree produced by ptmlParser#var_type.
def enterVar_type(self, ctx:ptmlParser.Var_typeContext):
pass
# Exit a parse tree produced by ptmlParser#var_type.
def exitVar_type(self, ctx:ptmlParser.Var_typeContext):
pass
# Enter a parse tree produced by ptmlParser#boolean.
def enterBoolean(self, ctx:ptmlParser.BooleanContext):
pass
# Exit a parse tree produced by ptmlParser#boolean.
def exitBoolean(self, ctx:ptmlParser.BooleanContext):
pass