[antlr-interest] Fwd: Referencing an expression on another parser tree branch

Des Hartman des at deshartman.com
Mon Feb 9 15:53:50 PST 2009


Hi,

I have been working on a formula input parser, using a lot of the code
Robert Stehwien wrote here
http://arcanearcade.blogspot.com/2008/04/using-antlr-to-create-excel-like.htmlI
changed the code to use the concept of a cell reference instead of
predefined values.

Think of this as an Excel spreadsheet where all the formulas of a column are
the same, so I refer to a column like this "=B+5-SUM(8,A)" for example. I am
stroring the row as a ";" separated string and thus process the ";" as part
of the input. I can get neat separation between cells and in the parser tree
you can see the value of each cell. this means I can store the values of
column A,B and C as follows:

34;12;=B+5-SUM(8,A)

I have attached my grammar code below and if you run the formula, you get a
nice grammar tree showing the decoded cells and references.

Question I have is, is there a way to now decode the references to the
previous cells A and B? In effect I want to "copy" the tress that the actual
cell has and then calculate the value. This is indicated by the red arrows
in the attached tree grammar.

another reason for doing this is that I want to check for circular
references while doing this, so if cell A has any references to cell C for
example, I will flag a circular reference.

I have been learning as fast as I can and really just need a nudge in the
right direction on this one, so any help would be great. Do I need to build
a specific tree grammar to do this?


Thanks
Des
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090210/c24e79c6/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: CellFormula.g
Type: application/octet-stream
Size: 2407 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20090210/c24e79c6/attachment.obj 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cellformulatree.GIF
Type: image/gif
Size: 37088 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20090210/c24e79c6/attachment.gif 


More information about the antlr-interest mailing list