Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » RPGLE Grammar - How to declare Keywords? (Xtext 2.10)(RPGLE Grammar - How to declare Keywords? (Xtext 2.10))
RPGLE Grammar - How to declare Keywords? (Xtext 2.10) [message #1751880] Mon, 16 January 2017 13:03 Go to next message
Christoff Erasmus is currently offline Christoff ErasmusFriend
Messages: 1
Registered: December 2016
Junior Member
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 
;
//------------------------------------------------------------------------------
Re: RPGLE Grammar - How to declare Keywords? (Xtext 2.10) [message #1751915 is a reply to message #1751880] Mon, 16 January 2017 18:51 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 10337
Registered: July 2009
Senior Member
the ast will be the same? won't it?!?
the only difference might be in the node model.
Re: RPGLE Grammar - How to declare Keywords? (Xtext 2.10) [message #1751934 is a reply to message #1751915] Mon, 16 January 2017 21:53 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 10337
Registered: July 2009
Senior Member
P.s. And I would not optimize too much upfront
Simply write a generator or test with real scale models to get a feeling. Measure. Then optimize
Previous Topic:Quickfix Tooltip Description Formatting
Next Topic:Unit-testing custom validators?
Goto Forum:
  


Current Time: Thu Mar 30 16:58:43 GMT 2017

Powered by FUDForum. Page generated in 0.01925 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software