Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Algorithmic language project for writing algorithms in French.(I have a bug that I cannot resolve despite numerous attempts.)
Algorithmic language project for writing algorithms in French. [message #1729454] Thu, 14 April 2016 09:38 Go to next message
Yves LEDUC is currently offline Yves LEDUCFriend
Messages: 54
Registered: May 2015
Member
Xtext Algorithmic project:

Grammar (simplified) of my language:

grammar com.infoly.xtext.algo.Algorithmic with org.eclipse.xtext.common.Terminals

generate algorithmic "http://www.infoly.com/xtext/algo/Algorithmic"

import "http://www.eclipse.org/emf/2002/Ecore" as ecore

/* 12 avril 2016
* PROJET ALGORITHMIC
* ***************************
*/

Algorithmic:
// typesUser=TypesDecl?
constantes=ConstsDecls?
variables=VarsDecls?
modules+=Module*;

Module:
module=MODULE_TYPE name=ModuleName '(' parameters=Parameters? ')' (':' typeReturn=Type)?
constlocales=ConstsDecls?
varlocales=VarsDecls?
body = Body
;

ModuleCall:
{ModuleCall}
ref= (ModuleRef | Library) ( '(' arguments+=Arguments? ')' )
;

ModuleRef: ref=[ModuleName];

ModuleName: name=ValidID;

Body:
{Body}
'Début'
statements+=Statement*
last=LastStatement?
'Fin'
;

Statement returns Expression:
StatementAssignment
| StatementCall
;

StatementCall:
ModuleCall
;

StatementAssignment returns Expression:
var=VarRef '<-' expr=Expression
;

LastStatement:
(isFunction?='Retourne') expr=Expression
;


/*
* EXPRESSIONs
*/
Expression:
expr=ExpressionPlusMinus
;

ExpressionPlusMinus returns Expression:
ExpressionMulDivModulo (
('+' {Expression_Plus.left=current} right=ExpressionMulDivModulo) |
('-' {Expression_Minus.left=current} right=ExpressionMulDivModulo)
)* ;

ExpressionMulDivModulo returns Expression:
ExpressionTerminal (
('*' {Expression_Mul.left=current} right=ExpressionTerminal)
| ('/' {Expression_Div.left=current} right=ExpressionTerminal)
| ('%' {Expression_Modulo.left=current} right=ExpressionTerminal)
)* ;


ExpressionTerminal returns Expression :
ExpressionValue // Un litéral: Value : INT | FLOAT | BOOL | STRING
| ExpressionDataOrModuleCall // Const, var, param ou module ou librairie
// | ExpressionData
// | ModuleCall
| ('(' Expression ')')
;

ExpressionValue:
{IntegerLiteral} value=INT |
{FloatLiteral} value=FLOAT |
{StringLiteral} value=STRING |
{StringLiteral} value=EXIT |
{BooleanLiteral} value=BOOL
;

ExpressionDataOrModuleCall returns Expression :
DataRef
| ModuleCall
// VARIOUS TRY
// | (Library | ModuleRef) ( '(' arguments+=Arguments? ')' )
// | (=> refM=ModuleRef '(' arguments+=Arguments? ')' )
// | (Library '(' arguments+=Arguments? ')' )
// ((AllRef '(') | (=>LibRef '(')) arguments+=Arguments? ')' // FACTORISE NOK
;

/*
* LIBRARY
*/
Library: {Library} (Display | Get);

LibRef: ref=[Library];

Display: 'afficher';
Get: 'saisir';

/*
* DATAs
*/

AllName:
ConstName | VarName | ParName | ModuleName
;

AllRef:
ref = [AllName]
;

DataName:
ConstName | VarName | ParName
;

DataRef:
refData = [DataName]
;

ConstsDecls :
('Constante:'|'Const:')
constantes += ConstsDecl (';'? constantes += ConstsDecl)*
;

ConstsDecl :
type=Type ':' conststype += Constante (',' conststype += Constante)*
;

Constante:
name=ConstName init=Init
;

ConstName:
name=ValidID
;

VarsDecls:
isWritable ?= ('Variable:'|'Var:')
variables += VarsDecl (';'? variables += VarsDecl)*
;

VarsDecl:
type=Type ':' varstype += Variable (',' varstype += Variable)*
;

VarRef:
ref = [Variables]
;

Variables:
Variable | Param
;

Variable:
VarName init=Init?
;

VarName:
name=ValidID
;

Parameters:
params += CategoryParams (';'? params += CategoryParams)* // Catégories E, E/S, S
;

CategoryParams:
category=PARAM_CATEGORY param=Params //| ConstsDecl
// isWritable=((category=PARAM_CATEGORY) ?= ('E:'|'E/S:')) param=Params
;

Params:
pars += ParamsDecl (';'? pars += ParamsDecl)*
;

ParamsDecl:
type=Type ':' parstype += Param (',' parstype += Param)*
;

Param:
ParName init=Init?
;

Arguments:
args += Expression (','? args += Expression)*
;

Init:
(isAssigned ?= '<-') value = Expression
;

ParName:
name=ValidID
;

ValidID:
ID
;

/*
* TYPEs
*/
TypesDecl: 'Type:' types += TypeDecl;
TypeDecl : base=Type ':' name=ValidID;
TypeUser : ref=[TypeDecl];

Type:
TypePrimitif | TypeStructured // | TypeUser
;

TypePrimitif:
TypeInt | TypeFloat | TypeBool | TypeChar
;

TypeInt: type = 'Entier' ;
TypeFloat: type = 'Réel';
TypeBool: type = 'Booléen';
TypeChar: type = 'Caractère';

TypeStructured:
TypeString | TypeArray | TypeStruct
;

TypeString: type = 'Chaine';
TypeArray: type = 'Tableau';
TypeStruct: type = 'Structure';

/*
* ENUMs
*/

enum MODULE_TYPE:
PROG='Programme' | FUNC='Fonction' | PROC='Procédure' | ONEVENT='SurEvénement'
;
enum PARAM_CATEGORY:
IN='E:' | INOUT='E/S:' | OUT='S:'
;

/* ------------------------------------------------------------------------
* TERMINALs
* ------------------------------------------------------------------------
*/
terminal fragment DIGIT: ('0'..'9');
terminal BOOL: ('VRAI'|'FAUX') ;
terminal EXIT: ('SUCCES' | 'ECHEC');
terminal FLOAT returns ecore::EFloat :
('+' | '-')? (('1'..'9' DIGIT* '.' DIGIT+ /* ? */) (('E' | 'e') ('+' | '-')? DIGIT+)?
| '0'? ('.' DIGIT+)? (('E' | 'e') ('+' | '-')? DIGIT+)? );


Problems
1) Sans le prédicat j'ai un conflit entre DataRef et ModuleRef. (LL Grammar)
2) Je voudrais faire ceci dans la grammaire :
1) Without the predicate I have a conflict between DataRef and ModuleRef. (LL Grammar)
2) I want to do this in the grammar:


ExpressionDataOrModuleCall returns Expression :
DataRef
| ModuleCall


I wish it allows entering a Constant, Variable, Library or Module name like this for example:

/*
* ##########################
* ALGORITHMIC
* ##########################
* ======== Grammaire =======
* NOK
*/

// Globales Datas
Const:
Chaine : gTITRE <- "Le titre"
Entier : gVERSION <- 1.0
Var:
Réel : gReal
Chaine : gTexte
Entier : gE1, gE2

// Main module
Programme prog( )
Const:
Chaine : pINVITE <- "Entrez un nombre : "
Réel : pPI <- 3.14159
Var:
Chaine : pTexte
Réel : pR1, pR2, pResultat
Début
rdt( ) // Statement call Module
affiche( ) // Statement call Module
rdt( 123, 234 ) // Statement call Module with arguments
pTexte <- "Aire du disque:" // Statement assignment litteral
afficher( pTexte ) // Statement call Library
pR2 <- 2 * pPI * pR1 // Statement assignment Expression with variables
pResultat <- saisir( ) // Expression call Library
pResultat <- rdt( 123, 234, pResultat ) // Expression call Module NOK : Error DataName rdt
// while is is a ModuleName in propositions !!!!
rdt( 123,234, pResultat )
pTexte <- rdt( gE1 ) + gTITRE
pResultat <- 123 + gE1*gE2 - pR1/pR2 + pPI
pResultat <- pResultat + rdt( pR1, pR2, gE1)
afficher( pINVITE , pResultat)
pR1 <- afficher( pINVITE , pResultat)
Retourne SUCCES
Fin

// Function
Fonction rdt( E: Réel : fp1, fp2, fp3 ) : Réel
Var:
Réel : fRes
Début

fRes <- (fp1 * fp2) / fp3
Retourne fRes
Fin

// Procedure
Procédure affiche( E: Chaine : prInvite, ppp ; Réel : prReal ; S: Booléen : prState)
Var:
Chaine : prTxt
Réel : prRes
Début
prTxt <- prInvite
prRes <- prReal
prState <- VRAI
Fin


But it appears a bug:
• In the list of proposals rtd is seen as a ModuleName, which is correct.
• The error message displays a DataName is expected. This is probably the predicate that causes it but I do not see how to fix this.
Thank you in advance for your assistance.
Re: Algorithmic language project for writing algorithms in French. [message #1730935 is a reply to message #1729454] Sat, 30 April 2016 07:14 Go to previous messageGo to next message
Yves LEDUC is currently offline Yves LEDUCFriend
Messages: 54
Registered: May 2015
Member
Solved by the predicate first.
Re: Algorithmic language project for writing algorithms in French. [message #1741389 is a reply to message #1730935] Wed, 24 August 2016 15:38 Go to previous message
Yves LEDUC is currently offline Yves LEDUCFriend
Messages: 54
Registered: May 2015
Member
Ok is good, thanks
Previous Topic:xText: Maven no class def found error
Next Topic:Strange org.eclipse.emf.ecore.xmi.IllegalValueException: Value 'org.eclipse.emf.ecore.impl.EAttribut
Goto Forum:
  


Current Time: Sun Dec 17 11:45:35 GMT 2017

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

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