Package cruise.umple.parser.analysis
Class GrammarAnalyzer
java.lang.Object
cruise.umple.parser.analysis.GrammarAnalyzer
public class GrammarAnalyzer
extends java.lang.Object
The grammar analayzer deals with first analyzing the root token of the grammar files, and constructing the rule graph for the grammar
then it has a execute function which will use the rule graph in the parsing of the umple file.
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
GrammarAnalyzer.Getter<T>
-
Constructor Summary
Constructors Constructor Description GrammarAnalyzer()
-
Method Summary
Modifier and Type Method Description boolean
addAnalyzer(Analyzer aAnalyzer)
void
addAnalyzerFromStack()
boolean
addAnalyzerRule(ChoiceRule aAnalyzerRule)
boolean
addCloseTerminal(Terminal aCloseTerminal)
boolean
addOpenTerminal(Terminal aOpenTerminal)
void
addParserAction(java.lang.String name, ParserAction action)
Adds a parser action to operate on an action token of the specified nameboolean
addThread(RuleBasedParserThread aThread)
void
analyze(Token tokens)
void
anonymousRule(Token token)
These are rules that are specified within brackets, and are therefore not Tokenized.void
braced(Token token)
{} and "" are special couple characters and are handled by making a BalancedRule which will ensure that the { is paired with the proper } and so onvoid
definition(Token token)
The definition token is used both for the rule definition, and anonymous rules(rules containsed within paratheses).void
delete()
void
execute()
Performs the parsing on the umple file.java.util.HashMap<java.lang.String,ParserAction>
getActionedTokens()
currently only implemented with useStatement as the only element of this hashmap, but it is extendable, should the need arise.Analyzer
getAnalyzer(int index)
AnalyzerGeneratorHandler
getAnalyzerGenerator()
The handler to control generation of Analyzer objects at runtimejava.util.Map<java.lang.String,Analyzer>
getAnalyzerMap()
ChoiceRule
getAnalyzerRule(int index)
ChoiceRule[]
getAnalyzerRules()
Analyzer[]
getAnalyzers()
java.util.Stack<Analyzer>
getAnalyzerStack()
Terminal[]
getCloseTerminal()
Terminal
getCloseTerminal(int index)
ParserDataPackage
getData()
the data package used during the parsing.boolean
getDone()
Position
getFailedPosition()
the failed position, if there was one, it will remain null if the parse was successfuljava.io.File
getFile()
Umple file that will be parsed(like Master.ump)boolean
getFirst()
java.util.HashMap<java.lang.String,java.lang.Object>
getGlobal()
hashmap of global variables(local to the class, not local to methods)java.lang.String
getInput()
filename of the file to be parsedGrammarAnalyzer.Getter<java.lang.Integer>
getInts()
java.util.HashMap<java.lang.String,java.lang.String[]>
getKeys()
The keys that will be used by the couples of this hash mapLinkedFileHandler
getLinkedFileHandler()
The handler for dealing with linked filesboolean
getMustSetupAnalyzers()
boolean
getNoSpaces()
if a balanced rule is created, it needs to know if the current context is nospaces or notTerminal[]
getOpenTerminal()
Terminal
getOpenTerminal(int index)
ParseResult
getParseResult()
resulting parse result from the parseToken
getRootToken()
rootToken which will be the result of the parsing of the umple file passedGrammarAnalyzer.Getter<ChoiceRule>
getRules()
Global variable getters and settersGrammarAnalyzer.Getter<java.util.Stack<ChoiceRule>>
getStacks()
GrammarAnalyzer.Getter<java.lang.String>
getStrings()
RuleBasedParserThread
getThread(int index)
RuleBasedParserThread[]
getThreads()
java.lang.String
getValue(Token token, java.lang.String name)
Simple method to handle token values.boolean
hasAnalyzerRules()
boolean
hasAnalyzers()
boolean
hasCloseTerminal()
boolean
hasOpenTerminal()
boolean
hasThreads()
int
indexOfAnalyzer(Analyzer aAnalyzer)
int
indexOfAnalyzerRule(ChoiceRule aAnalyzerRule)
int
indexOfCloseTerminal(Terminal aCloseTerminal)
int
indexOfOpenTerminal(Terminal aOpenTerminal)
int
indexOfThread(RuleBasedParserThread aThread)
void
init(java.io.File file, java.io.File[] linkedFiles)
Must be called before use with the execute function, this function sets up the file for parsingvoid
init(java.lang.String ruleName, java.lang.String input)
void
init(java.lang.String ruleName, java.lang.String input, java.lang.String fileName, Position usePosition, int lineNumber, int offset)
boolean
isNoSpaces()
boolean
makeAnalyzer(java.lang.String name)
int
numberOfAnalyzerRules()
int
numberOfAnalyzers()
int
numberOfCloseTerminal()
int
numberOfOpenTerminal()
int
numberOfThreads()
void
otherrule(Token token)
Otherrule tokens are for rule names within a definition, where the otherrule is defined elsewhere.boolean
removeAnalyzer(Analyzer aAnalyzer)
boolean
removeAnalyzerRule(ChoiceRule aAnalyzerRule)
boolean
removeCloseTerminal(Terminal aCloseTerminal)
boolean
removeOpenTerminal(Terminal aOpenTerminal)
boolean
removeThread(RuleBasedParserThread aThread)
void
rule(Token token)
The rule token denotes the beginning of a rule definition.void
rules(Token token)
--Analyze Rule Methods The rules token contains all the rules in a grammar file.void
separator(Token token)
The separator token denotes the | in a rule.protected void
set(java.lang.String string, java.lang.Object object)
This funciton is used for putting things into the global hashmap that contains all objectsboolean
setActionedTokens(java.util.HashMap<java.lang.String,ParserAction> aActionedTokens)
boolean
setAnalyzerGenerator(AnalyzerGeneratorHandler aAnalyzerGenerator)
boolean
setAnalyzerMap(java.util.Map<java.lang.String,Analyzer> aAnalyzerMap)
boolean
setAnalyzerStack(java.util.Stack<Analyzer> aAnalyzerStack)
boolean
setData(ParserDataPackage aData)
boolean
setDone(boolean aDone)
boolean
setFailedPosition(Position aFailedPosition)
boolean
setFile(java.io.File aFile)
boolean
setFirst(boolean aFirst)
boolean
setGlobal(java.util.HashMap<java.lang.String,java.lang.Object> aGlobal)
boolean
setInput(java.lang.String aInput)
boolean
setInts(GrammarAnalyzer.Getter<java.lang.Integer> aInts)
boolean
setKeys(java.util.HashMap<java.lang.String,java.lang.String[]> aKeys)
boolean
setLinkedFileHandler(LinkedFileHandler aLinkedFileHandler)
boolean
setMustSetupAnalyzers(boolean aMustSetupAnalyzers)
boolean
setNoSpaces(boolean aNoSpaces)
boolean
setParseResult(ParseResult aParseResult)
boolean
setRootToken(Token aRootToken)
boolean
setRules(GrammarAnalyzer.Getter<ChoiceRule> aRules)
boolean
setStacks(GrammarAnalyzer.Getter<java.util.Stack<ChoiceRule>> aStacks)
boolean
setStrings(GrammarAnalyzer.Getter<java.lang.String> aStrings)
void
setupAlphanumericTerminal(Terminal terminal)
Similar to the setupTerminal function this function makes sure that an alphanumeric does not take a value that is the value of then next terminal for instance if an association looks like * -- 1 Student sorted { }; the rolename is student not sorted.java.util.List<Analyzer>
setupAnalyzers()
java.util.List<Analyzer>
setupAnalyzers(Analyzer analyzer, ChoiceRule parent, java.util.List<ChoiceRule> checked)
void
setupTerminal(Terminal terminal)
Sets up the tokens with no premodifier to make sure they stop at the right place, for instance [type] [=list[]]? should stop before the [], so the type only contains String, instead of String[]void
setupTerminals()
There are some terminals that need to use their surroundings to determine what they can and cannot take on as values this function iterates through all such terminalsvoid
terminal(Token token)
Terminals are keywords or syntax.void
token(Token token)
Tokens are of the form [{premodifier}tokenname{:value}] and denote a Terminal rule where the a Token is created with the value specified by some premodifierjava.lang.String
toString()
-
Constructor Details
-
GrammarAnalyzer
public GrammarAnalyzer()
-
-
Method Details
-
setDone
public boolean setDone(boolean aDone) -
setFirst
public boolean setFirst(boolean aFirst) -
setLinkedFileHandler
-
setAnalyzerGenerator
-
setGlobal
public boolean setGlobal(java.util.HashMap<java.lang.String,java.lang.Object> aGlobal) -
setRootToken
-
setData
-
setFailedPosition
-
setRules
-
setStacks
-
setStrings
-
setInts
-
setActionedTokens
public boolean setActionedTokens(java.util.HashMap<java.lang.String,ParserAction> aActionedTokens) -
setKeys
public boolean setKeys(java.util.HashMap<java.lang.String,java.lang.String[]> aKeys) -
addThread
-
removeThread
-
setFile
public boolean setFile(java.io.File aFile) -
setInput
public boolean setInput(java.lang.String aInput) -
setNoSpaces
public boolean setNoSpaces(boolean aNoSpaces) -
setAnalyzerStack
-
setAnalyzerMap
-
setParseResult
-
addOpenTerminal
-
removeOpenTerminal
-
addCloseTerminal
-
removeCloseTerminal
-
addAnalyzerRule
-
removeAnalyzerRule
-
addAnalyzer
-
removeAnalyzer
-
setMustSetupAnalyzers
public boolean setMustSetupAnalyzers(boolean aMustSetupAnalyzers) -
getDone
public boolean getDone() -
getFirst
public boolean getFirst() -
getLinkedFileHandler
The handler for dealing with linked files -
getAnalyzerGenerator
The handler to control generation of Analyzer objects at runtime -
getGlobal
public java.util.HashMap<java.lang.String,java.lang.Object> getGlobal()hashmap of global variables(local to the class, not local to methods) -
getRootToken
rootToken which will be the result of the parsing of the umple file passed -
getData
the data package used during the parsing. -
getFailedPosition
the failed position, if there was one, it will remain null if the parse was successful -
getRules
Global variable getters and setters -
getStacks
-
getStrings
-
getInts
-
getActionedTokens
currently only implemented with useStatement as the only element of this hashmap, but it is extendable, should the need arise. -
getKeys
public java.util.HashMap<java.lang.String,java.lang.String[]> getKeys()The keys that will be used by the couples of this hash map -
getThread
-
getThreads
-
numberOfThreads
public int numberOfThreads() -
hasThreads
public boolean hasThreads() -
indexOfThread
-
getFile
public java.io.File getFile()Umple file that will be parsed(like Master.ump) -
getInput
public java.lang.String getInput()filename of the file to be parsed -
getNoSpaces
public boolean getNoSpaces()if a balanced rule is created, it needs to know if the current context is nospaces or not -
getAnalyzerStack
-
getAnalyzerMap
-
getParseResult
resulting parse result from the parse -
getOpenTerminal
-
getOpenTerminal
-
numberOfOpenTerminal
public int numberOfOpenTerminal() -
hasOpenTerminal
public boolean hasOpenTerminal() -
indexOfOpenTerminal
-
getCloseTerminal
-
getCloseTerminal
-
numberOfCloseTerminal
public int numberOfCloseTerminal() -
hasCloseTerminal
public boolean hasCloseTerminal() -
indexOfCloseTerminal
-
getAnalyzerRule
-
getAnalyzerRules
-
numberOfAnalyzerRules
public int numberOfAnalyzerRules() -
hasAnalyzerRules
public boolean hasAnalyzerRules() -
indexOfAnalyzerRule
-
getAnalyzer
-
getAnalyzers
-
numberOfAnalyzers
public int numberOfAnalyzers() -
hasAnalyzers
public boolean hasAnalyzers() -
indexOfAnalyzer
-
getMustSetupAnalyzers
public boolean getMustSetupAnalyzers() -
isNoSpaces
public boolean isNoSpaces() -
delete
public void delete() -
set
protected void set(java.lang.String string, java.lang.Object object)This funciton is used for putting things into the global hashmap that contains all objects -
addParserAction
Adds a parser action to operate on an action token of the specified name- Parameters:
name
- the name of the token to perform the actionaction
- the ParserAction to perform
-
init
public void init(java.io.File file, java.io.File[] linkedFiles)Must be called before use with the execute function, this function sets up the file for parsing -
init
public void init(java.lang.String ruleName, java.lang.String input) -
init
public void init(java.lang.String ruleName, java.lang.String input, java.lang.String fileName, Position usePosition, int lineNumber, int offset) -
execute
public void execute()Performs the parsing on the umple file. -
rules
--Analyze Rule Methods The rules token contains all the rules in a grammar file. -
makeAnalyzer
public boolean makeAnalyzer(java.lang.String name) -
rule
The rule token denotes the beginning of a rule definition. -
addAnalyzerFromStack
public void addAnalyzerFromStack() -
definition
The definition token is used both for the rule definition, and anonymous rules(rules containsed within paratheses). -
otherrule
Otherrule tokens are for rule names within a definition, where the otherrule is defined elsewhere. -
getValue
Simple method to handle token values. -
terminal
Terminals are keywords or syntax. -
token
Tokens are of the form [{premodifier}tokenname{:value}] and denote a Terminal rule where the a Token is created with the value specified by some premodifier -
anonymousRule
These are rules that are specified within brackets, and are therefore not Tokenized. -
braced
{} and "" are special couple characters and are handled by making a BalancedRule which will ensure that the { is paired with the proper } and so on -
separator
The separator token denotes the | in a rule. It means that everything before a separator is contained within one Rule and everything after the | is contained in a separate Rule. The parent to both of these rules is a ChoiceRule, meaning that each of the rules created will be tried. -
setupTerminals
public void setupTerminals()There are some terminals that need to use their surroundings to determine what they can and cannot take on as values this function iterates through all such terminals -
setupAlphanumericTerminal
Similar to the setupTerminal function this function makes sure that an alphanumeric does not take a value that is the value of then next terminal for instance if an association looks like * -- 1 Student sorted { }; the rolename is student not sorted. This works also for having * -- 1 Student sorted sorted { }; which will be a sorted list of students called sorted. (i.e. if the next one is accounted for then everything proceeds as normal) -
setupTerminal
Sets up the tokens with no premodifier to make sure they stop at the right place, for instance [type] [=list[]]? should stop before the [], so the type only contains String, instead of String[] -
analyze
-
setupAnalyzers
-
setupAnalyzers
public java.util.List<Analyzer> setupAnalyzers(Analyzer analyzer, ChoiceRule parent, java.util.List<ChoiceRule> checked) -
toString
public java.lang.String toString()- Overrides:
toString
in classjava.lang.Object
-