Hi sebastian,
I think I've found another bug, this time in treegenerator.py: when
an expression starts with a pre-increment or pre-decrement operator
and begins on a new line, soon after a loop or a block, the
treegenerator produces the wrong tree, making the treecompiler
produce wrong code (it transforms the prefix operator into a postfix
one applied to the preceding block).
For example:
while (a)
a -= 1;
++a;
becomes:
while(a)a-=1++;a;
The problem lies in the fact that ++ and -- can be either left or
right unary operators but they are right unary operators only if they
are not preceded by end-of-line (see ECMAScript grammar
[http://www.mozilla.org/js/language/E262-3.pdf] on page 54): the
treegenerator, after reading a loop, simply checks for the next token
to be in SINGLE_RIGHT_OPERATORS and finds it, while in this case it
really should be a SINGLE_LEFT_OPERATORS.
So I'm attaching a patch against 0.6.1 for you to apply, if you
like it: it traces if a token was immediately preceded by an eol
and, if so, it ignores SINGLE_RIGHT_OPERATORS.
Cheers,
Alessandro
--- treegenerator.orig.py 2006-09-20 20:11:06.000000000 +0200
+++ treegenerator.py 2006-09-21 23:50:38.000000000 +0200
@@ -26,6 +26,7 @@
self.tokens = tokens
self.commentsBefore = None
self.parsepos = -1
+ self.eolBefore = False
def curr (self):
"""Returns the current token."""
@@ -67,7 +68,7 @@
def next (self):
length = len(self.tokens)
- commentsBefore = None
+ self.eolBefore = False
token = None
while self.parsepos < length - 1:
@@ -75,6 +76,7 @@
token = self.tokens[self.parsepos]
if token["type"] == "eol":
+ self.eolBefore = True
# ignore end of line
pass
elif token["type"] == "comment":
@@ -93,6 +95,9 @@
else:
return token
+ def hadEolBefore(self):
+ return self.eolBefore
+
def clearCommentsBefore(self):
commentsBefore = self.commentsBefore
self.commentsBefore = None
@@ -329,7 +334,7 @@
raiseSyntaxException(stream.curr(), expectedDesc)
# check whether this is an operation
- if stream.currIsType("token", MULTI_TOKEN_OPERATORS) or
stream.currIsType("protected", MULTI_PROTECTED_OPERATORS) or
stream.currIsType("token", SINGLE_RIGHT_OPERATORS):
+ if stream.currIsType("token", MULTI_TOKEN_OPERATORS) or
stream.currIsType("protected", MULTI_PROTECTED_OPERATORS) or
(stream.currIsType("token", SINGLE_RIGHT_OPERATORS) and not
stream.hadEolBefore()):
# its an operation -> We've already parsed the first operand (in item)
parsedItem = item
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel