Skip to content
Snippets Groups Projects
Commit 58d00c8d authored by Erwan Jahier's avatar Erwan Jahier
Browse files

Fix the slice lexing problem properly (i.e., in the lexer, not in the parser).

Add a -tlex option to debug the lexer.

Also, rename the rules in parser.mly now that their appear in the manual.
This renaming work is in progress though.
parent dbddd9e8
No related branches found
No related tags found
No related merge requests found
...@@ -3,6 +3,12 @@ src/*.o ...@@ -3,6 +3,12 @@ src/*.o
*~ *~
src/TAGS src/TAGS
*log *log
*.dump
*.ec
*.c
*.h
*.exp
*.lus
*.diff *.diff
src/._bcdi/* src/._bcdi/*
src/._d/* src/._d/*
...@@ -12,4 +18,26 @@ src/parser.ml ...@@ -12,4 +18,26 @@ src/parser.ml
src/parser.mli src/parser.mli
src/lexer.ml src/lexer.ml
src/lexer.mli src/lexer.mli
*.lic *.lic
\ No newline at end of file release*
*.lus.tex
*.res
*.ps
*.annot
*gz
src/version.ml
work
fail
#*
lionel
pascal
polo
parser.tex
lv6-ref-man/objpdf/
lv6-ref-man/,poubelle/
lv6-ref-man/MANUEL_NICOLAS
lv6-ref-man/lv6-ref-man.pdf
old
,poub
src/prof
\ No newline at end of file
...@@ -121,6 +121,7 @@ include $(OCAMLMAKEFILE) ...@@ -121,6 +121,7 @@ include $(OCAMLMAKEFILE)
# cf ../release-lv6/Makefile pour une install complete. # cf ../release-lv6/Makefile pour une install complete.
verimag: verimag:
cp lus2lic /usr/local/tools/lustre-v6/current/bin cp lus2lic /usr/local/tools/lustre-v6/current/bin
cp lus2lic /home/jahier/lurette/i386-linux-gcc3/bin/
tags: tags:
/local/jahier/jahier/bin/otags $(SOURCES) $(shell ocamlc -where)/*.mli /local/jahier/jahier/bin/otags $(SOURCES) $(shell ocamlc -where)/*.mli
......
(** Time-stamp: <modified the 13/04/2010 (at 18:12) by Erwan Jahier> *) (** Time-stamp: <modified the 22/04/2010 (at 10:54) by Erwan Jahier> *)
open Lxm open Lxm
......
(** Time-stamp: <modified the 11/03/2009 (at 16:14) by Erwan Jahier> *) (** Time-stamp: <modified the 05/05/2010 (at 15:39) by Erwan Jahier> *)
(** Some global variables. *) (** Some global variables. *)
...@@ -22,7 +22,7 @@ let expand_enums = ref false ...@@ -22,7 +22,7 @@ let expand_enums = ref false
let expand_structs = ref false let expand_structs = ref false
(* the output channel *) (* the output channel *)
let oc = ref Pervasives.stdout let oc = ref Pervasives.stdout
let tlex = ref false
(* those functions are here as they modify some global vars *) (* those functions are here as they modify some global vars *)
......
...@@ -17,6 +17,8 @@ let handle_lexical_error fn lexbuf = ( ...@@ -17,6 +17,8 @@ let handle_lexical_error fn lexbuf = (
with Lexical_error(msg, _) -> with Lexical_error(msg, _) ->
raise(Lexical_error(msg, lxm)) raise(Lexical_error(msg, lxm))
) )
let unget_lexbuf lb =
lb.Lexing.lex_curr_pos <- lb.Lexing.lex_curr_pos - 1
(* table des mots-cl *) (* table des mots-cl *)
let keywords = Hashtbl.create 50 ;; let keywords = Hashtbl.create 50 ;;
...@@ -155,7 +157,6 @@ let token_code tk = ( ...@@ -155,7 +157,6 @@ let token_code tk = (
| TK_BODY lxm -> ("TK_BODY" , lxm) | TK_BODY lxm -> ("TK_BODY" , lxm)
| TK_END lxm -> ("TK_END" , lxm) | TK_END lxm -> ("TK_END" , lxm)
| TK_INCLUDE lxm -> ("TK_INCLUDE" , lxm) | TK_INCLUDE lxm -> ("TK_INCLUDE" , lxm)
| TK_SLICE_START lxm -> ("TK_SLICE_START" , lxm)
) )
} }
...@@ -243,32 +244,34 @@ rule lexer = parse ...@@ -243,32 +244,34 @@ rule lexer = parse
TK_LONGIDENT (lxm) TK_LONGIDENT (lxm)
} }
(* Une grosse bidouille pour feinter lex qui on arrive pas faire (* une chaine quelconque *)
comprendre que "[expr_min..expr_max]" est une tranche de tableau,
et pas 2 reels qui se suivent ("1..3"), ou bien l'acces une
structure ("0..max").
*)
| ['A'-'Z' 'a'-'z' '\'' '_' '0'-'9' ':'] * '.' '.'
{
let lxm = Lxm.make lexbuf in
TK_SLICE_START (lxm)
}
(* une chaine quelconque *)
| "\"" ['_' 'A'-'Z' 'a'-'z'] ['A'-'Z' '(' ')' '$' '/' 'a'-'z' '.' '-' '_'] * "\"" | "\"" ['_' 'A'-'Z' 'a'-'z'] ['A'-'Z' '(' ')' '$' '/' 'a'-'z' '.' '-' '_'] * "\""
{ {
let lxm = Lxm.make_string lexbuf in let lxm = Lxm.make_string lexbuf in
TK_STRING (lxm) TK_STRING (lxm)
} }
(* constantes entires et relles *) (* constantes entires *)
| chiffres { TK_ICONST (Lxm.make lexbuf ) } | chiffres { TK_ICONST (Lxm.make lexbuf ) }
(* constantes relles *)
(* XXX verifier pourquoi j'ai mis en dur le moins ici (le moins unaire existe !) *)
| ( '-' )? chiffres (exposant) { TK_RCONST (Lxm.make lexbuf ) } | ( '-' )? chiffres (exposant) { TK_RCONST (Lxm.make lexbuf ) }
| ( '-' )? chiffres '.' (chiffres)? (exposant)? | ( '-' )? chiffres '.' chiffres (exposant)?
{ TK_RCONST (Lxm.make lexbuf ) }
| ( '-' )? chiffres '.' (exposant)
{ TK_RCONST (Lxm.make lexbuf ) } { TK_RCONST (Lxm.make lexbuf ) }
| ( '-' )? '.' chiffres (exposant)? { TK_RCONST (Lxm.make lexbuf ) } | ( '-' )? '.' chiffres (exposant)? { TK_RCONST (Lxm.make lexbuf ) }
(* Pour dsambiguer le .. (slice) *)
| chiffres '.'[^'.'] {
unget_lexbuf lexbuf;
TK_RCONST (Lxm.make lexbuf)
}
(* mot-cl ou identificateur *) (* mot-cl ou identificateur *)
| ['_' 'A'-'Z' 'a'-'z'] ['A'-'Z' 'a'-'z' '\'' '_' '0'-'9'] * | ['_' 'A'-'Z' 'a'-'z'] ['A'-'Z' 'a'-'z' '\'' '_' '0'-'9'] *
{ {
......
(** Time-stamp: <modified the 13/04/2010 (at 17:59) by Erwan Jahier> *) (** Time-stamp: <modified the 05/05/2010 (at 16:03) by Erwan Jahier> *)
(** Here follows a description of the different modules used by this lus2lic compiler. (** Here follows a description of the different modules used by this lus2lic compiler.
...@@ -48,6 +48,16 @@ open Errors ...@@ -48,6 +48,16 @@ open Errors
open Parsing open Parsing
open Format open Format
let test_lex ( lexbuf ) = (
let tk = ref (Lexer.lexer lexbuf) in
while !tk <> Parser.TK_EOF do
match (Lexer.token_code !tk) with
( co , lxm ) ->
Printf.printf "line %3d col %2d to %2d : %15s = \"%s\"\n"
(line lxm) (cstart lxm) (cend lxm) co (str lxm) ;
tk := (Lexer.lexer lexbuf)
done
)
(*--------------------------------------------------------- (*---------------------------------------------------------
Les args sont des variables GLOBALES Les args sont des variables GLOBALES
...@@ -118,8 +128,6 @@ let rec arg_list = [ ...@@ -118,8 +128,6 @@ let rec arg_list = [
"<node>\n\t Do not expand node (useful in the expand mode only of course)." "<node>\n\t Do not expand node (useful in the expand mode only of course)."
); );
( "--lustre-v4", Arg.Unit ( "--lustre-v4", Arg.Unit
(fun _ -> set_v4_options ()), (fun _ -> set_v4_options ()),
"\t" "\t"
...@@ -143,6 +151,9 @@ let rec arg_list = [ ...@@ -143,6 +151,9 @@ let rec arg_list = [
"\n\t Run some (internal) unit tests" "\n\t Run some (internal) unit tests"
); );
("--test-lexer",Arg.Set Global.tlex,"Internal option used to test the lexer");
("-tlex",Arg.Set Global.tlex,"");
( "--verbose-level", Arg.Int(fun vl -> Verbose.set_level vl ), "<int>" ( "--verbose-level", Arg.Int(fun vl -> Verbose.set_level vl ), "<int>"
); );
( "-vl", Arg.Int(fun vl -> Verbose.set_level vl ), ( "-vl", Arg.Int(fun vl -> Verbose.set_level vl ),
...@@ -193,7 +204,7 @@ and ...@@ -193,7 +204,7 @@ and
(* Retourne un SyntaxTree.t *) (* Retourne un SyntaxTree.t *)
let lus_load lexbuf = let lus_load lexbuf =
let tree = Parser.sxLusFile Lexer.lexer lexbuf in let tree = Parser.program Lexer.lexer lexbuf in
Name.update_fresh_var_prefix (); Name.update_fresh_var_prefix ();
SolveIdent.recognize_predef_op tree SolveIdent.recognize_predef_op tree
...@@ -207,6 +218,7 @@ let (get_source_list : string list -> SyntaxTree.pack_or_model list) = ...@@ -207,6 +218,7 @@ let (get_source_list : string list -> SyntaxTree.pack_or_model list) =
let (get_one_source : string -> string list * maybe_packed list) = let (get_one_source : string -> string list * maybe_packed list) =
fun infile -> fun infile ->
let lexbuf = Global.lexbuf_of_file_name infile in let lexbuf = Global.lexbuf_of_file_name infile in
if !Global.tlex then test_lex lexbuf;
match (lus_load lexbuf) with match (lus_load lexbuf) with
| PRPackBody(incl_files, pbdy) -> incl_files, [Unpacked pbdy] | PRPackBody(incl_files, pbdy) -> incl_files, [Unpacked pbdy]
| PRPack_or_models(incl_files, nsl) -> incl_files, (List.map (fun ns -> Packed ns) nsl) | PRPack_or_models(incl_files, nsl) -> incl_files, (List.map (fun ns -> Packed ns) nsl)
......
This diff is collapsed.
(** Time-stamp: <modified the 23/10/2008 (at 18:12) by Erwan Jahier> *) (** Time-stamp: <modified the 22/04/2010 (at 10:55) by Erwan Jahier> *)
(** (Raw) Abstract syntax tree of source programs. *) (** (Raw) Abstract syntax tree of source programs. *)
......
...@@ -96,7 +96,7 @@ test_ec: ...@@ -96,7 +96,7 @@ test_ec:
echo -e "\n$(NL)====> $(LC) -ec $$d -o /tmp/xx.ec" >> test_ec.res; \ echo -e "\n$(NL)====> $(LC) -ec $$d -o /tmp/xx.ec" >> test_ec.res; \
$(LC0) -ec $$d -o /tmp/xx.ec >> test_ec.res 2>&1 ;\ $(LC0) -ec $$d -o /tmp/xx.ec >> test_ec.res 2>&1 ;\
echo -e "ec2c /tmp/xx.ec" >> test_ec.res; \ echo -e "ec2c /tmp/xx.ec" >> test_ec.res; \
(ec2c /tmp/xx.ec >> test_ec.res 2>&1 && echo -n "ok ") || echo " KO!";\ (ec2c /tmp/xx.ec >> test_ec.res 2>&1 && echo -n "ok ") || echo " KO ($$d)!";\
done; \ done; \
diff -u test_ec.res.exp test_ec.res > test_ec.diff || \ diff -u test_ec.res.exp test_ec.res > test_ec.diff || \
(cat test_ec.diff ; echo "cf test_ec.diff"; exit 1) (cat test_ec.diff ; echo "cf test_ec.diff"; exit 1)
...@@ -114,7 +114,7 @@ test_lv4: ...@@ -114,7 +114,7 @@ test_lv4:
echo -e "lus2ec /tmp/xx.lus $$node" >> test_lv4.res; \ echo -e "lus2ec /tmp/xx.lus $$node" >> test_lv4.res; \
(lus2ec /tmp/xx.lus $$node >> \ (lus2ec /tmp/xx.lus $$node >> \
test_lv4.res 2>&1 && echo -n "ok ") \ test_lv4.res 2>&1 && echo -n "ok ") \
|| echo " KO!";\ || echo " KO ($$d)!";\
done; \ done; \
done; \ done; \
diff -u test_lv4.res.exp test_lv4.res > test_lv4.diff || \ diff -u test_lv4.res.exp test_lv4.res > test_lv4.diff || \
......
...@@ -33,6 +33,8 @@ where [options] can be: ...@@ -33,6 +33,8 @@ where [options] can be:
Generate ec (actually just an alias for '-en -lv4'). Generate ec (actually just an alias for '-en -lv4').
-unit -unit
Run some (internal) unit tests Run some (internal) unit tests
--test-lexer Internal option used to test the lexer
-tlex
--verbose-level <int> --verbose-level <int>
-vl <int> -vl <int>
Set the verbose level. Set the verbose level.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment