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 ): Identifier list: Identifier | Identifier list comma identifier; Identifier: Identifier nondigit (identifier annotit | digit) *;

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:

  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); }   

where example.c is:

  int main () {// it is c int i = 0; // i in int / * double j = 0.0; C * /}   

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 ?:

  Line 3: 4 mismatch input ( 'hope {& lt; EOF & gt; , ','} Main () {int i = 0;}   

As you see, I am very confused about this. Can someone help me? Please ...

itemprop = "text">

with this line:

  CParser IdentifierListContext identifierContext = parser.identifierList ();   

You can convert your entire input to identifierList Switch to trying to parse. But your input just trying to be so is not.

Assuming that you use to start the parser at the entry point of grammar (rules compilationUnit is):

  MyCListener listener = new MyCListener (); ParseTreeWalker .DEFAULT.walk (listener,;   

edit

Here's a quick demonstration:

  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); }}   

which will be printed:

  Identifier - & gt; [Main, i]    

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -