Hello.
Currently I am implementing an Xtext grammer for the freefrom version of the RPGLE language.
My current focus is to implement the "StandAloneFields" aka variables.
Sample Statements:
// String Variable Declaration
dcl-s MyString char(100) ;
//Long Integer Variable Declaration, and initiation
dcl-s MyInt int(10) inz(123123);
//Number Variable
dcl-s MyNum num(10:2);
Derived grammar:
StandAloneField:
'dcl-s' name=ID keywords+=StandAloneFieldKeywords* ';'
;
Q1: Is my understanding correct?"
During the "Parsing" phase, I should not worry about duplicate or mutually exclusive "keywords" as this will be handled during the "Validation" phase of the AST.
Q2: How to implement the "StandAloneFieldKeywords" Rule?
Option 1:
StandAloneFieldKeywords:
{Keyword_Char} 'char' '(' length=INT ')' |
{Keyword_Int} 'int' '(' digits=INT ')' |
{KeyWord_Num} 'num' '(' digits=INT (':' precision=ID)? ')' |
{KeyWord_Inz} 'inz' ( '(' value= NamedConstantValue ')' )?
;
Option 2:
StandAloneFieldKeywords:
Keyword_Char |
Keyword_Int |
Keyword_Num |
Keyword_Inz
;
Keyword_Char:
'char' '(' length=INT ')'
;
Keyword_Int:
'int' '(' digits=INT ')'
;
Keyword_Num:
'num' '(' digits=INT (':' precision=ID)? ')'
;
Keyword_Inz:
'inz' ( '(' value= NamedConstantValue ')' )?
;
I am in faviour of Option2 (above), as the "Keyword" Rules can be re-used for "DataStructure" and "Parameter" Definitions
My concern is with regards to the AST memory foot print.
Legacy RPGLE programs are monolithic beasts, which contains @#$! load of variable declarations, thus the AST will grow quite large. I would like to start with a proper foundation for the grammar.
Work in Progress Grammer:
grammar free.as400.xtext.freeform.Rpgle with org.eclipse.xtext.common.Terminals
generate rpgle "http:// www. as400.free /xtext/freeform/Rpgle"
Model:
specifications += AbstractSpecification*
;
AbstractSpecification:
//AbstractControl |
//AbstractFileDescription |
Definition |
//AbstractInput |
//AbstractCalculation |
//AbstactOutput |
//AbstractProcedure
;
//Definitions --------------------------------------------------------------
Definition:
StandAloneField |
NamedConstant //|
//DataStructure //|
//Prototypes |
//ProcedureInterface |
//PrototypedParameters
;
//------------------------------------------------------------------------------
//Variables --------------------------------------------------------------------
StandAloneField:
'dcl-s' name=ID keywords+=StandAloneFieldKeywords* ';'
;
StandAloneFieldKeywords:
// ALT(array_name)
// ALTSEQ(*NONE)
'ASCEND' |
// BASED(basing_pointer_name)
// BINDEC(digits {: decimal-positions})
// CCSID definition keyword
// CHAR(length)
// CLASS(*JAVA:class-name)
'CTDATA' |
// DATE{(format{separator})}
// DATFMT(format{separator})
'DESCEND' |
// DIM(numeric_constant)
// DTAARA keyword
// EXPORT{(external_name)}
// EXTFMT(code)
// FLOAT(bytes)
// FROMFILE(file_name)
// GRAPH(length)
// IMPORT{(external_name)}
'IND' |
'INT' '(' digits=INT ')' |
// INZ{(initial value)}
// LEN(length)
// LIKE(name {: length-adjustment})
'NOOPT' |
// NULLIND{(null-indicator)}
// OBJECT{(*JAVA:class-name)}
// PACKED(digits {: decimal-positions})
// PERRCD(numeric_constant)
// POINTER{(*PROC)}
'PROCPTR' |
// STATIC{(*ALLTHREAD)}
'TEMPLATE'
// TIME{(format{separator})}
// TIMESTAMP{(fractional-seconds)}
// TIMFMT(format{separator})
// TOFILE(file_name)
// UCS2(length)
// UNS(digits)
// VARCHAR(length {:2 | 4})
// VARGRAPH(length {:2 | 4})
// VARUCS2(length {:2 | 4})
// VARYING{(2 | 4)}
// ZONED(digits {: decimal-positions})
;
//------------------------------------------------------------------------------
//Constants --------------------------------------------------------------------
NamedConstant:
'dcl-c' name=ID 'const('? value=NamedConstantValue ')'?
;
NamedConstantValue:
{IntConstant} value = INT |
{StringConstant} value = STRING
;
//------------------------------------------------------------------------------