/
gmSCParserClass
gmSCParserClass
Mark Juras
Owned by Mark Juras
The Parser Service Class
The service class Parser analyses character strings in a known computer language, according to the rules of that language. At the present time there are two language types processed by this class, Basic and the class of contemporary OOP languages referred to here simply as Java.The field commun
PrototypeUBYTE* commun;
The field fileType
Prototypeint fileType;
The field icol
Prototypeint icol;
The field ierc
Prototypeint ierc;
The field iorec
Prototypeint iorec;
The field iostate
Prototypeint iostate;
The field lcol
Prototypeint lcol;
The field token
PrototypeUBYTE token[];
The field tokenType
Prototypeint tokenType
The field Parser_scriptType
Prototypeint Parser_scriptType
The method Parser_CompareBounded
Prototypeint Parser_CompareBounded(CONST char* oper,int length);
Parameter | Description |
oper | Contains the symbol being checked for. It need not be null-terminated. |
length | Specifies the length of symbol |
If a match is found, then this method returns the length of the symbol and updates the current location in the coded record so that it points to the first character beyond the end of the match. If no match is found, then a zero is returned and the current location is left unchanged. If a match is found but there are additional identifier characters following immediately after then a minus one is returned.
The method Parser_CompareSymbol
Prototypeint Parser_CompareSymbol(CONST char* oper);
Parameter | Description |
oper | Contains the symbol being checked for in null-terminated form. |
If a match is found, then this method returns the length of the symbol and updates the current location in the coded record so that it points to the first character beyond the end of the match. If no match is found, then a zero is returned and the current location is left unchanged.
The method Parser_Expression
Prototypeint Parser_Expression(int* parents,int expType,int isSet,int level)
Token precedence */ lexeme VB JS opcode subcode type args VB JS */ ---------- ---- ---- ------ -------- ---- ---- -----------*/ MIN - - OPC_NEG BIN_Arithmetic TYP_VOID 1 10 11 NOT not ! OPC_NOT BIN_Arithmetic TYP_VOID 1 3 11 POW ^ OPC_EXP BIN_Arithmetic TYP_VOID 2 11 0 MUL * * OPC_MUL BIN_Arithmetic TYP_VOID 2 9 10 DIV / / OPC_DIV BIN_Arithmetic TYP_VOID 2 9 10 IDV \ OPC_IDV BIN_Arithmetic TYP_VOID 2 8 0 MOD mod % OPC_MOD BIN_Arithmetic TYP_VOID 2 7 10 ADD + + OPC_ADD BIN_Arithmetic TYP_VOID 2 6 9 SUB - - OPC_SUB BIN_Arithmetic TYP_VOID 2 6 9 CAT & + OPC_CAT BIN_Arithmetic TYP_VOID 2 5 9 NEQ <> != OPC_NEQ BIN_Arithmetic TYP_BOOLEAN 2 4 6 GTE >= >= OPC_GTE BIN_Arithmetic TYP_BOOLEAN 2 4 7 LTE <= <= OPC_LTE BIN_Arithmetic TYP_BOOLEAN 2 4 7 EQL = == OPC_EQL BIN_Arithmetic TYP_BOOLEAN 2 4 6 GTR > > OPC_GTR BIN_Arithmetic TYP_BOOLEAN 2 4 7 LTH < < OPC_LTH BIN_Arithmetic TYP_BOOLEAN 2 4 7 IOR or || OPC_IOR BIN_Arithmetic TYP_VOID 2 2 1 AND and && OPC_AND BIN_Arithmetic TYP_VOID 2 2 2 LIKE like === OPC_LIK BIN_Arithmetic TYP_VOID 2 4 6 ISA is i-of OPC_ISA BIN_Arithmetic TYP_VOID 2 4 7 XOR xor ^ OPC_XOR BIN_Arithmetic TYP_VOID 2 2 4 EQV equ OPC_XOR BIT_Equiv TYP_VOID 2 2 0 IMP imp OPC_XOR BIT_Implies TYP_VOID 2 2 0 BWA & OPC_AND BIN_BitWise TYP_VOID 2 0 5 BWO | OPC_IOR BIN_BitWise TYP_VOID 2 0 3
Parameter | Description |
parents | contains the number of parents controlling the current expression and the root offsets of those parents. |
expType | specifies the expected binary type of the expression. |
isSet | specifies the language context of the current expression |
level | specifies the current hierarchy level within the expression. It controls the recursive descent of this method and must always be set at -1 when called externally. |
The method returns the status of the factor and of the operator either preceding or following it when the end of the expression was reached:
Code | Meaning |
+i | The operation code of unary operator encountered immediately or the operation code of a binary operator immediately following a processed quantity expression. |
0 | the expression consisted of a simple l-value not followed by an operator. |
-1 | the expression consisted of a constant not followed by an operator. |
-2 | the expression consisted of a complex "parenthetical" expression not followed by an operator. |
The method Parser_ExtractToken
Prototypeint Parser_ExtractToken(char** Position,UBYTE* Lexeme);
Token | Description of meaning |
EndOfRecord | The end of the current record was encountered -- i.e., a null-byte was encountered. In this case the lexeme-length is set to zero. |
Identifier | The lexeme read was a valid identifier or keyword -- i.e., it begins with an identifier character and continues until a character that is neither an identifier nor a digit is encountered. |
Integer | The lexeme read was an integer constant. |
Float | The lexeme read was a floating-point constant. At this time ANSI-C format is assumed for floating point constants. |
Quoted | The lexeme was a quoted string. |
Special | The lexeme was some character that could not be classified as part of one of the above lexemes. In this the lexeme-length is one and the lexeme-value is the character value. |
Other tokens are defined via the two standard lists ParserReservedWords and ParserReservedSymbols. The parameters of the method are:
Parameter | Description |
Position | Contains a pointer to the pointer to the current position in the character string being parsed. When this method returns this parameter is updated to point to the character position immediately after the end of the lexeme, or to the null-byte in the case where the end-of-record is encountered. |
Lexeme | Receives the actual character form of the lexeme encountered in n-string form -- i.e., Lexeme[0] receives the length and Lexeme[1..] receive the characters making up the lexeme. To ensure compatibility the character sequence is then null-terminated as well. Lexemes longer than 255 characters are returned with a length of 255. In this case it is up to the caller to compute the actual length of the lexeme. |
The method returns the token value of the lexeme which might either be one of the generic values or might be a value taken from one of the two lists.
The method Parser_FindSymbol
Prototypeint Parser_FindSymbol(UBYTE* oper);
Parameter | Description |
oper | Contains the list of symbols in the StandardList form. |
If a match is found, then this method returns the offset in the symbol list of the start of the symbol information associated with the matched symbol and updates the current location in the coded record so that it points to the first character beyond the end of the match. If no match is found, then a zero is returned and the current location is left unchanged.
The method Parser_GetReservedWords
PrototypeUBYTE* Parser_GetReservedWords(int active);
Parameter | Description |
active | Specifies the language. A setting of LNG_BASIC specifies VB6, Visual Basic; a setting of zero specifies none; and any other setting specifies the generic OOP, Java here. |
The method Parser_GetSymbol
Prototypeint Parser_GetSymbol(char* Record);
Parameter | Description |
Record | Contains a null-terminated string which is assumed to begin with a non-whitespace character. |
The method returns the offset in the string of the first character in the string which is null or which has the whitespace attribute. A return value of zero, indicates that the string does not begin with a valid non-whitespace character.
The method Parser_GetIdentifier
Prototypeint Parser_GetIdentifier(UBYTE* Record,int nRecord);
Parameter | Description |
Record | Contains a string which may begin with an identifier character. |
nRecord | Specifies the length of the string. |
The method returns the offset in the string of the first character in the string which does not have the identifier attribute. A return value of zero, indicates that the string does not begin with an identifier character.
The method Parser_GetToken
Prototypeint Parser_GetToken(void);
The method Parser_LookAhead
Prototypeint Parser_LookAhead(void);
The method Parser_GetBuffer
PrototypeUBYTE* Parser_GetBuffer(void);
The method Parser_ResetInput
Prototypeint Parser_ResetInput(void);
The method Parser_SetDoubleQuotes
Prototypevoid Parser_SetDoubleQuotes(int status);
Parameter | Description |
status | Specifies if the status is to be on or off. A zero value, or LBC_False, sets the status off, while a nonzero value, or LBC_True sets it on. |
The method Parser_SetExternalLanguage
Prototypevoid Parser_SetExternalLanguage(int status);
Parameter | Description |
status | Specifies if the status is to be on or off. A zero value, or LBC_False, sets the status off, while a nonzero value, or LBC_True sets it on. |
The method Parser_SetNumericIdentifiers
Prototypevoid Parser_SetNumericIdentifiers(int status);
Parameter | Description |
status | Specifies if the status is to be on or off. A zero value, or LBC_False, sets the status off, while a nonzero value, or LBC_True sets it on. |
The method Parser_SetInput
Prototypevoid Parser_SetInput(int position);
Parameter | Description |
position | Specifies the starting position for the current and next input token. |
The method Parser_SetReserved
Prototypevoid Parser_SetReserved(int active);
Parameter | Description |
active | Specifies the type of language being processed. A setting of LNG_BASIC Specifies VB6, Visual Basic; a setting of zero specifies none; and any other setting specifies the generic OOP, Java here. |
Each of the two language types has two lists associated with it: words and symbols. The words list contains the reserved words to be recognized. A word must begin with an identifier character and may contain only identifier and digit characters. In this implementation reserved words are not case sensitive. The symbols list contains the reserved symbols to be recognized. A symbol must begin with a non-identifier character. There are no other restrictions, but they are case sensitive if they contain alphabetic characters (which most do not).
The method Parser_SetStatement
Prototypevoid Parser_SetStatement(char* record);
Parameter | Description |
record | Contains the string in null-terminated form to be copied into the communications buffer. |
The method Parser_SetWhiteSpaceBoundary
Prototypevoid Parser_SetWhiteSpaceBoundary(int status);
Parameter | Description |
status | Specifies if the status is to be on or off. A zero value, or LBC_False, sets the status off, while a nonzero value, or LBC_True sets it on. |
The method Parser_SetSkipWhiteSpace
Prototypevoid Parser_SetSkipWhiteSpace(int status);
Parameter | Description |
status | Specifies if the status is to be on or off. A zero value, or LBC_False, sets the status off, while a nonzero value, or LBC_True sets it on. |
The method Parser_SetAbbreviationSymbol
Prototypevoid Parser_SetAbbreviationSymbol(char symbol);
Parameter | Description |
symbol | Specifies the abbreviation symbol value. |
The method Parser_StringExpression
Prototypevoid Parser_StringExpression(int* Parents,int exp,char* strValue,int langType)
Parameter | Description |
parents | contains the number of parents controlling the current expression and the root offsets of those parents. |
exp | specifies the expected binary type of the expression. |
strValue | contains the actual expression to be parsed. |
langType | specifies the dialect of current statements being compiled. |
Table of Contents
, multiple selections available,
Related content
gmSCOpcodeClass
gmSCOpcodeClass
More like this
gmslCharacterClass
gmslCharacterClass
More like this
gmslLanguage
gmslLanguage
More like this
gmscStoreClass
gmscStoreClass
More like this
gmSCFileSystemClass
gmSCFileSystemClass
More like this
gmSCMessageHandlerClass
gmSCMessageHandlerClass
More like this