Commit ca24eea7 authored by POGODALLA Sylvain's avatar POGODALLA Sylvain

compilation for acg doesn't work yet

parent 280903ec
# Version 1.5.0
## The acgc.opt/acgc compiler and the acg.opt/acg interpreter:
* Removed the dependency to BOLT (replaced by Logs) and dypgen (replaced by menhir)
* Some syntax changes:
1. Prefix operators have the highest priority
2. Infix operators have a higher priority than application (*Note: this may break existing code*)
3. An associativity property (none, left, right) can be set to infix operators (left is the default), and a precedence level as well
# Version 1.4.0
## The acgc.opt/acgc compiler and the acg.opt/acg interpreter:
* Improved performance by better logging management (for debug)
......
......@@ -146,8 +146,18 @@ if it has to."
(add-hook 'acg-mode-hook 'acg-set-compile-command)
(require 'compile)
;; Add colors to the emacs buffer
(require 'ansi-color)
(defun colorize-compilation-buffer ()
(toggle-read-only)
(ansi-color-apply-on-region compilation-filter-start (point))
(toggle-read-only))
(add-hook 'compilation-filter-hook 'colorize-compilation-buffer)
;; find the line of the error
(defconst acg-error-regexp
;; "^[^\0-@]+ \"\\([^\"\n]+\\)\", [^\0-@]+ \\([0-9]+\\)[-,:]"
......
(* This files gives an example of how to use the ACG toolkit to illustrate
Montague's semantics on a bilingual fragment (French, English). *)
(* First we define the syntactic categories and the syntactic terms. *)
signature syntax =
(* the syntactic types *)
......@@ -66,7 +65,7 @@ lexicon realisation_francais (syntax) : francais =
returns the concatenation subject+loves+object *)
AIMER := lambda o s.s + aime + o;
VOULOIR_CV := lambda vp. Lambda s. s + veut + vp e;
VOULOIR_CV := lambda vp. Lambda s. s + veut + (vp e);
VOULOIR_SC := lambda sc s. s + veut + sc;
CHAQUE := lambda n P. P (chaque + n);
......@@ -112,7 +111,7 @@ lexicon realisation_anglais (syntax) : anglais =
(* LOVE is interpreted as a function taking two arguments. The first one is the object and the second one is the subject. It returns the concatenation subject+loves+object *)
AIMER := lambda o s.s + loves + o;
VOULOIR_CV := lambda vp. Lambda s. s + wants + to + vp e;
VOULOIR_CV := lambda vp. Lambda s. s + wants + to + (vp e);
VOULOIR_SC := lambda sc s. s + wants + sc;
CHAQUE := lambda n P. P (every + n);
......
This diff is collapsed.
%{
open Logic
open AcgData.Environment
open Script_lexer
let id = fun x -> x
let pr s = Logs.app (fun m -> m "%s" s)
......@@ -58,123 +57,320 @@
let ctx' = F.wait ctx in
(ctx',e)}
| WAIT HELP l = SEMICOLONN {
fun ctx e ->
let () = echo ctx l in
let () = F.help (F.Help (Some F.Wait)) in
ctx,e}
| DONT WAIT l = SEMICOLONN {
fun ctx e ->
let () = echo ctx l in
let ctx' = F.dont_wait ctx in (ctx',e)}
| DONT WAIT HELP l = SEMICOLONN {
fun ctx e ->
let () = echo ctx l in
let () = F.help (F.Help (Some F.Dont_Wait)) in
ctx,e}
| params = LOAD_DATA {
fun ctx e ->
let s,loc,l = params in
let () = echo ctx l in
let e' = F.load F.Data s (F.dirs ctx) e in
ctx,e'
}
| LOAD_OBJECT<s,loc,l> {fun e -> let () = echo dyp.global_data l in
let _,_,incl,_ = dyp.global_data in
F.load F.Object s incl e}
| LOAD_SCRIPT<s,loc,l> {fun e -> let () = echo dyp.global_data l in
let _,_,includes,_ = dyp.global_data in
let new_env = F.load (F.Script (snd dyp.last_local_data)) s includes e in
new_env}
| LIST SEMICOLONN<l> {fun e -> let () = echo dyp.global_data l in let () = F.list e in e}
| SELECT IDENTT<name,loc> SEMICOLONN<l> {fun e -> let () = echo dyp.global_data l in F.select name loc e}
| UNSELECT SEMICOLONN<l> { let () = echo dyp.global_data l in F.unselect}
| TRACE SEMICOLONN<l> { let () = echo dyp.global_data l in fun e -> let () = F.trace () in e}
| DONT TRACE SEMICOLONN<l> { let () = echo dyp.global_data l in fun e -> let () = F.dont_trace () in e}
| optional_ident<name> PRINT<p> SEMICOLONN<l> {
let () = echo dyp.global_data l in fun e ->
let loc =
match name with
| None -> p
| Some (_,l) -> l in
match name with
| None -> let () = F.print e loc in e
| Some (n,l) -> let () = F.print ~name:n e loc in e}
| optional_idents<names> ANALYSE<t,l,line> { let () = echo dyp.global_data line in fun e ->
match names with
| [] -> let () = F.analyse e t l in e
| _ -> let () = F.analyse ~names e t l in e}
| optional_idents<names> CHECK<t,l,line> {
let () = echo dyp.global_data line in fun e ->
match names with
| [] -> let () = F.check e t l in e
| _ -> let () = F.check ~names e t l in e}
| optional_idents<names> REALIZE<t,l,line> {
let () = echo dyp.global_data line in fun e ->
match names with
| [] -> let () = F.realize ?svg_output:(svg dyp.global_data) e t l in e
| _ -> let () = F.realize ~names ?svg_output:(svg dyp.global_data) e t l in e}
| optional_idents<names> REALIZE_SHOW<t,l,line> {
let () = echo dyp.global_data line in fun e ->
match names with
| [] -> let () = F.realize_show e t l in e
| _ -> let () = F.realize_show ~names e t l in e}
| optional_ident<name> PARSE<t,l,line> {
let () = echo dyp.global_data line in fun e ->
match name with
| None -> let () = F.parse e t l in e
| Some (n,lex_loc) -> let () = F.parse ~name:n e t lex_loc in e}
| optional_ident<name> QUERY<t,l,line> {
let () = echo dyp.global_data line in fun e ->
match name with
| None -> let () = F.query e t l in e
| Some (n,lex_loc) -> let () = F.query ~name:n e t lex_loc in e}
| optional_ident<name> IDB<p> SEMICOLONN<l> {
let () = echo dyp.global_data l in fun e ->
let loc =
match name with
| None -> p
| Some (_,l) -> l in
match name with
| None -> let () = F.idb e loc in e
| Some (n,l) -> let () = F.idb ~name:n e loc in e}
| optional_idents<names> ADD<t,l,line> { let () = echo dyp.global_data line in fun e ->
match names with
| [] -> F.add e t l
| _ -> F.add ~names e t l}
| COMPOSE IDENTT<n1> IDENTT <n2> AS IDENTT<n3> SEMICOLONN<l> { let () = echo dyp.global_data l in fun e -> F.compose n1 n2 n3 e}
| HELP SEMICOLONN<l> {let () = echo dyp.global_data l in fun e -> let () = F.help (F.Help None) in e}
| all_commands<c> HELP SEMICOLONN<l> {let () = echo dyp.global_data l in fun e -> let () = F.help (F.Help (Some c)) in e}
| LOAD_HELP SEMICOLONN<l> {let () = echo dyp.global_data l in fun e -> let () = F.help (F.Help (Some F.Load)) in e}
| LOAD_HELP SEMICOLONN<l> {let () = echo dyp.global_data l in fun e -> let () = F.help (F.Help (Some F.Load)) in e}
| ANALYSE_HELP SEMICOLONN<l> {let () = echo dyp.global_data l in fun e -> let () = F.help (F.Help (Some F.Analyse)) in e}
| REALIZE_HELP SEMICOLONN<l> {let () = echo dyp.global_data l in fun e -> let () = F.help (F.Help (Some F.Realize)) in e}
| REALIZE_SHOW_HELP SEMICOLONN<l> {let () = echo dyp.global_data l in fun e -> let () = F.help (F.Help (Some F.RealizeShow)) in e}
| CHECK_HELP SEMICOLONN<l> {let () = echo dyp.global_data l in fun e -> let () = F.help (F.Help (Some F.Check)) in e}
| PARSE_HELP SEMICOLONN<l> {let () = echo dyp.global_data l in fun e -> let () = F.help (F.Help (Some F.Parse)) in e}
| QUERY_HELP SEMICOLONN<l> {let () = echo dyp.global_data l in fun e -> let () = F.help (F.Help (Some F.Query)) in e}
| SAVE_HELP SEMICOLONN<l> {let () = echo dyp.global_data l in fun e -> let () = F.help (F.Help (Some F.Save)) in e}
| ADD_HELP SEMICOLONN<l> {let () = echo dyp.global_data l in fun e -> let () = F.help (F.Help (Some F.Add)) in e}
| CREATE_HELP SEMICOLONN<l> {let () = echo dyp.global_data l in fun e -> let () = F.help (F.Help (Some F.Create)) in e}
| CREATE_SIG IDENTT<n> SEMICOLONN<l> {let () = echo dyp.global_data l in fun e -> F.create_sig n e}
| CREATE_LEX IDENTT<n> IDENTT<n1> IDENTT<n2> SEMICOLONN<l> {let () = echo dyp.global_data l in fun e -> F.create_lex ~abs:n1 ~obj:n2 n e}
| optional_idents<names> SAVE<filename,l,line> { let () = echo dyp.global_data line in fun e ->
match names with
| [] -> let () = F.save filename e l in e
| _ -> let () = F.save ~names filename e l in e}
all_commands:
| WAIT {F.Wait}
| DONT WAIT {F.Dont_wait}
| LIST {F.List}
| SELECT {F.Select}
| UNSELECT {F.Unselect}
| TRACE {F.Trace}
| DONT TRACE {F.Dont_trace}
| PRINT {F.Print}
| ANALYSE {F.Analyse}
| CHECK {F.Check}
| REALIZE {F.Realize}
| REALIZE_SHOW {F.RealizeShow}
| PARSE {F.Parse}
| IDB {F.Idb}
| QUERY {F.Query}
| ADD {F.Add}
| COMPOSE {F.Compose}
| HELP {F.Help None}
| SAVE {F.Save}
ctx,e'}
| params = LOAD_OBJECT {
fun ctx e ->
let s,loc,l = params in
let () = echo ctx l in
ctx,F.load F.Object s (F.dirs ctx) e}
| params = LOAD_SCRIPT {
fun ctx e ->
let s,loc,l = params in
let () = echo ctx l in
ctx,F.load (F.Script (F.parse_script ctx)) s (F.dirs ctx) e }
| LIST l = SEMICOLONN {fun ctx e ->
let () = echo ctx l in
let () = F.list e in
ctx, e}
| LIST HELP l = SEMICOLONN {
fun ctx e ->
let () = echo ctx l in
let () = F.help (F.Help (Some F.List)) in
ctx,e}
| SELECT id = IDENTT l = SEMICOLONN {
fun ctx e ->
let name,loc = id in
let () = echo ctx l in
ctx,F.select name loc e}
| SELECT HELP l = SEMICOLONN {
fun ctx e ->
let () = echo ctx l in
let () = F.help (F.Help (Some F.Select)) in
ctx,e}
| UNSELECT l = SEMICOLONN {
fun ctx e ->
let () = echo ctx l in
ctx,F.unselect}
| UNSELECT HELP l = SEMICOLONN {
fun ctx e ->
let () = echo ctx l in
let () = F.help (F.Help (Some F.Unselect)) in
ctx,e}
| TRACE l = SEMICOLONN {
fun ctx e ->
let () = echo ctx l in
let () = F.trace () in
ctx,e}
| TRACE HELP l = SEMICOLONN {
fun ctx e ->
let () = echo ctx l in
let () = F.help (F.Help (Some F.Trace)) in
ctx,e}
| DONT TRACE l = SEMICOLONN {
fun ctx e ->
let () = echo ctx l in
let () = F.dont_trace () in
ctx,e}
| DONT TRACE HELP l = SEMICOLONN {
fun ctx e ->
let () = echo ctx l in
let () = F.help (F.Help (Some F.Dont_trace)) in
ctx,e}
| name = IDENTT? p = PRINT l = SEMICOLONN {
fun ctx e ->
let () = echo ctx l in
let () =
match name with
| None -> F.print e p
| Some (n,l) -> F.print ~name:n e loc in
ctx,e}
| IDENTT? PRINT HELP l = SEMICOLONN {
fun ctx e ->
let () = echo ctx l in
let () = F.help (F.Help (Some F.Print)) in
ctx,e}
| params = ANALYSE {
fun ctx e ->
let t,l,line = params in
let () = echo ctx line in
let () = F.analyse e t l in
ctx, e}
| names = IDENTT+ params = ANALYSE {
fun ctx e ->
let t,l,line = params in
let () = echo ctx line in
let () = F.analyse ~names e t l in
ctx, e}
| params = CHECK {
fun ctx e ->
let t,l,line = params in
let () = echo ctx line in
let () = F.check e t l in
ctx, e}
| names = IDENTT+ params = CHECK {
fun ctx e ->
let t,l,line = params in
let () = echo ctx line in
let () = F.check ~names e t l in
ctx, e}
| params = REALIZE {
fun ctx e ->
let t,l,line = params in
let () = echo ctx line in
let () = F.realize ?svg_output:(F.svg ctx) e t l in
ctx, e}
| names = IDENTT+ params = REALIZE {
fun ctx e ->
let t,l,line = params in
let () = echo ctx line in
let () = F.realize ~names ?svg_output:(F.svg ctx) e t l in
ctx, e}
| params = REALIZE_SHOW {
fun ctx e ->
let t,l,line = params in
let () = echo ctx line in
let () = F.realize_show e t l in
ctx,e}
| names = IDENTT+ params = REALIZE_SHOW {
fun ctx e ->
let t,l,line = params in
let () = echo ctx line in
let () = F.realize_show ~names e t l in
ctx,e}
| params = PARSE {
fun ctx e ->
let t,l,line = params in
let () = echo ctx line in
let () = F.parse e t l in
ctx,e}
| name = IDENTT params = PARSE {
fun ctx e ->
let t,l,line = params in
let () = echo ctx line in
let n,lex_loc = name in
let () = F.parse ~name:n e t lex_loc in
ctx,e}
| params = QUERY {
fun ctx e ->
let t,l,line = params in
let () = echo ctx line in
let () = F.query e t l in
ctx,e}
| name = IDENTT params = QUERY {
fun ctx e ->
let t,l,line = params in
let () = echo ctx line in
let n,lex_loc = name in
let () = F.query ~name:n e t lex_loc in
ctx,e}
| name = IDENTT? p = IDB l = SEMICOLONN {
fun ctx e ->
let () = echo ctx l in
let () =
match name with
| None -> F.idb e p
| Some (n,l) -> F.idb ~name:n e l in
ctx,e}
| name = IDENTT? p = IDB HELP l = SEMICOLONN {
fun ctx e ->
let () = echo ctx l in
let () = F.help (F.Help (Some F.IDB)) in
ctx,e}
| params = ADD {
fun ctx e ->
let t,l,line = params in
let () = echo ctx line in
ctx, F.add e t l}
| names = IDENTT+ params = ADD {
fun ctx e ->
let t,l,line = params in
let () = echo ctx line in
ctx, F.add ~names e t l}
| COMPOSE n1 = IDENTT n2 = IDENTT AS n3 = IDENTT l = SEMICOLONN {
fun ctx e ->
let () = echo ctx l in
ctx,F.compose n1 n2 n3 e}
| COMPOSE HELP l = SEMICOLONN {
fun ctx e ->
let () = echo ctx l in
let () = F.help (F.Help (Some F.Compose)) in
ctx,e}
| HELP l = SEMICOLONN {
fun ctx e ->
let () = echo ctx l in
let () = F.help (F.Help None) in
ctx,e}
| HELP HELP l = SEMICOLONN {
fun ctx e ->
let () = echo ctx l in
let () = F.help (F.Help (Some F.Help)) in
ctx,e}
| LOAD_HELP l = SEMICOLONN {
fun ctx e ->
let () = echo ctx l in
let () = F.help (F.Help (Some F.Load)) in
ctx,e}
| ANALYSE_HELP l = SEMICOLONN {
fun ctx e ->
let () = echo ctx l in
let () = F.help (F.Help (Some F.Analyse)) in
ctx,e}
| REALIZE_HELP l = SEMICOLONN {
fun ctx e ->
let () = echo ctx l in
let () = F.help (F.Help (Some F.Realize)) in ctx,e}
| REALIZE_SHOW_HELP l = SEMICOLONN {
fun ctx e ->
let () = echo ctx l in
let () = F.help (F.Help (Some F.RealizeShow)) in ctx,e}
| CHECK_HELP l = SEMICOLONN {
fun ctx e ->
let () = echo ctx l in
let () = F.help (F.Help (Some F.Check)) in ctx,e}
| PARSE_HELP l = SEMICOLONN {
fun ctx e ->
let () = echo ctx l in
let () = F.help (F.Help (Some F.Parse)) in ctx,e}
| QUERY_HELP l = SEMICOLONN {
fun ctx e ->
let () = echo ctx l in
let () = F.help (F.Help (Some F.Query)) in ctx,e}
| SAVE_HELP l = SEMICOLONN {
fun ctx e ->
let () = echo ctx l in
let () = F.help (F.Help (Some F.Save)) in ctx,e}
| ADD_HELP l = SEMICOLONN {
fun ctx e ->
let () = echo ctx l in
let () = F.help (F.Help (Some F.Add)) in ctx,e}
| CREATE_HELP l = SEMICOLONN {
fun ctx e ->
let () = echo ctx l in
let () = F.help (F.Help (Some F.Create)) in ctx,e}
| CREATE_SIG n = IDENTT l = SEMICOLONN {
fun ctx e ->
let () = echo ctx l in
ctx, F.create_sig n e}
| CREATE_LEX n = IDENTT n1 = IDENTT n2 = IDENTT l = SEMICOLONN {
fun ctx e ->
let () = echo ctx l in
ctx,F.create_lex ~abs:n1 ~obj:n2 n e}
| params = SAVE {
fun ctx e ->
let filename,l,line = params in
let () = echo ctx line in
let e' = F.save filename e l in
ctx,e'}
| names = IDENTT+ params = SAVE {
fun ctx e ->
let filename,l,line = params in
let () = echo ctx line in
let e' = F.save ~names filename e l in
ctx,e'}
......@@ -18,7 +18,7 @@
(**************************************************************************)
open UtilsLib
(*open Grammars.Environment*)
open AcgData.Environment
let info fd name =
let w,h =
......@@ -121,6 +121,10 @@ sig
val svg : context -> string option
val dirs : context -> string list
val parse_script : context -> (?verbose:bool -> ?svg_output:string option -> string -> string list -> Environment.t -> Environment.t)
val help : action -> unit
val exit : unit -> unit
......@@ -148,7 +152,8 @@ struct
wait:bool; (* whether a user return keypressed is expected before moving to the next command *)
echo:bool; (* whether the command should be echoed on the output *)
dirs:string list; (* list of the included dirs *)
svg:string option (* whether a svg output "file" (if relevant) should be produced *)
svg:string option; (* whether a svg output "file" (if relevant) should be produced *)
parse_function: parse_script : context -> (?verbose:bool -> ?svg_output:string option -> string -> string list -> Environment.t -> Environment.t);
}
......@@ -778,6 +783,10 @@ struct
let echo ctx = ctx.echo
let svg ctx = ctx.svg
let dirs ctx = ctx.dirs
let parse_script ctx = ctx.parse_function
let exit () = raise Quit
......
......@@ -18,7 +18,7 @@
(**************************************************************************)
val info : Unix.file_descr -> string -> unit
open AcgData.Environment
module type Action_sig =
......@@ -108,6 +108,10 @@ sig
val svg : context -> string option
val dirs : context -> string list
val parse_script : context -> (?verbose:bool -> ?svg_output:string option -> string -> string list -> Environment.t -> Environment.t)
val help : action -> unit
val exit : unit -> unit
......
(* This file was auto-generated based on "command_parser.messages.new". *)
(* Please note that the function [message] can raise [Not_found]. *)
let message =
fun s ->
match s with
| 1 ->
"<YOUR SYNTAX ERROR MESSAGE HERE>\n"
| 91 ->
"<YOUR SYNTAX ERROR MESSAGE HERE>\n"
| 3 ->
"<YOUR SYNTAX ERROR MESSAGE HERE>\n"
| 5 ->
"<YOUR SYNTAX ERROR MESSAGE HERE>\n"
| 0 ->
"<YOUR SYNTAX ERROR MESSAGE HERE>\n"
| 7 ->
"<YOUR SYNTAX ERROR MESSAGE HERE>\n"
| 8 ->
"<YOUR SYNTAX ERROR MESSAGE HERE>\n"
| 10 ->
"<YOUR SYNTAX ERROR MESSAGE HERE>\n"
| 90 ->
"<YOUR SYNTAX ERROR MESSAGE HERE>\n"