Re: #define and (brackets)



"Alan Carre" <alan@xxxxxxxxxxxxxxxxx> wrote in message
news:OoQb5opTJHA.5860@xxxxxxxxxxxxxxxxxxxx
"Igor Tandetnik" <itandetnik@xxxxxxxx> wrote in message
news:epMGpUoTJHA.3520@xxxxxxxxxxxxxxxxxxxxxxx
Alan Carre <alan@xxxxxxxxxxxxxxxxx> wrote:
-SHRINK_BOX_AMOUNT won't get parsed as --20, but as - -20 (which will
likely compile just fine, but I'm too lazy to check). Preprocessor
works after lexer, handling tokens rather than individual
characters. You need ## operator to create new tokens.


Nope, just try it. It won't compile, no spaces are inserted after the
minus sign.

This program successfully compiles:

#define X -1

int main()
{
return -X;
}

And --20 is not a *new* token, it is not a token at all!

--20 is parsed as two tokens, "--" and "20". -X in the above example
gets expanded to three tokens, "-", "-" and "1". Compiler proper works
on a stream of tokens (after lexer and preprocessor), not a stream of
characters. For more details, see C++ standard 2.1 "Phases of
translation".
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925


.



Relevant Pages

  • Re: Iron Heroes: the good things
    ... I really like the idea of customizing human characters. ... >> Essentially, you earn tokens for doing certain things, mostly in combat ... >> Skill Groups, which essentially allow the character to spend 1 skill ... The greatest thing about it is the Fury tokens. ...
    (rec.games.frp.dnd)
  • Re: [QUIZ] Bytecode Compiler (#100)
    ... So having written the lexer class, I now set up the state transition ... The tokens are ... # The lexer needs to know the character sets involved in deciding ... # Initialize the character set columns to be used by the lexer. ...
    (comp.lang.ruby)
  • Bytecode source
    ... You can compile bytecode and get Forth code ... But it will probably be fast to compress and to decompress, ... Forth word with the string token followed by the length followed by the ... those must be made to store tokens instead of strings. ...
    (comp.lang.forth)
  • Re: Problem defining egin{CJK} . . . end{CJK} in a macro
    ... The process of transforming stuff into tokens while reading input ... characters while reading them from input-file are treated like ... executed when defining takes place but when the defined macro ... - Start a CJK-environment ...
    (comp.text.tex)
  • Re: Splitting a string with Regex and keep the separator
    ... The regex is quite big already. ... a key/val pair. ... If this group captures multiple tokens they're added to the group's Captures collection in the order in which they're found. ... A token is made up of one or more alphanumeric characters. ...
    (microsoft.public.dotnet.languages.csharp)

Loading