Back to index

wims  3.65+svn20090927
Package Functions | Private Member Functions | Private Attributes
org.javia.arity.Compiler Class Reference

Compiles a textual arithmetic expression to a Function. More...

Collaboration diagram for org.javia.arity.Compiler:
Collaboration graph
[legend]

List of all members.

Package Functions

double eval (Symbols symbols, String expression) throws SyntaxException
FunctionAndName compile (Symbols symbols, String source) throws SyntaxException
double eval (Symbols symbols, String expression) throws SyntaxException
FunctionAndName compile (Symbols symbols, String source) throws SyntaxException

Private Member Functions

final SyntaxException exception new SyntaxException ()
final SyntaxException exception new SyntaxException ()

Private Attributes

final Lexer lexer = new Lexer(exception)
final RPN rpn = new RPN(exception)
final DeclarationParser declParser = new DeclarationParser(exception)
final OptCodeGen codeGen = new OptCodeGen(exception)
final SimpleCodeGen simpleCodeGen = new SimpleCodeGen(exception)
final Declaration decl = new Declaration()

Detailed Description

Compiles a textual arithmetic expression to a Function.

Definition at line 22 of file Compiler.java.


Member Function Documentation

FunctionAndName org.javia.arity.Compiler.compile ( Symbols  symbols,
String  source 
) throws SyntaxException [inline, package]

Definition at line 37 of file Compiler.java.

                                                                                   {
        Function fun = null;
        decl.parse(source, lexer, declParser);
        if (decl.arity == DeclarationParser.UNKNOWN_ARITY) {
            try {
                double value = eval(symbols, decl.expression);
                fun = new Constant(value);
            } catch (SyntaxException e) {
                if (e != SimpleCodeGen.HAS_ARGUMENTS) {
                    throw e;
                }
                // fall-through (see below)
            }
        }
                
        if (fun == null) { // either decl.arity was set, or an ArityException happened above
            symbols.pushFrame();
            symbols.addArguments(decl.args);
            try {
                rpn.setConsumer(codeGen.setSymbols(symbols));
                lexer.scan(decl.expression, rpn);
            } finally {
                symbols.popFrame();
            }
            int arity = decl.arity;
            if (arity == DeclarationParser.UNKNOWN_ARITY) {
                arity = codeGen.intrinsicArity;
            }
            fun = codeGen.getFun(arity);

            /*
            if (decl.name != null && addDefinition) {
                symbols.addDefinition(decl.name, fun, decl.arity==DeclarationParser.UNKNOWN_ARITY);
            }
            */
        }

        return new FunctionAndName(fun, decl.name);
    }

Here is the call graph for this function:

Here is the caller graph for this function:

FunctionAndName org.javia.arity.Compiler.compile ( Symbols  symbols,
String  source 
) throws SyntaxException [inline, package]

Definition at line 37 of file Compiler.java.

                                                                                   {
        Function fun = null;
        decl.parse(source, lexer, declParser);
        if (decl.arity == DeclarationParser.UNKNOWN_ARITY) {
            try {
                double value = eval(symbols, decl.expression);
                fun = new Constant(value);
            } catch (SyntaxException e) {
                if (e != SimpleCodeGen.HAS_ARGUMENTS) {
                    throw e;
                }
                // fall-through (see below)
            }
        }
                
        if (fun == null) { // either decl.arity was set, or an ArityException happened above
            symbols.pushFrame();
            symbols.addArguments(decl.args);
            try {
                rpn.setConsumer(codeGen.setSymbols(symbols));
                lexer.scan(decl.expression, rpn);
            } finally {
                symbols.popFrame();
            }
            int arity = decl.arity;
            if (arity == DeclarationParser.UNKNOWN_ARITY) {
                arity = codeGen.intrinsicArity;
            }
            fun = codeGen.getFun(arity);

            /*
            if (decl.name != null && addDefinition) {
                symbols.addDefinition(decl.name, fun, decl.arity==DeclarationParser.UNKNOWN_ARITY);
            }
            */
        }

        return new FunctionAndName(fun, decl.name);
    }

Here is the call graph for this function:

double org.javia.arity.Compiler.eval ( Symbols  symbols,
String  expression 
) throws SyntaxException [inline, package]

Definition at line 31 of file Compiler.java.

                                                                           {
        rpn.setConsumer(simpleCodeGen.setSymbols(symbols));
        lexer.scan(expression, rpn);
        return simpleCodeGen.getValue();
    }

Here is the call graph for this function:

double org.javia.arity.Compiler.eval ( Symbols  symbols,
String  expression 
) throws SyntaxException [inline, package]

Definition at line 31 of file Compiler.java.

                                                                           {
        rpn.setConsumer(simpleCodeGen.setSymbols(symbols));
        lexer.scan(expression, rpn);
        return simpleCodeGen.getValue();
    }

Here is the call graph for this function:

Here is the caller graph for this function:

final SyntaxException exception new org.javia.arity.Compiler.SyntaxException ( ) [final, private]
final SyntaxException exception new org.javia.arity.Compiler.SyntaxException ( ) [final, private]

Member Data Documentation

final OptCodeGen org.javia.arity.Compiler.codeGen = new OptCodeGen(exception) [private]

Definition at line 27 of file Compiler.java.

Definition at line 29 of file Compiler.java.

Definition at line 26 of file Compiler.java.

final Lexer org.javia.arity.Compiler.lexer = new Lexer(exception) [private]

Definition at line 24 of file Compiler.java.

final RPN org.javia.arity.Compiler.rpn = new RPN(exception) [private]

Definition at line 25 of file Compiler.java.

Definition at line 28 of file Compiler.java.


The documentation for this class was generated from the following files: