Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pascal to C converter [closed]

I'm writing program which translate Pascal to C and need some help. I started with scanner generator Flex. I defined some rules and created scanner which is working more or less ok. It breaks Pascal syntax into tokens, for now it's only printing what it found. But I have no idea what should I do next. Are there any articles or books covering this subject? What is the next step?

like image 881
Ziem Avatar asked Dec 20 '22 22:12

Ziem


1 Answers

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

If you just want to run some Pascal programs, it is simpler to use (or improve) existing compilers like gpc, or Pascal to C translators, like e.g. p2c

If you want to convert hand-written Pascal code to humanly-readable (and improvable) C code, the task is much more difficult; in particular, you probably want to convert the indentation, the comments, keep the same names as much as possible -but avoiding clashes with system names- etc!

You always want to parse some abstract syntax tree, but the precise nature of these trees is different. Perhaps flex + bison or even ANTLR may or not be adequate (you can always write a hand-written parser). Also, error recovery may or not be important to you (aborting on the first syntax error is very easy; trying to make sense of an ill-written syntactically-incorrect Pascal source is quite hard).

If you want to build a toy Pascal compiler, consider using LLVM (or perhaps even GCC middle-end and back-ends)

like image 144
Basile Starynkevitch Avatar answered Dec 28 '22 08:12

Basile Starynkevitch