Code covered by the BSD License  

Highlights from
mparser

4.5

4.5 | 2 ratings Rate this file 4 Downloads (last 30 days) File Size: 174.07 KB File ID: #32769

mparser

by David Wingate

 

01 Sep 2011

A matlab lexer and parser written with ANTLR, with a mex interface.

| Watch this File

File Information
Description

This is a MATLAB lexer and parser written using ANTLR. The goal of
this package is to provide a way to parse MATLAB code from within
MATLAB, and to be able to do source code translations on the resulting
AST.

The main workhorse of this package is "mparser", a MEX file which
  accepts either a string or a filename and parses it into a deeply
  nested set of MATLAB structures representing an AST. These can
  examined and manipulated from within MATLAB.

Includes a variety of other tools to parse and examine matlab code.

While I have made every effort to be as exact as I can, there are
still a few differences between this grammar and the "true" MATLAB
grammar. Most of these you will never notice, but there are a few
that are significant:

* The transpose operator ' is not supported (due to lexing confusion
  with the single quotes used in string constants).

* Constant matrices and cells must have individual elements separated
  by a comma.

* Block comments are not supported.

For others, please see the comments in matlab.g
Hopefully, future versions will remedy this.

MATLAB release MATLAB 7.11 (2010b)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (3)
02 Sep 2011 Egon Geerardyn  
09 Sep 2011 Donn Shull

There may be several reasons why a rating of lower than five should be given to this submission, however, David has clearly stated that this is a preliminary version of the parser. He has given us a commented grammar with notes on how to produce either the mex parser that he uses or a java parser which can be debugged using the tools from the antlr website.

I would encourage the use of H1 help lines in the m files to be in line with MATLAB normal coding standards, and facilitate the use of lookfor, etc. There is a lot of information on making good help text for m files. You can find it in the MATLAB documentation, in the style guidelines by Richard Johnson posted on the file exchange, or better yet in Richard Johnsons book "The Elements of MATLAB style.

Again a good effort which will be useful for someone developing MATLAB tools.

18 Feb 2012 Tamás Király

is this parser capable of parsing classdef files?

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
grammar David Wingate 02 Sep 2011 12:58:31
parser David Wingate 02 Sep 2011 12:58:31
lexer David Wingate 02 Sep 2011 12:58:31

Contact us at files@mathworks.com