Analytics Vidhya
Published in

Analytics Vidhya

Python from expressions — The ANTLR series (Part 3)

A gist of what the process looks like so far

https://www.stringtemplate.org/

Basics First

  • <attribute> evaluates to the string value of attribute(our expression in this case) if it exists else empty string.
    For example, <expression> will be referred by the key expression while working with StringTemplate object in Java. So, if the user puts any value against the “expression” key, it will be referred as an expression attribute in the template.
  • For custom or user defined objects inside the template, use <attribute.property> , this looks for property of attribute as a property then accessor methods like getProperty() or isProperty() or hasProperty().
  • <attribute:t1(argument-list): ... :tN(argument-list)> Basically, iterating over a list of objects for the same template substitution. This applies multiple templates in order from left to right. The result of a template application upon a multi-valued attribute is another multi-valued attribute. The overall expression evaluates to the concatenation of all template elements
  • <! comment !> Comments, as defined, are ignored by StringTemplate.
  • Template definitions look like function definitions with untyped arguments:
    templateName(arg1, arg2, ..., argN) ::= "single-line template"
    or
    templateName(arg1, arg2, ..., argN) ::= <<multi-line template>>
    or
    templateName(arg1, arg2, ..., argN) ::= <%multi-line template that ignores indentation and newlines%>

Input:

a gt b and c gt d
a eq b

Output:

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store