ANTLR C# Can't find 'IAstRuleReturnScope' - c#

I have downloaded the csharp grammar project from here http://antlrcsharp.codeplex.com/releases/view/47523, and it runs fine.
But when I add 'output=AST' to the grammar, I get a TON of errors:
I am admittedly new to ANTLR, so I am not sure how to proceed at this point. I would have assumed this type would have existed in the antlr csharp runtime dll, but obviously not. Has anyone come across this problem before?

I ran into this migrating from a v3.2 script generating from the Java tool to using v3.4 with the dotNet build tools.
I was able to figure out (thx to the documentation that comes with the .net VS integration) that the problem with not getting the right return type was because a class is only generated if you have a return type on the rule. Adding a dummy integer return type to my rules that had no return value cleared that up.
There is a discussion of the rule returns in the C# generator and target in the documentation from the C# target page at antlr, follow the link at the top of the page and check out section 4.1.1 "Return values"

About a year ago I did a project with Antlr and ran into an issue where I got tons of errors. As odd as it sounds but by using an older runtime I got it to work. I think I used a dll that had been compiled for the 2.0 .Net Framework.
I do not remember exactly what the error was or what had actually caused it. All I remember is that it solved the issue. I have no idea if this will help in your situation but it's worth a shot if you are stuck.

You are not the first person to have this problem. The patch at https://github.com/antlr/antlr/pull/1 addresses it by providing the missing file. Include it in your source and recompile.

Related

Xamarin iOS native linking failed for grpc.core

I've been attempting to make grpc work (ssl http2) on Xamarin Forms and after some pain I managed to get it to work on Android using Grpc.Core. However I couldn't get iOS to compile. Working through this problem I was trying to get anything grpc related to work on iOS, and eventually found the grpc experimental xamarin demo, HelloworldXamarin. Found here:
https://github.com/grpc/grpc/tree/master/examples/csharp/HelloworldXamarin
I downloaded the solution, but when I try to compile it I get the following errors:
Error Text:
Native linking failed, undefined symbol: operator delete(void*). Please verify that all the necessary frameworks have been referenced and native libraries are properly linked in.
Native linking failed. Please review the build log and the user flags provided to gcc: -LC:/g/examples/csharp/HelloworldXamarin/packages/Grpc.Core.2.23.0/build/Xamarin.iOS10/../../native/ios/universal -lgrpc_csharp_ext -force_load C:/g/examples/csharp/HelloworldXamarin/packages/Grpc.Core.2.23.0/build/Xamarin.iOS10/../../native/ios/universal/libgrpc_csharp_ext.a -LC:/g/examples/csharp/HelloworldXamarin/packages/Grpc.Core.2.23.0/build/Xamarin.iOS10/../../native/ios/universal -lgrpc -force_load C:/g/examples/csharp/HelloworldXamarin/packages/Grpc.Core.2.23.0/build/Xamarin.iOS10/../../native/ios/universal/libgrpc.a
linker command failed with exit code 1 (use -v to see invocation)
For the warning regarding not being able to find libgrpc_csharp_ext.a, I verified that the file was there.
There appears to be some issue with native linking, which I am very unfamiliar with. I'm using nearly the latest Visual Studio (well, 16.5.3), a mac build host with latest OS and XCode updated to latest. Didn't make any changes to the files pulled from git. I only just started working with Xamarin iOS this week, so everything should be in a fairly "default" state.
What could be wrong with my setup/system that makes this not work? I understand that this is an experimental feature still, but I can't tell if I've done something stupid or if there's been some change in something (like XCode? or it needing VS 2017?) that makes this no longer work? Is anyone else able to get this example to compile?
I've also tried newer versions of the grpc nuget packages and that only resulted in more errors.
Ultimately I'm trying to get latest Grpc.Core to work in iOS on Xamarin.Forms, though I have very little experience working with iOS. If there are issues with the latest versions of XCode/Visual Studio/Grpc.Core that are causing this, I'm willing to try to work through them, if someone can point me in the right direction.
It is not at all related to your versions or something that you did or didn't do.
First for some theory:
If someone wants to use Objective-C libraries or CocoaPods packages in their Xamarin project, they will need to create a binding library for this. Take it as some sort of a "bridge" between the native implementation and the later exposed C# code that you can use. You can learn more about the binding from the official documentation here and more specifically here.
To sum up the info - after the bindings have been created, you see a .lib or .a file. This is exactly what they have done - exposed some native code into the libgrpc_csharp_ext.a. Unfortunately, there are some bindings that are not correct. This is exactly what you are seeing here - the aftermath of an incorrect binding.
Looking a bit into the project I got to the following conclusions:
There is an open issue from May 2019 about this - https://github.com/grpc/grpc/issues/19172
Unfortunately, the issue is still active and there is no movement there.
I have confirmed that after version 1.21 (incl.) the build is not working. For now, you can downgrade to version 1.20.1 (last known to work). I have successfully built the solution with it. Please review the changelog and release notes for this specific version (if any) so that you know if it will fit your needs.
Basically, you have 2 options:
Downgrade to the last good version in order to use it;
If you want to use the latest version either wait for the issue to be fixed, or fork the repo and help with the fixing.
If you want to see their build script and help fix the issue, you can start from here.
Another useful resource is this video from the official Xamarin channel.

