Compiling user-written source code files for beginners? - linux

everyone.. I'm not a complete noob to linux, I'm using Fedora 16, but I've always had difficulty compiling programs from the command line and I would really like to learn how to do it the right way. I've had experience with Python, Ruby, Perl, PHP, Lua, bash and other languages, recently I've getting into Fortran code and here's the problem: Every time I run the f77 command with an option and filename, I get one of the following errors:
[code]
[Eddie_Nygma#localhost ~]$ f77 -S #classicpayroll.f#
f77: no input files
[Eddie_Nygma#localhost ~]$ f77 -o #classicpayroll.f#
f77: argument to `-o' missing [/code]
I really need to get this compiled and running for my cs class, somebody please help me out, could it possibly be some sort of a a syntax error or how do I correct it?

I used fortran long ago.
In fortran, the first letter in file name shuold be A-Z or a-z.
number or # is not allowed

Related

Subprocess.run() cannot find path

I have a problem with a script I wrote.
I'm just trying to run an executable (I took arduino.exe as an example). However, I either get a FileNotFoundError: [WinError 2] or a non-zero exit status (depending on Shell=True is off or on, respectively).
The code of my entire script is simple:
import subprocess
subprocess.run("C:\Program Files (x86)\Arduino\arduino.exe",shell=True,check=True)
I am aware that Shell=True poses a security risk, but have found no other way to solve the path not found error. My other guess is that the code struggles with the numbers and spaces in the path?
Any help is greatly appreciated.
you need to escape backslash character.
use \\ instead of \ for every backslash,
subprocess.run("C:\\Program Files (x86)\\Arduino\\arduino.exe",shell=True,check=True)
or you can use raw string literal,
subprocess.run(r"C:\Program Files (x86)\Arduino\arduino.exe",shell=True,check=True)

Can't parse COBOL source code with Antlr4

I'm learning on how to use Antlr4 to parse COBOL source codes. Currently, I'm following the steps, exactly as demonstrated by Enam Biswas in his Youtube video.
Basically, I've downloaded antlr-4.7.1-complete.jar and placed it in C:\Javalib. Yes, I've also include the path into my Windows environment and created the antlr.bat and grun.bat files.
For the grammar files, I'm using Cobol85.g4 and Cobol85Preprocessor.g4 which were taken from Ulrich Wolffgang github. On the same time, I use HellowWorl.cbl sample source code to see how the parsing works.
After running the antlr.bat, I executed the command below:
C:\Users\ffa\Desktop\COBOL>grun Cobol85Preprocessor startRule HellowWorld.cbl
As the result, I received the error message as shown below:
Warning: TestRig moved to org.antlr.v4.gui.TestRig; calling automatically
Can't load Cobol85.g4 as lexer or parser
As I'm not sure why I can't get it parsed as shown in the video, I also attempted below commands:
C:\Users\ffa\Desktop\COBOL>grun Cobol85 startRule HellowWorld.cbl
and
C:\Users\ffa\Desktop\COBOL>grun Cobol85* startRule HellowWorld.cbl
End up, I still get the same error message. So, I did my search through Google and found a suggestion to download antlr-runtime-4.7.1.jar. So, I downloaded the file and placed it in the same directory which is located at C:\Javalib.
When I executed the commands above, this time, I received a different message
Error: Could not find or load main class org.antlr.v4.runtime.misc.TestRig
Could anyone please assist me to parse the COBOL source code with Antlr4? It would also be good if someone could explain the difference between Cobol85.g4 and Cobol85Preprocessor.g4.
From your console, go into a new directory and do the following:
1. Download the ANTLR jar:
wget http://www.antlr.org/download/antlr-4.7.1-complete.jar
(or just download it if wget is not available on your console)
2. Download the COBOL grammar:
wget https://raw.githubusercontent.com/antlr/grammars-v4/master/cobol85/Cobol85.g4
3. Download a COBOL source file:
wget https://raw.githubusercontent.com/uwol/cobol85parser/master/src/test/resources/io/proleap/cobol/ast/HelloWorld.cbl
4. Generate all .java lexer and parser classes from the COBOL grammar:
java -jar antlr-4.7.1-complete.jar Cobol85.g4
5. Comile all .java source files:
javac -cp antlr-4.7.1-complete.jar *.java
6. Feed the COBOL source file to the generated lexer/parser
... and instruct the parser to start with the startRule rule:
java -cp .;antlr-4.7.1-complete.jar org.antlr.v4.gui.TestRig Cobol85 startRule -gui < HelloWorld.cbl
(*nix users, do java -cp .:antlr-4.7.1-complete.jar org.antlr.v4.gui.TestRig Cobol85 startRule -gui < HelloWorld.cbl)
If the < does not work on Windows, just do this:
java -cp .;antlr-4.7.1-complete.jar org.antlr.v4.gui.TestRig Cobol85 startRule -gui
The prompt will now be silent. It is writing for you to type in some source to be parsed. When you're done typing in some COBOL code, terminate with CTRL+Z (*nix users do CTRL+D).
That's it.
Now there are some errors printed to your console, meaning the COBOL parser
cannot properly parse the source file. Whether that has something to do with
first doing something with the pre-processor,
or the input that is invalid, I don't know.
Disclaimer: I am the author of these COBOL ANTLR4 grammar files.
The parser generated from grammar Cobol85.g4 has to be provided with COBOL source code, which has been preprocessed with a COBOL preprocessor. Cobol85Preprocessor.g4 is at the core of this preprocessor and enables parsing of statements such as COPY REPLACE, EXEC SQL etc.
Cobol85Preprocessor.g4 is meant to be augmented with quite extensive additional logic, which is not included in the grammar files and enables normalization of line formats, line breaks, comment lines, comment entries, EXEC SQL, EXEC CICS and so on.
The ProLeap COBOL parser written by me implements all of this in Java based on the files Cobol.g4 and Cobol85Preprocessor.g4.

byacc %defines syntax error when compiling with make command

I am trying to run Ymer tool in windows 10 platform. I have installed g++, gcc, yacc via cygwin. After configure command, When I am running make command to compile the application, it generates following error.
PS C:\ymer> make
/bin/sh ./ylwrap src/grammar.yy y.tab.c src/grammar.cc y.tab.h echo src/grammar.cc | sed -e s/cc$/hh/ -e s/cpp$/hpp/ -e s/cxx$/hxx/ -e s/c++$/h++/ -e s/c$/h/ y.output src/grammar.output -- byacc -d
byacc: e - line 514 of "/cygdrive/c/ymer/src/grammar.yy", syntax error
%defines
^
Makefile:2467: recipe for target 'src/grammar.cc' failed
make: *** [src/grammar.cc] Error 1
It seems the grammar.yy file causes the problem. Anyone knows how to solve this problem. BTW I am not familiar neither with yacc nor make files. I am just very new to cygwin as well.
Thank you,
The %defines declaration is bison-specific (not part of standard yacc). The file grammar.yy contains some bison features which byacc implements, but this is not one of those. (From the description in the manual page, it seems that this is equivalent to the standard command-line option -d, making it less than useful).

Handling command line options with multiple arguments for some flags

I'm writing a program where the command line usage should be something like:
mkblueprint FILE FILE FILE -o <output name> -s <string> -r <number> -p pOPT1 pOPT2 pOPT3
I'm currently using CmdLib and I can't figure out a way to handle this; a flag is required for each input(so I can't just have FILEs sitting alone) and there doesn't appear to be a way to pass multiple arguments to a flag, as with -p. These are extremely common in command line programs so I figure I'm just misunderstanding the documentation, but it's not mentioned in any command line library I look at for Haskell.
After some more work with CmdLib I was able to handle the bare FILE input via the Extra tag and then checking that each string is a valid file, which seems to be the standard way to handle it despite the name. -p pOPT1 pOPT2 pOPT3 is apparently not allowed under the POSIX standard, which is why I'm not finding libraries that will do it.
You might consider the GetOpt bindings that come with base. They're not as sexy as some of the more modern alternatives, but they support bare arguments and final options well.

Windres syntax error

I am working in MinGW environment (downloaded with their installer on 12/12/2011). I am attempting to compile a resource (.rc) file using Windres. The specific command I use is
Windres -O coff About1.rc -o About1.res
Windres generates at least 100 lines of warning messages reading: "warning: null characters ignored". Following this Windres emits: "Abouty1.rc:1:syntax error".
As a matter of fact, there are no null characters in the About1.rc file. In addtition, the first line of the file is an include statement: #include "dlgresource.h". I played around and eliminated this statement and it turns out that it doesn't matter what I put there, I get the same flurry of messages and the syntax error notification.
To make things more confusing, this same .rc file compiles without any problem using MSFT's rc.exe. The resulting .res file links smoothly with the program .obj file and runs perfectly.
I have no idea what is going on. Any ideas?
Thanks,
Mark Allyn
Your .rc file is probably encoded as UTF-16.
That's what's required in general by Microsoft's [rc.exe], in order to be able to deal with international characters, but GNU [windres.exe] can only deal with ANSI encoding.
One workaround is to convert the file to ANSI on the spot (possibly losing e.g. Russian or Greek characters):
> chcp 1252
Active code page: 1252
> type my.rc | windres --output-format=COFF -o my.res
> _
You probably used VS or a similar tool to generate the file. There are some parts of the character encodings that you cannot see resulting in null characters and etc.
Generate a new .res file with the same content, don't copy/paste the content, type it in yourself.
Try:
windres About1.rc -o About1.o
and then just use the resulting .o file instead of the originally intended .res file.
I've had the same troubles than you today. I know it has passed a lot of time from your question, but I'm writting this on the hope that it can be useful for someone.
First, I obtained an object file .o compiled using Cygwin, writting:
windres -o resource.o resource.rc
By doing that, you dont need to use the .res file, but the .o one, and you can then link this object with all the others, when you compile yout program, using GNU resources:
g++ Header_files CPP_files flags ... -o program.exe recource.o -lm
For instance.

Resources