just a token question

A Boolean\Math expression is a combination of tokens(Operators, ID and others):
a = b + 1
but correct me another-thing: an expression can be a token or is bad doing it that way?
that is the object oriented way. it depends on what you want to accomplish whether this is good or bad.
Unless I misunderstand your question (it is a bit short), an expression is not a token. A token is related to parsing, a rather low level act attempting to separate each uniquely meaningful collection of characters.

Tokens are applicable to statements that are not math expressions, and are thus an elementary component below that of the expression.

Of course, expressions in C++ could be fashioned from custom types which have no math involved, per se, like string operations.

I can't imagine, on the fly, an expression with only a single token. I believe it would be incomplete and not qualify as an expression.

Your question suggests a notion of considering an expression, comprised of a collection of simple tokens, as if it were a token. I don't think that is applicable. It has been a few decades sense I bothered to work on a compiler, but there are other, higher level notions of grouping expressions as units which are not tokens. A rather obvious example might be parenthetically enclosed expressions.

If one considered a C++ design for a parser, the token would be quite busy enough, as an object, without having to pull the duty of considering itself to contain an expression. That would naturally hint to either another object, or a feature of the objects representing expressions which allow them to be considered singular units as a more complex expression is built.

i took it to mean recursively defined OOP, not formal tokens in parsing (?).
eg
(a|b)|(c&d)
is one expression, made up of 2 lesser expressions..
so T1 = (a|b)
T2 = (c&d)
and parent = T1 | T2

or, an expression is made up of 2 tokens and an operator, where each token may be made up of 2 tokens and an operator.
the lowest level of the recursion, the tokens will be single entities, like 'a'.
this isnt the usual way to do it for expression parsing, but it may be a way to do other things.
could be useful for parallel computation of a big expression. But that seems far-fetched.
Last edited on
thank you so much for correct me... thank you...
i was asking because of these sample:

if ( booleanexpression)

token1 - 'if';
token2 - '(';
token3 - 'booleanexpression';
token4 - ')'


is what i mean...(is good for the rules)... but you correct me..
thank you so much for all
Topic archived. No new replies allowed.