How to compile a lex file on windows? - windows

I have correctly downloaded and installed flex, bison and Dev C++ in C:\ . Then I tried to compile myfile.l in command prompt, but it gives the error:
flex: can't open myfile.l.
What is the problem?

I can see from your question that you are a beginner in need of some instruction, so what follows is in tutorial style. I hope you don't mind the tone. Many of my students encounter the same problem as you did when first starting.
The files containing the code for flex, bison or the compiler gcc (or g++) are just text files, and not some specially encoded form of file. They are only named something.l, something.y and something.c (or something.cpp) by convention. We could just call them something.txt or even something.l.txt if we wanted to. The reason they are named the way they are is to enable all the different components of one program to be distinguished without cluttering up the name space. So, if we have a project, such as some homework done in flex and bison, we can use the word homework as the base name and have the following file set:
homework.l <-- The lexer source file for flex created for the homework
homework.y <-- The parser source file for bison created for the homework
homework.cpp <-- The C++ source file for g++ created for the homework
homework.obj <-- The object file created by g++
homework.exe <-- The final windows executable created by g++
(There will be many other files as well, but I'll skip over that for now).
As the source files are just forms of a text file they can be created by a text editor. You indicated you are using Dev C++ which is an IDE (Integrated Development Environment) which combines a text editor, a compiler and a debugger into one package. The text editor part works just like any other text editor, such as Notepad, NotePad++, vim, emacs or one of the myriad of other editor tools.
Commonly, by default, a text editor tool on Windows will save a text file with the postfix language code of .txt. Here is an example dialogue of saving such a file:
You can see that if I saved my file, which I called SOlexer.l by pressing the Save button, I would get a file called SOlexer.l.txt because the default is to always make a file withe the suffix of .txt.
Now this does not need to be a problem. If I tried to invoke flex, as you did:
$ flex SOlexer.l
flex: can't open SOlexer.l
I would get the same error message. However I can just call flex with the actual file name used and it would work:
$ flex SOlexer.l.txt
$
Alternatively, I could rename the file, and then use it:
$ rename SOlexer.l.txt SOlexer.l
$ flex SOlexer.l
$
Problem solved!
However, as you have discovered, it is best to just create the file with the desired (and more convenient) name in the first place. To do this one has to just make a different selection from the menu when saving the file, like this:
If we click on All types (*.*) we can create the file without the .txt suffix. This should work for most similar tools also.
To help my students who had difficulty using flex and bison on Windows I made a series of video tutorials. You are welcome to use them also.
In conclusion, although you had trouble getting your flex file to build, your problem is nothing to do with flex or bison, but a simple beginners problem with learning how to create and edit files on a Windows system.

Related

Atom and Pandoc

Using Atom, I'm trying to generate a PDF file from markdown.
I installed markdown-preview-plus plugin, which supports pandoc, and then installed pandoc and configured the plugin to use it.
Now, markdown-preview-plus does recognize pandoc, but I cannot see any command to generate a PDF. Plugin's web page seems to say nothing about that.. Can you help me?
markdown-preview-plus
Atom's markdown-preview-plus package generates an HTML preview, as #mb21 alluded to. This is clear by the fact that you can right click on the preview and select Copy as HTML. With the Enable Pandoc Parser option enabled, MPP is indeed using pandoc to generate this HTML preview.
In light of your question, I tried adding the following to the Pandoc Options: Commandline Arguments setting in MPP:
--to=latex, --output=temp.pdf
Note 1: you can't specify --to=pdf because pandoc can only generate PDF by first generating a LaTeX file.
Note 2: the above doesn't work because MPP essentially passes the contents of the editor window through pandoc 'on-the-fly', so you can't really hijack the --output setting.
Workarounds
AFAIK, there is no way to get a "live" PDF preview (the way you can get a "live" HTML preview using MPP). This means you will have to build the document whenever you'd like to view what's changed.
Assuming you want to view the PDF in the Atom window, you can install pdf-view and open the PDF in a pane, side-by-side with your source. Otherwise, you could simply open the PDF in your favorite PDF reader.
Build from the command line
As #mb21 suggested, you can build from the command line. I sometimes use BAT/CMD files to store lengthy, or complicated build commands (since I'm on Windows). For example, in my document source directory, I might have make.cmd, which contains:
pandoc --filter=pandoc-crossref --filter=pandoc-citeproc --smart --listings --number-sections --standalone file.md -o file.pdf
Then I run make.cmd from the command prompt using `./make.cmd'.
Alternatively, you could use Makefile.
Build from Atom
Install atom-script. Then, configure your run options (Ctrl-Alt-Shift-O, on Windows) with something along the lines of the following:
Command: pandoc
Command Arguments: --filter=pandoc-crossref --filter=pandoc-citeproc --standalone file.md -o file.pdf
As you edit your source and would like to update the PDF, you can execute the command via Ctrl-Shift-B
Build from Atom using panzer
You'll still need Atom's script package, but you'll also need to get panzer which is a utility that helps manage build configurations for pandoc.
Edit:
Automatically Build-on-Save via Grunt
Rather than having to press a key combination (e.g. building from command line or using atom-script), I thought of automatically building the output PDF upon saving using Grunt. I've captured the basic idea in this gist
I'm working on the same thing right now, only I am using embedded latex mathematical formulae etc.
The markdown-preview-plus gives a fair representation of what I'm likely to see, but I've been running the following command from the command line in order to compile my pdf
pandoc -f markdown myfile.md -o pdffile.pdf
This works in most simple cases, for trickier ones, or where I want to stitch a few things together, I'm taking my markdown files first to their latex equivalents using a command like
pandoc -f markdown+tex_math_dollars+pipe_tables myfile.md -o myfile.tex
Which creates a latex version of my original file that I can compile/combine with other latex files, or convert to pdf using
pandoc myfile.tex -o myfile.pdf
It's supposed to be possible to embed these various scripts into Atom, using the 'scripts' package, but I'm yet to try that - would be great if someone were to post up their methods too in this direction.
I got pandoc-pdf toolbar working on Atom after installing Perl on Windows, though PDF compilation is much slower with "Latexmk".
I recommend using markdown-preview enhanced and then use several other options available including pandoc, ebook etc.
markdown-preview-enhanced in Atom has support for PDF-on-save, similar to the Grunt workflow suggested above. The output command has several options in addition to PDF, such as MS Word.
Example:
---
layout: post
title: tentative tentacles
date: 2020-09-15 15:01
bibliography: bibliography.bib
output: pdf_document
export_on_save:
pandoc: true
---

OS X - Make returning "Nothing to be done for <filename>"

First of all, I would like to apologize if I'm on the wrong stackexchange network, and secondly, sorry if I'm overlooking something simple.
I was moving files from my old hard drive from an old PC when I came across several password protected ZIP Files. However, since those files were a bit old, I forgot the passwords already. I tried every password I could come up with but I still came up empty. After several google searches, I found this tool/utility for Mac OS X that could help me. So I go to the downloads page and download the Mac OSX utility tool and the source code.
However, I am having problems executing the make command for the file. It says on the downloads page:
If you are using linux or another unix, you need to download the source code, uncompress it and type "make" to compile the utility.
So far, what I've tried is
$make /Users/myname/Downloads/aapr-0.01-source/Makefile
I have also tried the other files in the source folder but nothing worked. After that, I'm pretty much blank. I tried double clicking the aapr file in the utility download for Mac (which is a Unix Executable) and it opens a new terminal window displaying the commands and such. Also, doing $aapr [options] [filename] only shows me -bash: aapr: command not found. I also updated XCodes command line tools.
Sorry if I'm missing out on something very basic, I don't usually use the terminal on the OS X.
Try running
cd /Users/myname/Downloads/aapr-0.01-source
make
A Makefile contains rules for building files from other files but it is based on paths and contents, etc. which depend on your current location. So generally you need to be in the directory of the project for it to work.
Edit (copied from my comment):
To execute a command from a specific location (that isn't in the normal $PATH) you need to specify a path for it. So something like /bin/bash or ./aapr (where ./ means the current directory).

QtCreator and `$$files(*.cpp)`. how to reload file list?

In my qmake-pro-file, I use something like SOURCES = $$files(*.cpp) which expresses exactly what I want and works great when I do qmake && make. However, when I work with QtCreator and when I add or rename some file, how can I get QtCreator to update the file list? I currently must restart QtCreator.
AFAIK, the only ways you can force qt-creator to re-parse the pro file is by either touching the pro file (i.e. $ touch project.pro), or by re-saving the pro file (i.e. by adding a random space somewhere, removing it again and saving the file).

Sublime Text 2 project default file(s) for building

I am a beginner user of Sublime Text 2, but I was trying to set up project specific default file(s) to build from. I'll explain myself:
When writing in LaTeX, I tend to separate the sections or chapters in different .tex files. When I build, I would like the main file to be the one passed to the compiler no matter what file has focus (a section/chapter .tex or the .log file or any other file for that matter).
Similarly, when writing C++ code, I would like to be able to specify a list of files to pass to the compiler.
Right now I am using a copy of the C++ build-system with *.cpp instead of the current file in the "cmd" line, but not always I want to build every cpp file in the folder. A similar modification on the LaTeX builder would be possible changing the file to build to something like main.tex and using main.tex for the main file every time.
Even though these are workarounds, I was wondering if there was a way of defining the default file(s) to the be passed to the compiler (or to a batch file if necessary) from the project specific files.

How to add copyrights to my current app in xcode using MAC OS

I am working on an app.I have finished the app development module ,now i am working on getting it ready for delivery to client.
I have to add client's copyrights to all the .h,.m files inn my projects.As there are around 700+ files in this .Also i don't want to use the cntrol+find in entire app and replace it with the copyright content required.
Is there any other approach i can look into to add the copyrights content to it.I heard of creating some sort of batch file and then using terminal to add copyrights to project but i am not sure how to implement this.
Any help would be appreciated.
Thanks
Hmm, this may need just a little shell scripting. In general, this is how I would attempt to tackle it:
Create a text file with your copyright.
Create a text file with the (code) file names you need to add the copyright to. (Should be pretty easy with something like ls *.m > script).
Open the script file with a text editor and modify each line so that it reads:
cat copyright 'filename' >
Should be pretty easy to do with a macro
Set the script file's execution bit: chmod a+x script
Run the script by: ./script
Notice that this produces files with '_out' at the end. Change it to what fits you.

Resources