Using MySQL ANTLR4 grammar in C#, getting "The type or namespace name 'MySQLBaseLexer' could not be found"

I am trying to play around with the ANTLR4 grammars for MySQL to do some basic statement parsing. This is my first time using ANTLR. I created a blank C# console project in VS2017, installed the ANTLR4, ANTLR4.CodeGenerator and Antlr4.Runtime nuget packages as well as the ANTLR Language Support extension. I added in the MySQLLexer.g4, MySQLParser.g4 and the predefined.tokens file. When I try to build the solution I get the following error:
The type or namespace name 'MySQLBaseLexer' could not be found (are you missing a using directive or an assembly reference?"
I have been looking through the tutorials, SO, and other blogs that discuss using ANTLR4 on C# but nothing seems to resolve the errors. Could anyone point me in the right direction to get this working correctly?
Thanks!
I assume you are using the two grammar files located here. While those grammars may not contain C++ code, it requires the base class you mention which is C++ code, so you will need to port MySQLBaseLexer.cpp and auxiliary code to C#, which is found in the Git repo. The readme in the ANTLR4 grammar directory contains a few more details about this requirement.
Also, why don't you try using Visual Studio 2019, the official Java Antlr Tool 4.7.2 (which requires Java), and my Net Core template for generating an Antlr C# program? Everything is integrated into a build and run F5. Check out this and this. The C# tool is at least two years behind the official release of Antlr. Further, the *.tokens is a generated file.
I don't understand why people keep checking in Antlr-generated files into a repo. It should not be checked in and used, especially if you use my template. The .g4 files are your source. If you need an extension for editing Antlr grammars in VS, you might want to check out my AntlrVSIX extension.
I was interested on this topic once I saw this topic, but went on vacations recently and I could finish the sample.
Here is a sample:
https://github.com/hmadrigal/playground-dotnet/tree/master/MsDotNetCore.MySqlParser
I created where the grammar provided by workbench (https://github.com/mysql/mysql-workbench/tree/8.0/library/parsers/grammars) has been adapted to work on .NET Core (using .NET standard for portability)
I created this sample project, it is not meant for production, and I am not an ANTLR expert, but I love coding and parsers.
Take a look at README.md and https://github.com/hmadrigal/playground-dotnet/blob/master/MsDotNetCore.MySqlParser/MySqlParser.TerminalApp/MySqlParserTester.cs could be your bootstrap. If I ever get to write a blog post I'll share the notes in here.

UWP - .NET Native tool chain compilation error

I've developed a simple and small Universal Windows App that uses EF7 and SQLite. It compiles and runs smoothly when the option "Compile with .NET Native tool chain" is unchecked.
If I check the option "Compile with .NET Native tool chain", I get the following compilation error:
Error Type 'System.MarshalByRefObject' was not included in compilation, but was referenced in type 'Microsoft.Data.Entity.Design.OperationExecutor'. There may have been a missing assembly.
After this there's a lot of other errors, but I believe that solving this one will also take care of the rest.
Does anyone know how to solve this?
I presume what has happened is that you're using a library that isn't targeting the .NET surface area available to UWP. The surface area for UWP is the set of APIs called .NET Core, you can see the source here: http://www.github.com/dotnet/corefx. Most likely you'll need a newer version of EF... although I know they've had some other issues with our ahead of time compilation strategy (see: https://github.com/aspnet/EntityFramework/issues/3603). We're continuing to work with them to get it sorted out and are hopeful that EF will be in a great place by Update 2 sometime in March.
The reason you only see this with .NET Native is because the compiler is walking your entire application at compile time in order to generate native code for everything that it thinks you're going to call. It happens to notice that this type is unavailable and correctly errors out. I presume you don't actually call this code path in your application because it would produce a similar error on CoreCLR... it would just happen at runtime and not compile time.
If you don't actually need this type (and everything else you need also doesn't need this type etc etc), it's possible that removing this directive from your application will allow the tree shaker to eliminate this type from your application before things go awry:
<Assembly Name="*Application*" Dynamic="Required All" />
This directive causes all of the types in your application and the non framework libraries you reference to be rooted and thus unable to be shaken away. Having this directive by default makes our analysis easier and keeps most folks from having to know too anything about our analysis engine. It's possible that removing this can help you avoid the issue.
Let me know if that works out or if you have any other questions. We always love to get feedback and provide some support at dotnetnative#microsoft.com.

Cannot define a class or member that utilizes 'dynamic' because the compiler required type 'System.Runtime.CompilerServices.DynamicAttribute'

I'm trying to run a .NET MVC application on my local computer that I got from GitHub.
When I hit run on Visual Studio, everything complies and a new browser window opens with the error:
CS1980: Cannot define a class or member that utilizes 'dynamic' because the compiler required type 'System.Runtime.CompilerServices.DynamicAttribute'
The compiler section in the same window, shows the following error:
I've checked on google and this seems to be the same error.
This guy was using a dynamic type himself, on the other hand I'm not using any dynamic type, this is being auto generated by .NET's compiler, and I'm using .net 4.5 which should has support for dynamics.
I tried to apply the same solution (Changing all System.Core references to 4.0)
but the thing is that all of them are version 4.0 already.
Do you have any idea how could I resolve this?
I had a similar error on a project I was trying to migrate. Try re-targeting the framework of the project back a version or two, and once you find a target version where you do not get the error, re-target back to the version you originally had trouble with.
I was getting the same error on a website project targeted for 4.6.2 that was referencing some older libraries, re-targeted it back to 4.5.1 and that resolved the error. I immediately re-targeted back to 4.6.2 and did not encounter the error again.
I had this same issue, but none of the answers here solved it, but did point me in the right direction. I think I didn't update the .NET version on my machine to the newer one. After installing it, I rolled back the targeted framework (as was suggested), retargeted the newer framework, and did a few extra things also:
Reinstalled ALL packages by running this in the package manager:
update-package -reinstall
I also compared my project to one that was working for 4.5 and did this:
Opened my project file and removed all "BCL" related elements.
Uninstalled all "BCL" packages in the NuGet package manager for the project (guess it's not needed moving to 4.5+...?)
Removed an old package version of System.Net.Http, which did not get updated for some reason (see web.config - versions should show oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0").
Have to restart VS.
Rebuild solution.
Error is now gone. ;)
One other thing I did to resolve some other errors was to clear the component cache by deleting all files in here:
C:\Users\{USERNAME}\AppData\Local\Microsoft\VisualStudio\14.0\ComponentModelCache\
[rant] Wasted a whole day with all this. Thanks to MS for stealing one more day of my life fixing senseless issues that should never be. Every time I upgrade I always get a wonderful surprise, and a lovely game of fix the red herring. Would it not hurt to detect these conflicts for those upgrading old projects? Perhaps better error traces when things go wrong? I doubt it would be that difficult. Perhaps even something like AsmSpy, but more advanced, built in to VS? [/rant]
Saw this in VS 2019. I excluded and re-included the problematic file (in my case _Layout.cshtml) and that fixed the problem.
I got this error suddenly a couple days after updating to VS2015.3 using 'traditional' MVC app (not new .NET Core / vNext app).
Turns out this error can be a complete red herring.
Make sure:
You haven't got any other errors at all
You've checked the output window for any errors that don't show in the 'Output' window.
Make sure you don't have any conflicting references
In my case I had a typescript error that was causing an error and for some reason triggering this weird 'red herring' dynamic error too.
My fix was to go into the .csproj file and update the typescript tools version to 1.8 (need to unload project and edit by hand). As I said this is unrelated to the error, but I mention the specifics because someone else may end up with this same problem.
I believe that 1.7 didn't accept 'None' for the typescript module system whereas 1.8 does, hence the error.
Adding a reference to System.Dynamic.Runtime did it for me.
I hesitate to write this as an answer, but for me the error appeared in a .cshtml file. I closed the page, rebuilt, and the error vanished. Always best to try the simple things first.
I had the same error, there were just 2 unused tables of my databaseset that I had to delete. I wonder why it worked when I manually change sth in an auto-generated code work but after deleting, it worked.
So be aware that such inconsistencies can also cause this error.
My solution was to correct the version of MVC in web.config under Views folder. E.g. the project referenced MVC assembly version 5.2.2.0 but in the Views/web.config file was version 5.2.4.0 (see image).
Image
Tried a few other answers with no luck, but the overall consensus appears to be that this some sort of issue with cached build artifacts or compiler state or something. Here's what worked for me:
Delete the problem .cshtml file, watch error disappear
Open source control and revert the deletion
This error will come because of the different versions of your Sitecore.Web.Mvc.Dll in solution reference folder(Project name->References->Sitecore.Web.Mvc->right click and check properties) and the version of Sitecore.Web.Mvc.Dll in Web.Config in views Folder.
For solving this error you have to make sure that the version of Sitecore.Web.Mvc.Dll is same in both folders.
Thanx.
For my case, I fixed to run the command line "update-package -reinstall" on the Package Manager Controler.
My problem was in the _Layout.cshtml.
None of the solutions above did the trick for me. I am using VS2017 for this project, upgraded an ran into the same message.
I had commented out a 2 lines in 1 comment #* *#
My solution was to comment out each line separately. What a mystery!
A few hours lost on this.

How do I use Clang from a C# project?

My goal is to use Clang within a C# program to parse C++ source code and build an AST.
If I understand correctly, I need to get libClang from somewhere as it is a C wrapper around Clang, and then I should be able to use the code in the following link to be able to use libClang from a C# project.
https://github.com/SimonRichards/clang-sharp
My problem is I am lost on how to install Clang. I have download the source from here:
https://github.com/FunkMonkey/libClang
and I tried running the makefiles through the visual studio command prompt but it just gives me an error:
Makefile(14) : fatal error U1034: syntax error : separator missing
Stop.
I'm quite confused as I'm not used to github and makefiles. I think the general process I need to follow is:
Install LLVM - where and what is this?
Install Clang - where is this?
Install libClang - how to run the makefiles?
Use SimonRichard's clang-sharp
I was unable to use the project listed here, however, I was able to get up and running using http://www.nuget.org/packages/ClangSharp
There are plenty of documentation how one can get started to use LLVM / Clang. And all this documentation is pretty explicitly mentioned on the websites:
http://llvm.org/docs/GettingStarted.html
http://llvm.org/docs/CMake.html
http://clang.llvm.org/get_started.html
And bunch of stuff around.

Categories