Add support for EBNF

Extended Backus–Naur form ([EBNF][]) is a metalanguage used to specify
language grammars.

[EBNF]: https://en.wikipedia.org/wiki/Extended_Backus–Naur_form
This commit is contained in:
René Schwaiger
2016-10-31 14:51:51 +01:00
parent 417239004a
commit 33899b9d6b
9 changed files with 184 additions and 0 deletions

24
samples/EBNF/grammar.ebnf Normal file
View File

@@ -0,0 +1,24 @@
(*
Source: https://github.com/sunjay/lion
License: MIT
*)
Statement = ( NamedFunction | AnonymousFunction | Assignment | Expr ) , "\n" ;
Expr = AnonymousFunction | Term | "(" , Expr , ")" ,
{ AnonymousFunction | Term | "(" , Expr , ")" } ;
Assignment = Symbol , "=" , Expr ;
AnonymousFunction = "\" , FunctionRHS ;
NamedFunction = Symbol , FunctionRHS ;
FunctionRHS = FunctionParams , "=" , FunctionBody ;
FunctionParams = FunctionParam , { FunctionParam } ;
FunctionParam = Term ;
FunctionBody = Expr ;
Term = Symbol | Number | SingleWordString ;
SingleWordString = '"' , Symbol , '"' ;
(* Symbol is a collection of valid symbol characters, not defined here *)
(* Number is a valid numeric literal *)

View File

@@ -0,0 +1,40 @@
(*
Source: https://github.com/io7m/jsom0
License: ISC
*)
name =
"name" , string , ";" ;
diffuse =
"diffuse" , real , real , real , ";" ;
ambient =
"ambient" , real , real , real , ";" ;
specular =
"specular" , real , real , real , real , ";" ;
shininess =
"shininess" , real , ";" ;
alpha =
"alpha" , real , ";" ;
mapping =
"map_chrome" | "map_uv" ;
texture =
"texture" , string , real , mapping , ";" ;
material =
"material" , ";" ,
name ,
diffuse ,
ambient ,
specular ,
shininess ,
alpha ,
[ texture ] ,
"end" , ";" ;

61
samples/EBNF/object.ebnf Normal file
View File

@@ -0,0 +1,61 @@
(*
Source: https://github.com/io7m/jsom0
License: ISC
*)
vertex_p3n3_name =
"vertex_p3n3" ;
vertex_p3n3t2_name =
"vertex_p3n3t2" ;
vertex_type =
vertex_p3n3_name | vertex_p3n3t2_name ;
vertex_position =
"position" , real , real , real , ";" ;
vertex_normal =
"normal" , real , real , real , ";" ;
vertex_uv =
"uv" , real , real , ";" ;
vertex_p3n3 =
vertex_p3n3_name , vertex_position , vertex_normal , "end" , ";" ;
vertex_p3n3t2 =
vertex_p3n3t2_name , vertex_position , vertex_normal , vertex_uv , "end" , ";" ;
vertex =
vertex_p3n3 | vertex_p3n3t2 ;
vertex_array =
"array" , positive , vertex_type , { vertex } , "end" , ";" ;
vertices =
"vertices" , ";" , vertex_array , "end" , ";" ;
triangle =
"triangle" , natural , natural , natural , ";" ;
triangle_array =
"array" , positive, "triangle" , { triangle } , "end" , ";" ;
triangles =
"triangles" , ";" , triangle_array , "end" , ";" ;
name =
"name" , string , ";" ;
material_name =
"material_name" , string , ";" ;
object =
"object" , ";" ,
name ,
material_name ,
vertices ,
triangles ,
"end" , ";" ;

20
samples/EBNF/types.ebnf Normal file
View File

@@ -0,0 +1,20 @@
(*
Source: https://github.com/io7m/jsom0
License: ISC
*)
digit_without_zero =
"1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ;
digit =
"0" | digit_without_zero ;
positive =
digit_without_zero , { digit } ;
natural =
"0" | positive ;
real =
[ "-" ] , digit , [ "." , { digit } ] ;