[antlr-interest] parsing MATLAB - 6.0/7.0 files

Monty Zukowski monty at codetransform.com
Wed May 18 06:34:15 PDT 2005


rahul wrote:
> Hi
> 
>    I am looking at parsing MATLAB files using ANTLR. The earlier
> version of MATLAB (6.x) had a file structure that looked like
> 
> function x = A(p1,p2)
> ...
> 
> function y = B(p3)
> ...
> 
> function z = C(p4)
> ...
> 
> with implicit ends to the function bodies. The new version 7.x has
> introduced the concept of nested functions, much like PASCAL.
> 
> function x = A(p1, p2)
> ...
>    function y = B(p3)
>    ...
>       function z = C(p4)
>       ...
>       end
>    ...
>    end
> ...
> end
> 
> function D(p5)
> 
> ...
> end
> 
> For the reason of compatibility MATLAB retains both these file
> structures and either can be used, but not mixed.
> 
> Is it possible to parse a file not knowing the format and using one
> single grammar?
> 
> Or do I need to make a quick initial run through a file first to
> detect the syntax and then invoke the parser to follow one of the
> formats.
> 
> If one sigle grammar is possible would it be efficient, say if I
> considered the use of syntactic predicates?
> 
yeah, a syntactic predicate like ((~("end"))* "end")=> would tell you 
whether an end is coming up later.  Hopefully "end" is only used to end 
a function definition.

Monty


More information about the antlr-interest mailing list