You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
" * " (asterisk) can be both a special symbol (pointer) and an operator (multiply) as a basic C++ token: how should we deal with this in our lexer ? should we look at context while lexing the token or deal with it during parsing ?
example:
int* p; (pointer)
int i = t*p; (multiply)
The text was updated successfully, but these errors were encountered:
As you say, you can't easily tell how the symbol is being used during lexing. To your
examples I'd add:
int *p;
int y = 5 * * p;
and
int *p;
int y = 5 * * * (& p);
You could try to track context in the lexer, but this becomes quite complex, as you end
up having to build a parser in the lexer in order to give symbols to the parser.
So this decision is something you should leave to the parser, with a single token that
represents a * for both contexts.
In the parser you'd then handle it as something like:
Expr : Mult
| Mult TAdd Expr
Mult : Deref
| Mult TStar Deref
Deref : Primitive
| TStar Primitive
Primitive : Id
| Num
| TLeft Expr TRight
" * " (asterisk) can be both a special symbol (pointer) and an operator (multiply) as a basic C++ token: how should we deal with this in our lexer ? should we look at context while lexing the token or deal with it during parsing ?
example:
int* p; (pointer)
int i = t*p; (multiply)
The text was updated successfully, but these errors were encountered: