[il-antlr-interest: 28276] Re: [antlr-interest] Grammar help
On Tue, Mar 16, 2010 at 4:54 AM, Brian Catlin bri...@sannas.org wrote: When I compile the grammar with ANTLR, I get the following: warning(149): Commands.g:0:0: rewrite syntax or operator with no output option; setting output=AST Hi Brian, The '!' and '^' are tree-rewrite operators, so ANTLR is telling you here that you're trying to rewrite something without specifying you're building a tree. Doing a CRL+F I found this rule: commands : ( script_command | dump_command ! show_command // - ! )* ; Notice the '!' (exclamation mark) that should be a '|' (pipe): commands : ( script_command | dump_command | show_command // - | )* ; Regards, Bart. 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: 28277] Re: [antlr-interest] Grammar help
On Tue, Mar 16, 2010 at 7:35 AM, Bart Kiers bki...@gmail.com wrote: On Tue, Mar 16, 2010 at 4:54 AM, Brian Catlin bri...@sannas.org wrote: When I compile the grammar with ANTLR, I get the following: warning(149): Commands.g:0:0: rewrite syntax or operator with no output option; setting output=AST ... The same goes for: qualifier : ALL ! CODE // should be a '|' instead of a '!' | TABLE ; Bart. 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: 28278] Re: [antlr-interest] Grammar help
Thanks Bart. Jeez, I feel stupid. While that gets rid of those warnings (why don't the warnings print a reasonable line number? I would call that a BUG), the fundamental problem of being able to parse (or otherwise capture the file name) still exists. Any ideas? -Brian -Original Message- From: antlr-interest-boun...@antlr.org [mailto:antlr-interest-boun...@antlr.org] On Behalf Of Bart Kiers Sent: Tuesday, March 16, 2010 14:37 To: antlr-interest@antlr.org Subject: Re: [antlr-interest] Grammar help On Tue, Mar 16, 2010 at 7:35 AM, Bart Kiers bki...@gmail.com wrote: On Tue, Mar 16, 2010 at 4:54 AM, Brian Catlin bri...@sannas.org wrote: When I compile the grammar with ANTLR, I get the following: warning(149): Commands.g:0:0: rewrite syntax or operator with no output option; setting output=AST ... The same goes for: qualifier : ALL ! CODE // should be a '|' instead of a '!' | TABLE ; Bart. List: http://www.antlr.org/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address 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: 28279] Re: [antlr-interest] Grammar help
On Tue, Mar 16, 2010 at 8:10 AM, Brian Catlin bri...@sannas.org wrote: While that gets rid of those warnings (why don't the warnings print a reasonable line number? I would call that a BUG), Note that the '!' is a valid operator inside your grammar, ANTLR just assumes that you're building trees. So, you're not doing anything wrong. But, yes, a warning with the line number of the improper use of rewrite operators would be nice. On Tue, Mar 16, 2010 at 8:10 AM, Brian Catlin bri...@sannas.org wrote: the fundamental problem of being able to parse (or otherwise capture the file name) still exists. Any ideas? The error message is telling that your FILE_NAME is ambiguous. When matching one or more characters from: ~('|' | '' | '' | '*' | '?')+ then line breaks will also be matched, yet after that, the following could be matched: ('\r'? '\n') which has already been eaten by the previous part of your rule. You could fix that by adding line breaks to that first part of your rule, like this: FILE_NAME: ~('|' | '' | '' | '*' | '?'| '\r' | '\n')+ (('\r'? '\n') | EOF); Regards, Bart. 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: 28281] [antlr-interest] How can i get the tree in java
Hi Friends Using the GUI tool ANTLRworks, I am getting a very nice tree when I give my program to test against the grammar I wrote. But is there a way I get that tree in a manageable form. Like some kind of java tree data structure or a java object so that i can manipulate it as per my requirements. Many thanks Ketan 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: 28284] [antlr-interest] Best version to use with c++?
Greetings! I am writing a parser for an application and I started to do it with pccts tool which is still available in debian and with which I had some experience about 8 years ago - but to my dissapointment it seems to be completely unmaintained now. So it looks like I will have (finally) to switch to antlr. This said, which version would you advise for use with C++: antlr2 or antlr3? I know there's no C++ support in v3, but is C support really usable from C++? If yes, are there any sample available? Or would it be easier to stick to v2? Also I used flex lexer with my old grammar. Would flex integrate into antlr2/antlr3 or will I have to change lexer to whatver is supplied by antlr? Best regards, -- Michael 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: 28285] [antlr-interest] C example error: PolyDiff
I tried to build the PolyDiff example from Examples-v3, using ANTLR-3.1-2009-06-28 and libantlr3c-3.2 in Visual Studio 2008. The output from the build: 1-- Rebuild All started: Project: polydiff, Configuration: Debug Win32 -- 1Deleting intermediate and output files for project 'polydiff', configuration 'Debug|Win32' 1Translating to parser/lexer combination 1Translating to parser/lexer combination 1Translating to parser/lexer combination 1Translating to parser/lexer combination 1.\PolyDifferentiator.g(0,0) : warning 138 : grammar PolyDifferentiator: no start rule (no rule can obviously be followed by EOF) 1Compiling... 1Simplifier.c 1PolyPrinter.c 1PolyParser.c 1PolyLexer.c 1PolyDifferentiator.c 1main.c 1Generating Code... 1Compiling manifest to resources... 1Microsoft (R) Windows (R) Resource Compiler Version 6.1.7600.16385 1Copyright (C) Microsoft Corporation. All rights reserved. 1Linking... 1LINK : C:\MIMOS\ANTLR\examples-v3\C\Debug\polydiff.exe not found or not built by the last incremental link; performing full link 1 Creating library C:\MIMOS\ANTLR\examples-v3\C\Debug\polydiff.lib and object C:\MIMOS\ANTLR\examples-v3\C\Debug\polydiff.exp 1Embedding manifest... 1Microsoft (R) Windows (R) Resource Compiler Version 6.1.7600.16385 1Copyright (C) Microsoft Corporation. All rights reserved. 1Build log was saved at file://c:\MIMOS\ANTLR\examples-v3\C\polydiff\Debug\BuildLog.htm 1polydiff - 0 error(s), 1 warning(s) == Rebuild All: 1 succeeded, 0 failed, 0 skipped == As you can see, there is a warning generating PolyDifferentiator.g When I run the resulting program, I get an access violation in addChild (antlr3basetree.c) at the -à, because child has not been initialized void addChild (pANTLR3_BASE_TREE tree, pANTLR3_BASE_TREE child) { ANTLR3_UINT32 n; ANTLR3_UINT32 i; if(child == NULL) { return; } --à if(child-isNilNode(child) == ANTLR3_TRUE) { if (child-children != NULL child-children == tree-children) 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: 28286] [antlr-interest] NEWBIE ANTLRWorks question: Missing zeroes in input
Hello everyone. I am sorry to post which is probably a lame question, but have been pulling my hair over this one and still can't figure it out. I wrote a grammar to parse a simple string that begins with a fixed preamble and contains hex characters, such as this one: 0009FFF6415049A0022B28CC901F41D001000300060A900F6D00012232037B3808035906A49A10F981F5381B803B5A27D50CDE7F73AFBD However, after pasting the string to use it as inputthis is what appears in the Input debug window: 0009FFF6415049A022B28CC901F41D0103060A90F6D012232037B3808035906A49A10F981F5381B803B5A27D50CDE7F73AFBD As you can see, sequences of zeroes have been compressed into one zero only. The leading ones are not, but that may be because of the definition of the grammar. If I escape the zeroes preceding them with a \ like so 0009FFF6415049A0\022B28CC901F41D0\010\0\030\0\060A90\0F6D0\0\012232037B3808035906A49A10F981F5381B803B5A27D50CDE7F73AFBD the string is shown correctly in the input window and the grammar works as (I) expect. Please note that the zero-stripping appears in the input window, I don't see how this can be affected by the grammar. Just in case I'll post it - sorry if it's messy, it's my first one. Thanks very much in advance, Álvaro --- grammar GrammarLog; tokens { REG7_TIPO='0007FFF8'; REG9_TIPO='0009FFF6'; } log : (reg7|reg9)* EOF; reg7: REG7_TIPO regbody7 crc16 {System.out.println(found register 7 ); }; regbody7: secuencial_registro numero_sam latitud longitud fecha_hora tipo_pto_not tipo_det_pto_not codigo_pto_not seq_sam sello_sam {System.out.println(body: ); }; reg9:REG9_TIPO regbody9 crc16; regbody9: secuencial_registro numero_sam fecha_hora nro_boleto tipo_viaje tipo_dto tipo_tarifa parada_o parada_d ordinal_tramo cant_pasajeros latitud longitud importe seq_sam sello_sam ; nro_boleto :bytes04; tipo_viaje : bytes04; tipo_dto: bytes02; tipo_tarifa : bytes02; parada_o: bytes02; parada_d: bytes02; ordinal_tramo : byte01; cant_pasajeros : byte01; importe : bytes02; crc16 : bytes02 {System.out.println(CRC16 - + $bytes02.text); }; secuencial_registro : bytes04 {System.out.println(secuencial_registro - + $bytes04.text + = + Integer.decode(0x + $bytes04.text)); }; numero_sam : bytes02 {System.out.println(numero_sam - + $bytes02.text + = + Integer.decode(0x + $bytes02.text)); }; latitud : bytes04 {System.out.println(latitud - + $bytes04.text ); }; longitud: bytes04 {System.out.println(longitud - + $bytes04.text ); }; fecha_hora : bytes04 {System.out.println(fecha_hora - + $bytes04.text ); }; velocidad : byte01 {System.out.println(velocidad - + $byte01.text ); }; seq_sam : bytes08 {System.out.println(seq_sam - + $bytes08.text ); }; sello_sam : bytes08 {System.out.println(sello_sam - + $bytes08.text ); }; tipo_pto_not:byte01 {System.out.println(tipo_pto_not - + $byte01.text + = + Integer.decode(0x + $byte01.text)); }; tipo_det_pto_not: byte01 {System.out.println(tipo_det_pto_not - + $byte01.text + = + Integer.decode(0x + $byte01.text)); }; codigo_pto_not : bytes02 {System.out.println(codigo_pto_not - + $bytes02.text ); }; byte01 :(HEX_DIGIT HEX_DIGIT); bytes02 :(HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT); h4hex :(HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT); bytes04 :(HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT); bytes08 :(HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT); HEX_DIGIT : ('a'..'f'|'A'..'F'|'0'..'9'); 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: 28287] [antlr-interest] Import problems when splitting out tokens
Doing upgrades and want to split the current composite grammar to serve as a base for two new grammars that will share approx 90% rules. After going through the process of splitting out tokens from rules, I'm left with: parser RootParser; value_expr: .. ; ... lexer RootLexer; LeftParen: '('; ... grammar Timer; options{ tokenVocab = RootLexer; } import RootParser @header{package com.timer.parser;} start:value_expr; ... grammar Calculator; options{ tokenVocab = RootLexer; } import RootParser @header{package com.timer.parser;} start:value_expr | control | txt_alias; control_spec: ... Although the grammar in the above checks out, the problem surfaces when generating source code - specifically the token files. Unlike with composite grammar where the lexer (RootLexer.java) is generated when generating the parser, I manually generate the lexer and subsequently generate the parser. The generated files are: RootLexer.java, RootLexer.tokens, TimerParser.java, Timer_RootParser.java, Timer.tokens, CalculatorParser.java, Calculator_RootParser.java, Calculator.tokens. On inspecting the token files, I noticed the token values in the lexer file did not match up with the equivalents in the two parser token files. From what I understand in all that I read, this cannot be as it will cause incorrect switch jumps, amongst other errors. As alternatives, I tried: - remove the tokenVocab options and import both RootParser and RootLexer - import the RootLexer into RootParser instead. This generates an error parser rule value_expr not allowed in lexer which seems to have something to do with the parser grammar RootParser definition on the opening line - removed parser qualifier from grammar definition. Generated error due to importing combined grammar Timer/Calculator. - tried import instead of tokenVocab on RootLexer. It too generated combined grammar error. Is there some way to specify the created lexer when generating the parser? I dislike the idea of having to resort to two grammars that are essentially the same. Any help would be much appreciated. Roger __ Be smarter than spam. See how smart SpamGuard is at giving junk email the boot with the All-new Yahoo! Mail. Click on Options in Mail and switch to New Mail today or register for free at http://mail.yahoo.ca 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: 28288] [antlr-interest] Using the results
Its been a long time since I last used antlr and I'm now getting the chance to use it again. I happened on a rather conspicuous gap in my knowledge: I have no idea what the right way take actions based on parsed results. Should I parse my input to an AST and then walk the AST? This seems like it'd be a pain to maintain. Should I call actions directly from antlr? This simpler but in practice is really cumbersome and makes using antlrworks much more difficult. Both of these are going to leave me with gobs of code translating from the AST representation to my domain objects. What is the best practice for doing this? Nik 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: 28290] Re: [antlr-interest] Using the results
On Tue, Mar 16, 2010 at 4:26 PM, Nikolas Everett nik9...@gmail.com wrote: Its been a long time since I last used antlr and I'm now getting the chance to use it again. I happened on a rather conspicuous gap in my knowledge: I have no idea what the right way take actions based on parsed results. At least you recognize that :). Should I parse my input to an AST and then walk the AST? This seems like it'd be a pain to maintain. Should I call actions directly from antlr? This simpler but in practice is really cumbersome and makes using antlrworks much more difficult. Which one of the above you'll want will be largely dependent on what your needs are and how complicated everything becomes. If you're dealing with something simple, then putting the actions directly in ANTLR's action code is a perfectly reasonable solution and may result in the least amount of code and the code that's easiest to understand (for those not versed in the ANTLR tree-walking process). If you end up needing something more complicated and need information from various parts in your processing, such as you might if you support mutually recursive types, then using a tree walker and deferring as much of the processing and validation as possible until later. There's likely a continuum between the two. For example, I've found that I can often create builder classes which I call within the actions of my parser. These builder classes provide a consistent interface that I can use to test without dealing directly with the parser, and provide an easy interface that the parser can use. When used with a good set of ANTLR features, such as scopes and actions on non-terminal fragments, this can make for a very clean structure. If you want specifics it would be helpful if you could provide more concrete details. HTH. -- Kaleb Pederson Blog - http://kalebpederson.com Twitter - http://twitter.com/kalebpederson 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: 28291] Re: [antlr-interest] Using the results
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.