I'm working on a parser that's getting a complex/large file in C++. Since each rule gets its own class created, for rules that are not dependent on each other I was wondering if there's a way to instruct the antlr tool to generate the C++ code in separate .cpp files.
Regards,
JZ
I was wondering if there's a way to instruct the antlr tool to generate the C++ code in separate .cpp files
No, there is no such thing possible out of the box.
Related
So I'm trying to use stb_image in my Kotlin/Native project and I am having trouble trying to include it in my project. It's a header only library and konan seems to expect a compiled object file anyways so I was wondering if there is any way of just generating the cstubs and then using the header for linking unless I have to compile a basic translation file since stb_image only requires you to have a translation unit that defines STB_IMAGE_IMPLEMENTATION however I have that defined in my compilerOpts -GSTB_IMAGE_IMPLEMENTATION. Would it be easier to just compile a translation unit, create the static object, and then link against it or does K/N have some way of doing that for me?
I am using Gradle Multiplatform so if there is some gradle script I can run then please let me know.
My -GSTB_IMAGE_IMPLEMENTATION is supposed to be -DSTB_IMAGE_IMPLEMENTATION and I needed to put my -I switch in my compilerOpts not linkerOpts.
I recommend actually creating a translation file but it's not required.
You can just give the header file with the compileropts as you've done and that should work.
You can look at this as a reference. I'm working on a wrapper in my free time.
I want to make a plugin for a language for the Intellij Idea IDE. The language has been developped using Eclipse Xtext and is open source. A plugin already exists for Eclipse.
My goal is to port this language to Intellij Idea. I want to be able to use Intellij to create source files, to have the specific syntax highlighting and to be able to compile and run programs written with this language.
Is there a simple way to generate the Intellij Idea plugin using the Xtext project?
If not is there an efficient solution to be able to have the specific syntax highlighting in Intellij? (an automatic way if possible, I would prefer not rewriting everything everytime the Xtext project is updated)
Short answer
Yes, with a bit of work.
Long Answer
Sadly, Xtext uses antlr in the background and IntelliJ use their own grammar kit based on Parsing Expression Grammars. As such, the parsing and editor code generated by XText, as you might have guessed, will not work.
In order to get your language working in IntelliJ you will need to:
Create grammar *.bnf file
Generate lexer *.flex file, possibly tweak it and then run JFlex generator
Implement helper classes to provide, among others, file recognition via file extension, syntax highlighting, color settings page, folding, etc.
The *.flex file is generated from the bnf. Luckily, most of the classes in step 3 follow a very similar structure so they can be easily generated (more on that later). So basically, if you manage to generate the *.bnf file, you are 80% there.
Although from different technologies, the syntax of bnf files is very similar to XText files. I recently migrated some antlr grammars to IntelliJ's bnf and I had to do very small changes. Thus, it should be possible to autogenerate the bnf files from your XText ones.
That brings me back to point 3. Using XTend, Epsilon's EGL, or similar, it would be easy to generate all the boiler plate classes. As part of the migration I mentioned before I also did this. I am in the process of making the code public, so I will post it here when done and add some details.
Let's say I have a source code file. I want to give this file to the ANTLR and generate the same code and save it to an output file.
Usage:
To beautify the input file.
To add some comments to the input file.
To inject some code into the input file.
Is it possible to do such a thing by exploiting ANTLR?
Basically, I am trying to do a source-to-source transformation with ANTLR from C/C++ to C/C++.
I am interested to add, delete, replace, or modify some lines of the code and generate an output that complies with C/C++ language rules.
P.S.: Please let me know if you know any other tool (other than CLANG) that does the same thing. Parsing C/C++ (or even Fortran) and providing some events to the user and let the user modify the source code.
I want to write a minimalistic XML parser for my timetabling application. I do no want to use any libraries or parsers that will support XML parsing because they be less efficient for my use(as I only need to recognize a few tags only). Hence I have decided to write a parser using lex and yacc.
Is there any way that I can use the functions in the .h file created by lex and yacc in my code directly rather than writing the application code in the yacc itself.
The functions exported by your lex and yacc generated programs are minimal. The parser is invoked by calling yyparse. It calls yylex in the lexer. Everything else can be outside.
It is convenient and customary to have some parsing support routines in the lex and yacc files themselves (helpers which are called by lexing and parsing actions, and not by anything else). But not the application logic. (Except for very trivial textbook examples for Yacc.)
Do Objective-C or MATLAB/Octave have source file extensions besides .m? I ask because I'm putting Hello World programs in a single folder and I can't have two hello.m files.
The only way I see is to create subdirectories for each of the programs and put your files there. You can tell Obj-C to treat other extensions as Obj-C, but that would not solve the problem for the other programs.
Update
To compile any extension as Objective-C, use -x objective-c on the command line or Select Objective-C from "Compile Sources As" in the target build settings. Default is "According To File Type", which means that only .m files are compield as Objective-C.
FWIW, there are many subtle differences between Objective-C++ and Objective-C. I myself would use subfolders to separate the .m files, as I already said above.
A workaround would be to use .mm for Objective-C. .mm is used for Objective-C++ source files and it is a superset of Objective-C so it should compile fine.
This is by no mean a clean solution. A much better way would be to reorganize your folder into subfolders as suggested by Ruddy Velthuis, or simply to call your source files hello-objective-c.m and hello-matlab.m.
MATLAB cannot find files unless they have the .m extension (very important!)
Now I know very little about Objective-C, I presume it's a superset of C (just like C++ is). If so, and similar to C/C++, you should be able to pass any file name as input to the compiler:
g++ -c myfile.m.txt