java - Using Antlr to get identifiers and function names -
I'm trying to use Antielar and understand, it went written is new to me my Objective-C source Read the code file and remove it from the identifier (names of variables and functions).
Consider in my grammar (file CG4 ): Public Class Mayseelaistr Cached Mistress {@Override Public Zero Entry Entry List (CPR. Identifier ListContacts CTX) {List & lt; Parsetree & gt; Children = ctx children; (Parsity Parsity: Children) {System.out.println (parseTree.getText ()); }} Then I have this main square in it: where example.c is: What am I doing wrong? Maybe I did not write myicalist properly, or the identifier list is not what I need to hear ... I do not really know. I'm sorry, but I did not understand your output, why is a lexical error ?: As you see, I am very confused about this. Can someone help me? Please ... with this line: You can convert your entire input to Assuming that you use to start the parser at the entry point of grammar (rules Here's a quick demonstration: which will be printed: Identifier list: Identifier | Identifier list comma identifier; Identifier: Identifier nondigit (identifier annotit | digit) *;
string fileurl = "C: /example.c"; Kensor Leczer; Try {lexer = new clencer (new ANTLR filestream (filerel)); Common Token Stream Token = New Common Token Stream (Lexer); Septor parser = new cps (token); CParser.IdentifierListContext identifierContext = parser.identifierList (); Presty walker walker = new parserwalker (); MyCListener listener = new MyCListener (); Walker Walk (listeners, identifiers, Context); } Hold (IOException pre) {Logger.getLogger (Main.class.getName ()). Log (Level.SEVERE, null, ex); }
int main () {// it is c int i = 0; // i in int / * double j = 0.0; C * /}
Line 3: 4 mismatch input ( 'hope {& lt; EOF & gt; , ','} Main () {int i = 0;}
CParser IdentifierListContext identifierContext = parser.identifierList ();
identifierList Switch to trying to parse. But your input just trying to be so is not.
compilationUnit is):
MyCListener listener = new MyCListener (); ParseTreeWalker .DEFAULT.walk (listener,;
edit
public square key {public static zero main (string [] args) exception Throws {final list & lt; String & g; Identifier = new arreelist & lt; String & gt; (); String source = "int main () {\ n" + "\ n" + "// it \ n" + "\ n" + "int i = 0; // is int \ n" + "/ * Double j = 0.0; \ n "+" c \ n "+" * / \ n "+"} "; CLexer lexer = new clencer (new ANTLRISTstream (source)); Septor parser = new ciphers (new common trunkstream (Lexer)); ParseTreeWalker.DEFAULT.walk (New CBaseListener () {@Override public void enterDirectDeclarator (@NotNull CParser.DirectDeclaratorContext ctx) {if (ctx.Identifier ()! = NULL) {identifiers.add (ctx.Identifier (). Gettext () );}} // Perhaps override other rules that use `identifier`, parser.compilationUnit ()); System.out.println ("Identifier - & gt;" + identifier); }}
Identifier - & gt; [Main, i]
Comments
Post a Comment