Very simple SmaCC grammar for MSE files

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Very simple SmaCC grammar for MSE files

Gustavo Santos
Hi all,

I don't know if someone already did this but I was working with SmaCC from scratch
so I did a very simple parser for MSE files. It parses all right with a Java model
although I need to check and specialize the grammar for what I intend to do.

Cheers,

----

%start Model ;
%left <close>;
%glr;

<whitespace> : \s+ ;
<eol> : \r | \n | \r\n ;
<letter> : [a-zA-Z_] ;
<digit> : [0-9] ;
<integer> : \-? <digit>+ ;
<number> : \-? <digit>+ ( \. <digit>+ ) ? ( [eE] ( \- | \+ ) ? <digit>+ ) ? ;
<string> : \'  [^\']* \' (\' [^\']* \')* ;
<boolean> : true | false ;
<open> : \( ;
<close> : \) ;
<simpleName> : <letter> ( <letter> | <digit> ) * ;
<qualifiedName> : <letter> ( <letter> | <digit> ) * ( \. <letter> ( <letter> | <digit> ) * ) * ;

Model : <open> ElementNodes <close> ;
ElementNodes : ElementNode | ElementNode ElementNodes ;

ElementNode : <open> Name Identifier AttributeNodes <close> ;
Identifier : <open> IdentifierToken Integer <close> ;
IdentifierToken : "id:" 'refToken';

AttributeNodes :  | AttributeNode AttributeNodes ;
AttributeNode : <open> SimpleName ValueNodes <close> ;

ValueNodes : ValueNode | ValueNode ValueNodes ;
ValueNode : Primitive | Reference ;
Primitive : String | Integer | Number | Boolean ;

Reference : IntegerReference | NameReference ;
IntegerReference : <open> ReferenceToken Integer <close>;
NameReference : <open> ReferenceToken QualifiedName <close>;
ReferenceToken : "ref:" 'refToken';

Integer : <integer> 'integer';
Number : <number> 'number' ;
String: <string> 'string';
Boolean: <boolean> 'boolean';
Name : SimpleName | QualifiedName ;
SimpleName : <simpleName> 'simpleName';
QualifiedName : <qualifiedName> 'qualifiedName';

--

_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.list.inf.unibe.ch/listinfo/moose-dev
Reply | Threaded
Open this post in threaded view
|

Re: Very simple SmaCC grammar for MSE files

Stéphane Ducasse
This is cool we should submit it also to the Smaccers
On 19 Sep 2017, at 15:37, Gustavo Santos <[hidden email]> wrote:

Hi all,

I don't know if someone already did this but I was working with SmaCC from scratch
so I did a very simple parser for MSE files. It parses all right with a Java model
although I need to check and specialize the grammar for what I intend to do.

Cheers,

----

%start Model ;
%left <close>;
%glr;

<whitespace> : \s+ ;
<eol> : \r | \n | \r\n ;
<letter> : [a-zA-Z_] ;
<digit> : [0-9] ;
<integer> : \-? <digit>+ ;
<number> : \-? <digit>+ ( \. <digit>+ ) ? ( [eE] ( \- | \+ ) ? <digit>+ ) ? ;
<string> : \'  [^\']* \' (\' [^\']* \')* ;
<boolean> : true | false ;
<open> : \( ;
<close> : \) ;
<simpleName> : <letter> ( <letter> | <digit> ) * ;
<qualifiedName> : <letter> ( <letter> | <digit> ) * ( \. <letter> ( <letter> | <digit> ) * ) * ;

Model : <open> ElementNodes <close> ;
ElementNodes : ElementNode | ElementNode ElementNodes ;

ElementNode : <open> Name Identifier AttributeNodes <close> ;
Identifier : <open> IdentifierToken Integer <close> ;
IdentifierToken : "id:" 'refToken';

AttributeNodes :  | AttributeNode AttributeNodes ;
AttributeNode : <open> SimpleName ValueNodes <close> ;

ValueNodes : ValueNode | ValueNode ValueNodes ;
ValueNode : Primitive | Reference ;
Primitive : String | Integer | Number | Boolean ;

Reference : IntegerReference | NameReference ;
IntegerReference : <open> ReferenceToken Integer <close>;
NameReference : <open> ReferenceToken QualifiedName <close>;
ReferenceToken : "ref:" 'refToken';

Integer : <integer> 'integer';
Number : <number> 'number' ;
String: <string> 'string';
Boolean: <boolean> 'boolean';
Name : SimpleName | QualifiedName ;
SimpleName : <simpleName> 'simpleName';
QualifiedName : <qualifiedName> 'qualifiedName';

