Pascal to C Converter

I am writing a program that translates Pascal to C and needs some help. I started with a Flex scanner generator. I defined some rules and created a scanner that works more or less normally. It breaks the Pascal syntax into tokens, since now it only prints what it found. But I have no idea what to do next. Are there any articles or books on this topic? What is the next step?

+3
source share
4 answers

Why do you want to make such a Pascal to C converter?

If you just want to run several Pascal programs, it’s easier to use (or improve) existing compilers, for example gpc , or Pascal in C, for example p2c

If you want to convert Pascal handwritten code into human-readable (and improved) C code, the task is much more complicated; in particular, you probably want to convert indents, comments, keep as many names as possible, but avoid collisions with system names, etc.

, . , flex + bison ANTLR ( ). , ( , Pascal ).

Pascal, LLVM (, , GCC )

+4

" " .

+4

, , C . (IIRC Pascal , C ). flex , , . , Pascal , .

+1

, C () "-" (.. ...), C.

Then, when you have a token stream using some method, for example LR, you can find a semantic tree that matches the sequence of the applied Pascal rule and convert each rule to the corresponding C rule (this can easily be done using Bison).

Note that Pascal and C do not have contextual free grammars, so more control is required.

+1
source

All Articles