[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH for Dlang support 1/2] d: change the return value of yylex fr
From: |
H. S. Teoh |
Subject: |
Re: [PATCH for Dlang support 1/2] d: change the return value of yylex from TokenKind to YYParser.Symbol |
Date: |
Fri, 20 Nov 2020 10:29:46 -0800 |
Hi Adela,
On Fri, Nov 20, 2020 at 04:40:54PM +0200, Adela Vais wrote:
[...]
> + case '+': return Calc.Symbol(TokenKind.PLUS, new YYLocation(startPos,
> endPos));
> + case '-': return Calc.Symbol(TokenKind.MINUS, new
> YYLocation(startPos, endPos));
> + case '*': return Calc.Symbol(TokenKind.STAR, new YYLocation(startPos,
> endPos));
> + case '/': return Calc.Symbol(TokenKind.SLASH, new
> YYLocation(startPos, endPos));
> + case '(': return Calc.Symbol(TokenKind.LPAR, new YYLocation(startPos,
> endPos));
> + case ')': return Calc.Symbol(TokenKind.RPAR, new YYLocation(startPos,
> endPos));
Is YYLocation a struct? If so, you should not use `new`, because that
incurs a GC allocation per construction.
If not, it probably should be made one, since as far as I can tell it's
only used for storing a start/end point for position, is not
polymorphic, and therefore does not need to be a class.
[...]
> + return Calc.Symbol(TokenKind.EOL, new YYLocation(startPos, endPos));
[...]
Ditto.
--T