Commit 9b572d88 authored by POGODALLA Sylvain's avatar POGODALLA Sylvain

Contectual management of keywords added (fixes #13)

parent 3248332d
......@@ -30,7 +30,7 @@ and
************
acgc is a "compiler" of ACG source code, i.e. files containing
definitions of signarures and lexicons. It basically checks whether
definitions of signatures and lexicons. It basically checks whether
they are correctly written (syntactically and wrt types and constant
typing) and outputs a .acgo object file. An interactive mode is
available to parse terms according to signatures.
......@@ -299,3 +299,17 @@ context-free lambda grammars).
```
lexicon my_new_lex = lex_2 << lex_1
3. Keywords
The keywords are "signature, "lexicon, "nl_lexicon", "end", "type",
"prefix", "infix", "binder", "lambda", and "Lambda".
The reserved symbols are '=', '<<', ';', ':', ',', '('), ')', '.',
'->', '=>', and ':='.
Inside a signature or a lexicon, "signature", "lexicon" and
"nl_lexicon" are not considered as keywords and can be used as
identifier.
Other keywords can be used as identifier when escaped with '\' (e.g.,
"\end").
......@@ -9,7 +9,7 @@ A list of related publications is available at the [ACG web page](http://calligr
## acgc
`acgc` is a "compiler" of ACG source code, i.e. files containing definitions of signarures and lexicons. It basically checks whether they are correctly written (syntactically and wrt types and constant typing) and outputs a `.acgo` object file. An interactive mode is available to parse terms according to signatures.
`acgc` is a "compiler" of ACG source code, i.e. files containing definitions of signatures and lexicons. It basically checks whether they are correctly written (syntactically and wrt types and constant typing) and outputs a `.acgo` object file. An interactive mode is available to parse terms according to signatures.
Run
```bash
......@@ -187,6 +187,7 @@ end
* `SYM t` if `SYM` is a prefix symbol (highest priority)
* `BINDER x y z.t` if `BINDER` is a binder
### Lexicons
There are two ways to define a lexicon:
......@@ -213,3 +214,13 @@ There are two ways to define a lexicon:
lexicon my_new_lex = lex_2 << lex_1
```
## Keywords
The keywords are "signature, "lexicon, "nl_lexicon", "end", "type", "prefix", "infix", "binder", "lambda", and "Lambda".
The reserved symbols are '=', '<<', ';', ':', ',', '('), ')', '.', '->', '=>', and ':='.
Inside a signature or a lexicon, "signature", "lexicon" and "nl_lexicon" are not considered as keywords and can be used as identifier.
Other keywords can be used as identifier when escaped with '\' (e.g., "\end").
; -*-org-*-
* DONE Add an optional ";" before the "end" keyword
* TODO Change lexers to avoid problems with keywords
* DONE Change lexers to avoid problems with keywords
* TODO Add precedence values and management in the signature
* TODO Add (+) notation style to prevent the infix use of +
* TODO Add syntactic extensions to handle associativity and precedence of infix operators
......@@ -10,3 +10,4 @@
* TODO change README and INSTALL files:
+ [X] to indicate new dependencies (menhir, logs...)
+ [ ] to document syntax extensions for infix operators, precedence of the latter over application. Highest precedence for prefix operators
* TODO What about lexicon composition when one lexicon at least is non-linear?
......@@ -38,8 +38,21 @@
| [] -> ()
| (p1,p2)::__ -> let () = brackets := [] in
raise (Error.Error (Error.Lexer_error (Error.Mismatch_parentheses,(p1,p2))))
type context =
| NoContext
| Signature
| Lexicon
| LexiconComposition
let ctx = ref NoContext
let set c = ctx:=c
let tok_in_context c t1 t2 =
if !ctx = c then t1 else t2
}
......@@ -49,6 +62,7 @@ let digit = ['0'-'9']
let string = (letter|digit|'_')*'\''*
let symbol = ['|' '!' '"' '#' '$' '%' '&' '\'' '*' '+' '-' '/' '<' '>' '?' '@' '[' '\\' ']' '^' '`' '{' '}' '~' ]
let keyword = ("end" | "type" | "prefix" | "infix" | "binder" | "lambda" | "Lambda")
rule lexer =
parse
......@@ -59,12 +73,34 @@ rule lexer =
| eof {
let () = check_brackets () in
Data_parser.EOI}
| "signature" as id {
let () = check_brackets () in
if !ctx = NoContext then
let () = set Signature in
Data_parser.SIG_OPEN(loc lexbuf)
else
IDENT(id,loc lexbuf)}
| "lexicon" as id {
let () = check_brackets () in
if !ctx = NoContext then
let () = set Lexicon in
Data_parser.LEX_OPEN(loc lexbuf)
else
IDENT(id,loc lexbuf)}
| "nl_lexicon" as id {
let () = check_brackets () in
if !ctx = NoContext then
let () = set Lexicon in
Data_parser.NL_LEX_OPEN(loc lexbuf)
else
IDENT(id,loc lexbuf)}
| ['='] {
let () = check_brackets () in
Data_parser.EQUAL(loc lexbuf)}
| "<<" {
let () = check_brackets () in
Data_parser.COMPOSE(loc lexbuf)}
let () = check_brackets () in
let () = set NoContext in
Data_parser.COMPOSE(loc lexbuf)}
| [';'] {
let () = check_brackets () in
Data_parser.SEMICOLON(loc lexbuf)}
......@@ -84,18 +120,12 @@ rule lexer =
Data_parser.RPAREN brac_loc}
| ['.'] {
Data_parser.DOT(loc lexbuf)}
| "signature" {
let () = check_brackets () in
Data_parser.SIG_OPEN(loc lexbuf)}
| "lexicon" {
let () = check_brackets () in
Data_parser.LEX_OPEN(loc lexbuf)}
| "nl_lexicon" {
let () = check_brackets () in
Data_parser.NL_LEX_OPEN(loc lexbuf)}
| "end" {
let () = check_brackets () in
Data_parser.END_OF_DEC(loc lexbuf)}
| '\\' keyword as id {
let () = check_brackets () in
Data_parser.IDENT(id,loc lexbuf)}
| "type" {
let () = check_brackets () in
Data_parser.TYPE(loc lexbuf)}
......@@ -135,3 +165,4 @@ rule lexer =
| _ {comment depth lexbuf}
This diff is collapsed.
......@@ -7,27 +7,8 @@
module Typing_env = Utils.StringSet
type toto = Environment.t
type context =
| Signature of Environment.Signature1.t
| Abs_and_obj of (Environment.Signature1.t * Environment.Signature1.t)
| Env of Environment.t
type type_or_cst =
| Type of (string*Abstract_syntax.location)
| Term of (string*Abstract_syntax.location)
let type_or_cst_to_string = function
| Type _ -> "Type"
| Term _ -> "Term"
exception Is_type
exception Is_cst
let emit_parse_error e loc = raise (Error.Error (Error.Parse_error (e,loc)))
let new_loc (s,_) (_,e) = (s,e)
let get_term_location = function
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment