[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: grammar questions
"Etienne M. Gagnon" wrote:
> and in CustomLexer (extends Lexer), you must override the peek(), next()
> and filter() methods. I'll let you figure out the details.
I did that and it all works perfectly. Thanks a bunch. It wasn't as difficult
as I had imagined.
> > It won't be as fast probably tho.
> If you do as suggested above, it shouldn't be slow. I just hope you
> don't need recursive behavior (in other words, it shouldn't be possible
> in your grammar to have an embedded "if" statement in an expression).
> If it's possible, then you will have to add recursive behavior to the
> above algorithm.
I put all the tokens into a linked list and return from there until
it's empty in peek() and next() methods. Easy, clean and most of all, fast.
No recursion needed.
> I just had a question for you: Are you sure of your interpretation of
> PHP's specification (I have not read it!). Personally I would have
> thought the following statement possible:
> if (a)
> x = 3;
> elseif (b):
> x = 4;
> y = 5;
> In other words, you could mismatch the colon and no-colon modes in the
> different parts of an "if" statement. The only requirement would be
> that a ":" imposes a closing token for the related part. e.g.
> if(a) :
> x = 3;
> y = 4;
> elseif (b)
> y = 5;
> would be also valid as there's no need for an "endif" following an
> "elseif exp stmt".
This is not valid PHP syntax. And it would break the rule of symmetry/
consistency (if there is such a rule). But there is no such thing as PHP
specification, the specification is in a bison file and there they just let
it shift. So yes, I'm a bit creative. But my grammar accepts all files
accepted by current php implementation + couple of creative addons.
Anyways I have couple of questions about the code the sablecc generates.
I was looking through the nodes code once and stumbled onto couple
When I specify a rule in grammar like xxx* there's a function for setting
that node's data - generated into the node source file:
public void setXXX(List list)
Object temp = list.toArray();
for(int i = 0; i < temp.length; i++)
Wouldn't this all be equivalent to '_xxx_.addAll (list)' ?
Isn't creating arrays like that slow?
And more. Isn't that functions used for modfifying the tree by users?
If so then it doesn't replace the list but appends the contents. Is
that valid behavior? Shouldn't it clear() it first?
And in TypedLinkedList.java you duplicate most of LinkedList
methods. Has this to do with compatibility or something?
Anyway thanks, sableCC ain't bad at all.