rewrite compound-assignment operators in the BNF

This commit is contained in:
John Kerl 2020-09-07 23:32:07 -04:00
parent 90c4276972
commit 0357ddf97f
11 changed files with 76371 additions and 75805 deletions

View file

@ -25,6 +25,7 @@ const (
NodeTypeDirectFieldName = "DirectFieldName"
NodeTypeIndirectFieldName = "IndirectFieldName"
NodeTypeFullSrec = "FullSrec"
NodeTypeIndexedLvalue = "IndexedLvalue"
NodeTypeStatementBlock = "StatementBlock"
NodeTypeAssignment = "Assignment"
@ -167,10 +168,15 @@ func NewASTNodeUnary(itok, childA interface{}, nodeType TNodeType) (*ASTNode, er
}
// Signature: Token Node Node Type
func NewASTNodeBinary(itok, childA, childB interface{}, nodeType TNodeType) (*ASTNode, error) {
func NewASTNodeBinaryNestable(itok, childA, childB interface{}, nodeType TNodeType) *ASTNode {
parent := NewASTNodeNestable(itok, nodeType)
convertToBinary(parent, childA, childB)
return parent, nil
return parent
}
// Signature: Token Node Node Type
func NewASTNodeBinary(itok, childA, childB interface{}, nodeType TNodeType) (*ASTNode, error) {
return NewASTNodeBinaryNestable(itok, childA, childB, nodeType), nil
}
func NewASTNodeTernary(itok, childA, childB, childC interface{}, nodeType TNodeType) (*ASTNode, error) {

View file

@ -65,7 +65,7 @@ var ActTab = ActionTable{
Ignore: "",
},
ActionRow{ // S11
Accept: 76,
Accept: 75,
Ignore: "",
},
ActionRow{ // S12
@ -129,11 +129,11 @@ var ActTab = ActionTable{
Ignore: "",
},
ActionRow{ // S27
Accept: 75,
Accept: 4,
Ignore: "",
},
ActionRow{ // S28
Accept: 6,
Accept: 5,
Ignore: "",
},
ActionRow{ // S29
@ -149,7 +149,7 @@ var ActTab = ActionTable{
Ignore: "",
},
ActionRow{ // S32
Accept: 77,
Accept: 76,
Ignore: "",
},
ActionRow{ // S33
@ -157,7 +157,7 @@ var ActTab = ActionTable{
Ignore: "",
},
ActionRow{ // S34
Accept: 78,
Accept: 77,
Ignore: "",
},
ActionRow{ // S35
@ -177,23 +177,23 @@ var ActTab = ActionTable{
Ignore: "",
},
ActionRow{ // S39
Accept: 7,
Accept: 8,
Ignore: "",
},
ActionRow{ // S40
Accept: 4,
Accept: 6,
Ignore: "",
},
ActionRow{ // S41
Accept: 4,
Accept: 6,
Ignore: "",
},
ActionRow{ // S42
Accept: 5,
Accept: 7,
Ignore: "",
},
ActionRow{ // S43
Accept: 4,
Accept: 6,
Ignore: "",
},
ActionRow{ // S44
@ -209,93 +209,93 @@ var ActTab = ActionTable{
Ignore: "",
},
ActionRow{ // S47
Accept: 13,
Ignore: "",
},
ActionRow{ // S48
Accept: 56,
Ignore: "",
},
ActionRow{ // S49
ActionRow{ // S48
Accept: 19,
Ignore: "",
},
ActionRow{ // S50
ActionRow{ // S49
Accept: 16,
Ignore: "",
},
ActionRow{ // S51
ActionRow{ // S50
Accept: 18,
Ignore: "",
},
ActionRow{ // S52
ActionRow{ // S51
Accept: 51,
Ignore: "",
},
ActionRow{ // S53
ActionRow{ // S52
Accept: 44,
Ignore: "",
},
ActionRow{ // S54
ActionRow{ // S53
Accept: 45,
Ignore: "",
},
ActionRow{ // S55
ActionRow{ // S54
Accept: 52,
Ignore: "",
},
ActionRow{ // S56
ActionRow{ // S55
Accept: 0,
Ignore: "",
},
ActionRow{ // S57
ActionRow{ // S56
Accept: 17,
Ignore: "",
},
ActionRow{ // S58
ActionRow{ // S57
Accept: 49,
Ignore: "",
},
ActionRow{ // S59
ActionRow{ // S58
Accept: 20,
Ignore: "",
},
ActionRow{ // S60
ActionRow{ // S59
Accept: 61,
Ignore: "",
},
ActionRow{ // S60
Accept: 0,
Ignore: "",
},
ActionRow{ // S61
Accept: 0,
Ignore: "",
},
ActionRow{ // S62
Accept: 0,
Ignore: "",
},
ActionRow{ // S63
Accept: 40,
Ignore: "",
},
ActionRow{ // S64
ActionRow{ // S63
Accept: 36,
Ignore: "",
},
ActionRow{ // S65
ActionRow{ // S64
Accept: 31,
Ignore: "",
},
ActionRow{ // S66
ActionRow{ // S65
Accept: 29,
Ignore: "",
},
ActionRow{ // S67
ActionRow{ // S66
Accept: 34,
Ignore: "",
},
ActionRow{ // S68
ActionRow{ // S67
Accept: 41,
Ignore: "",
},
ActionRow{ // S68
Accept: 0,
Ignore: "",
},
ActionRow{ // S69
Accept: 0,
Ignore: "",
@ -313,17 +313,17 @@ var ActTab = ActionTable{
Ignore: "",
},
ActionRow{ // S73
Accept: 0,
Ignore: "",
},
ActionRow{ // S74
Accept: 70,
Ignore: "",
},
ActionRow{ // S75
ActionRow{ // S74
Accept: 71,
Ignore: "",
},
ActionRow{ // S75
Accept: 0,
Ignore: "",
},
ActionRow{ // S76
Accept: 0,
Ignore: "",
@ -333,15 +333,15 @@ var ActTab = ActionTable{
Ignore: "",
},
ActionRow{ // S78
Accept: 0,
Accept: 13,
Ignore: "",
},
ActionRow{ // S79
Accept: 12,
Accept: 27,
Ignore: "",
},
ActionRow{ // S80
Accept: 27,
Accept: 0,
Ignore: "",
},
ActionRow{ // S81
@ -349,107 +349,107 @@ var ActTab = ActionTable{
Ignore: "",
},
ActionRow{ // S82
Accept: 0,
Accept: 12,
Ignore: "",
},
ActionRow{ // S83
Accept: 11,
Ignore: "",
},
ActionRow{ // S84
Accept: 26,
Ignore: "",
},
ActionRow{ // S85
ActionRow{ // S84
Accept: 30,
Ignore: "",
},
ActionRow{ // S86
ActionRow{ // S85
Accept: 0,
Ignore: "",
},
ActionRow{ // S86
Accept: 11,
Ignore: "",
},
ActionRow{ // S87
Accept: 10,
Ignore: "",
},
ActionRow{ // S88
Accept: 23,
Ignore: "",
},
ActionRow{ // S89
ActionRow{ // S88
Accept: 53,
Ignore: "",
},
ActionRow{ // S90
ActionRow{ // S89
Accept: 0,
Ignore: "",
},
ActionRow{ // S91
ActionRow{ // S90
Accept: 21,
Ignore: "",
},
ActionRow{ // S92
ActionRow{ // S91
Accept: 61,
Ignore: "",
},
ActionRow{ // S92
Accept: 0,
Ignore: "",
},
ActionRow{ // S93
Accept: 0,
Ignore: "",
},
ActionRow{ // S94
Accept: 0,
Ignore: "",
},
ActionRow{ // S95
Accept: 61,
Ignore: "",
},
ActionRow{ // S96
ActionRow{ // S95
Accept: 60,
Ignore: "",
},
ActionRow{ // S97
ActionRow{ // S96
Accept: 14,
Ignore: "",
},
ActionRow{ // S98
ActionRow{ // S97
Accept: 15,
Ignore: "",
},
ActionRow{ // S99
ActionRow{ // S98
Accept: 0,
Ignore: "",
},
ActionRow{ // S100
ActionRow{ // S99
Accept: 72,
Ignore: "",
},
ActionRow{ // S101
ActionRow{ // S100
Accept: 65,
Ignore: "",
},
ActionRow{ // S102
ActionRow{ // S101
Accept: 64,
Ignore: "",
},
ActionRow{ // S103
ActionRow{ // S102
Accept: 66,
Ignore: "",
},
ActionRow{ // S104
ActionRow{ // S103
Accept: 68,
Ignore: "",
},
ActionRow{ // S105
ActionRow{ // S104
Accept: 67,
Ignore: "",
},
ActionRow{ // S106
ActionRow{ // S105
Accept: 69,
Ignore: "",
},
ActionRow{ // S106
Accept: 10,
Ignore: "",
},
ActionRow{ // S107
Accept: 9,
Accept: 0,
Ignore: "",
},
ActionRow{ // S108
@ -457,11 +457,11 @@ var ActTab = ActionTable{
Ignore: "",
},
ActionRow{ // S109
Accept: 0,
Accept: 9,
Ignore: "",
},
ActionRow{ // S110
Accept: 8,
Accept: 0,
Ignore: "",
},
ActionRow{ // S111
@ -469,11 +469,11 @@ var ActTab = ActionTable{
Ignore: "",
},
ActionRow{ // S112
Accept: 0,
Accept: 61,
Ignore: "",
},
ActionRow{ // S113
Accept: 61,
Accept: 0,
Ignore: "",
},
ActionRow{ // S114
@ -481,7 +481,7 @@ var ActTab = ActionTable{
Ignore: "",
},
ActionRow{ // S115
Accept: 0,
Accept: 61,
Ignore: "",
},
ActionRow{ // S116
@ -489,7 +489,7 @@ var ActTab = ActionTable{
Ignore: "",
},
ActionRow{ // S117
Accept: 61,
Accept: 0,
Ignore: "",
},
ActionRow{ // S118
@ -497,49 +497,49 @@ var ActTab = ActionTable{
Ignore: "",
},
ActionRow{ // S119
Accept: 0,
Ignore: "",
},
ActionRow{ // S120
Accept: 62,
Ignore: "",
},
ActionRow{ // S121
ActionRow{ // S120
Accept: 0,
Ignore: "",
},
ActionRow{ // S122
ActionRow{ // S121
Accept: 61,
Ignore: "",
},
ActionRow{ // S123
ActionRow{ // S122
Accept: 0,
Ignore: "",
},
ActionRow{ // S123
Accept: 61,
Ignore: "",
},
ActionRow{ // S124
Accept: 61,
Ignore: "",
},
ActionRow{ // S125
Accept: 61,
Accept: 0,
Ignore: "",
},
ActionRow{ // S126
Accept: 0,
Ignore: "",
},
ActionRow{ // S127
Accept: 62,
Ignore: "",
},
ActionRow{ // S128
ActionRow{ // S127
Accept: 0,
Ignore: "",
},
ActionRow{ // S129
ActionRow{ // S128
Accept: 61,
Ignore: "",
},
ActionRow{ // S129
Accept: 0,
Ignore: "",
},
ActionRow{ // S130
Accept: 0,
Ignore: "",
@ -553,30 +553,26 @@ var ActTab = ActionTable{
Ignore: "",
},
ActionRow{ // S133
Accept: 0,
Ignore: "",
},
ActionRow{ // S134
Accept: 74,
Ignore: "",
},
ActionRow{ // S135
ActionRow{ // S134
Accept: 0,
Ignore: "",
},
ActionRow{ // S136
ActionRow{ // S135
Accept: 73,
Ignore: "",
},
ActionRow{ // S136
Accept: 0,
Ignore: "",
},
ActionRow{ // S137
Accept: 0,
Ignore: "",
},
ActionRow{ // S138
Accept: 0,
Ignore: "",
},
ActionRow{ // S139
Accept: 63,
Ignore: "",
},

View file

@ -11,8 +11,8 @@ import (
const (
NoState = -1
NumStates = 140
NumSymbols = 228
NumStates = 139
NumSymbols = 226
)
type Lexer struct {
@ -181,164 +181,162 @@ Lexer symbols:
65: '%'
66: ';'
67: '='
68: '$'
69: '['
70: ']'
71: '|'
68: '['
69: ']'
70: '$'
71: '['
72: '|'
73: '='
74: '^'
73: '|'
74: '='
75: '^'
76: '='
77: '&'
76: '^'
77: '='
78: '&'
79: '='
80: '|'
81: '='
82: '^'
83: '='
84: '&'
85: '='
79: '&'
80: '='
81: '|'
82: '='
83: '^'
84: '='
85: '<'
86: '<'
87: '<'
88: '='
87: '='
88: '>'
89: '>'
90: '>'
91: '='
92: '+'
93: '='
94: '.'
95: '='
96: '-'
97: '='
98: '*'
99: '='
100: '/'
101: '='
90: '='
91: '+'
92: '='
93: '.'
94: '='
95: '-'
96: '='
97: '*'
98: '='
99: '/'
100: '='
101: '/'
102: '/'
103: '/'
104: '='
105: '%'
106: '='
103: '='
104: '%'
105: '='
106: '*'
107: '*'
108: '*'
109: '='
110: '?'
111: ':'
108: '='
109: '?'
110: ':'
111: '|'
112: '|'
113: '|'
113: '^'
114: '^'
115: '^'
115: '&'
116: '&'
117: '&'
118: '='
119: '~'
120: '!'
121: '='
122: '~'
117: '='
118: '~'
119: '!'
120: '='
121: '~'
122: '='
123: '='
124: '='
125: '!'
126: '='
124: '!'
125: '='
126: '>'
127: '>'
128: '>'
129: '='
128: '='
129: '<'
130: '<'
131: '<'
132: '='
133: '|'
134: '^'
135: '&'
131: '='
132: '|'
133: '^'
134: '&'
135: '<'
136: '<'
137: '<'
137: '>'
138: '>'
139: '>'
140: '+'
141: '-'
142: '.'
143: '+'
144: '.'
145: '-'
146: '.'
147: '*'
139: '+'
140: '-'
141: '.'
142: '+'
143: '.'
144: '-'
145: '.'
146: '*'
147: '/'
148: '/'
149: '/'
150: '/'
151: '%'
152: '.'
153: '*'
154: '.'
155: '/'
156: '.'
150: '%'
151: '.'
152: '*'
153: '.'
154: '/'
155: '.'
156: '/'
157: '/'
158: '/'
159: '!'
160: '~'
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: 'e'
203: 'E'
204: 't'
205: 'r'
206: 'u'
207: 'e'
208: 'f'
209: 'a'
210: 'l'
211: 's'
212: 'e'
213: ' '
214: '\t'
215: '\n'
216: '\r'
217: 'a'-'z'
218: 'A'-'Z'
219: '0'-'9'
220: '0'-'9'
221: 'a'-'f'
222: 'A'-'F'
223: 'A'-'Z'
224: 'a'-'z'
225: '0'-'9'
226: \u0100-\U0010ffff
227: .
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: 'e'
201: 'E'
202: 't'
203: 'r'
204: 'u'
205: 'e'
206: 'f'
207: 'a'
208: 'l'
209: 's'
210: 'e'
211: ' '
212: '\t'
213: '\n'
214: '\r'
215: 'a'-'z'
216: 'A'-'Z'
217: '0'-'9'
218: '0'-'9'
219: 'a'-'f'
220: 'A'-'F'
221: 'A'-'Z'
222: 'a'-'z'
223: '0'-'9'
224: \u0100-\U0010ffff
225: .
*/

View file

@ -219,8 +219,6 @@ var TransTab = TransitionTable{
switch {
case r == 38: // ['&','&']
return 46
case r == 61: // ['=','=']
return 47
}
return NoState
},
@ -240,9 +238,9 @@ var TransTab = TransitionTable{
func(r rune) int {
switch {
case r == 42: // ['*','*']
return 48
return 47
case r == 61: // ['=','=']
return 49
return 48
}
return NoState
},
@ -250,7 +248,7 @@ var TransTab = TransitionTable{
func(r rune) int {
switch {
case r == 61: // ['=','=']
return 50
return 49
}
return NoState
},
@ -264,7 +262,7 @@ var TransTab = TransitionTable{
func(r rune) int {
switch {
case r == 61: // ['=','=']
return 51
return 50
}
return NoState
},
@ -272,17 +270,17 @@ var TransTab = TransitionTable{
func(r rune) int {
switch {
case r == 42: // ['*','*']
return 52
return 51
case r == 43: // ['+','+']
return 53
return 52
case r == 45: // ['-','-']
return 54
return 53
case r == 47: // ['/','/']
return 55
return 54
case 48 <= r && r <= 57: // ['0','9']
return 56
return 55
case r == 61: // ['=','=']
return 57
return 56
}
return NoState
},
@ -290,9 +288,9 @@ var TransTab = TransitionTable{
func(r rune) int {
switch {
case r == 47: // ['/','/']
return 58
return 57
case r == 61: // ['=','=']
return 59
return 58
}
return NoState
},
@ -300,15 +298,15 @@ var TransTab = TransitionTable{
func(r rune) int {
switch {
case r == 46: // ['.','.']
return 60
return 59
case 48 <= r && r <= 57: // ['0','9']
return 16
case r == 69: // ['E','E']
return 61
return 60
case r == 101: // ['e','e']
return 61
return 60
case r == 120: // ['x','x']
return 62
return 61
}
return NoState
},
@ -316,13 +314,13 @@ var TransTab = TransitionTable{
func(r rune) int {
switch {
case r == 46: // ['.','.']
return 60
return 59
case 48 <= r && r <= 57: // ['0','9']
return 16
case r == 69: // ['E','E']
return 61
return 60
case r == 101: // ['e','e']
return 61
return 60
}
return NoState
},
@ -342,9 +340,9 @@ var TransTab = TransitionTable{
func(r rune) int {
switch {
case r == 60: // ['<','<']
return 63
return 62
case r == 61: // ['=','=']
return 64
return 63
}
return NoState
},
@ -352,9 +350,9 @@ var TransTab = TransitionTable{
func(r rune) int {
switch {
case r == 61: // ['=','=']
return 65
return 64
case r == 126: // ['~','~']
return 66
return 65
}
return NoState
},
@ -362,9 +360,9 @@ var TransTab = TransitionTable{
func(r rune) int {
switch {
case r == 61: // ['=','=']
return 67
return 66
case r == 62: // ['>','>']
return 68
return 67
}
return NoState
},
@ -378,9 +376,9 @@ var TransTab = TransitionTable{
func(r rune) int {
switch {
case r == 73: // ['I','I']
return 69
return 68
case r == 78: // ['N','N']
return 70
return 69
}
return NoState
},
@ -388,11 +386,11 @@ var TransTab = TransitionTable{
func(r rune) int {
switch {
case r == 70: // ['F','F']
return 71
return 70
case r == 80: // ['P','P']
return 72
return 71
case r == 82: // ['R','R']
return 73
return 72
}
return NoState
},
@ -400,9 +398,9 @@ var TransTab = TransitionTable{
func(r rune) int {
switch {
case r == 70: // ['F','F']
return 74
return 73
case r == 82: // ['R','R']
return 75
return 74
}
return NoState
},
@ -410,11 +408,11 @@ var TransTab = TransitionTable{
func(r rune) int {
switch {
case r == 70: // ['F','F']
return 76
return 75
case r == 80: // ['P','P']
return 77
return 76
case r == 82: // ['R','R']
return 78
return 77
}
return NoState
},
@ -434,9 +432,9 @@ var TransTab = TransitionTable{
func(r rune) int {
switch {
case r == 61: // ['=','=']
return 79
return 78
case r == 94: // ['^','^']
return 80
return 79
}
return NoState
},
@ -444,7 +442,7 @@ var TransTab = TransitionTable{
func(r rune) int {
switch {
case r == 97: // ['a','a']
return 81
return 80
}
return NoState
},
@ -452,7 +450,7 @@ var TransTab = TransitionTable{
func(r rune) int {
switch {
case r == 114: // ['r','r']
return 82
return 81
}
return NoState
},
@ -466,9 +464,9 @@ var TransTab = TransitionTable{
func(r rune) int {
switch {
case r == 61: // ['=','=']
return 83
return 82
case r == 124: // ['|','|']
return 84
return 83
}
return NoState
},
@ -488,7 +486,7 @@ var TransTab = TransitionTable{
func(r rune) int {
switch {
case r == 126: // ['~','~']
return 85
return 84
}
return NoState
},
@ -636,7 +634,7 @@ var TransTab = TransitionTable{
func(r rune) int {
switch {
case r == 37: // ['%','%']
return 86
return 85
}
return NoState
},
@ -650,21 +648,21 @@ var TransTab = TransitionTable{
func(r rune) int {
switch {
case r == 61: // ['=','=']
return 87
return 86
}
return NoState
},
// S47
func(r rune) int {
switch {
case r == 61: // ['=','=']
return 87
}
return NoState
},
// S48
func(r rune) int {
switch {
case r == 61: // ['=','=']
return 88
}
return NoState
},
@ -701,13 +699,19 @@ var TransTab = TransitionTable{
// S54
func(r rune) int {
switch {
case r == 47: // ['/','/']
return 88
}
return NoState
},
// S55
func(r rune) int {
switch {
case r == 47: // ['/','/']
case 48 <= r && r <= 57: // ['0','9']
return 55
case r == 69: // ['E','E']
return 89
case r == 101: // ['e','e']
return 89
}
return NoState
@ -715,65 +719,61 @@ var TransTab = TransitionTable{
// S56
func(r rune) int {
switch {
case 48 <= r && r <= 57: // ['0','9']
return 56
case r == 69: // ['E','E']
return 90
case r == 101: // ['e','e']
return 90
}
return NoState
},
// S57
func(r rune) int {
switch {
case r == 61: // ['=','=']
return 90
}
return NoState
},
// S58
func(r rune) int {
switch {
case r == 61: // ['=','=']
return 91
}
return NoState
},
// S59
func(r rune) int {
switch {
case 48 <= r && r <= 57: // ['0','9']
return 91
case r == 69: // ['E','E']
return 92
case r == 101: // ['e','e']
return 92
}
return NoState
},
// S60
func(r rune) int {
switch {
case r == 45: // ['-','-']
return 93
case 48 <= r && r <= 57: // ['0','9']
return 92
case r == 69: // ['E','E']
return 93
case r == 101: // ['e','e']
return 93
return 94
}
return NoState
},
// S61
func(r rune) int {
switch {
case r == 45: // ['-','-']
return 94
case 48 <= r && r <= 57: // ['0','9']
return 95
case 65 <= r && r <= 70: // ['A','F']
return 95
case 97 <= r && r <= 102: // ['a','f']
return 95
}
return NoState
},
// S62
func(r rune) int {
switch {
case 48 <= r && r <= 57: // ['0','9']
return 96
case 65 <= r && r <= 70: // ['A','F']
return 96
case 97 <= r && r <= 102: // ['a','f']
case r == 61: // ['=','=']
return 96
}
return NoState
@ -781,8 +781,6 @@ var TransTab = TransitionTable{
// S63
func(r rune) int {
switch {
case r == 61: // ['=','=']
return 97
}
return NoState
},
@ -807,13 +805,15 @@ var TransTab = TransitionTable{
// S67
func(r rune) int {
switch {
case r == 61: // ['=','=']
return 97
}
return NoState
},
// S68
func(r rune) int {
switch {
case r == 61: // ['=','=']
case r == 76: // ['L','L']
return 98
}
return NoState
@ -821,7 +821,7 @@ var TransTab = TransitionTable{
// S69
func(r rune) int {
switch {
case r == 76: // ['L','L']
case r == 82: // ['R','R']
return 99
}
return NoState
@ -829,7 +829,7 @@ var TransTab = TransitionTable{
// S70
func(r rune) int {
switch {
case r == 82: // ['R','R']
case r == 83: // ['S','S']
return 100
}
return NoState
@ -853,8 +853,6 @@ var TransTab = TransitionTable{
// S73
func(r rune) int {
switch {
case r == 83: // ['S','S']
return 103
}
return NoState
},
@ -867,6 +865,8 @@ var TransTab = TransitionTable{
// S75
func(r rune) int {
switch {
case r == 83: // ['S','S']
return 103
}
return NoState
},
@ -889,21 +889,21 @@ var TransTab = TransitionTable{
// S78
func(r rune) int {
switch {
case r == 83: // ['S','S']
return 106
}
return NoState
},
// S79
func(r rune) int {
switch {
case r == 61: // ['=','=']
return 106
}
return NoState
},
// S80
func(r rune) int {
switch {
case r == 61: // ['=','=']
case r == 108: // ['l','l']
return 107
}
return NoState
@ -911,7 +911,7 @@ var TransTab = TransitionTable{
// S81
func(r rune) int {
switch {
case r == 108: // ['l','l']
case r == 117: // ['u','u']
return 108
}
return NoState
@ -919,36 +919,34 @@ var TransTab = TransitionTable{
// S82
func(r rune) int {
switch {
case r == 117: // ['u','u']
return 109
}
return NoState
},
// S83
func(r rune) int {
switch {
case r == 61: // ['=','=']
return 109
}
return NoState
},
// S84
func(r rune) int {
switch {
case r == 61: // ['=','=']
return 110
}
return NoState
},
// S85
func(r rune) int {
switch {
case r == 112: // ['p','p']
return 110
}
return NoState
},
// S86
func(r rune) int {
switch {
case r == 112: // ['p','p']
return 111
}
return NoState
},
@ -967,42 +965,44 @@ var TransTab = TransitionTable{
// S89
func(r rune) int {
switch {
case r == 45: // ['-','-']
return 111
case 48 <= r && r <= 57: // ['0','9']
return 112
}
return NoState
},
// S90
func(r rune) int {
switch {
case r == 45: // ['-','-']
return 112
case 48 <= r && r <= 57: // ['0','9']
return 113
}
return NoState
},
// S91
func(r rune) int {
switch {
case 48 <= r && r <= 57: // ['0','9']
return 91
case r == 69: // ['E','E']
return 113
case r == 101: // ['e','e']
return 113
}
return NoState
},
// S92
func(r rune) int {
switch {
case r == 45: // ['-','-']
return 114
case 48 <= r && r <= 57: // ['0','9']
return 92
case r == 69: // ['E','E']
return 114
case r == 101: // ['e','e']
return 114
return 115
}
return NoState
},
// S93
func(r rune) int {
switch {
case r == 45: // ['-','-']
return 115
case 48 <= r && r <= 57: // ['0','9']
return 116
}
@ -1012,7 +1012,7 @@ var TransTab = TransitionTable{
func(r rune) int {
switch {
case 48 <= r && r <= 57: // ['0','9']
return 117
return 94
}
return NoState
},
@ -1021,18 +1021,16 @@ var TransTab = TransitionTable{
switch {
case 48 <= r && r <= 57: // ['0','9']
return 95
case 65 <= r && r <= 70: // ['A','F']
return 95
case 97 <= r && r <= 102: // ['a','f']
return 95
}
return NoState
},
// S96
func(r rune) int {
switch {
case 48 <= r && r <= 57: // ['0','9']
return 96
case 65 <= r && r <= 70: // ['A','F']
return 96
case 97 <= r && r <= 102: // ['a','f']
return 96
}
return NoState
},
@ -1045,14 +1043,14 @@ var TransTab = TransitionTable{
// S98
func(r rune) int {
switch {
case r == 69: // ['E','E']
return 117
}
return NoState
},
// S99
func(r rune) int {
switch {
case r == 69: // ['E','E']
return 118
}
return NoState
},
@ -1101,13 +1099,15 @@ var TransTab = TransitionTable{
// S107
func(r rune) int {
switch {
case r == 115: // ['s','s']
return 118
}
return NoState
},
// S108
func(r rune) int {
switch {
case r == 115: // ['s','s']
case r == 101: // ['e','e']
return 119
}
return NoState
@ -1115,21 +1115,21 @@ var TransTab = TransitionTable{
// S109
func(r rune) int {
switch {
case r == 101: // ['e','e']
return 120
}
return NoState
},
// S110
func(r rune) int {
switch {
case r == 97: // ['a','a']
return 120
}
return NoState
},
// S111
func(r rune) int {
switch {
case r == 97: // ['a','a']
case 48 <= r && r <= 57: // ['0','9']
return 121
}
return NoState
@ -1138,23 +1138,23 @@ var TransTab = TransitionTable{
func(r rune) int {
switch {
case 48 <= r && r <= 57: // ['0','9']
return 122
return 112
}
return NoState
},
// S113
func(r rune) int {
switch {
case r == 45: // ['-','-']
return 122
case 48 <= r && r <= 57: // ['0','9']
return 113
return 123
}
return NoState
},
// S114
func(r rune) int {
switch {
case r == 45: // ['-','-']
return 123
case 48 <= r && r <= 57: // ['0','9']
return 124
}
@ -1164,7 +1164,7 @@ var TransTab = TransitionTable{
func(r rune) int {
switch {
case 48 <= r && r <= 57: // ['0','9']
return 125
return 115
}
return NoState
},
@ -1179,15 +1179,15 @@ var TransTab = TransitionTable{
// S117
func(r rune) int {
switch {
case 48 <= r && r <= 57: // ['0','9']
return 117
case r == 78: // ['N','N']
return 125
}
return NoState
},
// S118
func(r rune) int {
switch {
case r == 78: // ['N','N']
case r == 101: // ['e','e']
return 126
}
return NoState
@ -1195,22 +1195,22 @@ var TransTab = TransitionTable{
// S119
func(r rune) int {
switch {
case r == 101: // ['e','e']
return 127
}
return NoState
},
// S120
func(r rune) int {
switch {
case r == 110: // ['n','n']
return 127
}
return NoState
},
// S121
func(r rune) int {
switch {
case r == 110: // ['n','n']
return 128
case 48 <= r && r <= 57: // ['0','9']
return 121
}
return NoState
},
@ -1218,7 +1218,7 @@ var TransTab = TransitionTable{
func(r rune) int {
switch {
case 48 <= r && r <= 57: // ['0','9']
return 122
return 128
}
return NoState
},
@ -1226,7 +1226,7 @@ var TransTab = TransitionTable{
func(r rune) int {
switch {
case 48 <= r && r <= 57: // ['0','9']
return 129
return 123
}
return NoState
},
@ -1241,40 +1241,40 @@ var TransTab = TransitionTable{
// S125
func(r rune) int {
switch {
case 48 <= r && r <= 57: // ['0','9']
return 125
case r == 65: // ['A','A']
return 129
case r == 85: // ['U','U']
return 130
}
return NoState
},
// S126
func(r rune) int {
switch {
case r == 65: // ['A','A']
return 130
case r == 85: // ['U','U']
return 131
}
return NoState
},
// S127
func(r rune) int {
switch {
case r == 105: // ['i','i']
return 131
}
return NoState
},
// S128
func(r rune) int {
switch {
case r == 105: // ['i','i']
return 132
case 48 <= r && r <= 57: // ['0','9']
return 128
}
return NoState
},
// S129
func(r rune) int {
switch {
case 48 <= r && r <= 57: // ['0','9']
return 129
case r == 77: // ['M','M']
return 132
}
return NoState
},
@ -1289,7 +1289,7 @@ var TransTab = TransitionTable{
// S131
func(r rune) int {
switch {
case r == 77: // ['M','M']
case r == 99: // ['c','c']
return 134
}
return NoState
@ -1297,7 +1297,7 @@ var TransTab = TransitionTable{
// S132
func(r rune) int {
switch {
case r == 99: // ['c','c']
case r == 69: // ['E','E']
return 135
}
return NoState
@ -1305,28 +1305,28 @@ var TransTab = TransitionTable{
// S133
func(r rune) int {
switch {
case r == 69: // ['E','E']
return 136
}
return NoState
},
// S134
func(r rune) int {
switch {
case r == 37: // ['%','%']
return 136
}
return NoState
},
// S135
func(r rune) int {
switch {
case r == 37: // ['%','%']
return 137
}
return NoState
},
// S136
func(r rune) int {
switch {
case r == 37: // ['%','%']
return 137
}
return NoState
},
@ -1339,14 +1339,6 @@ var TransTab = TransitionTable{
return NoState
},
// S138
func(r rune) int {
switch {
case r == 37: // ['%','%']
return 139
}
return NoState
},
// S139
func(r rune) int {
switch {
}

View file

@ -302,7 +302,9 @@ Assignment :
// Lvalue which is an indexed Lvalue.
Lvalue
: BaseLvalue
// | IndexedLvalue -- adapt the indexed-rvalue logic
| IndexedLvalue
// | SlicedLvalue -- like $text[3:7] = "interpolated"
// | ENVValue -- only ENV["foo"] but not arbitrarily indexable like ENV["foo"]["bar"]
;
BaseLvalue
@ -317,9 +319,19 @@ BaseLvalue
// braced oosvar @{...}
// fulloosvar @*
// local variable abcd
// ENV -- only ENV["foo"] but not arbitrarily indexable
;
IndexedLvalue
: Lvalue "[" Rvalue "]"
<< dsl.NewASTNodeBinary(
dsl.NewASTToken("[]", $1),
$0,
$2,
dsl.NodeTypeIndexedLvalue,
)>>
;
// ----------------------------------------------------------------
FieldName
: DirectFieldName
| IndirectFieldName
@ -357,26 +369,155 @@ FullSrec
;
// ----------------------------------------------------------------
// xxx awkward factorization -- there will be huge cardinality if this is
// number of assignment operators times number of possible LHSes.
// REWRITE COMPOUND ASSIGNMENT OPERATORS
//
// Transform '$x += 1' which would have AST
//
// +=
// $x
// 1
//
// into '$x = $x + 1' with AST
//
// =
// $x
// +
// $x
// 1
//
// right here in the parser.
//
// Use the NewASTToken to clone the "||=" into "||" and so on.
Assignment
: Lvalue "||=" Rvalue << dsl.NewASTNodeBinary($1, $0, $2, dsl.NodeTypeAssignment) >>
| Lvalue "^^=" Rvalue << dsl.NewASTNodeBinary($1, $0, $2, dsl.NodeTypeAssignment) >>
| Lvalue "&&=" Rvalue << dsl.NewASTNodeBinary($1, $0, $2, dsl.NodeTypeAssignment) >>
| Lvalue "|=" Rvalue << dsl.NewASTNodeBinary($1, $0, $2, dsl.NodeTypeAssignment) >>
| Lvalue "^=" Rvalue << dsl.NewASTNodeBinary($1, $0, $2, dsl.NodeTypeAssignment) >>
| Lvalue "&=" Rvalue << dsl.NewASTNodeBinary($1, $0, $2, dsl.NodeTypeAssignment) >>
| Lvalue "<<=" Rvalue << dsl.NewASTNodeBinary($1, $0, $2, dsl.NodeTypeAssignment) >>
| Lvalue ">>=" Rvalue << dsl.NewASTNodeBinary($1, $0, $2, dsl.NodeTypeAssignment) >>
| Lvalue "+=" Rvalue << dsl.NewASTNodeBinary($1, $0, $2, dsl.NodeTypeAssignment) >>
| Lvalue ".=" Rvalue << dsl.NewASTNodeBinary($1, $0, $2, dsl.NodeTypeAssignment) >>
| Lvalue "-=" Rvalue << dsl.NewASTNodeBinary($1, $0, $2, dsl.NodeTypeAssignment) >>
| Lvalue "*=" Rvalue << dsl.NewASTNodeBinary($1, $0, $2, dsl.NodeTypeAssignment) >>
| Lvalue "/=" Rvalue << dsl.NewASTNodeBinary($1, $0, $2, dsl.NodeTypeAssignment) >>
| Lvalue "//=" Rvalue << dsl.NewASTNodeBinary($1, $0, $2, dsl.NodeTypeAssignment) >>
| Lvalue "%=" Rvalue << dsl.NewASTNodeBinary($1, $0, $2, dsl.NodeTypeAssignment) >>
| Lvalue "**=" Rvalue << dsl.NewASTNodeBinary($1, $0, $2, dsl.NodeTypeAssignment) >>
: Lvalue "||=" Rvalue
<< dsl.NewASTNodeBinary(
dsl.NewASTToken("=", $1),
$0,
dsl.NewASTNodeBinaryNestable(dsl.NewASTToken("||", $1), $0, $2, dsl.NodeTypeOperator),
dsl.NodeTypeAssignment,
) >>
| Lvalue "^^=" Rvalue
<< dsl.NewASTNodeBinary(
dsl.NewASTToken("=", $1),
$0,
dsl.NewASTNodeBinaryNestable(dsl.NewASTToken("^^", $1), $0, $2, dsl.NodeTypeOperator),
dsl.NodeTypeAssignment,
) >>
| Lvalue "&&=" Rvalue
<< dsl.NewASTNodeBinary(
dsl.NewASTToken("=", $1),
$0,
dsl.NewASTNodeBinaryNestable(dsl.NewASTToken("&&", $1), $0, $2, dsl.NodeTypeOperator),
dsl.NodeTypeAssignment,
) >>
| Lvalue "|=" Rvalue
<< dsl.NewASTNodeBinary(
dsl.NewASTToken("=", $1),
$0,
dsl.NewASTNodeBinaryNestable(dsl.NewASTToken("|", $1), $0, $2, dsl.NodeTypeOperator),
dsl.NodeTypeAssignment,
) >>
| Lvalue "^=" Rvalue
<< dsl.NewASTNodeBinary(
dsl.NewASTToken("=", $1),
$0,
dsl.NewASTNodeBinaryNestable(dsl.NewASTToken("^", $1), $0, $2, dsl.NodeTypeOperator),
dsl.NodeTypeAssignment,
) >>
| Lvalue "^=" Rvalue
<< dsl.NewASTNodeBinary(
dsl.NewASTToken("=", $1),
$0,
dsl.NewASTNodeBinaryNestable(dsl.NewASTToken("^", $1), $0, $2, dsl.NodeTypeOperator),
dsl.NodeTypeAssignment,
) >>
| Lvalue "<<=" Rvalue
<< dsl.NewASTNodeBinary(
dsl.NewASTToken("=", $1),
$0,
dsl.NewASTNodeBinaryNestable(dsl.NewASTToken("<<", $1), $0, $2, dsl.NodeTypeOperator),
dsl.NodeTypeAssignment,
) >>
| Lvalue ">>=" Rvalue
<< dsl.NewASTNodeBinary(
dsl.NewASTToken("=", $1),
$0,
dsl.NewASTNodeBinaryNestable(dsl.NewASTToken(">"+">", $1), $0, $2, dsl.NodeTypeOperator),
dsl.NodeTypeAssignment,
) >>
| Lvalue "+=" Rvalue
<< dsl.NewASTNodeBinary(
dsl.NewASTToken("=", $1),
$0,
dsl.NewASTNodeBinaryNestable(dsl.NewASTToken("+", $1), $0, $2, dsl.NodeTypeOperator),
dsl.NodeTypeAssignment,
) >>
| Lvalue ".=" Rvalue
<< dsl.NewASTNodeBinary(
dsl.NewASTToken("=", $1),
$0,
dsl.NewASTNodeBinaryNestable(dsl.NewASTToken(".", $1), $0, $2, dsl.NodeTypeOperator),
dsl.NodeTypeAssignment,
) >>
| Lvalue "-=" Rvalue
<< dsl.NewASTNodeBinary(
dsl.NewASTToken("=", $1),
$0,
dsl.NewASTNodeBinaryNestable(dsl.NewASTToken("-", $1), $0, $2, dsl.NodeTypeOperator),
dsl.NodeTypeAssignment,
) >>
| Lvalue "*=" Rvalue
<< dsl.NewASTNodeBinary(
dsl.NewASTToken("=", $1),
$0,
dsl.NewASTNodeBinaryNestable(dsl.NewASTToken("*", $1), $0, $2, dsl.NodeTypeOperator),
dsl.NodeTypeAssignment,
) >>
| Lvalue "/=" Rvalue
<< dsl.NewASTNodeBinary(
dsl.NewASTToken("=", $1),
$0,
dsl.NewASTNodeBinaryNestable(dsl.NewASTToken("/", $1), $0, $2, dsl.NodeTypeOperator),
dsl.NodeTypeAssignment,
) >>
| Lvalue "//=" Rvalue
<< dsl.NewASTNodeBinary(
dsl.NewASTToken("=", $1),
$0,
dsl.NewASTNodeBinaryNestable(dsl.NewASTToken("//", $1), $0, $2, dsl.NodeTypeOperator),
dsl.NodeTypeAssignment,
) >>
| Lvalue "%=" Rvalue
<< dsl.NewASTNodeBinary(
dsl.NewASTToken("=", $1),
$0,
dsl.NewASTNodeBinaryNestable(dsl.NewASTToken("%", $1), $0, $2, dsl.NodeTypeOperator),
dsl.NodeTypeAssignment,
) >>
| Lvalue "**=" Rvalue
<< dsl.NewASTNodeBinary(
dsl.NewASTToken("=", $1),
$0,
dsl.NewASTNodeBinaryNestable(dsl.NewASTToken("**", $1), $0, $2, dsl.NodeTypeOperator),
dsl.NodeTypeAssignment,
) >>
;
// ================================================================
@ -665,7 +806,6 @@ ArrayLiteralElements
dsl.NodeTypeArrayLiteral,
) >>
// xxx temp -- needs to adopt children
// Allow trailing final comma, especially for multiline map literals
| ArrayLiteralElement "," ArrayLiteralElements
<< dsl.PrependChild(
@ -680,9 +820,10 @@ ArrayLiteralElement
: Rvalue
;
// ----------------------------------------------------------------
// ================================================================
// For Array or Map -- which one, to be determined at runtime.
// ----------------------------------------------------------------
MlrvalOrFunction : ArrayOrMapIndexAccess ;
ArrayOrMapIndexAccess
@ -695,6 +836,7 @@ ArrayOrMapIndexAccess
)>>
;
// ----------------------------------------------------------------
MlrvalOrFunction : ArraySliceAccess ;
ArraySliceAccess
@ -812,7 +954,6 @@ MapLiteralKeyValuePairs
dsl.NodeTypeMapLiteral,
) >>
// xxx temp -- needs to adopt children
// Allow trailing final comma, especially for multiline map literals
| MapLiteralKeyValuePair "," MapLiteralKeyValuePairs
<< dsl.PrependChild(

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -11,8 +11,8 @@ import (
)
const (
numProductions = 123
numStates = 1049
numProductions = 125
numStates = 1051
numSymbols = 115
)

File diff suppressed because it is too large Load diff

View file

@ -123,16 +123,16 @@ var TokMap = TokenMap{
"$",
";",
"=",
"[",
"]",
"md_token_field_name",
"$[",
"]",
"md_token_full_srec",
"||=",
"^^=",
"&&=",
"|=",
"^=",
"&=",
"<<=",
">>=",
"+=",
@ -194,7 +194,6 @@ var TokMap = TokenMap{
"md_token_FNR",
"md_token_FILENAME",
"md_token_FILENUM",
"[",
",",
"{",
"}",
@ -205,16 +204,16 @@ var TokMap = TokenMap{
"$": 1,
";": 2,
"=": 3,
"md_token_field_name": 4,
"$[": 5,
"]": 6,
"md_token_full_srec": 7,
"||=": 8,
"^^=": 9,
"&&=": 10,
"|=": 11,
"^=": 12,
"&=": 13,
"[": 4,
"]": 5,
"md_token_field_name": 6,
"$[": 7,
"md_token_full_srec": 8,
"||=": 9,
"^^=": 10,
"&&=": 11,
"|=": 12,
"^=": 13,
"<<=": 14,
">>=": 15,
"+=": 16,
@ -276,9 +275,8 @@ var TokMap = TokenMap{
"md_token_FNR": 72,
"md_token_FILENAME": 73,
"md_token_FILENUM": 74,
"[": 75,
",": 76,
"{": 77,
"}": 78,
",": 75,
"{": 76,
"}": 77,
},
}

View file

@ -60,6 +60,7 @@ TOP OF LIST:
o indirect field names, at LHS and RHS
o full indexable at LHS/RHS -- e.g. $*["a"] = $b
o support the filter verb
o there should have always been a >>> and >>>=
! the DSL needs a full, written-down-and-published spell-out of reference/copy semantics
* then careful CST impl