U
U
Username2015-07-16 07:28:41
Programming
Username, 2015-07-16 07:28:41

From the point of view of C lexemes minus this?

From the point of view of C lexemes, are the minus signs in the first and second expressions different signs?
I break the C code into tokens and assign the minus sign to a lexeme called "operations".
1) int a = -1;
2) int a = 2-1;
Minus in both cases is it a separate lexeme? If so, how do you tell the resolver that -1 is an indivisible structure?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
J
jcmvbkbc, 2015-07-16
@dalv_happy

Minus in both cases is it a separate lexeme?

This is one and the same separate token, which, due to the context, turns into different operators.
-1 in terms of the C standard is an expression: unary minus applied to a constant, not an indivisible structure.

M
Mrrl, 2015-07-16
@Mrl

We'll have to teach the recognizer to perform operations on constants. Then both -1 and 2-1 will be compile-time constants, while (-x) and x-1 will be the result of various minus operations (which don't have to be related in any way).

A
Antony, 2015-07-16
@RiseOfDeath

From the point of view of the language, these are two different operators:
Unary minus and binary minus.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question