Skip to content

Commit

Permalink
Remove the parsing hack needed to maintain compatibility with a bug i…
Browse files Browse the repository at this point in the history
…n the old parser.

This requires a tiny tweak to the grammar (making it correct, whereas before
it was subtly broken). It also requires updating the bootstrap compiler.
While we're at it, update the bootstrap linker.
  • Loading branch information
ltratt committed Dec 19, 2011
1 parent 29911f1 commit c43538b
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 49 deletions.
Binary file modified bootstrap/64bit_little_endian/convergec.bootstrap
Binary file not shown.
Binary file modified bootstrap/64bit_little_endian/convergel.bootstrap
Binary file not shown.
11 changes: 8 additions & 3 deletions compiler/Compiler/IMod_Gen.cv
Original file line number Diff line number Diff line change
Expand Up @@ -1243,10 +1243,15 @@ class IMod_Gen:

func _t_binary(self, node, extra_src_infos):

// binary ::= expr binary_op expr
// binary ::= expr "*" expr
// | expr "/" expr
// | expr "%" expr
// | expr "+" expr
// | expr "-" expr

op_node := node[1][0]
if op_node.type == "*":

op_node := node[1]
ndif op_node.type == "*":
type := ITree::BINARY_MUL
elif op_node.type == "/":
type := ITree::BINARY_DIV
Expand Down
11 changes: 5 additions & 6 deletions compiler/Compiler/Parser.cv
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,11 @@ not ::= "NOT" expr

neg ::= "-" expr

binary ::= expr binary_op expr
binary_op ::= "*" %precedence 40
| "/" %precedence 30
| "%" %precedence 30
| "+" %precedence 20
| "-" %precedence 20
binary ::= expr "*" expr %precedence 40
| expr "/" expr %precedence 30
| expr "%" expr %precedence 30
| expr "+" expr %precedence 20
| expr "-" expr %precedence 20

comparison ::= expr comparison_op expr
comparison_op ::= "IS"
Expand Down
40 changes: 0 additions & 40 deletions pypyvm/Modules/Con_C_Earley_Parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,49 +518,9 @@ def _resolve_ambiguities(vm, alts, tok_os, rn_os, n):
return

ffamilies = [_flatten_kids(k) for k in n.families]
rn_ss = [type_check_string(vm, x).v for x in rn_os]
#i = 1
#for ks in ffamilies:
# print "possibility", i
# i += 1
# for c in ks:
# print c.pp(2, names=rn_ss, alts=alts)
# print "\n"
for fkids in ffamilies:
if len(fkids) != len(ffamilies[0]):
break
else:
# This is a hack to maintain compatibility with the old VMs somewhat broken parser.
for i in range(len(ffamilies[0])):
precs = []
for j in range(len(ffamilies)):
c = ffamilies[j][i]
if isinstance(c, Tree_Term):
precs.append(0)
else:
assert isinstance(c, Tree_Non_Term)
precs.append(alts[c.s].precedence)

lp = precs[0]
for p in precs:
lp = min(lp, p)
if lp == 0:
continue
nlp = 0
for p in precs:
if p == lp:
nlp += 1
#print i, precs, lp, nlp#, ffamilies
if nlp < len(precs):
j = 0
while j < len(ffamilies):
if precs[j] != lp:
del precs[j]
del ffamilies[j]
else:
j += 1
if len(ffamilies) == 1:
break

if len(ffamilies) > 1:
# We still have ambiguities left, so, as a sensible default, we prefer
Expand Down

0 comments on commit c43538b

Please sign in to comment.