christianwulf / csharpgrammar Goto Github PK
View Code? Open in Web Editor NEWC# 4.0 preprocessor, lexer, and parser written with ANTLR
C# 4.0 preprocessor, lexer, and parser written with ANTLR
Hey man,
I'm working on a plugin to implement C# into netbeans: https://github.com/Chris2011/CSharp-for-netbeans
Do you want to help me with this or do you have time? First I read a lot of tutorials to implement a new language into netbeans. I read about ANTLR that I need a grammar file and with this file, the ANTLR api (In netbeans) creates a lot of other files, that I need. Lexer, token files? Don't know. Maybe I don't need it because you already created it. I don't know atm.
First thing that I tried is ANTLRWorks2: http://tunnelvisionlabs.com/products/demo/antlrworks. It's an application created as a netbeans standalone application, to have syntax highlighting for .g files and generator. When I tried to open your file and hit the action "Generate Recognizer..." I got the error: This command is not valid in legacy (ANTLR 3) mode. But I don't know which. Possible that the syntax, which you need, is available in ANTLR 4 first and not in 3? Whatever I created a bug: tunnelvisionlabs/antlrworks2#55
So let me know, if the project sounds great for you to help or not.
Cheers
Chris
I tried to use your project to build a syntax tree, but your CSharp4.java
parser is not configured to do so. I used csParser.java
directly and it seems to fail recognizing comparison expressions. It seems to be a problem in the grammar definition, that causes the parser to try to match a generic construction when it finds something like f = i < 1
.
The error is: line 7:11 no viable alternative at input '1'
namespace ConsoleApplication1 {
public class TestFileTwo {
public void foo ( ) {
f = i <mismatched token: [@53,108:108='1',<36>,7:11], resync=< 1> ;
}
}
}
I used AntlrPluginIDE in eclipse to compile .g files.
All done without error.
I then ran csMain and I got the following error :
Exception in thread "main" java.lang.NullPointerException
at lang.csharp.CSharp4PreProcessor.mTokens(CSharp4PreProcessor.java:2698)
at lang.csharp.CSharp4PreProcessorImpl.mTokens(CSharp4PreProcessorImpl.java:44)
at org.antlr.runtime.Lexer.nextToken(Lexer.java:89)
at org.antlr.runtime.BufferedTokenStream.fetch(BufferedTokenStream.java:133)
at org.antlr.runtime.BufferedTokenStream.sync(BufferedTokenStream.java:127)
at org.antlr.runtime.CommonTokenStream.skipOffTokenChannels(CommonTokenStream.java:110)
at org.antlr.runtime.CommonTokenStream.LT(CommonTokenStream.java:99)
at org.antlr.runtime.BufferedTokenStream.LA(BufferedTokenStream.java:162)
at lang.csharp.CSharp4.all_member_modifiers(CSharp4.java:16026)
at lang.csharp.CSharp4.type_declaration(CSharp4.java:14524)
at lang.csharp.CSharp4.namespace_member_declaration(CSharp4.java:14458)
at lang.csharp.CSharp4.namespace_member_declarations(CSharp4.java:14384)
at lang.csharp.CSharp4.compilation_unit(CSharp4.java:13778)
at grammar.antlr.csMain.parseWithCSharp4(csMain.java:63)
at grammar.antlr.csMain.main(csMain.java:44)
Then source code line is :
gUnicode.mTokens(); if (state.failed) return ;
in CSharp4PreProcessor.java function :
public void mTokens() throws RecognitionException {
// C:\\Users\\olivier\\workspace\\CSharpGrammar-master\\grammars\\CSharp4PreProcessor.g:1:8: ( Pp_directive | Unicode. Tokens | CSharp4Lexer. Tokens )
int alt64=3;
alt64 = dfa64.predict(input);
switch (alt64) {
case 1 :
// C:\\Users\\olivier\\workspace\\CSharpGrammar-master\\grammars\\CSharp4PreProcessor.g:1:10: Pp_directive
{
mPp_directive(); if (state.failed) return ;
}
break;
case 2 :
// C:\\Users\\olivier\\workspace\\CSharpGrammar-master\\grammars\\CSharp4PreProcessor.g:1:23: Unicode. Tokens
{
gUnicode.mTokens(); if (state.failed) return ;
}
break;
case 3 :
// C:\\Users\\olivier\\workspace\\CSharpGrammar-master\\grammars\\CSharp4PreProcessor.g:1:38: CSharp4Lexer. Tokens
{
gCSharp4Lexer.mTokens(); if (state.failed) return ;
}
break;
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.