Skip to content
Snippets Groups Projects
Commit 73236163 authored by Kylian Fontaine's avatar Kylian Fontaine
Browse files

No commit message

No commit message
parent 1d3c5dfa
No related branches found
No related tags found
No related merge requests found
_build/
\ No newline at end of file
# DSL pour Robotique en essaim
## Getting started
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
## Add your files
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
```
cd existing_repo
git remote add origin https://gitlab.liris.cnrs.fr/kfontaine/dsl-pour-robotique-en-essaim.git
git branch -M main
git push -uf origin main
```
## Integrate with your tools
- [ ] [Set up project integrations](https://gitlab.liris.cnrs.fr/kfontaine/dsl-pour-robotique-en-essaim/-/settings/integrations)
## Collaborate with your team
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
- [ ] [Set auto-merge](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
## Test and Deploy
Use the built-in continuous integration in GitLab.
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
***
# Editing this README
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template.
## Suggestions for a good README
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
## Name
Choose a self-explaining name for your project.
## Description
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
## Badges
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
## Visuals
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
## Installation
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
## Usage
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
## Support
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
## Roadmap
If you have ideas for releases in the future, it is a good idea to list them in the README.
## Contributing
State if you are open to contributions and what your requirements are for accepting them.
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
## Authors and acknowledgment
Show your appreciation to those who have contributed to the project.
## License
For open source projects, say how it is licensed.
## Project status
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
(executable
(public_name dsl)
(name main)
(libraries dsl unix))
open Dsl
let c = Coordonnee.Coord1D 5;;
let c2 = Coordonnee.Coord2D (5,2.5);;
let c3 = Coordonnee.Coord3D (3.8,2.5,8);;
let cwd = Unix.getcwd ();;
let () = print_endline cwd;;
let file_test = "./bin/test"
let desc = Interface.parse_description file_test;;
print_endline (Ast.string_of_description desc);;
print_endline (Coordonnee.string_of_coord string_of_int c);;
print_endline (Coordonnee.string_of_coord string_of_int ~f':string_of_float c2);;
print_endline (Coordonnee.string_of_coord string_of_float ~f':string_of_float ~f'':string_of_int c3)
bin/test 0 → 100644
/*Description environnement et capacité robot*/
Sync := FSYNC
Espace := Anneau 5
Byzantin := 0
Capacite := [(Light : Extern Red, Blue);(Memory: Finite 2);(Rigidity : Flexible 0.5)]
Sensors := [(Range : Limited 5);(Multi : Weak Local);(Opacity: Opaque)]
Robot := Private : Batterie; Temperature; Coordonnee [5;1.8]
Public : Id
/* Possibilité sur attribution des role des robots :
Roles := [(0 : Compagnon);(2 : Byzantin); (5: Byzantin)] id : role_choisie_par_user*/
%%
/*Robogram*/
let c = Obs.coord /*une liste de coordonnee*/
let destination
if c_empty then destination = 00
else destination = Geometry.Barycentre c
return destination
\ No newline at end of file
dsl.opam 0 → 100644
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
synopsis: "A short synopsis"
description: "A longer description"
maintainer: ["Maintainer Name"]
authors: ["Author Name"]
license: "LICENSE"
tags: ["topics" "to describe" "your" "project"]
homepage: "https://github.com/username/reponame"
doc: "https://url/to/documentation"
bug-reports: "https://github.com/username/reponame/issues"
depends: [
"ocaml"
"dune" {>= "3.15"}
"odoc" {with-doc}
]
build: [
["dune" "subst"] {dev}
[
"dune"
"build"
"-p"
name
"-j"
jobs
"@install"
"@runtest" {with-test}
"@doc" {with-doc}
]
]
dev-repo: "git+https://github.com/username/reponame.git"
(lang dune 3.15)
(using menhir 3.0)
(name dsl)
(generate_opam_files true)
(source
(github username/reponame))
(authors "Author Name")
(maintainers "Maintainer Name")
(license LICENSE)
(documentation https://url/to/documentation)
(package
(name dsl)
(synopsis "A short synopsis")
(description "A longer description")
(depends ocaml dune)
(tags
(topics "to describe" your project)))
; See the complete stanza docs at https://dune.readthedocs.io/en/stable/dune-files.html#dune-project
(*DESCRIPTION DE L'ENVIRONNEMENT*)
(** type syncho :
Fsync -> Full synchronisé
Ssync -> Semi synchronisé
Async -> Asynchronisé*)
type synchro =
| Fsync
| Ssync
| Async
(** type espace :
R -> une ligne
Rm -> un millefeuille de ligne (convoie)
R2 -> un plan
R2m -> millefeuille de plan (simplification de R3)
ZnZ -> anneau prennant n -> positions congruantes
*)
type espace =
| R
| Rm
| R2
| R2m
| ZnZ of int
(* type range :
Full -> Full range
Limited -> range limité a un delta
K_rand -> range limité a un delta + capable de voir k robots au dela de delta choisie rand
K_enemy -> range limité a un delta + capable de voir k robots au dela de delta choisie par un ennemie*)
type range =
| Full
| Limited of int
| K_rand of int * int
| K_enemy of int * int
(* type multiplicite :
No -> Pas de multiplicité
Weak -> Multiplicité faible : sait si 1 ou plusieurs robots mais pas combien de robot
Strong -> Multiplicité forte : connait le nombre de robot
Local -> robot ne connait que sur sa position
Global -> robot connait pour toute les positions observés
*)
type multiplicite =
| No
| Weak_Local
| Strong_Local
| Weak_Global
| Strong_Global
(* type light : Les lumieres sont indiqué par leur nombre FIXME: Interessant? ou vaut mieux avoir un type couleur et les lumieres pourraient etre une liste de couleur
Intern -> Les lumieres vu par le robot lui meme
Extern -> Les lumieres vu par les robots autre que lui meme
All -> Les lumieres vu par tout les robots lui meme compris
Vaut mieux liste de string pour chaque couleurs ou autre chose, un simple int correspondant au nombre de lumiere ?
*)
(*type lumiere =
| Interne of int
| Externe of int
| All of int
*)
type color =
| Red
| Blue
| Yellow
| Green
| Purple
| Orange
type lights =
| Intern of color list
| Extern of color list
| All of color list
(* type memoire :
Oblivious -> memoire reset a chaque Look-Compute-Move
Finite -> memoire persistante entre deux Look-Compute-Move
Infinite -> se rappel de tout
*)
type memory =
| Oblivious
| Finite of int
| Infinite
(* type opacite :
Opaque -> Les robots sont opques
Transparant -> Les robots sont transparant
SemiOpaque n -> Transparant a partir d'une distance n ? (aucune idée des decomposition possible des probleme)
*)
type opacity =
| Opaque
| Transparent
(*type rigidite :
Rigide -> les robots atteignent leur destination final, ils ne sont pas interrompu pendant leur mouvement
Flexible of float -> Les robots peuvent etre interrompu pendant leur mouvement, ils n'atteignent pas forcement leur
destinations final cependant il parcourt au minimum une distance delta
*)
type rigidite =
| Rigide
| Flexible of float
(* type capacite : regroupement des capacités des robots*)
type capacite =
| Lights of lights
| Memory of memory
| Rigidite of rigidite
(* type sensor : regroupement des capteurs des robots *)
type sensor =
| Range of range
| Opacity of opacity
| Multi of multiplicite
(** type value : valeur pouvant etre utilisant dans les champs field*)
type value =
| Empty
| Int of int
| Float of float
| String of string
| Liste of value list
(** type field : type correspondant au champs que l'utilisateur va renseigner pour le robot*)
type field =
| Private of (string * value)
| Public of (string * value)
type information =
| Sync of synchro
| Espace of espace
| Byzantin of int
| Capacites of capacite list
| Sensors of sensor list
| Robot of field list
(*ROBOGRAM*)
type binop =
| Plus
| Minus
| Mult
| Div
| And
| Or
| Sup
| Inf
| Equal
| Diff
(*tail::head au lieu de head::tail pour optimisation mémoire, éviter les empilements inutiles
(((vide,x),y),z)
pour le set x,y,z*)
type 'a set =
| Vide
| Some of ('a set) * 'a
(*type pour l'utilisation de point avec obs, self, les package etc*)
type objet =
| Self
| Obs
| Geometry
type expr =
| None (*variable declaré mais non défini*)
| Bool of bool
| Cst of int
| Cstf of float
| BinOp of expr * binop * expr
| Cond of expr * expr * expr
| Boucle of expr * expr
| Var of string (* est ce qu'on ratache un type a la variable?*)
| Let of string * expr
| Affectation of string * expr (* variable deja declaré avec let et on change sa valeur*)
| Set of expr set (* FIXME: Est ce qu'on veut vraiment un set d'expression? donc avoir des possibilités tel que : [Boucle(cond, e); Cst 1;....] *)
| LengthSet of expr (* lors de l'interpretation qu'on checkera que l'expression donné soit bien un set*)
| PushSet of expr * expr
| Point of objet * string
(* Une description c'est 1: description de l'environnement et des capacites des robot
2: robogram *)
type description = Description of ((information list) * (expr list))
(*FONCTION SUR LES SETS*)
(** [length s] retourne la longueur du set [s]
@param [s] 'a set dont on veut la longueur
@return int la longueur du set*)
let rec length_set (s:'a set): int =
match s with
| Vide -> 0
| Some (s,_) -> 1 + (length_set s)
(*[push s e] ajoute un element e au set s
@param s de type 'a set
@param e de type 'a
@return un set correspondant au set s avec l'ajout de e *)
let push (s:'a set) (e : 'a) :'a set = Some(s,e)
(*CONVERTION EN STRING*)
let rec string_of_set (s: 'a set) (f : 'a -> string) : string =
match s with
| Vide -> "Vide"
| Some (s',e) -> "("^ string_of_set s' f ^"," ^ f e ^")"
(** [string_of_expression e] Permet d'obtenir un string correspondant a l'expression [e]
@param [e] expression dont on souhaite le string
@return string correspondant a l'expression [e]
*)
let rec string_of_expression (e : expr) : string =
match e with
| None -> "None"
| Bool b -> string_of_bool b
| Cst i -> string_of_int i
| Cstf f -> string_of_float f
| BinOp(x,op ,y) -> (match op with
| Plus -> string_of_expression(x) ^ " + " ^string_of_expression(y)
| Minus -> string_of_expression(x) ^ " - " ^string_of_expression(y)
| Mult -> string_of_expression(x) ^ " * " ^string_of_expression(y)
| Div -> string_of_expression(x) ^ " / " ^string_of_expression(y)
| And -> string_of_expression(x) ^ " && " ^string_of_expression(y)
| Or -> string_of_expression(x) ^ " || " ^string_of_expression(y)
| Sup -> string_of_expression(x) ^ " > " ^string_of_expression(y)
| Inf -> string_of_expression(x) ^ " < " ^string_of_expression(y)
| Equal -> string_of_expression(x) ^ " == " ^string_of_expression(y)
| Diff -> string_of_expression(x) ^ " != " ^string_of_expression(y)
)
| Var v -> v
| Cond(c,e1,e2) -> "if (" ^string_of_expression c ^ ") then \n {" ^string_of_expression e1^ "} \n else {" ^string_of_expression e2 ^ "}"
| Boucle(c,e1) -> "while " ^ string_of_expression c ^ " do \n \t" ^ string_of_expression e1
| Affectation(v,e) -> v ^ " prend la valeur " ^ string_of_expression e
| Set s -> string_of_set s string_of_expression ^" longueur du set : " ^ string_of_int (length_set s)
| Let (v,e) -> "Déclaration de la variable " ^ v ^ " avec definition : " ^ string_of_expression e
| Point (o,f) -> (match o with
|Self -> "Valeur du champs "^ f^ " de Self"
|Obs -> "Valeur du champs "^ f^ " de Observation"
|Geometry -> "Fonction " ^f ^ " du Package Geometry")
| LengthSet s -> (match s with
| Set s' -> "Taille de "^string_of_expression s ^ " : " ^ string_of_int (length_set s')
| Var s' -> "Taille de "^string_of_expression s ^ " : Implementation de la recupération du set a la variable" ^ s' ^" non implementé"
| _ -> "Pas un set")
| PushSet (e,s)-> (match s with
| Set s' -> "Push "^string_of_expression e ^ " dans le set " ^ string_of_expression s ^ " : " ^ string_of_expression (Set(push s' e))
| Var _ -> "Push "^string_of_expression e ^ " dans le set " ^ string_of_expression s ^ " : "
| _ -> "Pas un set")
(* | _ -> "501 Not implemented"*)
let string_of_synchro (s:synchro) : string =
match s with
| Fsync -> "Full Synchro"
| Ssync -> "Semi Synchro"
| Async -> "Asynchro"
let string_of_espace (e:espace) : string =
match e with
| R -> "R"
| Rm -> "Rm"
| R2 -> "R2"
| R2m ->"R2m"
| ZnZ n -> "Z/"^ string_of_int n ^"Z"
let string_of_color (c : color) : string =
match c with
| Red -> "Red"
| Blue -> "Blue"
| Yellow -> "Yellow"
| Green -> "Green"
| Purple -> "Purple"
| Orange -> "Orange"
let string_of_capacite (c: capacite) : string =
match c with
| Lights l -> (match l with
| Intern l' -> "Lights Intern : " ^ String.concat ", " (List.map string_of_color l')
| Extern l' -> "Lights Extern : "^ String.concat ", " (List.map string_of_color l')
| All l' -> "Lights All : " ^ String.concat ", " (List.map string_of_color l'))
| Memory m -> (match m with
| Oblivious -> "Memory: Oblivious"
| Finite i -> "Memory: Finite " ^ string_of_int i
| Infinite -> "Memory: Infinite")
| Rigidite r ->(match r with
| Rigide -> "Rigidity: Rigide"
| Flexible d -> "Rigidity: Flexible d'une distance delta = " ^ string_of_float d)
(*let string_of_capacites (c: capacites) : string =
let string_of_pair (s, i) = s ^ ": " ^ string_of_capacite i in
String.concat "; \n " (List.map string_of_pair c)*)
let string_of_sensor (s : sensor) : string =
match s with
| Range r -> (match r with
| Full -> "Range Full"
| Limited x -> "Range Limité a : " ^ string_of_int x
| K_rand(x,y) -> "Range K_rand limité a : " ^ string_of_int x ^ " et k = " ^ string_of_int y
| K_enemy(x,y) -> "Range K_enemy limité a : " ^ string_of_int x ^ " et k = " ^ string_of_int y)
| Multi m -> (match m with
| No -> "Multiplicity Aucune multiplicité"
| Weak_Local -> "Multiplicity Faible local"
| Strong_Local -> "Multiplicity Forte local"
| Weak_Global -> "Multiplicity Faible global"
| Strong_Global -> "Multiplicity Forte global")
| Opacity o -> (match o with
| Opaque -> "Opacity Opaque"
| Transparent -> "Opacity Transparent")
let rec string_of_value (v : value) : string =
match v with
| Empty -> "None"
| Int i -> string_of_int i
| String s -> s
| Float f -> string_of_float f
| Liste l -> "[" ^String.concat "; " (List.map string_of_value l) ^"]"
let string_of_field (f : field) : string =
match f with
| Private (s,v)-> "Private: "^s^"->"^ string_of_value v
| Public (s,v) -> "Public: "^s^"->"^ string_of_value v
let rec string_of_description (desc:description) : string =
match desc with
| Description (infos,robogram) ->
"Description environnement:\n" ^String.concat "\n" (List.map string_of_information infos)
^"\nRobogram : \n " ^ String.concat "\n" (List.map string_of_expression robogram)
and string_of_information (info: information) : string =
match info with
| Sync s -> "Sync: " ^ (string_of_synchro s)
| Espace e -> "Espace: " ^ (string_of_espace e)
| Byzantin b -> string_of_int b ^" Byzantin(s)"
| Capacites c -> "Capacite: [" ^ String.concat "; " (List.map string_of_capacite c) ^ " ]"
| Sensors s -> "Sensors: [" ^ String.concat "; " (List.map string_of_sensor s) ^ "] "
| Robot r-> "Robot : ["^ String.concat "; " (List.map string_of_field r) ^ "]"
(** [info_sync i] verifie qu'une information est une information sur la synchronisation
@param i information
@return bool *)
let info_sync (i : information):bool =
match i with
| Sync _ -> true
| _ -> false
(** [info_espace i] verifie qu'une information est une information sur l'espace
@param i information
@return bool *)
let info_espace (i : information):bool =
match i with
| Espace _ -> true
| _ -> false
(** [check_description d] verifie que la description [d] possède bien les informations minimales
attendu pour une description et que chaque type d'information soit unique
(deux définition de l'espace le quel choisir ?...)
@param [d] description à vérifier
@return true si la description repond aux critères false sinon
TODO: A finir/ utilisation de valeur par defaut si non fourni? pourquoi pas
*)
let check_description (d : description) :bool =
let unique f d = List.length (List.filter f d) = 1
in
match d with
| Description (d',_) -> if not(unique info_sync d')
then (print_endline "Probleme de definition de la synchronisation"; false)
else (
if not(unique info_espace d')
then (print_endline "Probleme de definition de l'espace";false)
else true
) ;;
type ('a,'b,'c) coord =
| Coord1D of 'a
| Coord2D of 'a * 'b
| Coord3D of 'a * 'b * 'c
let string_of_coord (string_of_a: 'a -> string)
?(f' = fun _ -> "")
?(f'' = fun _ -> "")
(c:('a,'b,'c) coord) : string =
match c with
| Coord1D x -> string_of_a x
| Coord2D (x,y) -> string_of_a x ^"; "^f' y
| Coord3D (x,y,z) -> string_of_a x^"; "^f' y^"; "^f'' z
\ No newline at end of file
(ocamllex lexer)
(menhir
(modules parser))
(library
(name dsl))
(** [parse f filename] est une fonction qui prend en paramètres une fonction [f] et une chaîne de caractères [filename].
Elle utilise un analyseur lexical pour convertir la chaîne de caractères en un flux de tokens,
puis utilise la fonction [f] pour analyser les tokens et renvoyer le résultat.
Si une erreur de parsing se produit, une exception de type [Failure] est levée avec le message "Parse error".
@param [f] fonction d'analyse des tokens
@param [filename] string correspondant au chemin du fichier a parser.
@return L'arbre syntaxique résultant du parsing.*)
let parse_file f filename =
let in_channel = open_in filename in
let lexbuf = Lexing.from_channel in_channel in
try
let result = f Lexer.token lexbuf in
Lexing.set_filename lexbuf filename;
close_in in_channel;
result
with Parser.Error ->
close_in in_channel;
raise (Failure ("Invalid Syntax line " ^ string_of_int !Lexer.numero_ligne ^". Problem close to '" ^ Lexing.lexeme lexbuf ^"'"))
let parse_description filename =
parse_file Parser.description filename
\ No newline at end of file
{
open Parser
let numero_ligne = ref 1 (*Permet la mutation, numero_ligne permet juste remonter la ligne qui pose une erreur*)
}
let digit = ['0' - '9']
let integer = digit+
let float = integer '.' integer
let alpha = ['a'-'z' 'A'-'Z']
let space = [' ' '\t']+
let variable = (alpha | integer | '_')+
rule token = parse
| "Sync" {SYNC}
| "FSYNC" {FSYNC}
| "SSYNC" {SSYNC}
| "ASYNC" {ASYNC}
| "Espace" {ESPACE}
| "R" {R}
| "Rm" {RM}
| "R2" {R2}
| "R2m" {R2M}
| "Anneau" {ANNEAU}
| "Byzantin" {BYZANTIN}
| "Capacite" {CAPACITE}
| "Sensors" {SENSORS}
| "Robot" {ROBOT}
| "Private" {PRIVATE}
| "Public" {PUBLIC}
| "Range" {RANGE}
| "Full" {FULL}
| "Limited" {LIMITED}
| "K_rand" {K_RAND}
| "K_enemy" {K_ENEMY}
| "Multi" {MULTI}
| "No" {NO_MEM}
| "Weak Local" {WEAKL}
| "Strong Local" {STRONGL}
| "Weak Global" {WEAKG}
| "Strong Global" {STRONGG}
| "Memory" {MEMOIRE}
| "Light" {LUMIERE}
| "Intern" {INTERNE}
| "Extern" {EXTERNE}
| "Red" {RED}
| "Blue" {BLUE}
| "Yellow" {YELLOW}
| "Green" {GREEN}
| "Orange" {ORANGE}
| "Purple" {PURPLE}
| "Oblivious" {OBLIVIOUS}
| "Finite" {FINITE}
| "Infinite" {INFINITE}
| "Opacity" {OPACITY}
| "Opaque" {OPAQUE}
| "Transparent" {TRANSPARENT}
| "Rigidity" {RIGIDITY}
| "Rigide" {RIGIDE}
| "Flexible" {FLEXIBLE}
| "[" {BRACKETOPEN}
| "]" {BRACKETCLOSE}
| "." {POINT}
| ":" {COLON}
| "::" {PUSH}
| ";" {SEMICOLON}
| "," {COMMA}
| "(" {PARENOPEN}
| ")" {PARENCLOSE}
| "%%" {SEPARATOR}
| "if" {IF}
| "then"{THEN}
| "else"{ELSE}
| "true" | "false" {BOOLEAN (bool_of_string (Lexing.lexeme lexbuf))}
| "let" {LET}
| "=" {AFFECT}
| "while" {WHILE}
| "do" {DO}
| ":=" {IS}
| '+' {PLUS}
| '-' {MINUS}
| '*' {MULT}
| '/' {DIV}
| "&&" {AND}
| "||" {OR}
| '>' {SUP}
| '<' {INF}
| "==" {EQUAL}
| "!=" {DIFF}
| "/*" {comment lexbuf}
| "Self" {SELF}
| "Obs" {OBS}
| "Geometry" {GEOMETRY}
| integer {INT (int_of_string (Lexing.lexeme lexbuf))}
| float {FLOAT (float_of_string(Lexing.lexeme lexbuf) )}
| variable {VARIABLE (Lexing.lexeme lexbuf)}
| space {token lexbuf}
| "\n" {numero_ligne := !numero_ligne + 1 ; token lexbuf}
| eof {EOF}
| _ {raise (Failure ("Character not allowed in source text: '" ^
Lexing.lexeme lexbuf ^ "'"))}
and comment = parse
| "*/" {token lexbuf}
| "\n" {numero_ligne := !numero_ligne + 1 ; comment lexbuf}
| _ {comment lexbuf}
\ No newline at end of file
%{
open Ast
%}
%token EOF
%token <int> INT
%token <float> FLOAT
%token IS
%token SYNC FSYNC SSYNC ASYNC
%token ESPACE R RM R2 R2M ANNEAU
%token BYZANTIN
%token CAPACITE SENSORS
%token RANGE FULL LIMITED K_RAND K_ENEMY
%token MULTI NO_MEM WEAKL STRONGL WEAKG STRONGG
%token LUMIERE INTERNE EXTERNE ALL RED BLUE YELLOW GREEN PURPLE ORANGE
%token OPACITY OPAQUE TRANSPARENT
%token MEMOIRE OBLIVIOUS FINITE INFINITE
%token RIGIDITY RIGIDE FLEXIBLE
%token COLON BRACKETOPEN BRACKETCLOSE SEMICOLON PARENOPEN PARENCLOSE COMMA
%token POINT SELF OBS GEOMETRY
%token ROBOT PUBLIC PRIVATE
%token SEPARATOR
%token <bool> BOOLEAN
%token <string> VARIABLE
%token IF THEN ELSE
%token WHILE DO
%token LET AFFECT
%token PLUS MINUS MULT DIV AND OR
%token SUP INF EQUAL DIFF
%token LENGTH PUSH
%nonassoc AFFECT
%left PLUS MINUS
%left MULT DIV
%left OR
%left AND
%nonassoc SUP INF EQUAL DIFF
%nonassoc ELSE
%nonassoc DO
%nonassoc LENGTH
%nonassoc PUSH
%type <Ast.description> description
%start description
%%
description :
| information* SEPARATOR robogram EOF {Description ($1,$3)}
/* DESCRIPTION DE L'ENVIRONNEMENT*/
information :
/* Sync := s */
| SYNC IS s = sync {Sync s}
/* Espace := e */
| ESPACE IS e = espace {Espace e}
/* Capacite := [(...:...);(...:...);...]*/
| CAPACITE IS l = list_capa {Capacites l}
/* Sensors := [(....:...);(...:...);...] */
| SENSORS IS l = list_sensors {Sensors l}
/* Robot := Private ....
Public .... */
| ROBOT IS r = list_field {Robot r}
/* Byzantin := entier*/
| BYZANTIN IS i = INT {Byzantin i}
/*plusieurs liste, peut etre trouver une solution pour une generalisation?
mais si generaliser -> on pourrais ecrire (Range : limited ..) dans la liste Capacite ou field
et ce qu'on veut que ce soit une erreur ici, ou plus tard?*/
list_capa :
| BRACKETOPEN elements_list_capa BRACKETCLOSE {$2}
elements_list_capa :
| {[]}
| capacite {$1::[]} /* permet de ne pas mettre ; au debut */
| elements_list_capa SEMICOLON capacite {$3::$1} /* trouver solution pour avoir []::... au lieu de ...::[]*
et pour la semicolon pour qu'elle soit entre deux pair_capa*/
list_sensors :
| BRACKETOPEN elements_list_sensors BRACKETCLOSE {$2}
elements_list_sensors :
| {[]}
| sensor {$1::[]}
| elements_list_sensors SEMICOLON sensor {$3::$1}
list_field :
| PRIVATE COLON l1 = elements_private PUBLIC COLON l2 = elements_public {l1@l2}
elements_private :
| {[]}
| field {(Private $1)::[]}
| elements_private SEMICOLON field {(Private $3)::$1}
elements_public :
| {[]}
| field {(Public $1)::[]}
| elements_public SEMICOLON field {(Public $3)::$1}
%inline sync :
/*Fully synchro*/
| FSYNC {Fsync}
/*Semi Synchro*/
| SSYNC {Ssync}
/*Assynchro*/
| ASYNC {Async}
%inline espace :
/* Espace R */
| R {R}
/*Esapce R en millefeuille*/
| RM {Rm}
/*Espace RxR */
| R2 {R2}
/*Espace RxR en millefeuille*/
| R2M {R2m}
/*Anneau ZnZ avec n donnée*/
| ANNEAU n = INT {ZnZ(n)}
%inline capacite :
/*(Lumiere : l) */
| PARENOPEN LUMIERE COLON l = lights PARENCLOSE {Lights l}
/*(Memoire : m)*/
| PARENOPEN MEMOIRE COLON m = memoire PARENCLOSE {Memory m}
/*(Rigidite : r)*/
| PARENOPEN RIGIDITY COLON r = rigidite PARENCLOSE {Rigidite r}
%inline sensor :
/*(Multi : m) */
| PARENOPEN MULTI COLON m = multi PARENCLOSE {Multi m}
/*(Range : r) */
| PARENOPEN RANGE COLON r = range PARENCLOSE{Range r}
/*(Opacite : o)*/
| PARENOPEN OPACITY COLON o = opacite PARENCLOSE {Opacity o}
%inline field :
| s = VARIABLE v = value {(s,v)}
value_list :
| value {$1::[]}
| value_list SEMICOLON value {$3::$1}
value :
| {Empty}
|i = INT {Int i}
|f = FLOAT {Float f}
|s = VARIABLE {String s}
| BRACKETOPEN value_list BRACKETCLOSE {Liste $2}
lights:
/*Nombre de lumiere interne -> visible que par le robot*/
| INTERNE i = color_list {Intern i}
/*Nombre de lumiere externe -> visible que par les autres robots*/
| EXTERNE i = color_list {Extern i}
/*Nombre de lumiere visible par tous */
| ALL i = color_list {All i}
color_list :
| l = color {[l]}
| l = color COMMA ll = color_list {l::ll}
%inline color :
| RED {Red}
| BLUE {Blue}
| YELLOW {Yellow}
| GREEN {Green}
| PURPLE {Purple}
| ORANGE {Orange}
%inline range :
/*Range maximal */
| FULL {Full}
/*Range Limité a une distance r*/
| LIMITED r = INT {Limited r}
/*Limite a une distance r et k ,un nombre random, de robot au dela de r*/
| K_RAND r = INT k = INT {K_rand(r,k)}
/*Limite a une distance r et k ,un nombre choisie par l'ennemie, de robot au dela de r*/
| K_ENEMY r = INT k = INT {K_enemy(r,k)}
%inline multi :
/* Pas de multiplicité */
| NO_MEM {No}
/*Multiplicité faible local -> 1 robot ou des robots la ou je suis*/
| WEAKL {Weak_Local}
/*Multiplicité forte local -> connait le nombre de robot la ou je suis*/
| STRONGL {Strong_Local}
/* Multiplicité faible global -> 1 robot ou des robots partout*/
| WEAKG {Weak_Global}
/*Multiplicité forte local -> connait le nombre de robot partout*/
| STRONGG {Strong_Global}
%inline memoire :
/*Aucune mémoire*/
| OBLIVIOUS {Oblivious}
/*Mémoire que du coup précédent*/
| FINITE i = INT {Finite i}
/*Mémoire de tout */
| INFINITE {Infinite}
%inline opacite:
/*Autres robots ne peuvent pas voir derriere lui*/
| OPAQUE {Opaque}
/*Autres robots peuvent voir derriere lui*/
| TRANSPARENT {Transparent}
%inline rigidite:
| RIGIDE {Rigide}
| FLEXIBLE d = FLOAT {Flexible d}
/*DESCRIPTION DU ROBOGRAM*/
robogram:
| expression * {$1}
expression:
/*(e)*/
| PARENOPEN e = expression PARENCLOSE {e}
/*booleen*/
| b = BOOLEAN {Bool b}
/*entier*/
| i = INT {Cst i}
/*flottant*/
| f = FLOAT {Cstf f}
/*if e1 then e2 else e3*/
| IF e1 = expression THEN e2 = expression ELSE e3 = expression {Cond(e1,e2,e3)}
/*nom_variable*/
| v = VARIABLE {Var v}
/*e1 binop e2 avec binop appartient a {+ ; - ; * ; / ; || ; &&; == ; != ; < ; > ;*/
| e1 = expression op = binop e2 = expression {BinOp(e1,op,e2)}
/* while (cond) do e*/
| WHILE PARENOPEN cond= expression PARENCLOSE DO e = expression {Boucle(cond,e)}
/*let nom_variable */
| LET v = VARIABLE {Let(v,None)}
/*let nom_variable = e*/
| LET v = VARIABLE AFFECT e= expression {Let(v,e)}
/*nom_variable = e*/
| v = VARIABLE AFFECT e = expression {Affectation(v,e)}
/*[a;z;e;r;t....]*/
| BRACKETOPEN s = set BRACKETCLOSE {Set s}
/* e::[a;z] */
| e = expression PUSH s = expression {PushSet(e,s)}
| LENGTH s = expression {LengthSet s}
/*X.y*/
| x = objet POINT e = VARIABLE {Point(x,e)}
set :
| e = expression SEMICOLON s = set {Some(s,e)}
| e = expression {Some(Vide,e)}
| {Vide}
%inline binop :
| PLUS {(*Format.eprintf "PLUS ";*) Plus}
| MINUS {Minus}
| MULT {Mult}
| DIV {Div}
| SUP {Sup}
| INF {Inf}
| EQUAL {Equal}
| DIFF {Diff}
| AND {And}
| OR {Or}
%inline objet:
| SELF {Self}
| OBS {Obs}
| GEOMETRY {Geometry}
\ No newline at end of file
(test
(name dsl)
(libraries dsl unix))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment