ilog.rules.brl.translation

Class IlrBRLTranslator

  • java.lang.Object
    • ilog.rules.brl.translation.IlrBRLTranslator
  • All Implemented Interfaces:
    ilog.rules.brl.syntaxtree.IlrSyntaxTreeTranslator


    public class IlrBRLTranslator
    extends java.lang.Object
    implements ilog.rules.brl.syntaxtree.IlrSyntaxTreeTranslator
    This class handles the whole translation process and is the main class of the translation framework.

    A translator needs to be provided with two things:

    • An instance of IlrCodeGenerator that is in charge of producing code for a specific target language.
    • An instance of IlrTranslationSupport that will provide translation services.

    Once an instance of IlrBRLTranslator has been created, it can accept a new translation input as an IlrTranslatorInput. To start a translation and get the resulting string, you have to call printTranslation(Writer). The translation is done in two phases:

    1. First it builds an intermediate form of the BRL rule by exploring the abstract syntax tree from its root and calling the method IlrNodeTranslator.process(IlrSyntaxTree.Node, IlrTranslationContext) of the IlrNodeTranslator attached to the node, if there is one. In this method, an intermediate form of the rule is progressively built. Note that this first phase of construction of the intermediate form must be done independently of the target language. The intermediate form is then passed to the second phase of the translation.
    2. The second phase is code generation from the intermediate form. The IlrCodeGenerator explores the produced IlrIntermediateForm, and prints the code for a specific target language.

    The same instance of this class may be used for translating several sources. Call setTranslatorInput(IlrTranslatorInput) to change the input and start a new translation with printTranslation(Writer).

    It is not necessary to subclass this class. Translator extension can be done by :

    • Creating an IlrNodeTranslator instance for new grammar nodes.
    • Creating an IlrCodeGeneatorExtender instance to generate specific code for a new language construct.

    For more information on translation extensions, please read the BRLDF Translation manual.

    • Constructor Detail

      • IlrBRLTranslator

        public IlrBRLTranslator(IlrCodeGenerator codeGenerator,
                        IlrTranslationSupport support)
        Creates a new instance of IlrBRLTranslator with a codeGenerator and a support. It will use the default class loader of the class.
        Parameters:
        codeGenerator - The code generator.
        support - The translation support.
      • IlrBRLTranslator

        public IlrBRLTranslator(IlrCodeGenerator codeGenerator,
                        IlrTranslationSupport support,
                        java.lang.ClassLoader cl)
        Creates a new instance of IlrBRLTranslator with a codeGenerator, a support and the specified ClassLoader to load required classes (node translators, and value translators).
        Parameters:
        codeGenerator - The code generator.
        support - The translation support.
        cl - The class loader.
    • Method Detail

      • setTranslatorInput

        public void setTranslatorInput(IlrTranslatorInput input)
        Sets a new translator input.
        Parameters:
        input - The new translator input.
      • setClassLoader

        public void setClassLoader(java.lang.ClassLoader cl)
        Sets a specific class loader.
        Parameters:
        cl - The class loader.
      • printTranslation

        public void printTranslation(java.io.Writer writer)
        Translates the current translator input to the specified writer.
        Parameters:
        writer - The writer.
      • getTranslationSupport

        public IlrTranslationSupport getTranslationSupport()
        Returns the translation support of this translator.
        Returns:
        The translation support.
      • getVocabulary

        public IlrVocabulary getVocabulary()
        Returns the vocabulary. The vocabulary is retrieved from the syntax tree of the translator input. It returns null if there is no input.
        Returns:
        The vocabulary.
      • getTranslatorInput

        public IlrTranslatorInput getTranslatorInput()
        Returns the current translator input.
        Returns:
        The current translator input.
      • getCodeGenerator

        public IlrCodeGenerator getCodeGenerator()
        Returns the code generator attached to this translator.
        Returns:
        The code generator.
      • getClassLoader

        public java.lang.ClassLoader getClassLoader()
        Returns the class loader. This class loader is used to load the translator extenders and the value translators. If the class loader has not been set using setClassLoader(ClassLoader), then the class loader of the BRLDefinition of the syntax tree is used.
        Returns:
        The class loader of the translator input.

© Copyright IBM Corp. 1987, 2017