Question

I'm trying to set up a build environment for the Mono C# compiler on my Mac. The purpose is to extend the grammar for a research project. I've struggling to set up the build. I'm sure the answer is very easy but so far I've be unable to find any useful informaiton.

I would prefer to have a solution in MonoDevelop that the grammar is part of and where any changes to the grammar is taking into account when the project compiles.

The solution file I've found so far as my only starting point includes a cs-parser.cs file which does not exist in the source drop I've gotten from the project pages. I'm guessing that this file is the result of running the parser generator on cs-parser.jay but I can't find information on how to set this up as a build step (or for that matter running the parser generator by hand)

Links to walk-throughs tutorials on how to work with the mcs would be appreciated or a simple step by step

Was it helpful?

Solution

From README.makefiles:

If your program has 'built sources', that is, source files generated from other files (say, generated by jay), define a variable called BUILT_SOURCES and do not list the sources in $(PROGRAM).sources:

========================================
PROGRAM = myprogram.exe
LOCAL_MCS_FLAGS = /r:System.Xml.dll
BUILT_SOURCES = parser.cs
CLEAN_FILES = y.output

include ../build/executable.make

parser.cs: parser.jay
        $(topdir)/jay/jay $< > $@
========================================

executable.make will automatically delete the $(BUILT_SOURCES) files on 'make clean'. Since this situation is a common occurrence and jay happens to leave behind y.output files, you can also define a variable called $(CLEAN_FILES) that lists extra files to be deleted when 'make clean' is called. (That's in addition to your executable and the built sources).


So, cs-parser.cs is made in precisely this fashion:

[mono] ~/custom/MONO/mono/mcs/jay @ make
/usr/bin/make all-local
make[1]: Entering directory `/home/sehe/custom/MONO/mono/mcs/jay'
make[1]: Nothing to be done for `all-local'.
make[1]: Leaving directory `/home/sehe/custom/MONO/mono/mcs/jay'

[mono] ~/custom/MONO/mono/mcs/jay @ cd ../mcs

[mono] ~/custom/MONO/mono/mcs/mcs @ make
/usr/bin/make all-local
make[1]: Entering directory `/home/sehe/custom/MONO/mono/mcs/mcs'
./../jay/jay -cv < ./../jay/skeleton.cs cs-parser.jay > jay-tmp.out && mv jay-tmp.out cs-parser.cs
./../jay/jay: 9 shift/reduce conflicts.

(reduced output)

It resulted in 10470 lines of un-user-servicable code in cs-parser.cs


Alternative, thinking out of the box:

  1. Just a thought, can you not use a preprocessing c# -> c# converter? This has the additional benefits that you can make it work with any C# tool/compiler. Think of using #line pragmas to map back to the original source for debug information

  2. Also, there are a number of Aspect Oriented code weavers for C#/.NET. You might leverage a combination of 1. and 2. to get the functionality you want?


Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top