Except that the rule "type" does not allow an ID as the type, and so this is a plain syntax error that is not picked up because of the lack of EOF at the end of the start rule.
Jim > -----Original Message----- > From: [email protected] [mailto:antlr-interest- > [email protected]] On Behalf Of Ian Kaplan > Sent: Wednesday, November 09, 2011 9:09 AM > To: Mari Matinlassi > Cc: [email protected] > Subject: Re: [antlr-interest] Fundamental question > > There is nothing wrong as far as the syntax goes with this. There > could, for example, be a user defined type called strig (strings for > trigonometry :). So this is grammatically correct. What is not > correct is the semantics. In fact, there probably is no user defined > type strig. So this is an error may be issued after the syntax tree is > built, when a semantic phase makes a pass over the tree. The semantic > phase would discover that there was no type strig and report an error > ("No type 'strig' on line 42"). > > > On Wed, Nov 9, 2011 at 8:18 AM, Mari Matinlassi > <[email protected]>wrote: > > > Hi, > > > > There is something fundamental and important that I have not > > understood with ANTLR grammars. > > > > If I need to parse something like... > > > > int test; > > strig another; > > int variable; > > string here; > > > > You notice there is a typing error on the second line ('strig' > instead > > of 'string'). > > > > How do I make a grammar that will not stop parsing but, continues > > after an error?? > > > > Below is an example how I CANNOT make it work the right way (created > > AST contains only 'int test ;').. > > > > grammar List; > > > > options { > > language = CSharp3; > > TokenLabelType = CommonToken; > > output=AST; > > ASTLabelType = CommonTree; > > } > > > > @lexer::namespace{ConsoleApplication4} > > @parser::namespace{ConsoleApplication4} > > > > > > public r > > : variables* > > ; > > > > variables > > : type ID ';' > > ; > > > > type > > : 'int' > > | 'string' > > ; > > > > ID : 'a'..'z' + ; > > > > WS : (' ' |'\n' |'\r' ) {$channel=Hidden;} ; > > > > > > Many thanks for your time and help, > > > > Mari > > > > > > > > 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 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 [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/il-antlr-interest?hl=en.
