diff --git a/Basis/Basis_lexer.mll b/Basis/Basis_lexer.mll index 691f708..5ac3885 100644 --- a/Basis/Basis_lexer.mll +++ b/Basis/Basis_lexer.mll @@ -12,7 +12,7 @@ let ang_mom = ['S' 'P' 'D' 'F' 'G' 'H' 'I' 'J' 'K' 'L' 'M' 'N' 'O' 's' 'p' 'd' 'f' 'g' 'h' 'i' 'j' 'k' 'l' 'm' 'n' 'o' ] white let integer = ['0'-'9']+ -let real = '-'? integer '.' integer (['e' 'E'] '-'? integer)? +let real = '-'? integer '.' integer (['e' 'E'] ('+'|'-')? integer)? rule read_all_rule = parse diff --git a/Makefile b/Makefile index 210eda4..50fbdc4 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,10 @@ .NOPARALLEL: +INCLUDE_DIRS=Nuclei,Utils,Basis LIBS= PKGS= OCAMLCFLAGS="-g" -OCAMLBUILD=ocamlbuild -j 0 -cflags $(OCAMLCFLAGS) -lflags $(OCAMLCFLAGS) -I Utils -I Basis +OCAMLBUILD=ocamlbuild -j 0 -cflags $(OCAMLCFLAGS) -lflags $(OCAMLCFLAGS) -Is $(INCLUDE_DIRS) MLLFILES=$(wildcard */*.mll) $(wildcard *.mll) MLYFILES=$(wildcard */*.mly) $(wildcard *.mly) MLFILES= $(wildcard */*.ml) $(wildcard *.ml) diff --git a/Nuclei/Nuclei.ml b/Nuclei/Nuclei.ml new file mode 100644 index 0000000..9684842 --- /dev/null +++ b/Nuclei/Nuclei.ml @@ -0,0 +1 @@ +type xyz_input = string * ( (string * (float array)) array) diff --git a/Nuclei/Nuclei_lexer.mll b/Nuclei/Nuclei_lexer.mll new file mode 100644 index 0000000..86efdb3 --- /dev/null +++ b/Nuclei/Nuclei_lexer.mll @@ -0,0 +1,38 @@ +{ +open Nuclei_parser +} + +let eol = ['\n'] +let white = [' ' '\t']+ +let word = [^' ' '\t' '\n']+ +let letter = ['A'-'Z' 'a'-'z'] +let integer = ['0'-'9']+ +let real = '-'? integer '.' integer (['e' 'E'] ('+'|'-')? integer)? + + +rule read_all = parse + | eof { EOF } + | eol { EOL } + | white as w { SPACE w } + | integer as i { INTEGER (int_of_string i) } + | real as f { FLOAT (float_of_string f) } + | word as w { WORD w } + + +{ + let debug () = + let ic = open_in "caffeine.xyz" in + let lexbuf = Lexing.from_channel ic in + while true do + let s = + match read_all lexbuf with + | EOL -> "EOL" + | SPACE w -> "SPACE("^w^")" + | INTEGER i -> "INTEGER("^(string_of_int i)^")" + | FLOAT f -> "FLOAT("^(string_of_float f)^")" + | WORD w -> "WORD("^w^")" + | EOF -> "EOF" + in + print_endline s + done; +} diff --git a/Nuclei/Nuclei_parser.mly b/Nuclei/Nuclei_parser.mly new file mode 100644 index 0000000..7c7d888 --- /dev/null +++ b/Nuclei/Nuclei_parser.mly @@ -0,0 +1,55 @@ +/* Parses basis sets in GAMESS format */ + +%{ +exception InputError of string +%} + +%token EOL +%token SPACE +%token WORD +%token INTEGER +%token FLOAT +%token EOF + +%start input +%type input + +%% /* Grammar rules and actions follow */ + +input: + | integer title atoms { + let len = List.length $3 in + if len <> $1 then + let error_msg = Printf.sprintf "%d atoms entered, expected %d" len $1 in + raise (InputError error_msg) + else + ($2,Array.of_list $3) + } + +integer: + | INTEGER EOL { $1 } + | INTEGER SPACE EOL { $1 } + +title: + | title_list EOL { $1 } + +text: + | WORD {$1 } + | SPACE {$1 } + | FLOAT {(string_of_float $1)} + | INTEGER {(string_of_int $1)} + +title_list: + | { "" } + | title_list text { $1 ^ $2 } + +atoms: + | atoms_list EOL { List.rev $1 } + | atoms_list EOF { List.rev $1 } + +atoms_list: + | { [] } + | atoms_list WORD SPACE FLOAT SPACE FLOAT SPACE FLOAT EOL { ($2, [| $4;$6;$8 |]) :: $1 } + | atoms_list WORD SPACE FLOAT SPACE FLOAT SPACE FLOAT SPACE EOL { ($2, [| $4;$6;$8 |]) :: $1 } + +