[il-antlr-interest: 28996] [antlr-interest] What's wrong with org.antlr.Tool.main(String[] args)?
Hi all, Using ANTLR v3.2, in the runtime I generate the lexer and parser Java files using this code: org.antlr.Tool.main(new String[]{projectPath+GrammarFile.g}); The problem is that, after this line of code, no other code gets executed, for example, in this piece of code: System.out.println(Before); org.antlr.Tool.main(new String[]{projectPath+GrammarFile.g}); System.out.println(After); Output: Before will be printed, the lexer and parser will be generated, BUT After will NOT be printed.. Using Java Graphical User Interface, whenever I call this line of code in my application, it indeed creates the lexer and parser but then the application freezes.. Any idea why this happens? Or how I can avoid it? -- 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.
[il-antlr-interest: 28971] [antlr-interest] Context-Sensitive Follow Sets.. Bug?
Here is the same message without formatting: -- Forwarded message -- From: Sameh W. Zaky sameh...@gmail.com Date: Sun, May 23, 2010 at 3:29 PM Subject: [antlr-interest] Context-Sensitive Follow Sets.. Bug? To: antlr-interest@antlr.org Hello everyone.. After reading the wiki article http://www.antlr.org/wiki/display/ANTLR3/Custom+Syntax+Error+Recovery, (thanks to Jim Idle, Yes, you def. deserve a Masters too ;-)) I went on with developing my own example to test the method: computeContextSensitiveRuleFOLLOW() (described here: http://www.antlr.org/api/Java/classorg_1_1antlr_1_1runtime_1_1_base_recognizer.html#2b566e00e5d771f66dd4e29a4a27a1c4 ) The method works perfectly in all cases except in the case of zero or one, Consider the following simple grammar: = start : animal (AND acClass)? service EOF; animal : (DOG | CAT ); service : (HARDWARE | SOFTWARE) ; AND : 'and'; DOG : 'dog'; CAT : 'cat'; HARDWARE: 'hardware'; SOFTWARE: 'software'; acClass @init { System.out.println(computeContextSensitiveRuleFOLLOW().toString());} : ; = Testing this grammar, with let's say input: dog and software, the result in the console is: {4, 7, 8} (which stands for tokens {THE, HARDWARE, SOFTWARE}), although it is supposed to be: {7,8} (which stand for tokens {HARDWARE, SOFTWARE} only).. Because after acClass in start rule, if we get the as next token this will make the input invalid.. Any idea why this happens? Or how we can overcome it? Thanks a bunch.. -- Sameh W. Zaky Regards -- 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.
[il-antlr-interest: 28950] [antlr-interest] Java Target - How to Generate the Parser and Lexer at Runtime?
Greetings, I am still an ANTLR beginner.. I run a software where I generate the .g grammar file automatically. So I would love to know how to generate the lexer and parser at runtime given the .g file? Thanks! -- 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.
[il-antlr-interest: 28957] Re: [antlr-interest] Java Target - How to Generate the Parser and Lexer at Runtime?
Dear Brat, You're right.. But now I need to change my question because I found out that Parser.java generated from this action is different than Parser.java generated when I click 'Run..' in ANTLRWorks and give it an input text.. So my new question is: How, from the command line, do I run the grammar (giving it an input text file, let's say)? On Sat, May 22, 2010 at 1:54 PM, Bart Kiers bki...@gmail.com wrote: On Sat, May 22, 2010 at 1:33 PM, Sameh W. Zaky sameh...@gmail.com wrote: Greetings, I am still an ANTLR beginner.. I run a software where I generate the .g grammar file automatically. So I would love to know how to generate the lexer and parser at runtime given the .g file? When generating lexers/parser on the command line, you'd do something like this: java -cp .:antlr-3.2.jar org.antlr.Tool /path/to/your/grammar.g (the Tool class has a static main method taking a command line parameter!) So generating them in your own code would look like: String yourGrammarFile = /path/to/your/grammar.g; org.antlr.Tool.main(new String[]{yourGrammarFile}); Kind regards, Bart. ** -- 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.
[il-antlr-interest: 28959] Re: [antlr-interest] Java Target - How to Generate the Parser and Lexer at Runtime?
OK, I will clarify my question (sorry that I was not clear in my previous mail). The 2 files are different mainly in the constructors *When I use the method you told me about in the first message, the output Parser.java has the constructors:* *public **RulesGrammarParser(TokenStream input) {* *this(input, new RecognizerSharedState());* *}* *public RulesGrammarParser(TokenStream input, RecognizerSharedState state) { * *super(input, state);* * * *}* *But when I use click 'Run..' in ANTLRWorks I get the output Parser.java has the constructors:* *public RulesGrammarParser(TokenStream input) {* *this(input, DebugEventSocketProxy.DEFAULT_DEBUGGER_PORT, new RecognizerSharedState());* *}* *public RulesGrammarParser(TokenStream input, int port, RecognizerSharedState state) {* *super(input, state);* *DebugEventSocketProxy proxy =* *new DebugEventSocketProxy(this, port, null);* *setDebugListener(proxy);* *try {* *proxy.handshake();* *}* *catch (IOException ioe) {* *reportError(ioe);* *}* *}* *public RulesGrammarParser(TokenStream input, DebugEventListener dbg) {* *super(input, dbg, new RecognizerSharedState());* *}* *In addition to this method:* *protected boolean evalPredicate(boolean result, String predicate) {* *dbg.semanticPredicate(result, predicate);* *return result;* *}* *and these declarations:* *public static final String[] ruleNames = new String[] {* *invalidRule, in, evaluation, gt, consequence, lte, * *times, lte_math, divided_by, enumeration_value, gte_math, * *range, check, variable, last_connection, numeric_value, * *term, gte, modulus, plus, source_name, connection, lt, * *source, function, equal, name_of_quality, condition, primary, * *minus, value_of_quality, arithmeticExpression* *};* * * *public int ruleLevel = 0;* *public int getRuleLevel() { return ruleLevel; }* *public void incRuleLevel() { ruleLevel++; }* *public void decRuleLevel() { ruleLevel--; }* And by input text, I mean the input.. The text that I write in ANTLRWorks when I click 'Run..' Thanks for your time :-) On Sat, May 22, 2010 at 8:41 PM, Bart Kiers bki...@gmail.com wrote: But now I need to change my question because I found out that Parser.java generated from this action is different than Parser.java generated when I click 'Run..' in ANTLRWorks and give it an input text.. Please explain what different means. And what do you mean by input text? Kind regards, Bart. -- 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.
[il-antlr-interest: 28938] [antlr-interest] Java Target - Where to put Jar files?
Hey folks, I am using ANTLRWorks 1.3.1 I am importing some packages in the section @lexer::hearder.. The problem is that I do not know where to put the corresponding .jar files of these packages.. (They are not found when I put them in the same folder as the .g grammar nor when I put them in the output folder) Any idea? Thanks in advance.. -- 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.
[il-antlr-interest: 28892] [antlr-interest] The Java Method that Generates the Lexer and the Parser
Dear All, I am a Java developer using ANTLR 1.3.1 I am working is some dynamic environment, so my grammar is changing over time due to the continuous change in vocabulary.. So I was thinking of generating my *.g grammar file automatically not to write it by myself.. But now I face the problem that I cannot find the runtime method that takes the grammar file as input, and gives as output the generation of the tokens file, lexer.java file, and parser.java file.. In other words, I simply want the method that does the exact same task as the Generate Code option in the Generate menu in ANTLR 1.3.1 :-) Any help? Thanks in Advance ;-) -- 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.
[il-antlr-interest: 28893] Re: [antlr-interest] The Java Method that Generates the Lexer and the Parser
Sorry, I meant ANTLRWorks 1.3.1.. On Wed, May 19, 2010 at 11:37 AM, Sameh W. Zaky sameh...@gmail.com wrote: Dear All, I am a Java developer using ANTLR 1.3.1 I am working is some dynamic environment, so my grammar is changing over time due to the continuous change in vocabulary.. So I was thinking of generating my *.g grammar file automatically not to write it by myself.. But now I face the problem that I cannot find the runtime method that takes the grammar file as input, and gives as output the generation of the tokens file, lexer.java file, and parser.java file.. In other words, I simply want the method that does the exact same task as the Generate Code option in the Generate menu in ANTLR 1.3.1 :-) Any help? Thanks in Advance ;-) -- Sameh W. Zaky -- 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.
[il-antlr-interest: 28869] [antlr-interest] Find X :-)
Dear All, I have in my grammar: fragment UNIT_NAME :; ID : ('a'..'z'|'_')* { if ( myLookUpMethod( *X* ) ) $type=UNIT_NAME; } ; === Instead of *X*, I wanna refer to the text that is in red.. For example, the token w_aw_s is ID. I want to take the text of this token w_aw_s and look it up in a certain array and if it is in this array then I set its type to UNIT_NAME. P.S.: I tried to replace *X* with *$text* but I receive the error: [16:15:56] symbol : method myLookUpMethod(java.lang.String) [16:15:56] location: class SimpleTestLexer [16:15:56] if(myLookUpMethod(getText())) _type=UNIT_NAME; [16:15:56]^ [16:15:56] 1 error Find X :-) Many Thanks ! -- 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.
[il-antlr-interest: 28870] Re: [antlr-interest] Find X :-)
OK, Sorry for that! Just after I have sent this message I realized that the problem is that ANTLR cannot find my method myLookUpMethod.. I have defined it in @members{} part of the grammar file.. But ANTLR still cannot find it.. Any idea? On Tue, May 18, 2010 at 4:35 PM, Sameh W. Zaky sameh...@gmail.com wrote: Dear All, I have in my grammar: fragment UNIT_NAME :; ID : ('a'..'z'|'_')* { if ( myLookUpMethod( *X* ) ) $type=UNIT_NAME; } ; === Instead of *X*, I wanna refer to the text that is in red.. For example, the token w_aw_s is ID. I want to take the text of this token w_aw_s and look it up in a certain array and if it is in this array then I set its type to UNIT_NAME. P.S.: I tried to replace *X* with *$text* but I receive the error: [16:15:56] symbol : method myLookUpMethod(java.lang.String) [16:15:56] location: class SimpleTestLexer [16:15:56] if(myLookUpMethod(getText())) _type=UNIT_NAME; [16:15:56]^ [16:15:56] 1 error Find X :-) Many Thanks ! -- Sameh W. Zaky -- 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.
[il-antlr-interest: 28881] Re: [antlr-interest] ANTLR Two Simple Questions :-)
That was helpful, thanks :-) On Tue, May 18, 2010 at 5:31 PM, Jim Idle j...@temporal-wave.com wrote: Well, err the method inArray() is an imaginary method that you will write. It just needs to take a string and see if that string is currently something that should be a UNIT_NAME. If it is real simple then you could just use a standard List object of your choice. Please replay to the list and not my personal email - thanks J Jim From: Sameh W. Zaky [mailto:sameh...@gmail.com] Sent: Tuesday, May 18, 2010 7:21 AM To: Jim Idle Subject: Re: [antlr-interest] ANTLR Two Simple Questions :-) Dear Jim, thanks for your reply. Concerning point (1): I did as you said: fragment UNIT_NAME :; ID : ('a'..'z'|'_')* { if(inArray($text)) $type=UNIT_NAME; } ; But when I click 'run' to run a test I get the error: D:\My Documents\Downloads\Simple Test Grammar\output\SimpleTestLexer.java:604: cannot find symbol [16:15:56] symbol : method inArray(java.lang.String) [16:15:56] location: class SimpleTestLexer [16:15:56] if(inArray(getText())) _type=UNIT_NAME; Any idea, how I can overcome this? Thanks again for your time :-) On Mon, May 17, 2010 at 6:54 PM, Jim Idle j...@temporal-wave.com wrote: -Original Message- From: antlr-interest-boun...@antlr.org [mailto:antlr-interest- boun...@antlr.org] On Behalf Of Sameh W. Zaky Sent: Monday, May 17, 2010 7:33 AM To: antlr-interest@antlr.org Subject: [antlr-interest] ANTLR Two Simple Questions :-) 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)* Match the possible sequences generally, then change the token type if the strings match your dynamic list: fragment SERVICE : ; ID : ('a'..'z')+ { If (myLookupMethod($text)) { $type = SERVICE; } } ; So the token ID will be returned if the matched text is not in your list and the token SERVICE will be returned if it is. 2) Given a certain grammar, how can I (or: is it possible to) get the list of all possible next tokens? Read: http://www.antlr.org/wiki/display/ANTLR3/Custom+Syntax+Error+Recovery Do I get a masters too? ;-) Jim List: http://www.antlr.org/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address -- Sameh W. Zaky List: http://www.antlr.org/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address -- 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.
[il-antlr-interest: 28851] [antlr-interest] ANTLR Two Simple Questions :-)
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.
[il-antlr-interest: 28863] [antlr-interest] ANTLR Problem When a Token Name is a Prefix of Another Token Name
Hey all, In the following simple grammar: *start* : *ANIMAL* ('or' *ANIMAL*)* 'and' *SERVICE EOF* ; *ANIMAL* : ('dog' | 'cat' | 'horse') ; *SERVICE* : ('dog hardware' | 'software') ; NOTICE: 'dog' is a proper prefix of 'dog hardware'.. == *When I run this grammar by giving an input sentence, something goes wrong whenever I use the token 'dog'..* dog and software -- dog and disappears in the input box, and also in the tree dog or cat or software -- dog or disappears in the input box, and also in the tree cat or dog and software -- dog and disappears.. *While there is no problem with the token 'dog hardware'* cat and dog hardware -- works fine.. I know the reason.. It's because the grammar is confused when one token is a proper prefix of another token.. So the token with the bigger length works fine while the other one doesn't.. Any solution to this problem? (Other than changing the name of the token because in my real grammar I really need the token names to stay as they are) 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.