N
N
NFly2016-02-18 19:32:12
C++ / C#
NFly, 2016-02-18 19:32:12

How to feed an existing compiler a new syntax?

Let's say there is a language c++ or c, there is a compiler for them. If you do not change anything in the structure of the language, but change its syntax, then how to make the compiler understand the new spelling? That is, instead
for ( var i =1; i < 3; I ++)
of writing
for i, 1, 3 do
What needs to be changed?
What books to read on this topic? Where to look?

Answer the question

In order to leave comments, you need to log in

5 answer(s)
M
maaGames, 2016-02-18
@maaGames

syntax defines the structure of the language.
Specifically, here you suggest that the compiler independently deduce the type of the loop counter (quite realistic in the new standards), decide on its own what to do the comparison for less (in algorithms they often use != for iterators) and decide that the counter increase is an increment. Those. it's not a different syntax at all, it's a whole different thing.
Stubborn Olympiads love to make macros like:
#define FOR( A, B, C ) for( int A = B; B < C; ++A )
DO NOT DO THIS!!!

J
jcmvbkbc, 2016-02-18
@jcmvbkbc

Where to look?

In the source code of the compiler, of course. You can start here , for example .

R
redakoc, 2016-02-18
@redakoc

The preprocessor is the easiest.

B
beduin01, 2016-02-18
@beduin01

Here are good sources https://github.com/SDC-Developers/SDC

M
Maxim Moseychuk, 2016-02-19
@fshp

If you are not interested in this particular example, but in general, then there are 2 wonderful books: SICP and The Book of the Dragon.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question