SilverScar / C-Language-Parser

A complete Parser for C-Language using Yacc.
95 stars 37 forks source link

Makefile for MinGW and msys2 using bison and flex (probably works for cygwin and Linux) #2

Open FilkerZero opened 4 years ago

FilkerZero commented 4 years ago

I put together a Makefile for this project that builds the parser under msys2 using the MinGW toolchain, bison in place of yacc, and flex in place of lex. I have attached it in the file "project-Makefile-2.zip". As always, scan and examine the file to check for malware, and look at the contents of "Makefile" inside the .zip file. When I created it, the .zip file was 473 bytes long.

If you don't trust the .zip file, the contents should look like the following. All lines with whitespace on the left should begin with the "tab" character; "make" usually doesn't treat spaces and tabs the same on the left margin.

# Make the C language parser using 'flex' and 'bison' on MSYS2
# Probably also works in cygwin and on Linux.  The "-L/usr/lib"
# may need to be changed depending on where "libfl.a" is installed.
CC = gcc
RM = rm -f
YACC = bison -d
LEX = flex
LIBS += -L/usr/lib -lfl -lm

.PHONEY : clean test

parser : lex.yy.c y.tab.c
  $(CC) $(CFLAGS) $(CPPFLAGS) -o $@ $< $(LIBS)

lex.yy.c : project.l
  $(LEX) $<

y.tab.c: project.y
  $(YACC) -v -o $@ $<

test : parser
  ./parser <inp

clean :
  $(RM) *~ *.o lex.yy.c y.tab.c y.tab.h parser parser.exe *.output

When "Makefile" is in the directory "src", the command "make parser" will create "parser" (or "parser.exe") instead of "a.out" from "project.y" and "project.l". the command "make clean" will remove any generated files, including the executable, plus emacs backup files. "make test" will run the generated "parser" using the file "inp" as input. If you start with "make test" and "parser" has not yet been made, the program will be built before an attempt to run it.

$ make test
flex project.l
bison -d -v -o y.tab.c project.y
gcc -o parser lex.yy.c y.tab.c -L/usr/lib -lfl -lm
./parser <inp
Parsing Successful

$

Correction: I used the wrong version of the Makefile, so it has an error in it. I've attached a new .zip file, "project-Makefile-2.zip" with the corrected file. I have edited the above file to show the correct version. The new .zip file is 473 bytes. project-Makefile-2.zip

Original .zip file (489 bytes): project-Makefile.zip (I messed up, you'll have to check history on this posting to find the original. Sorry)