[antlr-interest] Antlr v2 question

pepone.onrez pepone.onrez at gmail.com
Thu Feb 7 09:13:58 PST 2008


I creation a language parser based on java.g example of antrl  v2 for my on
language that is and idl

I want antlr genearte a tree for each compilation unit that is a diferent
file.

Here is my compiltation unit parser rule.

I add the operator ^ to the first newline of white space and this makes
antlr create a root tree for all the other rules
but how can I do the same with out need this WS NEWLINE at the bigining of
each file.

mpl_compile_unit:
    {
        std::cerr<<"mpl_compile_unit begin"<<std::endl;
    }
    (WS^ | NEWLINE^)
    (mpl_include_directive (WS|NEWLINE))*
    (WS|NEWLINE)* (mpl_module_definition)?
    {
        std::cerr<<"mpl_compile_unit end"<<std::endl;
    };



Here is the tree that's i generate with antlr

(
 ( # include   < oz / meta . mpl > )
 ( # include   < oz / meta . mpl > )

 ( module   oz {
         ( module   files {
                 ( class   Node ( extends     Object   ) {
                         ( int ( [ ' name '   =   ' value ' ] )     id ; )
                         ( int   parent ; )
                         ( string   name ; )
                 } ; )

                 ( class   File ( extends     Node ) {
                         ( Node *   parent ; )
                         ( string   value ; )
                         ( Object ( [ ' sql '   =   ' blabla ' ] ) ( [ ' sql
'   =   ' blabla2 ' ] )     more ; )
                 } ; )

                 ( interface   IFile { } ; )
         } ; )
 } ; ) )


Thanks in advance
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080207/fa303a6a/attachment.html 


More information about the antlr-interest mailing list