--
_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.list.inf.unibe.ch/listinfo/moose-dev

--------------------------------------------
Stéphane Ducasse
03 59 35 87 52
Assistant: Julie Jonas 
FAX 03 59 57 78 50
TEL 03 59 35 86 16
S. Ducasse - Inria
40, avenue Halley, 
Parc Scientifique de la Haute Borne, Bât.A, Park Plaza
Villeneuve d'Ascq 59650
France


_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.list.inf.unibe.ch/listinfo/moose-dev
Reply | Threaded
Open this post in threaded view
|

Re: Very simple SmaCC grammar for MSE files

Nicolas Anquetil

great job gustavo

not directly related but couldn't we switch to ston/json as a serialization format ?

that would allow us to interact more easily with other languages/platforms

nicolas


On 19/09/2017 21:18, Stéphane Ducasse wrote:
This is cool we should submit it also to the Smaccers
On 19 Sep 2017, at 15:37, Gustavo Santos <[hidden email]> wrote:

Hi all,

I don't know if someone already did this but I was working with SmaCC from scratch
so I did a very simple parser for MSE files. It parses all right with a Java model
although I need to check and specialize the grammar for what I intend to do.

Cheers,

----

%start Model ;
%left <close>;
%glr;

<whitespace> : \s+ ;
<eol> : \r | \n | \r\n ;
<letter> : [a-zA-Z_] ;
<digit> : [0-9] ;
<integer> : \-? <digit>+ ;
<number> : \-? <digit>+ ( \. <digit>+ ) ? ( [eE] ( \- | \+ ) ? <digit>+ ) ? ;
<string> : \'  [^\']* \' (\' [^\']* \')* ;
<boolean> : true | false ;
<open> : \( ;
<close> : \) ;
<simpleName> : <letter> ( <letter> | <digit> ) * ;
<qualifiedName> : <letter> ( <letter> | <digit> ) * ( \. <letter> ( <letter> | <digit> ) * ) * ;

Model : <open> ElementNodes <close> ;
ElementNodes : ElementNode | ElementNode ElementNodes ;

ElementNode : <open> Name Identifier AttributeNodes <close> ;
Identifier : <open> IdentifierToken Integer <close> ;
IdentifierToken : "id:" 'refToken';

AttributeNodes :  | AttributeNode AttributeNodes ;
AttributeNode : <open> SimpleName ValueNodes <close> ;

ValueNodes : ValueNode | ValueNode ValueNodes ;
ValueNode : Primitive | Reference ;
Primitive : String | Integer | Number | Boolean ;

Reference : IntegerReference | NameReference ;
IntegerReference : <open> ReferenceToken Integer <close>;
NameReference : <open> ReferenceToken QualifiedName <close>;
ReferenceToken : "ref:" 'refToken';

Integer : <integer> 'integer';
Number : <number> 'number' ;
String: <string> 'string';
Boolean: <boolean> 'boolean';
Name : SimpleName | QualifiedName ;
SimpleName : <simpleName> 'simpleName';
QualifiedName : <qualifiedName> 'qualifiedName';

--
_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.list.inf.unibe.ch/listinfo/moose-dev

--------------------------------------------
Stéphane Ducasse
03 59 35 87 52
Assistant: Julie Jonas 
FAX 03 59 57 78 50
TEL 03 59 35 86 16
S. Ducasse - Inria
40, avenue Halley, 
Parc Scientifique de la Haute Borne, Bât.A, Park Plaza
Villeneuve d'Ascq 59650
France



_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.list.inf.unibe.ch/listinfo/moose-dev

-- 
Nicolas Anquetil -- MCF (HDR)
Project-Team RMod

_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.list.inf.unibe.ch/listinfo/moose-dev
Reply | Threaded
Open this post in threaded view
|

Re: Very simple SmaCC grammar for MSE files

Fuhrmanator
On Wed, Sep 20, 2017 at 10:22 AM, Nicolas Anquetil <[hidden email]> wrote:

not directly related but couldn't we switch to ston/json as a serialization format ?

