public abstract class AbstractCodeParser extends AbstractPhase implements Lexer, EmbeddedCodeProcessor
This is done so that the CodeParser can be generated from a syntaxt file
| Modifier and Type | Field and Description |
|---|---|
protected int |
actLine |
protected boolean |
bActionDone |
char |
currentChar |
protected String |
currentNonTerminalName |
protected int |
currentRuleIndex |
protected Type |
currentType |
protected static String |
DISTINGUISHED_SYMBOL_NAME |
protected boolean |
finalActions |
protected Stack<Character> |
inputChars |
protected boolean |
isCurlyBrace |
protected boolean |
isEqual |
protected boolean |
isError |
protected boolean |
isErrorToken |
protected boolean |
isFirstToken |
protected boolean |
isRegexSlash |
protected int |
markers |
protected boolean |
mustClose |
protected int |
numberOfErrorTokens |
String |
recognized |
protected Associativity |
ruleAssociativity |
protected int |
rulePrecedence |
protected int |
tokenActionCount |
protected int |
tokenNumber |
environment, runtimeData| Constructor and Description |
|---|
AbstractCodeParser(Environment environment)
Default Constructor
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
computeAssociativityAndPrecedence(String tokenName)
A %prec was given, and as such I need to load its context globally
|
protected void |
computeRootSymbol()
Find out my root symbol
|
boolean |
declareOneItem(String symbolName,
int value,
boolean mustClose)
Adds one rule item to the current list of items
|
protected boolean |
declareOneNonTerminal(String typeName,
String name)
Declare one non terminal in the symbol table
|
protected Terminal |
declareOneTerminal(String id,
boolean isErrorToken,
Associativity associativity,
int precedence,
Type type,
int tokenNumber,
String fullName)
Declare a token
|
protected boolean |
declareOneType(String typeName)
Declare one given type
|
protected boolean |
declareStart(String id) |
protected char |
decodeControlChar()
Use the character stream to decode a control char
|
protected char |
decodeEscape()
Use the character stream to decode the next escaped character
(i.e.
|
protected char |
decodeHex()
Use the character stream to decode a character entered with hex codes
|
protected char |
decodeOctal()
Use the character stream to decode one character from octal
|
abstract void |
dumpTokens() |
abstract void |
execute() |
protected void |
finalizeRules()
set rule numbers and print
|
protected void |
finalizeSymbols()
Assign ids, numbers, and print them.
|
protected void |
generateCaseEnd()
A statement for code generation was found.
|
protected int |
generateCaseStatement(int ruleNumber,
String comment)
Output the case for a given rule
|
protected void |
generateCodeGeneratorFooter()
Generate the ending portion of the code generation
|
protected void |
generateCodeGeneratorHeader()
Output the top of the rules if needed
|
boolean |
generateConstant(Lexer lexer,
char characterType)
Scan the stream unti a string that starts with the given character ends
|
protected boolean |
generateDeclaration()
During a declaration, emit the accompanying code
|
protected boolean |
generateDefaultRegexCode(int dfaNode,
Terminal token)
Produce the if statement that will match the regex symbol and the default return code
|
boolean |
generateDollarDollar(Lexer lexer,
int elementCount,
String nonTerminalId,
Type type)
$$ detected.
|
boolean |
generateDollarLetter(Lexer lexer,
int elementCount,
Type type,
String nonTerminalId)
$Letter was detected.
|
boolean |
generateDollarNumber(Lexer lexer,
int elementCount,
Type type,
int sign)
$1, $2, $-3, etc detected.
|
protected boolean |
generateLexerCode(String lexerMode,
Terminal token)
copy action until the next ';' or '}' that actually closes
|
protected void |
generateLexerFooter()
Generate the bottom of the lexer
|
protected boolean |
generateRegexCode(String lexerMode,
int dfaNode,
Terminal token)
Produce the if statement that will match the regex symbol and include additional code
|
protected boolean |
generateStructure()
For yacc compatibility this is called the union, but it is
really a structure
|
protected void |
generateTokenDefinitions()
token definitions are declared as static or #define
|
protected void |
generateTopRecoveryTable()
The recovery table deals with tokens that can be used to recognize
syntax context and can recover from errors.
|
char |
getCurrentCharacter()
Do not get the next character character.
|
protected int |
getDollarTextIndexFromStream()
Find the $Letter[<digits>] digits.
|
char |
getNextCharacter()
Get one character.
|
protected Symbol |
getSymbolWithName(String name)
Obtain a symbol, either terminal or non terminal, with the given name.
|
Type |
getTypeFromStream(Lexer lexer)
EMBEDDED CODE PROCESSOR
|
boolean |
groupTokens(List<String> tokens,
String groupName,
String displayName)
group a list of tokens
|
protected int |
lineNumber(Rule rule) |
protected Rule |
locateRuleWithId(int id)
Locate a rule whose left hand if is the given id
|
protected boolean |
nameOneNonTerminal(String name,
String fullName)
Change the display name of a non terminal
|
protected Rule |
newEmptyRule()
new rule with no elements
|
protected RuleItem |
newItem(Symbol elem)
new rule item with the given symbol
|
protected Rule |
newRootRule(NonTerminal root)
Starting rule.
|
protected Rule |
newRule()
new rule with the currently recognized items
|
protected void |
reviewDeclarations()
Check non terminals whose precedence is zero, and make them terminals.
|
protected boolean |
ruleAction(int ruleNumber,
int elementCount,
String nonTerminalName)
Found a rule action.
|
protected boolean |
setLeftHandOfLastRule(String name)
This routine places the non terminal left hand of a rule
|
boolean |
skipAndOutputCompositeComment(Lexer lexer,
char secondaryCharacter,
char characterToFind)
Skip a comment, and copying it to the output
|
void |
ungetChar(char c)
Reverse one character.
|
indent, left, right, span, spanclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetNormalSymbolprotected static final String DISTINGUISHED_SYMBOL_NAME
protected boolean bActionDone
protected int currentRuleIndex
protected Type currentType
protected int markers
protected boolean isCurlyBrace
protected boolean isEqual
protected boolean isRegexSlash
protected boolean isError
protected int tokenNumber
protected String currentNonTerminalName
protected boolean mustClose
protected boolean finalActions
protected boolean isErrorToken
protected Associativity ruleAssociativity
protected int rulePrecedence
protected int tokenActionCount
protected int actLine
protected boolean isFirstToken
protected int numberOfErrorTokens
public char currentChar
public String recognized
public AbstractCodeParser(Environment environment)
environment - is the syntax environmentprotected Terminal declareOneTerminal(String id, boolean isErrorToken, Associativity associativity, int precedence, Type type, int tokenNumber, String fullName)
id - is the short name of the tokenisErrorToken - specifies if this token was declared with %errorassociativity - defines if a token is defined with %left, %right, etc.precedence - is the numeric precedence of the tokentype - is the type of the non-terminaltokenNumber - is the number of the token, or its valuefullName - is the fullname, if given, of the tokenprotected boolean declareOneNonTerminal(String typeName, String name)
typeName - the desired typename - the name of the symbolprotected boolean declareOneType(String typeName)
typeName - the desired typepublic boolean declareOneItem(String symbolName, int value, boolean mustClose)
symbolName - the name of the symbol being usedvalue - the integer value of the symbolmustClose - whether this token must closepublic boolean groupTokens(List<String> tokens, String groupName, String displayName)
tokens - the list of tokensgroupName - the name of the groupdisplayName - the display name of the grouppublic boolean computeAssociativityAndPrecedence(String tokenName)
tokenName - is the name of the token given in the %precprotected boolean nameOneNonTerminal(String name, String fullName)
name - is the short name of the non terminalfullName - is its full nameprotected boolean setLeftHandOfLastRule(String name)
name - is the non terminal's nameprotected char decodeOctal()
for instance '\017'
protected char decodeControlChar()
\a - \z
protected char decodeHex()
for instance \x1f
protected char decodeEscape()
public char getNextCharacter()
LexergetNextCharacter in interface Lexerpublic void ungetChar(char c)
Lexerpublic char getCurrentCharacter()
LexergetCurrentCharacter in interface Lexerpublic Type getTypeFromStream(Lexer lexer)
getTypeFromStream in interface EmbeddedCodeProcessorlexer - the element that will give me the lexical logicpublic boolean generateDollarLetter(Lexer lexer, int elementCount, Type type, String nonTerminalId)
When two rule items have the same symbol, a disambiguating index like $Symbol[1], $Symbol[2], etc. can be used. The Left hand symbol is only used when non indexed;
generateDollarLetter in interface EmbeddedCodeProcessorlexer - the element that will give me the lexical logicelementCount - the number of elements in the rulenonTerminalId - the non terminal id for the ruletype - the type of the elementprotected Symbol getSymbolWithName(String name)
name - the name of the symbolprotected int getDollarTextIndexFromStream()
public boolean generateDollarNumber(Lexer lexer, int elementCount, Type type, int sign)
generateDollarNumber in interface EmbeddedCodeProcessorlexer - the element that will give me the lexical logicelementCount - the number of elements in the ruletype - the type of the elementsign, - 1 for possitive, -1 for negativepublic boolean generateDollarDollar(Lexer lexer, int elementCount, String nonTerminalId, Type type)
generateDollarDollar in interface EmbeddedCodeProcessorlexer - the element that will give me the lexical logicelementCount - the number of elements in the rulenonTerminalId - the non terminal id for the ruletype - the type of the elementpublic boolean generateConstant(Lexer lexer, char characterType)
EmbeddedCodeProcessorgenerateConstant in interface EmbeddedCodeProcessorlexer - the object in charge of managing the input streampublic boolean skipAndOutputCompositeComment(Lexer lexer, char secondaryCharacter, char characterToFind)
EmbeddedCodeProcessorskipAndOutputCompositeComment in interface EmbeddedCodeProcessorlexer - the element that will give me the lexical logicprotected void generateCaseEnd()
protected int generateCaseStatement(int ruleNumber,
String comment)
ruleNumber - is the rule number to be emitted in the case statementcomment - is the commentprotected void generateCodeGeneratorHeader()
protected boolean generateLexerCode(String lexerMode, Terminal token)
lexerMode - is the mode of the lexertoken - is the token related to the generation. Used in $tprotected boolean generateDefaultRegexCode(int dfaNode,
Terminal token)
dfaNode - is the index of the dfa vertextoken - is the token related to the generation. Used in $tprotected boolean generateRegexCode(String lexerMode, int dfaNode, Terminal token)
lexerMode - is the mode of the scannerdfaNode - is the index of the dfa vertextoken - is the token related to the generation. Used in $tprotected void generateCodeGeneratorFooter()
protected void generateLexerFooter()
protected boolean generateDeclaration()
protected boolean generateStructure()
protected RuleItem newItem(Symbol elem)
elem - is the symbol associated to the ruleprotected Rule newEmptyRule()
protected Rule newRule()
protected Rule newRootRule(NonTerminal root)
root - is the root symbolprotected void reviewDeclarations()
protected void computeRootSymbol()
protected void generateTopRecoveryTable()
protected void finalizeSymbols()
protected void finalizeRules()
protected void generateTokenDefinitions()
protected Rule locateRuleWithId(int id)
id - is the id of the non terminal on the left hand sideprotected int lineNumber(Rule rule)
rule - is the rule's line numberprotected boolean ruleAction(int ruleNumber,
int elementCount,
String nonTerminalName)
ruleNumber - the rule indexelementCount - the elements in the rulenonTerminalName - the left hand symbol of the ruleprotected boolean declareStart(String id)
public abstract void execute()
throws ParsingException
ParsingExceptionpublic abstract void dumpTokens()
throws ParsingException
ParsingExceptionCopyright © 2017. All rights reserved.