MS Excel grammar, BNF?

aamshukov@cogeco.ca
26 Jul 2005 13:18:31 -0400

          From comp.compilers

Related articles
MS Excel grammar, BNF? aamshukov@cogeco.ca (2005-07-26)
| List of all articles for this month |
From: aamshukov@cogeco.ca
Newsgroups: comp.compilers
Date: 26 Jul 2005 13:18:31 -0400
Organization: http://groups.google.com
Keywords: parse, question
Posted-Date: 26 Jul 2005 13:18:31 EDT

Hi,


I am looking for an MS Excel grammar, could not find (except
FishBrain:Excel).
In the meantime I created the following grammar:


  1. TRANSLATION-UNIT --> FORMULA


  2. FORMULA --> SCALAR-FORMULA
  3. FORMULA --> ARRAY-FORMULA
  4. SCALAR-FORMULA --> '=' PRIMARY-EXPRESSION
  5. ARRAY-FORMULA --> '=' '{' PRIMARY-EXPRESSION '}'


  6. PRIMARY-EXPRESSION --> EXPRESSION | '(' EXPRESSION ')'


  7. EXPRESSION --> LOGICAL-EXPRESSION


  8. LOGICAL-EXPRESSION --> CONCAT-EXPRESSION
            |
                                                                        LOGICAL-EXPRESSION '='
CONCAT-EXPRESSION |
                                                                        LOGICAL-EXPRESSION '<'
CONCAT-EXPRESSION |
                                                                        LOGICAL-EXPRESSION '<='
CONCAT-EXPRESSION |
                                                                        LOGICAL-EXPRESSION '>'
CONCAT-EXPRESSION |
                                                                        LOGICAL-EXPRESSION '>='
CONCAT-EXPRESSION |
                                                                        LOGICAL-EXPRESSION '<>'
CONCAT-EXPRESSION |
                                                                        LOGICAL-EXPRESSION '!='
CONCAT-EXPRESSION


  9. CONCAT-EXPRESSION --> ADDITIVE-EXPRESSION |
                                                                        CONCAT-EXPRESSION '&'
ADDITIVE-EXPRESSION


10. ADDITIVE-EXPRESSION --> MULTIPLICATIVE-EXPRESSION
                            |
                                                                        ADDITIVE-EXPRESSION '+'
MULTIPLICATIVE-EXPRESSION |
                                                                        ADDITIVE-EXPRESSION '-'
MULTIPLICATIVE-EXPRESSION


11. MULTIPLICATIVE-EXPRESSION --> EXPONENTIATION-EXPRESSION
                                        |
                                                                        MULTIPLICATIVE-EXPRESSION '*'
EXPONENTIATION-EXPRESSION |
                                                                        MULTIPLICATIVE-EXPRESSION '/'
EXPONENTIATION-EXPRESSION


12. EXPONENTIATION-EXPRESSION --> PERCENT-EXPRESSION |
                                                                        EXPONENTIATION-EXPRESSION '^'
PERCENT-EXPRESSION


13. PERCENT-EXPRESSION --> UNARY-EXPRESSION |
                                                                        PERCENT-EXPRESSION '%'


14. UNARY-EXPRESSION --> UNARY-OPERATOR UNARY-EXPRESSION |
UNION-EXPRESSION


15. UNION-EXPRESSION --> INTERSECTION-EXPRESSION |
                                                                        UNION-EXPRESSION ','
INTERSECTION-EXPRESSION


16. INTERSECTION-EXPRESSION --> REFERENCE-EXPRESSION |
                                                                        INTERSECTION-EXPRESSION ' '
REFERENCE-EXPRESSION


17. REFERENCE-EXPRESSION --> '(' EXPRESSION ')' |
                                                                        PRIMITIVE |
                                                                        CONST-ARRAY |
                                                                        REFERENCE |
                                                                        R1C1-REFERENCE |
                                                                        FUNCTION-CALL


18. REFERENCE --> REFERENCE-PREFIX AREA-REFERENCE |
REFERENCE-PREFIX CELL


19. REFERENCE-PREFIX --> WORKBOOK | SHEET | e
20. WORKBOOK --> WORKBOOK-NAME SHEET
21. WORKBOOK-NAME --> '[workbook_path/filename.xls]' |
'strsq'
22. SHEET --> SHEETNAME '!'
23. SHEETNAME --> IDENTIFIER | 'strsq'


24. AREA-REFERENCE --> RANGE | VECTOR | INTERSECTION |
UNION
25. RANGE --> CELL ':' CELL | SHEET : CELL
26. VECTOR --> COLUMN-RANGE | ROW-RANGE
27. COLUMN-RANGE --> COLUMN ':' COLUMN
28. ROW-RANGE --> ROW ':' ROW
29. INTERSECTION --> AREA-REFERENCE ' ' AREA-REFERENCE
30. UNION --> AREA-REFERENCE ',' AREA-REFERENCE


31. CELL --> ABSOLUTE-REF-OPT COLUMN-OPT
ABSOLUTE-REF-OPT ROW-OPT
32. ABSOLUTE-REF-OPT --> '$' | e


33. COLUMN-OPT --> COLUMN | e
34. COLUMN --> 'column-designator' //
[A-Z] | [A-H][A-Z] | I[A-Z]
35. ROW-OPT --> ROW | e
36. ROW --> 'int' // [1...65536]


37. R1C1-REFERENCE --> R1C1-REF-ROW R1C1-REF-COL
38. R1C1-REF-COL --> 'C' R1C1-REF-OFFSET | 'C' | e
39. R1C1-REF-ROW --> 'R' R1C1-REF-OFFSET
40. R1C1-REF-OFFSET --> '[' '-' 'int' ']' | '[' '+' 'int'
']' | '[' 'int' ']' | 'int' | e


41. CONST-ARRAY --> '{' ARRAY-ELEMENT-LIST-OPT '}'
42. ARRAY-ELEMENT-LIST-OPT --> ARRAY-ELEMENT-LIST | e
43. ARRAY-ELEMENT-LIST --> ARRAY-ELEMENT
  |
                                                                        ARRAY-ELEMENT-LIST ','
ARRAY-ELEMENT |
                                                                        ARRAY-ELEMENT-LIST ';'
ARRAY-ELEMENT
44. ARRAY-ELEMENT --> PRIMITIVE |
                                                                        ERROR-ZERO |
                                                                        ERROR-NOT-AVAILABLE |
                                                                        ERROR-UNKNOWN-NAME |
                                                                        ERROR-NULL |
                                                                        ERROR-NUM |
                                                                        ERROR-REF |
                                                                        ERROR-VALUE |
                                                                        ERROR-TOO-LONG |
                                                                        e


45. FUNCTION-CALL --> FUNC-NAME-PREFIX-OPT IDENTIFIER '('
ARGUMENT-LIST-OPT ')'
46. FUNC-NAME-PREFIX-OPT --> FUNC-NAME-PREFIX | e
47. ARGUMENT-LIST-OPT --> ARGUMENT-LIST | e
48. ARGUMENT-LIST --> ARGUMENT | ARGUMENT-LIST ','
ARGUMENT
49. ARGUMENT --> PRIMARY-EXPRESSION | e


50. PRIMITIVE --> UNARY-OPERATOR-OPT INTEGER |
UNARY-OPERATOR-OPT FLOAT | BOOLEAN | STRING | IDENTIFIER | ERROR


51. INTEGER --> 'int'
52. FLOAT --> 'float'
53. BOOLEAN --> 'TRUE' | 'FALSE'
54. STRING --> 'strsq' | 'strdq' // single and
double quoted


55. UNARY-OPERATOR-OPT --> UNARY-OPERATOR | e
56. UNARY-OPERATOR --> '+' | '-'


57. ERROR --> '#DIV/0!' | '#N/A' | '#NAME?' |
'#NULL!' | '#NUM!' | '#REF!' | '#VALUE!' | '#####'




The parser is based on the Earley algorithm.
I tried a set of formulas from different sources, looks like ok.
But any comments or sugestions are highly appreciated.


Thanks


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.