There is PEG.js that could possibly work to convert MSE to JSON (especially with Gustavo's grammar). There are a couple of online development environments to play with it: http://peg.arcanis.fr/ and https://pegjs.org/online

The Wiki has some sample grammars: https://github.com/pegjs/pegjs/wiki/Useful-Grammars

_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.list.inf.unibe.ch/listinfo/moose-dev
Reply | Threaded
Open this post in threaded view
|

Re: Very simple SmaCC grammar for MSE files

CyrilFerlicot
In reply to this post by Nicolas Anquetil
On Wed, Sep 20, 2017 at 4:22 PM, Nicolas Anquetil
<[hidden email]> wrote:
> great job gustavo
>
> not directly related but couldn't we switch to ston/json as a serialization
> format ?
>
> that would allow us to interact more easily with other languages/platforms
>
> nicolas
>

We discussed this at Esug with Anne, Stephane, Doru and Pavel and this
is a feature we would like. Probably the JSON format to be more
compatible with other languages.

>
> --
> Nicolas Anquetil -- MCF (HDR)
> Project-Team RMod
>
>
> _______________________________________________
> Moose-dev mailing list
> [hidden email]
> https://www.list.inf.unibe.ch/listinfo/moose-dev
>



--
Cyril Ferlicot
https://ferlicot.fr

http://www.synectique.eu
2 rue Jacques Prévert 01,
59650 Villeneuve d'ascq France
_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.list.inf.unibe.ch/listinfo/moose-dev
Reply | Threaded
Open this post in threaded view
|

Re: Very simple SmaCC grammar for MSE files

Stéphane Ducasse
In reply to this post by Nicolas Anquetil
Yes we could :)

Stef

On 20 Sep 2017, at 16:22, Nicolas Anquetil <[hidden email]> wrote:

great job gustavo

not directly related but couldn't we switch to ston/json as a serialization format ?

that would allow us to interact more easily with other languages/platforms

nicolas


On 19/09/2017 21:18, Stéphane Ducasse wrote:
This is cool we should submit it also to the Smaccers
On 19 Sep 2017, at 15:37, Gustavo Santos <[hidden email]> wrote:

Hi all,

I don't know if someone already did this but I was working with SmaCC from scratch
so I did a very simple parser for MSE files. It parses all right with a Java model
although I need to check and specialize the grammar for what I intend to do.

Cheers,

----

%start Model ;
%left <close>;
%glr;

<whitespace> : \s+ ;
<eol> : \r | \n | \r\n ;
<letter> : [a-zA-Z_] ;
<digit> : [0-9] ;
<integer> : \-? <digit>+ ;
<number> : \-? <digit>+ ( \. <digit>+ ) ? ( [eE] ( \- | \+ ) ? <digit>+ ) ? ;
<string> : \'  [^\']* \' (\' [^\']* \')* ;
<boolean> : true | false ;
<open> : \( ;
<close> : \) ;
<simpleName> : <letter> ( <letter> | <digit> ) * ;
<qualifiedName> : <letter> ( <letter> | <digit> ) * ( \. <letter> ( <letter> | <digit> ) * ) * ;

Model : <open> ElementNodes <close> ;
ElementNodes : ElementNode | ElementNode ElementNodes ;

ElementNode : <open> Name Identifier AttributeNodes <close> ;
Identifier : <open> IdentifierToken Integer <close> ;
IdentifierToken : "id:" 'refToken';

AttributeNodes :  | AttributeNode AttributeNodes ;
AttributeNode : <open> SimpleName ValueNodes <close> ;

ValueNodes : ValueNode | ValueNode ValueNodes ;
ValueNode : Primitive | Reference ;
Primitive : String | Integer | Number | Boolean ;

Reference : IntegerReference | NameReference ;
IntegerReference : <open> ReferenceToken Integer <close>;
NameReference : <open> ReferenceToken QualifiedName <close>;
ReferenceToken : "ref:" 'refToken';

Integer : <integer> 'integer';
Number : <number> 'number' ;
String: <string> 'string';
Boolean: <boolean> 'boolean';
Name : SimpleName | QualifiedName ;
SimpleName : <simpleName> 'simpleName';
QualifiedName : <qualifiedName> 'qualifiedName';

--
_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.list.inf.unibe.ch/listinfo/moose-dev

--------------------------------------------
Stéphane Ducasse
03 59 35 87 52
Assistant: Julie Jonas 
FAX 03 59 57 78 50
TEL 03 59 35 86 16
S. Ducasse - Inria
40, avenue Halley, 
Parc Scientifique de la Haute Borne, Bât.A, Park Plaza
Villeneuve d'Ascq 59650
France



_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.list.inf.unibe.ch/listinfo/moose-dev

-- 
Nicolas Anquetil -- MCF (HDR)
Project-Team RMod
_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.list.inf.unibe.ch/listinfo/moose-dev

--------------------------------------------
Stéphane Ducasse
03 59 35 87 52
Assistant: Julie Jonas 
FAX 03 59 57 78 50
TEL 03 59 35 86 16
S. Ducasse - Inria
40, avenue Halley, 
Parc Scientifique de la Haute Borne, Bât.A, Park Plaza
Villeneuve d'Ascq 59650
France


_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.list.inf.unibe.ch/listinfo/moose-dev