[antlr-interest] Pie and simple expression calculator
goodwin
goodwin at essence-property.com
Mon Jan 2 12:31:01 PST 2012
Yes, I looked at MATLAB, i also looked at GDL (which is much too big and
complex to start with, and is in C rather than Java). I have just looked at
the Cminus example also.
My problem is that there are so many example starting points, i don't know
where to start.
I thought maybe Pie was the best starting point, but maybe it is not, if it
is more complex than necessary because of the problems with white space.
I am OK with starting with a simple language, and then waiting for v4 before
doing the full language. I need a prototype which works reliably in the next
few weeks, and then a longer term solution next year (2013).
An example of the language:
function myFunction() {
a = 3.7
b = get("myAttr")
return a + b
end
x = 1.2
y = {0.0, 1.0, 2.3,......}
x[4] = 1.5
z = x ^ y + myFunction
z = z + data("myData")
if (x > 0.0 ) then
z = sin(z) * 1.1
else
z = 0
endif
h = integrate(z)
print (h)
Notes:
- all variables are float arrays (let's assume for the moment they are all
the same length, 100).
- the integrate function integrates the array and returns a new array e.g.
h[5] is z[0] + ... + z[5]
- the if block is done on an element by element basis (so there is an
implied loop around it), similar to R concepts
- functions normally do not take any parameters, but could do so in future
- the 'get' function retrieves a special scalar value from a hashmap or
database, which may be different on each invocation.
- data("myData") retrieves a preexisting scalar held in a Hashmap, which is
used to initialise an array.
- the language operates on a preexisting Java database and Java memory - it
is used to derive new data from pre-existing data.
- I would rather have something a little verbose and readable - error
handling is also essential as the language is to be used by engineers, not
software engineers. They often forget to put in ';' for example, so the
above language does not need it.
- the whole concept is based on something which an old colleague did using
Antlr v2 back in 2003 - all his work has since been lost.
-----Original Message-----
From: Kyle Ferrio <kferrio at gmail.com>
To: goodwin at essence-property.com
Cc: antlr-interest at antlr.org
Date: Mon, 2 Jan 2012 11:10:51 -0700
Subject: Re: [antlr-interest] Pie and simple expression calculator
Your language ounds a little like MATLAB. Someone posted an approximate
MATLAB grammar a few months ago for antlr 3.x.
If you are familiar with classic "calculator" examples for flex/bison, then
you might really like how Honey Badger (antlr 4) makes short work of
expression parsing.
If you want to get going quickly, you might want to avoid things like
pythonesque significant whitespace. And strongly visual scope delimiters
may make it easier to get started. Your resulting language would not be the
first to be accused of being "noisy." :)
Kyle
On Jan 2, 2012 10:45 AM, "goodwin" <goodwin at essence-property.com> wrote:
I am new to ANTLR, and want some capabilities similar to Pie and the
expression calculator, as extended with functions. I work with floating
point data, and want to extend the intrinsic functions (e.g. Sin, Cos etc.)
and all calculations will actually be done on float arrays.
I want a simple grammar suitable for engineers - not too sure whether Python
is the best starting point...I myself prefer a few brackets and endif etc.
However, the implementations of Pie and the simple expression calculator are
very different.
Do you think it is best for me to start with Pie and adapt it for my needs,
or look at both approaches and learn from them both?
My main purpose is to progress rapidly, not to become an expert in ANTLR.
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org/mailman/options/antlr-interest/your-email-address
More information about the antlr-interest
mailing list