|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--jeops.compiler.Main
Main class in the Jeops phase of converting rule files into Java classes.
When invoked, the method convert()
will create a java file
in the same directory as the rule file (with the extension changed from
.rules
to .java
). In this way, rule files can
be grouped into packages in the same way as java classes.
Field Summary | |
private java.util.Vector |
allDeclForLocalDecl
The index of all declared identifiers used by some rule local declaration. |
private java.util.Vector |
convertedRuleDeclarations
The converted declarations of the current rule. |
private java.util.Vector |
convertedRuleLocalDeclarations
The converted local declarations of the current rule. |
private java.util.Vector |
declaredClassNames
The classes of the identifiers generated in the new java file. |
private ImportList |
importList
The import list of this rule base. |
private java.lang.String |
javaFileName
The name of the generated java file. |
private java.util.Vector |
lastDeclForLocalDecl
The index of the last declared identifier used by some rule local declaration. |
private java.util.Vector |
localDeclClasses
Vector (of vectors) of the classes of the local declarations. |
private java.util.Vector |
numberOfConditions
The number of conditions in each rule. |
private java.util.Vector |
numberOfDeclarations
The number of declarations in each rule. |
private java.util.Vector |
numberOfLocalDeclarations
The number of local declarations in each rule. |
private java.lang.String |
ruleBaseName
The name of this rule base. |
private java.util.Vector |
ruleDeclarations
The declarations of the current rule. |
private java.lang.String |
ruleFileName
The name of the rules file. |
private java.util.Vector |
ruleLocalDeclarations
The local declarations of the current rule. |
private java.lang.String |
ruleName
The name of the rule being converted. |
private java.util.Vector |
ruleNames
The names of the rules. |
private Scanner |
scanner
The scanner used to read from the input file. |
private boolean |
thereIsRuleBase
Flag that indicates whether a rule base is declared in the file. |
private Token |
token
The current token. |
private java.util.Vector |
variableIdents
The list of the identifiers of the instance variables of the generated java file. |
private java.util.Vector |
variables
The list of declaration of instance variables of the generated java file. |
private java.io.PrintWriter |
writer
The writer used to create the java file. |
Fields inherited from interface jeops.compiler.parser.TokenConstants |
ACTIONS,
ASTERISK,
CLOSE_CURLY_BRACKET,
COMMA,
COMMENT,
CONDITIONS,
DECLARATIONS,
DOT,
EOF,
EQUALS,
ERROR,
EXTENDS,
IDENT,
IMPLEMENTS,
IMPORT,
LOCALDECL,
NONE_ABOVE,
OPEN_CURLY_BRACKET,
PACKAGE,
PUBLIC,
RULE,
RULE_BASE,
SEMICOLON,
STRING,
WHITE_SPACE |
Constructor Summary | |
Main(java.lang.String ruleFileName)
Class constructor. |
Method Summary | |
private void |
checkToken(Token token,
int[] tokenTypes,
java.lang.String message)
Checks whether a token is one of several given types, throwing an exception if it's not. |
private void |
checkToken(Token token,
int tokenType,
java.lang.String message)
Checks whether a token is of a given type, throwing an exception if it's not. |
private boolean |
compileSourceFile(java.lang.String className)
Attempts to find a source file and compile it into a .class file. |
void |
convert()
Creates a java source file that behaves as defined in the rules file. |
private void |
convertRule(java.io.PrintWriter writer)
Converts a rule into a set of java methods. |
private void |
convertRuleActions(java.io.PrintWriter writer)
Processes the actions part of a rule. |
private void |
convertRuleConditions(java.io.PrintWriter writer)
Processes the conditions part of a rule. |
private void |
convertRuleDeclarations(java.io.PrintWriter writer)
Processes the declaration part of a rule. |
private void |
convertRuleLocalDeclarations(java.io.PrintWriter writer)
Processes the local declarations part of a rule. |
static void |
main(java.lang.String[] args)
Test method for this class. |
private void |
processEndOfRuleBase(java.io.PrintWriter writer)
Processes the end of the rule base, adding control information. |
private void |
processImport(java.io.PrintWriter writer)
Processes an import statement of a rule base. |
private void |
processPackage(java.io.PrintWriter writer)
Processes the package statement of a rule base. |
private Token |
readNextToken()
Reads the next token from the scanner, throwing an exception in case of an error. |
private void |
skipWhiteSpace(java.io.PrintWriter writer,
boolean outputComments)
Auxiliar method used to advance through white space and comments. |
Methods inherited from class java.lang.Object |
|
Field Detail |
private java.io.PrintWriter writer
private java.lang.String ruleFileName
private java.lang.String javaFileName
private java.lang.String ruleBaseName
private Scanner scanner
private Token token
private java.util.Vector variables
private java.util.Vector variableIdents
private java.util.Vector declaredClassNames
private java.lang.String ruleName
private java.util.Vector numberOfDeclarations
private java.util.Vector numberOfLocalDeclarations
private java.util.Vector numberOfConditions
private java.util.Vector ruleNames
private ImportList importList
private java.util.Vector ruleDeclarations
private java.util.Vector convertedRuleDeclarations
private java.util.Vector ruleLocalDeclarations
private java.util.Vector convertedRuleLocalDeclarations
private java.util.Vector lastDeclForLocalDecl
private java.util.Vector allDeclForLocalDecl
private boolean thereIsRuleBase
private java.util.Vector localDeclClasses
Constructor Detail |
public Main(java.lang.String ruleFileName) throws java.io.IOException
ruleFileName
- the name of the rules file.Method Detail |
private void checkToken(Token token, int[] tokenTypes, java.lang.String message) throws JeopsException
token
- the token to be checked.types
- the desired token types.message
- the message in the exception.private void checkToken(Token token, int tokenType, java.lang.String message) throws JeopsException
token
- the token to be checked.type
- the desired token type.message
- the message in the exception.private boolean compileSourceFile(java.lang.String className) throws JeopsException
className
- the name of the class to be compiled.true
if the compilation could be performed;
false
otherwise.public void convert() throws java.io.IOException, JeopsException
private void convertRule(java.io.PrintWriter writer) throws java.io.IOException, JeopsException
writer
- the print writer used to write to the generated file.private void convertRuleActions(java.io.PrintWriter writer) throws java.io.IOException, JeopsException
In order to be correctly invoked, the current token
type must be ACTIONS
. After successful completion,
the token type is CLOSE_CURLY_BRACKET
, indicating
the end of the rule.
writer
- the print writer used to write to the generated file.private void convertRuleConditions(java.io.PrintWriter writer) throws java.io.IOException, JeopsException
In order to be correctly invoked, the current token
type must be CONDITIONS
. After successful completion,
the token type is ACTIONS
.
writer
- the print writer used to write to the generated file.private void convertRuleDeclarations(java.io.PrintWriter writer) throws java.io.IOException, JeopsException
ruleDeclaration
and
convertedRuleDeclaration
fields with the declared
variables and their counterpart in the generated java file. It
will also fill the condGrouping
field.
This method also deals with the optional section of local
declarations of the rule, so that it guarantees that after this
method is successfully invoked, the token type is
CONDITIONS
.
In order to be correctly invoked, the current token
type must be DECLARATIONS
. After successful completion,
the token type is CONDITIONS
.
writer
- the print writer used to write to the generated file.private void convertRuleLocalDeclarations(java.io.PrintWriter writer) throws java.io.IOException, JeopsException
ruleLocalDeclaration
and
convertedRuleLocalDeclaration
fields with the
locally declared variables and their counterpart in the
generated java file.
In order to be correctly invoked, the current token
type must be LOCALDECL
. After successful
completion, the token type is CONDITIONS
.
writer
- the print writer used to write to the generated file.public static void main(java.lang.String[] args)
args
- command-line arguments. None is needed, but
one can pass the rule file name for the converting.private void processEndOfRuleBase(java.io.PrintWriter writer) throws java.io.IOException
writer
- the print writer used to write to the generated file.private void processImport(java.io.PrintWriter writer) throws java.io.IOException, JeopsException
writer
- the print writer used to write to the generated file.private void processPackage(java.io.PrintWriter writer) throws java.io.IOException, JeopsException
writer
- the print writer used to write to the generated file.private Token readNextToken() throws java.io.IOException, JeopsException
private void skipWhiteSpace(java.io.PrintWriter writer, boolean outputComments) throws java.io.IOException
writer
- the print writer used to write to the generated file.outputComments
- if the white space and comments should be
written to the output file
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |