org.eclipse.ocl.lpg
Class AbstractParser

java.lang.Object
  extended by lpg.lpgjavaruntime.PrsStream
      extended by org.eclipse.ocl.lpg.AbstractParser
All Implemented Interfaces:
lpg.lpgjavaruntime.ParseErrorCodes, lpg.lpgjavaruntime.TokenStream
Direct Known Subclasses:
AbstractOCLParser

public abstract class AbstractParser
extends lpg.lpgjavaruntime.PrsStream

The AbstractParser supports syntactic analysis of a tokens produced by an AbstractLexer to create a corresponding CST, that may in turn be exploited by an AbstractAnalyzer to create an AST. Derived classes should extend the abstract support for AST from CST from tokens from text parsing and analysis to support the AST and CST classes appropriate to a particular language.


Field Summary
 
Fields inherited from interface lpg.lpgjavaruntime.ParseErrorCodes
BEFORE_CODE, DELETION_CODE, EOF_CODE, ERROR_CODE, errorMsgText, INSERTION_CODE, INVALID_CODE, INVALID_TOKEN_CODE, LEX_ERROR_CODE, MERGE_CODE, MISPLACED_CODE, SCOPE_CODE, SECONDARY_CODE, SUBSTITUTION_CODE
 
Constructor Summary
AbstractParser(AbstractLexer lexer)
           
AbstractParser(BasicEnvironment environment)
           
 
Method Summary
 String computeInputString(int left, int right)
          Returns a single line string representation of the input chars for the given range.
 int getDefaultRepairCount()
           
 BasicEnvironment getEnvironment()
           
 lpg.lpgjavaruntime.ErrorToken getErrorTokenAtCharacter(int offset)
          This function returns the index of the token element containing the offset specified.
 int getErrorTokens()
           
 AbstractLexer getLexer()
           
 int getTokenIndexAtCharacter(int offset)
          Overridden to search only the non-Error nodes, which are the only tokens in monotonic order.
 int makeErrorToken(int firsttok, int lasttok, int errortok, int kind)
           
 CSTNode parseTokensToCST()
           
abstract  CSTNode parseTokensToCST(lpg.lpgjavaruntime.Monitor monitor, int error_repair_count)
           
 void reportError(int errorCode, String locationInfo, int leftToken, int rightToken, String tokenText)
           
 void reportErrorTokenMessage(int error_token, String msg)
          Report error message for given error_token.
 void resetLexStream(lpg.lpgjavaruntime.LexStream lexStream)
           
 void setDefaultRepairCount(int defaultRepairCount)
          Sets the number of repairs to be performed by a parser capable of performing repairs (the BacktrackingParser) unless overridden on the specific parser invocation method.
 void setLexStream(AbstractLexer lexStream)
           
protected  void setOffsets(CSTNode cstNode, CSTNode startEnd)
          Sets the start and end offsets of the given CSTNode to the start and end offsets of the 2nd given CSTNode
protected  void setOffsets(CSTNode cstNode, CSTNode start, CSTNode end)
          Sets the start and end offsets of the given CSTNode to the start offset of the 2nd given CSTNode and the end offset of the 3rd given CSTNode
protected  void setOffsets(CSTNode cstNode, CSTNode start, lpg.lpgjavaruntime.IToken end)
          Sets the start and end offsets of the given CSTNode to the start offset of the 2nd given CSTNode and the end offset of the given IToken
protected  void setOffsets(CSTNode cstNode, lpg.lpgjavaruntime.IToken startEnd)
          Sets the start and end offsets of the given CSTNode to the start and end offsets of the given IToken
protected  void setOffsets(CSTNode cstNode, lpg.lpgjavaruntime.IToken start, CSTNode end)
          Sets the start and end offsets of the given CSTNode to the start offset of the given IToken and the end offset of the 2nd given CSTNode
protected  void setOffsets(CSTNode cstNode, lpg.lpgjavaruntime.IToken start, lpg.lpgjavaruntime.IToken end)
          Sets the start and end offsets of the given CSTNode to the start offset of the 1std given IToken and the end offset of the 2nd given IToken
protected  String unquote(String quoted)
          Removes the "s surrounding a quoted string, if any.
 
Methods inherited from class lpg.lpgjavaruntime.PrsStream
addAdjunct, addToken, afterEol, badToken, dumpToken, dumpTokens, getAdjuncts, getColumn, getColumnOfTokenAt, getEndColumn, getEndColumnOfTokenAt, getEndLine, getEndLineNumberOfTokenAt, getEndOffset, getFileName, getFirstErrorToken, getFirstRealToken, getFollowingAdjuncts, getInputChars, getIToken, getKind, getLastErrorToken, getLastRealToken, getLexStream, getLine, getLineNumberOfTokenAt, getName, getNext, getPrecedingAdjuncts, getPrevious, getSize, getStartOffset, getStreamIndex, getStreamLength, getToken, getToken, getTokenAt, getTokenAtCharacter, getTokenLength, getTokens, getTokenText, makeAdjunct, makeToken, mapKind, orderedTerminalSymbols, peek, remapTerminalSymbols, reportError, reportError, reportError, reset, reset, resetTokenStream, setSize, setStreamIndex, setStreamLength, setStreamLength
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractParser

public AbstractParser(BasicEnvironment environment)

AbstractParser

public AbstractParser(AbstractLexer lexer)
Method Detail

computeInputString

public String computeInputString(int left,
                                 int right)
Returns a single line string representation of the input chars for the given range.

Parameters:
left - left most char index
right - right most char index
Returns:
a single line string representation of the input chars

getEnvironment

public BasicEnvironment getEnvironment()

getErrorTokenAtCharacter

public lpg.lpgjavaruntime.ErrorToken getErrorTokenAtCharacter(int offset)
This function returns the index of the token element containing the offset specified. If such a token does not exist, it returns the negation of the index of the element immediately preceding the offset.

Since:
1.3

getDefaultRepairCount

public int getDefaultRepairCount()
Since:
1.3

getErrorTokens

public int getErrorTokens()
Since:
1.3

getLexer

public AbstractLexer getLexer()

getTokenIndexAtCharacter

public int getTokenIndexAtCharacter(int offset)
Overridden to search only the non-Error nodes, which are the only tokens in monotonic order.

Overrides:
getTokenIndexAtCharacter in class lpg.lpgjavaruntime.PrsStream

makeErrorToken

public int makeErrorToken(int firsttok,
                          int lasttok,
                          int errortok,
                          int kind)
Specified by:
makeErrorToken in interface lpg.lpgjavaruntime.TokenStream
Overrides:
makeErrorToken in class lpg.lpgjavaruntime.PrsStream

parseTokensToCST

public CSTNode parseTokensToCST()

parseTokensToCST

public abstract CSTNode parseTokensToCST(lpg.lpgjavaruntime.Monitor monitor,
                                         int error_repair_count)

reportError

public void reportError(int errorCode,
                        String locationInfo,
                        int leftToken,
                        int rightToken,
                        String tokenText)
Specified by:
reportError in interface lpg.lpgjavaruntime.TokenStream
Overrides:
reportError in class lpg.lpgjavaruntime.PrsStream

reportErrorTokenMessage

public final void reportErrorTokenMessage(int error_token,
                                          String msg)
Report error message for given error_token.

Parameters:
error_token - the error taken index
msg - the message to report
Since:
1.3

resetLexStream

public void resetLexStream(lpg.lpgjavaruntime.LexStream lexStream)
Overrides:
resetLexStream in class lpg.lpgjavaruntime.PrsStream

setDefaultRepairCount

public void setDefaultRepairCount(int defaultRepairCount)
Sets the number of repairs to be performed by a parser capable of performing repairs (the BacktrackingParser) unless overridden on the specific parser invocation method.

Parameters:
defaultRepairCount - the default repair count
Throws:
IllegalArgumentException - if the defaultRepairCount is negative
Since:
1.3

setLexStream

public void setLexStream(AbstractLexer lexStream)

setOffsets

protected void setOffsets(CSTNode cstNode,
                          lpg.lpgjavaruntime.IToken startEnd)
Sets the start and end offsets of the given CSTNode to the start and end offsets of the given IToken

Parameters:
cstNode - CSTNode to set offsets
startEnd - IToken to retrieve offsets from

setOffsets

protected void setOffsets(CSTNode cstNode,
                          CSTNode startEnd)
Sets the start and end offsets of the given CSTNode to the start and end offsets of the 2nd given CSTNode

Parameters:
cstNode - CSTNode to set offsets
startEnd - CSTNode to retrieve offsets from

setOffsets

protected void setOffsets(CSTNode cstNode,
                          CSTNode start,
                          CSTNode end)
Sets the start and end offsets of the given CSTNode to the start offset of the 2nd given CSTNode and the end offset of the 3rd given CSTNode

Parameters:
cstNode - CSTNode to set offsets
start - CSTNode to retrieve start offset from
end - CSTNode to retrieve end offset from

setOffsets

protected void setOffsets(CSTNode cstNode,
                          CSTNode start,
                          lpg.lpgjavaruntime.IToken end)
Sets the start and end offsets of the given CSTNode to the start offset of the 2nd given CSTNode and the end offset of the given IToken

Parameters:
cstNode - CSTNode to set offsets
start - CSTNode to retrieve start offset from
end - IToken to retrieve end offset from

setOffsets

protected void setOffsets(CSTNode cstNode,
                          lpg.lpgjavaruntime.IToken start,
                          CSTNode end)
Sets the start and end offsets of the given CSTNode to the start offset of the given IToken and the end offset of the 2nd given CSTNode

Parameters:
cstNode - CSTNode to set offsets
start - IToken to retrieve start offset from
end - CSTNode to retrieve end offset from

setOffsets

protected void setOffsets(CSTNode cstNode,
                          lpg.lpgjavaruntime.IToken start,
                          lpg.lpgjavaruntime.IToken end)
Sets the start and end offsets of the given CSTNode to the start offset of the 1std given IToken and the end offset of the 2nd given IToken

Parameters:
cstNode - CSTNode to set offsets
start - IToken to retrieve start offset from
end - IToken to retrieve end offset from

unquote

protected String unquote(String quoted)
Removes the "s surrounding a quoted string, if any.

Parameters:
quoted - a possibly quoted string
Returns:
quoted without the surrounding quotes, or just quoted verbatim if there were none

Copyright 2002, 2007 IBM Corporation and others.
All Rights Reserved.