Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implementation of a C pre-processor in Python or JavaScript? [closed]

Is there a known implementation of the C pre-processor tool implemented either in Python or JavaScript? I am looking for a way to robustly pre-process C (and C like) source code and want to be able to process, for example, conditional compilation and macros without invoking an external CPP tool or native code library. Another potential use case is pre-processing within a web application, within the web browser.

So far, I have found implementations in Java, Perl, and of course, C and C again. It may be plausible to use one of the C to JavaScript compilers now becoming available.

The PLY (Python Lex and Yacc) tools include a cpp implemented in Python.

like image 260
grrussel Avatar asked Dec 03 '10 23:12

grrussel


People also ask

Does Python have a preprocessor?

#Macros for logical operators import sys #Macro definitions #in python, function definitions are used as macros #There is no preprocessors in python #Variable Initialization a = int(raw_input("Enter Three Numbers : ")) b = int(raw_input("Enter Three Numbers : ")) c = int(raw_input("Enter Three Numbers : ")) if a > b ...

What happens during preprocessing in C?

The preprocessor provides the ability for the inclusion of header files, macro expansions, conditional compilation, and line control. In many C implementations, it is a separate program invoked by the compiler as the first part of translation.

What is the purpose of the pre processor in the C program compilation process?

The C Preprocessor. The C preprocessor is a macro processor that is used automatically by the C compiler to transform your program before actual compilation. It is called a macro processor because it allows you to define macros, which are brief abbreviations for longer constructs.

What is pre processor directives in C programming?

Preprocessor directives are lines of the source file where the first non-whitespace character is # , which distinguishes them from other lines of text. The effect of each preprocessor directive is a change to the text and the result is a transformation of the text that does not contain the directives nor comments.


2 Answers

The Firefox build system does something similar for its chrome. A source file named jar.mn lists all the XUL/JS files needed, and optionally these files are preprocessed before they are shipped. Thus the script that ships the files also invokes a mini-preprocessor.

like image 140
Neil Avatar answered Oct 12 '22 01:10

Neil


Check out PLY, an implementation of Lex and Yacc on Python which contains a cpp tool implemented in python using the PLY lexer. There is also pycparser, a parser built on top of PLY for the C language.

like image 40
vz0 Avatar answered Oct 12 '22 01:10

vz0