org.jlab.coda.afecs.cool.parser
Class CCompiler

java.lang.Object
  extended by org.jlab.coda.afecs.cool.parser.CCompiler

public class CCompiler
extends java.lang.Object

JSA: Thomas Jefferson National Accelerator Facility
This software was developed under a United States Government license,
described in the NOTICE file included as part of this distribution.
Copyright (c), Aug 18, 2009


Constructor Summary
CCompiler(java.lang.String s)
          Constructor removes all control characters from the cool rule code
 
Method Summary
 boolean checkLastBrase(java.lang.String s)
          Simple check if the coded description ends with the curly bracket
 java.util.ArrayList<ACondition> compile()
          Parses the string codded using COOL state machine description language
 java.util.LinkedHashMap<java.lang.Integer,java.lang.String> findConditionalOperators(java.lang.String s)
          Finds AND or OR boolean operators (& |)
 java.util.LinkedHashMap<java.lang.Integer,java.lang.Integer> findConditionalStatements(java.lang.String s)
          Finds conditional statement limits.
 boolean findConditonScope(java.lang.String s)
          Finds begining and ending indexes of the conditions and related scopes.
 java.lang.String getConditionalKeyWord(java.lang.String s)
          get conditional key word of a condition
static void main(java.lang.String[] args)
           
 AStatement parseStatement(java.lang.String s)
          Parses conditonal or action statements
 java.util.ArrayList<AStatement> parseStatements(java.lang.String s)
          Parses string containing mutiple statements, separated by the ;
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CCompiler

public CCompiler(java.lang.String s)
Constructor removes all control characters from the cool rule code

Parameters:
s - code of the rule
Method Detail

findConditonScope

public boolean findConditonScope(java.lang.String s)
Finds begining and ending indexes of the conditions and related scopes. Matches opening and closing brackets and records the indexes into the arraylists. Then it finds the matching brackets and recods the begining and the end of the scope into the HashMap. Next it finds the condition for that scopes. N.B. no nested scopes are supported.

Parameters:
s - input string
Returns:
status of the execution

findConditionalStatements

public java.util.LinkedHashMap<java.lang.Integer,java.lang.Integer> findConditionalStatements(java.lang.String s)
Finds conditional statement limits.

Parameters:
s - condition string to be analyzed
Returns:
map of all conditional statents limits or null if syntax error

findConditionalOperators

public java.util.LinkedHashMap<java.lang.Integer,java.lang.String> findConditionalOperators(java.lang.String s)
Finds AND or OR boolean operators (& |)

Parameters:
s - input string of a condition
Returns:
map containing key = index of the operator and value = operator

getConditionalKeyWord

public java.lang.String getConditionalKeyWord(java.lang.String s)
get conditional key word of a condition

Parameters:
s - input string of a condition
Returns:
conditional keyword ( if, else, while elseif), null if syntax error

checkLastBrase

public boolean checkLastBrase(java.lang.String s)
Simple check if the coded description ends with the curly bracket

Parameters:
s - string codded using COOL state machine description language
Returns:
true or false

parseStatement

public AStatement parseStatement(java.lang.String s)
Parses conditonal or action statements

Parameters:
s - statement string
Returns:
AStatement object

parseStatements

public java.util.ArrayList<AStatement> parseStatements(java.lang.String s)
Parses string containing mutiple statements, separated by the ;

Parameters:
s - input string
Returns:
ArrayList of AStatement objects

compile

public java.util.ArrayList<ACondition> compile()
Parses the string codded using COOL state machine description language

Returns:
arraylist of ACondition objects

main

public static void main(java.lang.String[] args)