Dear All, I am a Masters student, I use Java, and I am trying to make my parser with the help of ANTLR. I need this for my Masters project. I am using ANTLRWorks 1.3.1 I had 2 questions concerning it:
1) How can I have a dynamic token name (or dynamic lexer)? *Example: (the symbol SERVICE, will have different token values, depending on certain list (array) whose contents change over time)* * * So, in some scenario, SERVICE will, let's say, have the following form: *SERVICE* : ('networking' | 'internet' | 'intranet') ; But in other scenario, I want service to address a different set of token values, let's say: *SERVICE* : ('hardware' | 'software') ; ========================================================= I tried to solve it in 2 ways: A) each time the contents of the array change, I generate a new grammar file, *but I faced the problem:* that I did not find the method that takes as input the grammar file (.g) and generates the tokens file, the lexer.java, and the parser.java (i.e. the exact task that is done by the button 'Generate Code' in ANTLRWorks 1.3.1) B) I tried to play in the generated Lexer.java, but I fear that this might destroy my plans in point 2 (if what I will ask in this point is doable) 2) Given a certain grammar, how can I (or: is it possible to) get the list of all possible next tokens? In other words, is there a method (or a trick to make such a method) that takes as input a grammar, and a non-complete (but so far correct) sentence of this grammar and gives as output the set of all possible next tokens that can be inserted to keep the sentence true? *Example: (the good thing is that all tokens to be used are pre-defined, so we do NOT have a rule such as ID : ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'.. 'Z'|'0'..'9'|'_')*;)* *start* : *ANIMAL* ('or' *ANIMAL*)* 'and' *SERVICE EOF* ; *ANIMAL* : ('dog' | 'cat' | 'horse') ; *SERVICE* : ('hardware' | 'software') ; ========================================================== So, imagine this scenario: A) the user inserts "dog" and now asks for the autocomplete, so I want to give the user the list of possible next tokens that he can write, and the list will be "or, and" B) Now let's say the user chose "or", so the sentence now is "dog or" and then asks for the autocomplete so I display the list "dog, cat, horse" C) .. and so forth :-) Any Idea? Many Thanks for your time :-) -- Sameh W. Zaky List: http://www.antlr.org/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address -- You received this message because you are subscribed to the Google Groups "il-antlr-interest" group. To post to this group, send email to il-antlr-inter...@googlegroups.com. To unsubscribe from this group, send email to il-antlr-interest+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/il-antlr-interest?hl=en.