Antlr4 and expression parsing (Part 2)

Introduction If you have not read part 1 of this blog post (Using ANTLR to parse and calculate expressions), you can do so here. In the previous post, we talked about creating a custom ANTLR4 grammar that would parse formulas with the basic Mathematical operators, and some custom expressions that we need in order to get a decimal result, which might indicate a price, amount, rate… etcetera. In our grammar, we have two operators that have widespread use in probably every trading and banking system in the world. They are: UomConvert(FromUnitOfMeasure, ToUnitOfMeasure) FXRate(‘CurrencyPair’) The first one converts between units of measure. The second one is a simplified version of what might be interpreted as an FX Spot Rate between two currencies. (FX Spot Rates are meaningless without a date component, but for the purposes of this post, we will keep it simple and always assume ‘latest known FX Rate’). It is essential, however, to have a basic calculator working. To do that we’ll need to be able to handle the different inputs in this table. Input Result Comments 2 2 Number identity should work. 2 * 2 4 Standard math operators (addition, multiplication, subtraction and division) (2 + 2) *… continue reading

Continue reading Antlr4 and expression parsing (Part 2). This article appeared first on CTRM Center.

Source: CTRM Center

Related Posts

Leave a reply