简体   繁体   English

Jay,单声道C#编译器并更改语法

[英]Jay, the mono C# compiler and changing the grammar

I'm trying to set up a build environment for the Mono C# compiler on my Mac. 我正在尝试为Mac上的Mono C#编译器设置构建环境。 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. 我希望在MonoDevelop中有一个解决方案,该语法是语法的一部分,在项目编译时要考虑语法的任何更改。

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. 到目前为止,我找到的解决方案文件只有一个cs-parser.cs文件,该文件在我从项目页面获取的源代码中不存在。 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) 我猜想这个文件是在cs-parser.jay上运行解析器生成器的结果,但是我找不到有关如何将其设置为构建步骤的信息(或者为此手动运行解析器生成器)

Links to walk-throughs tutorials on how to work with the mcs would be appreciated or a simple step by step 有关如何使用mcs的演练教程的链接将不胜感激,也可以通过简单的逐步操作来逐步实现

From README.makefiles : 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: 如果你的程序的内置光源“,即从其他文件(比如由jay生成),定义一个变量BUILT_SOURCES调用并没有列出在$(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'. execute.make将自动删除'make clean'上的$(BUILT_SOURCES)文件。 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. 由于这种情况是很常见的,并且jay恰好会留下y.output文件,因此您还可以定义一个名为$(CLEAN_FILES)的变量,该变量列出了在调用“ make clean”时要删除的其他文件。 (That's in addition to your executable and the built sources). (这是可执行文件和内置源的补充)。


So, cs-parser.cs is made in precisely this fashion: 因此,cs-parser.cs正是以这种方式制作的:

[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 结果导致cs-parser.cs中有10470行非用户可服务的代码


Alternative, thinking out of the box: 或者,开箱即用地思考:

  1. Just a thought, can you not use a preprocessing c# -> c# converter? 只是一个想法,您可以不使用预处理c#-> c#转换器吗? This has the additional benefits that you can make it work with any C# tool/compiler. 这还有其他好处,您可以使其与任何C#工具/编译器一起使用。 Think of using #line pragmas to map back to the original source for debug information 考虑使用#line编译指示映射回原始源以获取调试信息

  2. Also, there are a number of Aspect Oriented code weavers for C#/.NET. 此外,还有许多针对C#/。NET的面向方面的代码编织器。 You might leverage a combination of 1. and 2. to get the functionality you want? 您可能会结合使用1.2.获得所需的功能?


声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM