openEHR / adl-antlr

Antrl4 grammars for ADL
Apache License 2.0
1 stars 4 forks source link

adl rules have no operator precedence #4

Open pieterbos opened 8 years ago

pieterbos commented 8 years ago

The operators in the rules section have no operator precedence. It's very useful to include this in the antlr grammar. Something along the lines of:

expr:  mult ('+' mult)* ;
mult:  atom ('*' atom)* ;
atom:  INT | '(' expr ')' ;

You can then simply walk the tree to evaluate expressions.

Useful both for arithmetic and boolean expressions.

wolandscat commented 8 years ago

The parsing order of precedence should be correct now.

pieterbos commented 8 years ago

Your fix for the parsing of operator precedence does not yet work. I fixed it in Archie.

See the branch rule_evaluation of archie at https://github.com/nedap/archie/tree/rule_evaluation. I fixed operator precedence both for boolean and arithmetic expressions, with soms tests. I also implemented expression variables declarations in both the grammar and evaluation. I'll create a pull request for the grammar as soon as i have more of the grammar implemented, working and tested.

Also, the ADL language spec is missing the modulo operator. The AOM spec does list it.

pieterbos commented 8 years ago

For the latest rule grammar in archie, see the grammar in the master-branch of archie.

That does not yet parse function calls and it has some simple changes to the language to fix some rather hard to fix ambiguity i mentioned on the mailing list. I'll respond to that mail soon :)

wolandscat commented 8 years ago

My view on this at the moment is that its' better to wait until you get a (reasonably) complete working 'rules' section grammar that corresponds to the Expressions Language spec (where the latter might need some tweaks as well), and then when those two are in sync, I'll replace the current adl_rules.g4 with what you have.