@method(AST.Text.StackLocation)
def get_text(self, python = False):
return (
- '(yystack[{0:d}][2])'.format(self.offset + self.index - 2)
+ '(yystack[{0:d}][2])'.format(self.offset + self.index - 1)
if python else
'(yylsp[{0:d}])'.format(self.offset + self.index)
)
return (
(
'(yystack[{0:d}][1].{1:s})'.format(
- self.offset + self.index - 2,
+ self.offset + self.index - 1,
self.tag_name
)
if python else
if len(self.tag_name) else
(
'(yystack[{0:d}][1])'.format(
- self.offset + self.index - 2,
+ self.offset + self.index - 1,
)
if python else
'(yyvsp[{0:d}])'.format(
# GENERATE INITIALACTION
- state = 0
- yystack = [(-1, yylval, yylloc.copy())] # kludge for bison compatibility
+ yystack = [(0, yylval, yylloc.copy())]
yychar = -1
while True:
+ state = yystack[-1][0]
#print('state', state, 'yystack', yystack)
reduce = yy_lr1dfa_states[state][4]
if reduce == -1:
if action == -1:
raise Exception('syntax error')
if (action & 1) == 0:
- yystack.append((state, yylval, yylloc.copy()))
- state = action >> 1
- #print('shift', state)
+ yystack.append((action >> 1, yylval, yylloc.copy()))
+ #print('shift', yystack[-1][0])
yychar = -1
continue
reduce = action >> 1
#print('reduce', reduce)
len_symbols, ref_data = yy_lr1dfa_productions[reduce]
+ yyval = yystack[-len_symbols][1] if len_symbols else None
# GENERATE YYLLOC_DEFAULT
- base = len(yystack) - len_symbols
- yystack.append((state, None, None)) # only has effect if len_symbols == 0
- state, yyval, _ = yystack[base]
ref_data()
- del yystack[base:]
+ del yystack[len(yystack) - len_symbols:]
if reduce == 0:
- assert base == 1
+ assert len(yystack) == 1
break
- yystack.append((state, yyval, yyloc.copy()))
- state = yy_lr1dfa_states[state][3][
- bisect.bisect_right(yy_lr1dfa_states[state][2], reduce)
- ]
- assert state != -1
+ state = yystack[-1][0]
+ yystack.append(
+ (
+ yy_lr1dfa_states[state][3][
+ bisect.bisect_right(yy_lr1dfa_states[state][2], reduce)
+ ],
+ yyval,
+ yyloc.copy()
+ )
+ )
+ assert yystack[-1][0] != -1
# GENERATE SECTION3
# GENERATE INITIALACTION
- state = 0
- yystack = [(-1, yylval, yylloc.copy())] # kludge for bison compatibility
+ yystack = [(0, yylval, yylloc.copy())]
yychar = -1
yy_element_stack = []
while True:
+ state = yystack[-1][0]
#print('state', state, 'yystack', yystack)
reduce = yy_lr1dfa_states[state][4]
if reduce == -1:
if action == -1:
raise Exception('syntax error')
if (action & 1) == 0:
- yystack.append((state, yylval, yylloc.copy()))
-
# push space then AST element contiguously onto yy_element_stack
# even numbered elements are spaces, odd numbered elements are AST
yy_element_stack.extend(
[lex_yy.yy_element_space, lex_yy.yy_element_token]
)
- state = action >> 1
- #print('shift', state)
+ yystack.append((action >> 1, yylval, yylloc.copy()))
+ #print('shift', yystack[-1][0])
yychar = -1
continue
reduce = action >> 1
#print('reduce', reduce)
len_symbols, ref_data = yy_lr1dfa_productions[reduce]
+ yyval = yystack[-len_symbols][1] if len_symbols else None
# GENERATE YYLLOC_DEFAULT
- base = len(yystack) - len_symbols
- yystack.append((state, None, None)) # only has effect if len_symbols == 0
- state, yyval, _ = yystack[base]
ref_data()
- del yystack[base:]
+ del yystack[len(yystack) - len_symbols:]
if reduce == 0:
- assert base == 1
+ assert len(yystack) == 1
break
- yystack.append((state, yyval, yyloc.copy()))
# action creates empty space in yy_element_stack[base * 2] if needed
+ base = len(yystack) - len_symbols
assert len(yy_element_stack) >= base * 2 - 1
# concatenate yy_element_stack[base * 2 - 1:] to a single AST element
)
]
- state = yy_lr1dfa_states[state][3][
- bisect.bisect_right(yy_lr1dfa_states[state][2], reduce)
- ]
- assert state != -1
+ state = yystack[-1][0]
+ yystack.append(
+ (
+ yy_lr1dfa_states[state][3][
+ bisect.bisect_right(yy_lr1dfa_states[state][2], reduce)
+ ],
+ yyval,
+ yyloc.copy()
+ )
+ )
+ assert yystack[-1][0] != -1
# return space then AST then space in the user's choice of element type
yy_element_stack.append(lex_yy.yy_element_space)
%locations
-%blah
%token NUM
%left '+' '-'