[antlr-interest] High level semantic analysis

Tiller, Michael (M.M.) mtiller at ford.com
Mon May 19 10:51:05 PDT 2003

Hmmm...The JBurg stuff doesn't really appear to address what I was getting
at.  I wasn't talking about code generation (in fact, I have no interest at
all in code generation).

Let me explain my interest in this.  I'm working with this language,
Modelica, and I want to develop tools for analyzing the code.  There isn't
so much a code generation phase as an "instantiation" phase where the
complex AST is "flattened" into a much simpler (and less general) version by
resolving lots of "modifications".  Let me give you a simple example:

model RLC_Circuit
  Resistor R1(R=15);
  Resistor R2(R=5000);
  Capacitor C(C=100e-6);
  Inductor L(L=100e-3);
  VoltageSource Vs;
  Ground g;
end RLC_Circuit;

Such a model, combined with component models written in a similar way, e.g.

model Resistor
  import Modelica.SIunits;
  parameter SIunits.Resistance R=300;
  ElectricalPin p, n;
  R*p.i = p.v-n.v;
  pi+n.i = 0;
end Resistor;

Should ultimately get me to a flattened model (as output) that simplifies
all this structure down to:

model RLC2
  import Modelica.SIunits;

  parameter SIunits.Resistance R1=15;
  parameter SIunits.Resistance R2=5000;
  parameter SIunits.Capacitance C=100e-6;
  parameter SIunits.Inductance L=100e-3;

  SIunits.Voltage V_a, V_b, V_c;
  SIunits.Current i_V, i_R1, i_R2, i_C, i_L;
  V_a = if time>=1 then 1.0 else 0; // From the VoltageSource model
  L*der(i_L) = V_a - V_b; // From the inductor model
  R1*i_R1 = V_b - V_c; // From the resistor model
  i_C = C*der(V_c); // From the capacitor model
  R2*i_R2 = V_b; // From the other resistor model
  i_V - i_L = 0; // Kirchoff's current law
  i_L - i_R1 - i_R2 = 0; // Kirchoff's current law
  i_R1 - i_C = 0; // Kirchoff's current law
end RLC2;

So this last model would be the output after what is formally called the
"instantiation" process (i.e. to create an instance of the RLC_Circuit
model).  On the surface, this might seem like a pretty simple elaboration or
expansion process, but there are lots of features I haven't shown here
(think C++ templates) and lots of different types of classes and objects
with detailed semantics.  The result is that you have to program lots of
rules that govern this instantiation process.

I'm currently trying to leverage some work that another group is doing
(called Open Source Modelica) since I am neither an expert in building
compilers nor paid to do this kind of thing anyway.  They are the ones using
RML.  RML looks pretty cool and powerful because it seems more declarative.
I think of it, perhaps incorrectly, as being more PROLOG like.  It appears
that you simply state semantic rules (in a way that is very similar to what
is in the Modelica specification) and it can not only use those rules for
the transformation process, but it could even identify dubious sets of rules
(I suppose, I don't know for sure).  It seems like it would fit naturally
into the whole ANTLR philosophy of developing high-level capabilities for
the compiler development process.  It seems to me that it is something of a
META-tree walker.

Like I said, this seems really cool and useful (and the declarative aspect
is very much in the spirit of the language I'm applying it to, i.e.
Modelica).  It struck me that perhaps people know of other similar tools
that integrate better with ANTLR or that perhaps this would stimulate some
thinking about how to incorporate similar features.

As it stands now, I don't really have a problem with the way I'm dealing
with this now.  I was just hoping that this kind of discussion might lead to
better integration of the ANTLR system with similar ideas in the future.


> -----Original Message-----
> From: mzukowski at yci.com [mailto:mzukowski at yci.com]
> Sent: Monday, May 19, 2003 1:16 PM
> To: antlr-interest at yahoogroups.com
> Subject: RE: [antlr-interest] High level semantic analysis
> You can use JBurg to do the matching & optimization type 
> stuff.  See Ter's
> lecture http://www.cs.usfca.edu/~parrt/course/652/labs/jburg.html.
> Not sure about how to link in the theorem proving aspect of that stuff
> though.  RML as described seems like a somewhat incomplete 
> beast judging
> from the thesis on the open source modelica implementation.  
> I couldn't find
> too much written about it, maybe I was looking in the wrong 
> places.  I guess
> I need an example a bit more compelling than addition to see what the
> advantages of RML are.
> Monty
> -----Original Message-----
> From: Tiller, Michael (M.M.) [mailto:mtiller at ford.com] 
> Sent: Monday, May 19, 2003 5:28 AM
> To: 'antlr-interest at yahoogroups.com'
> Subject: [antlr-interest] High level semantic analysis
> I'm not much of an expert on building compilers, but I came 
> across something
> that I thought was quite interesting and I was wondering if 
> anyone here
> would care to comment on the applicability of these ideas to ANTLR.
> Specifically, I recognize the the treewalker functionality in 
> the ANTLR is
> very nice way to explore and translate ASTs.  I was wondering 
> if anybody is
> interested in adding some higher-level functionality like 
> what is described
> in this report:
> http://www.modelica.org/papers/scs98sem.pdf
> --
> Mike
> Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service. 
> Your use of Yahoo! Groups is subject to 
> http://docs.yahoo.com/info/terms/ 


Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 

More information about the antlr-interest mailing list