From 58d00c8d117f6ccef9917706e06a51b3e07a6d2c Mon Sep 17 00:00:00 2001 From: Erwan Jahier <jahier@imag.fr> Date: Wed, 5 May 2010 16:28:39 +0200 Subject: [PATCH] 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. --- .gitignore | 30 ++- src/Makefile | 1 + src/getEff.ml | 2 +- src/global.ml | 4 +- src/lexer.mll | 31 ++- src/main.ml | 20 +- src/parser.mly | 580 +++++++++++++++++++++--------------------- src/syntaxTreeCore.ml | 2 +- src/test/Makefile | 4 +- src/test/test.res.exp | 2 + 10 files changed, 360 insertions(+), 316 deletions(-) diff --git a/.gitignore b/.gitignore index 39369c26..a9caf040 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,12 @@ src/*.o *~ src/TAGS *log +*.dump +*.ec +*.c +*.h +*.exp +*.lus *.diff src/._bcdi/* src/._d/* @@ -12,4 +18,26 @@ src/parser.ml src/parser.mli src/lexer.ml src/lexer.mli -*.lic \ No newline at end of file +*.lic +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 diff --git a/src/Makefile b/src/Makefile index 4b7c43f1..025bff5b 100644 --- a/src/Makefile +++ b/src/Makefile @@ -121,6 +121,7 @@ include $(OCAMLMAKEFILE) # cf ../release-lv6/Makefile pour une install complete. verimag: cp lus2lic /usr/local/tools/lustre-v6/current/bin + cp lus2lic /home/jahier/lurette/i386-linux-gcc3/bin/ tags: /local/jahier/jahier/bin/otags $(SOURCES) $(shell ocamlc -where)/*.mli diff --git a/src/getEff.ml b/src/getEff.ml index 7582619a..b78c043c 100644 --- a/src/getEff.ml +++ b/src/getEff.ml @@ -1,4 +1,4 @@ -(** 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 diff --git a/src/global.ml b/src/global.ml index 0cbfd9b1..0154b0d2 100644 --- a/src/global.ml +++ b/src/global.ml @@ -1,4 +1,4 @@ -(** 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. *) @@ -22,7 +22,7 @@ let expand_enums = ref false let expand_structs = ref false (* the output channel *) let oc = ref Pervasives.stdout - +let tlex = ref false (* those functions are here as they modify some global vars *) diff --git a/src/lexer.mll b/src/lexer.mll index c560f029..a43cb389 100644 --- a/src/lexer.mll +++ b/src/lexer.mll @@ -17,6 +17,8 @@ let handle_lexical_error fn lexbuf = ( with Lexical_error(msg, _) -> raise(Lexical_error(msg, lxm)) ) +let unget_lexbuf lb = + lb.Lexing.lex_curr_pos <- lb.Lexing.lex_curr_pos - 1 (* table des mots-clé *) let keywords = Hashtbl.create 50 ;; @@ -155,7 +157,6 @@ let token_code tk = ( | TK_BODY lxm -> ("TK_BODY" , lxm) | TK_END lxm -> ("TK_END" , lxm) | TK_INCLUDE lxm -> ("TK_INCLUDE" , lxm) - | TK_SLICE_START lxm -> ("TK_SLICE_START" , lxm) ) } @@ -243,32 +244,34 @@ rule lexer = parse TK_LONGIDENT (lxm) } -(* Une grosse bidouille pour feinter lex à qui on arrive pas à faire - 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 *) +(* une chaine quelconque *) | "\"" ['_' 'A'-'Z' 'a'-'z'] ['A'-'Z' '(' ')' '$' '/' 'a'-'z' '.' '-' '_'] * "\"" { let lxm = Lxm.make_string lexbuf in TK_STRING (lxm) } -(* constantes entières et réelles *) +(* constantes entières *) | chiffres { TK_ICONST (Lxm.make lexbuf ) } + +(* constantes réelles *) +(* XXX verifier pourquoi j'ai mis en dur le moins ici (le moins unaire existe !) *) | ( '-' )? 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 ) } | ( '-' )? '.' chiffres (exposant)? { TK_RCONST (Lxm.make lexbuf ) } +(* Pour désambiguer le .. (slice) *) + | chiffres '.'[^'.'] { + unget_lexbuf lexbuf; + TK_RCONST (Lxm.make lexbuf) + } + (* mot-clé ou identificateur *) | ['_' 'A'-'Z' 'a'-'z'] ['A'-'Z' 'a'-'z' '\'' '_' '0'-'9'] * { diff --git a/src/main.ml b/src/main.ml index 64a4a79f..ed754b3d 100644 --- a/src/main.ml +++ b/src/main.ml @@ -1,4 +1,4 @@ -(** 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. @@ -48,6 +48,16 @@ open Errors open Parsing 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 @@ -118,8 +128,6 @@ let rec arg_list = [ "<node>\n\t Do not expand node (useful in the expand mode only of course)." ); - - ( "--lustre-v4", Arg.Unit (fun _ -> set_v4_options ()), "\t" @@ -143,6 +151,9 @@ let rec arg_list = [ "\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>" ); ( "-vl", Arg.Int(fun vl -> Verbose.set_level vl ), @@ -193,7 +204,7 @@ and (* Retourne un SyntaxTree.t *) 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 (); SolveIdent.recognize_predef_op tree @@ -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) = fun infile -> let lexbuf = Global.lexbuf_of_file_name infile in + if !Global.tlex then test_lex lexbuf; match (lus_load lexbuf) with | PRPackBody(incl_files, pbdy) -> incl_files, [Unpacked pbdy] | PRPack_or_models(incl_files, nsl) -> incl_files, (List.map (fun ns -> Packed ns) nsl) diff --git a/src/parser.mly b/src/parser.mly index 018b2462..55de7df9 100644 --- a/src/parser.mly +++ b/src/parser.mly @@ -101,7 +101,6 @@ open ParserUtils %token <Lxm.t> TK_END %token <Lxm.t> TK_INCLUDE %token <Lxm.t> TK_STRING -%token <Lxm.t> TK_SLICE_START /* %token <Lxm.t> TK_QUOTE */ /* Priorities */ @@ -126,9 +125,9 @@ open ParserUtils %right TK_COMA %right TK_FBY -/* sxEntry point */ -%start sxLusFile -%type <SyntaxTree.t> sxLusFile +/* Entry point */ +%start program +%type <SyntaxTree.t> program %% @@ -144,9 +143,9 @@ hash table (i.e. each declaration makes a side effect) - Any rule that produces a caml list builds it in THE REVERSE ORDER (in order to save the yacc stack and to avoid the use of the caml @ operator). This is why they are -named "sxTotoReverseList". This is why they must not be +named "TotoReverseList". This is why they must not be used in other rules: onr have to use the corresponding -"sxTotoList" which finally reverse the list. +"TotoList" which finally reverse the list. -------------------------------------------------------*/ /* @@ -154,42 +153,42 @@ A lustre file is either an old-fashioned list of item decl, or a list of pack/model declaration */ -sxLusFile: +program: /* WARNING ! il faut remettre la liste à l'endroit */ - sxIncludeList sxPackBody TK_EOF + IncludeList PackBody TK_EOF { SyntaxTree.PRPackBody($1, $2) } -| sxIncludeList sxPackList TK_EOF +| IncludeList PackList TK_EOF { SyntaxTree.PRPack_or_models ($1, List.rev $2) } ; -sxPackList: - sxOnePack +PackList: + OnePack { [$1] } -| sxPackList sxOnePack +| PackList OnePack { $2::$1 } ; -sxOnePack: - sxModelDecl +OnePack: + ModelDecl { SyntaxTree.NSModel $1 } -| sxPackDecl +| PackDecl { SyntaxTree.NSPack $1 } -| sxPackEq +| PackEq { SyntaxTree.NSPack $1 } ; -sxInclude: +Include: TK_INCLUDE TK_STRING { (Lxm.str $2) } ; -sxIncludeList: +IncludeList: { [] } -| sxInclude sxIncludeList +| Include IncludeList { $1::$2 } ; @@ -198,55 +197,49 @@ Pour les provides, on rend des decls, bien que syntaxiquement, on n'autorise pas n'importe quoi ... */ -sxProvides: +Provides: /* nada */ { None } -/* | TK_PROVIDES sxStaticParamList TK_SEMICOL */ -| TK_PROVIDES sxProvideList TK_SEMICOL +/* | TK_PROVIDES StaticParamList TK_SEMICOL */ +| TK_PROVIDES ProvideList TK_SEMICOL { Some (List.rev $2) } ; -sxProvideList: sxOneProvide +ProvideList: Provide { [$1] } - | sxProvideList TK_SEMICOL sxOneProvide + | ProvideList TK_SEMICOL Provide { $3::$1 } ; -sxConstDefOpt: - { None} -| TK_EQ sxExpression - { - Some $2 - } -sxOneProvide: +Provide: /* constante abstraite */ - TK_CONST sxIdent TK_COLON sxType sxConstDefOpt + TK_CONST Ident TK_COLON Type ConstDefOpt { Lxm.flagit (ConstInfo (ExternalConst (Lxm.id $2, $4, $5))) $2 } /* noeud abstrait */ -| TK_NODE sxIdent sxParams TK_RETURNS sxParams +| TK_NODE Ident Params TK_RETURNS Params { treat_abstract_node true $2 $3 $5 } /* fonction abstraite */ -| TK_FUNCTION sxIdent sxParams TK_RETURNS sxParams +| TK_FUNCTION Ident Params TK_RETURNS Params { treat_abstract_node false $2 $3 $5 } /* type abstrait... */ -| TK_TYPE sxIdent +| TK_TYPE Ident { Lxm.flagit (TypeInfo (ExternalType (Lxm.id $2))) $2 } /* un alias sur type immédiat */ -| TK_TYPE sxIdent TK_EQ sxType +| TK_TYPE Ident TK_EQ Type { Lxm.flagit (TypeInfo (AliasedType (Lxm.id $2, $4))) @@ -254,7 +247,7 @@ sxOneProvide: } /* type énuméré */ /* WARNING ! la liste n'est pas à l'endroit */ -| TK_TYPE sxIdent TK_EQ TK_ENUM TK_OPEN_BRACE sxIdentList TK_CLOSE_BRACE +| TK_TYPE Ident TK_EQ TK_ENUM TK_OPEN_BRACE IdentList TK_CLOSE_BRACE { let fields = List.rev_map lexeme_to_ident_flagged $6 in Lxm.flagit @@ -263,8 +256,8 @@ sxOneProvide: } /* type structure à champs nommés */ /* WARNING ! la liste est déjà à l'endroit */ -| TK_TYPE sxIdent TK_EQ opt_TK_STRUCT - TK_OPEN_BRACE sxTypedValuedIdents TK_CLOSE_BRACE +| TK_TYPE Ident TK_EQ OptStruct + TK_OPEN_BRACE TypedValuedIdents TK_CLOSE_BRACE { let sti = make_struct_type_info $2 $6 in Lxm.flagit @@ -273,14 +266,21 @@ sxOneProvide: } ; -sxModelDecl: - TK_MODEL sxIdent - sxUses - /* TK_NEEDS sxPackParamList TK_SEMICOL */ - TK_NEEDS sxStaticParamList TK_SEMICOL - sxProvides +ConstDefOpt: + { None} +| TK_EQ Expression + { + Some $2 + } +; +ModelDecl: + TK_MODEL Ident + Uses + /* TK_NEEDS PackParamList TK_SEMICOL */ + TK_NEEDS StaticParamList TK_SEMICOL + Provides TK_BODY - sxPackBody + PackBody TK_END { let mdecl = { @@ -295,12 +295,12 @@ sxModelDecl: ; -sxPackDecl: - TK_PACKAGE sxIdent - sxUses - sxProvides +PackDecl: + TK_PACKAGE Ident + Uses + Provides TK_BODY - sxPackBody + PackBody TK_END { let pdef = PackGiven { @@ -318,24 +318,24 @@ sxPackDecl: /* pack params are identical to node static Packparams (?) */ /* -sxPackParamList: - sxStaticParamList +PackParamList: + StaticParamList { $1 } ; */ -sxUses: +Uses: /* nada */ { [] } -| TK_USES sxIdentList TK_SEMICOL +| TK_USES IdentList TK_SEMICOL { List.rev_map lexeme_to_pack_name_flagged $2 } ; /* */ -sxEq_or_Is: +Eq_or_Is: | TK_EQ {} | TK_IS @@ -343,9 +343,9 @@ sxEq_or_Is: /* I don't like by-pos notation, but keep it for backward compatibility */ -sxPackEq: - TK_PACKAGE sxIdent sxEq_or_Is sxIdent TK_OPEN_PAR - sxByNameStaticArgList +PackEq: + TK_PACKAGE Ident Eq_or_Is Ident TK_OPEN_PAR + ByNameStaticArgList TK_CLOSE_PAR TK_SEMICOL { let pdef = PackInstance { @@ -360,13 +360,13 @@ sxPackEq: } ; -/* sxPackBody : +/* PackBody : les informations collectées dans les tables sont figées, et on remet les tables à 0 ... */ -sxPackBody: - sxDeclList +PackBody: + DeclList { let res = SyntaxTree.make_packbody const_table type_table node_table (List.rev !def_list) in @@ -379,27 +379,27 @@ sxPackBody: } ; -/* sxDeclarations */ +/* Declarations */ -sxDeclList: sxOneDecl +DeclList: OneDecl { } - | sxDeclList sxOneDecl + | DeclList OneDecl { } ; -sxOneDecl: - sxConstDecl +OneDecl: + ConstDecl { } - | sxTypeDecl + | TypeDecl { } - | sxExtNodeDecl + | ExtNodeDecl { } - | sxNodeDecl + | NodeDecl { } ; -/* sxIdentifiers and lists */ -sxIdentRef : +/* Identifiers and lists */ +IdentRef : /* simple or long ... */ TK_IDENT { idref_of_lxm $1 } @@ -407,152 +407,152 @@ sxIdentRef : { idref_of_lxm $1 } ; -/* sxIdentifiers and lists */ -sxIdent: TK_IDENT sxPragma +/* Identifiers and lists */ +Ident: TK_IDENT Pragma { (ParserUtils.make_ident $1 $2) } ; -sxIdentList: sxIdent +IdentList: Ident { [$1] } - | sxIdentList TK_COMA sxIdent + | IdentList TK_COMA Ident { $3::$1 } ; -sxTypedIdentsList: sxTypedIdents +TypedIdentsList: TypedIdents { [ $1 ] } - | sxTypedIdentsList TK_SEMICOL sxTypedIdents + | TypedIdentsList TK_SEMICOL TypedIdents { $3::$1 } ; -sxTypedIdents: sxIdentList TK_COLON sxType +TypedIdents: IdentList TK_COLON Type /* WARNING ! il faut remettre la liste à l'endroit */ { ((List.rev $1), $3 ) } ; -sxTypedValuedIdents: sxTypedValuedIdent +TypedValuedIdents: TypedValuedIdent { $1 } - | sxTypedValuedIdents TK_SEMICOL sxTypedValuedIdent + | TypedValuedIdents TK_SEMICOL TypedValuedIdent { List.append $1 $3 } ; -sxTypedValuedIdent : +TypedValuedIdent : /* Les listes d'idents en partie gauche sont acceptées pour les idents SANS valeur */ - sxIdent TK_COLON sxType + Ident TK_COLON Type { (id_valopt_list_of_id_list [$1] $3 ) } - | sxIdent TK_COMA sxIdentList TK_COLON sxType + | Ident TK_COMA IdentList TK_COLON Type { (id_valopt_list_of_id_list ($1::(List.rev $3)) $5) } /* Mais pas pour les constantes définies : */ - | sxIdent TK_COLON sxType TK_EQ sxExpression + | Ident TK_COLON Type TK_EQ Expression { [id_valopt_of_id_val $1 $3 $5] } ; /* constantes */ -sxConstDecl: TK_CONST sxConstDeclList {} ; +ConstDecl: TK_CONST ConstDeclList {} ; -sxConstDeclList: - | sxOneConstDecl TK_SEMICOL {} - | sxConstDeclList sxOneConstDecl TK_SEMICOL {} ; +ConstDeclList: + | OneConstDecl TK_SEMICOL {} + | ConstDeclList OneConstDecl TK_SEMICOL {} ; -sxOneConstDecl: +OneConstDecl: /* Les listes d'idents en partie gauche sont acceptées pour les constantes externes : */ - | sxIdent TK_COLON sxType { (treat_external_const_list [$1] $3 ) } - | sxIdent TK_COMA sxIdentList TK_COLON sxType + | Ident TK_COLON Type { (treat_external_const_list [$1] $3 ) } + | Ident TK_COMA IdentList TK_COLON Type { (treat_external_const_list ($1::(List.rev $3)) $5) } /* Mais pas pour les constantes définies : */ -| sxIdent TK_COLON sxType TK_EQ sxExpression +| Ident TK_COLON Type TK_EQ Expression { (treat_defined_const $1 (Some $3) $5) } -| sxIdent TK_EQ sxExpression +| Ident TK_EQ Expression { (treat_defined_const $1 (None) $3 ) } ; /* types */ -sxTypeDecl: TK_TYPE sxTypeDeclList +TypeDecl: TK_TYPE TypeDeclList {} ; -sxTypeDeclList: sxOneTypeDecl TK_SEMICOL +TypeDeclList: OneTypeDecl TK_SEMICOL {} - | sxTypeDeclList sxOneTypeDecl TK_SEMICOL + | TypeDeclList OneTypeDecl TK_SEMICOL {} ; -sxOneTypeDecl: +OneTypeDecl: /* liste de types abstraits (externes) */ - sxIdentList + IdentList { treat_external_type_list (List.rev $1) } /* un alias sur type immédiat */ - | sxIdent TK_EQ sxType + | Ident TK_EQ Type { treat_aliased_type $1 $3 } /* type énuméré */ /* WARNING ! il faut remettre la liste à l'endroit */ - | sxIdent TK_EQ TK_ENUM TK_OPEN_BRACE sxIdentList TK_CLOSE_BRACE + | Ident TK_EQ TK_ENUM TK_OPEN_BRACE IdentList TK_CLOSE_BRACE { treat_enum_type $1 (List.rev $5) } /* type structure à champs nommés */ /* WARNING ! la liste est déjà à l'endroit */ - | sxIdent TK_EQ opt_TK_STRUCT TK_OPEN_BRACE sxTypedValuedIdents TK_CLOSE_BRACE + | Ident TK_EQ OptStruct TK_OPEN_BRACE TypedValuedIdents TK_CLOSE_BRACE { treat_struct_type $1 $5 } ; /* COMPATIBILITY : "struct" keyword is optional */ -opt_TK_STRUCT: +OptStruct: /* nothing */ {} | TK_STRUCT {} ; /* Notation de type "immédiat" */ -sxType: +Type: /* prédéfini */ TK_BOOL { {src=$1; it=Bool_type_exp } } | TK_INT { {src=$1; it=Int_type_exp } } | TK_REAL { {src=$1; it=Real_type_exp } } /* ref à un type nommé */ - | sxIdentRef { {src=$1.src; it= Named_type_exp $1.it } } + | IdentRef { {src=$1.src; it= Named_type_exp $1.it } } /* ou tableau immédiat */ - | sxType TK_HAT sxExpression + | Type TK_HAT Expression { {src=$2; it=Array_type_exp ($1 , $3) } } ; /* extern nodes */ -sxExtNodeDecl: - TK_EXTERN TK_FUNCTION sxIdent sxParams TK_RETURNS sxParams sxOptSemicol +ExtNodeDecl: + TK_EXTERN TK_FUNCTION Ident Params TK_RETURNS Params OptSemicol { treat_external_node false $3 $4 $6 } -| TK_EXTERN TK_NODE sxIdent sxParams TK_RETURNS sxParams sxOptSemicol +| TK_EXTERN TK_NODE Ident Params TK_RETURNS Params OptSemicol { treat_external_node true $3 $4 $6 } ; /* noeuds */ -sxNodeDecl: sxLocalNode {}; +NodeDecl: LocalNode {}; -sxLocalNode: -| TK_NODE sxIdent sxStaticParams sxParams TK_RETURNS sxParams sxOptSemicol - sxLocals sxBody sxOptEndNode +LocalNode: +| TK_NODE Ident StaticParams Params TK_RETURNS Params OptSemicol + Locals Body OptEndNode { treat_node_decl true $2 $3 $4 $6 $8 (fst $9) (snd $9) } -| TK_FUNCTION sxIdent sxStaticParams sxParams TK_RETURNS sxParams sxOptSemicol - sxLocals sxBody sxOptEndNode +| TK_FUNCTION Ident StaticParams Params TK_RETURNS Params OptSemicol + Locals Body OptEndNode { treat_node_decl false $2 $3 $4 $6 $8 (fst $9) (snd $9) } -| TK_NODE sxIdent sxStaticParams sxNodeProfileOpt TK_EQ sxEffectiveNode sxOptSemicol +| TK_NODE Ident StaticParams NodeProfileOpt TK_EQ EffectiveNode OptSemicol { treat_node_alias true $2 $3 $4 $6 } ; -| TK_FUNCTION sxIdent sxStaticParams sxNodeProfileOpt TK_EQ sxEffectiveNode sxOptSemicol +| TK_FUNCTION Ident StaticParams NodeProfileOpt TK_EQ EffectiveNode OptSemicol { treat_node_alias false $2 $3 $4 $6 } ; -sxNodeProfileOpt : +NodeProfileOpt : /* nada */ { None } -| sxParams TK_RETURNS sxParams +| Params TK_RETURNS Params { let invars = clocked_ids_to_var_infos VarInput $1 in let outvars = clocked_ids_to_var_infos VarOutput $3 in @@ -560,23 +560,23 @@ sxNodeProfileOpt : } ; -sxStaticParams: /*rien*/ +StaticParams: /*rien*/ { [] } - | TK_OPEN_STATIC_PAR sxStaticParamList TK_CLOSE_STATIC_PAR + | TK_OPEN_STATIC_PAR StaticParamList TK_CLOSE_STATIC_PAR { (List.rev $2) } ; -sxStaticParamList: - sxStaticParam +StaticParamList: + StaticParam { [$1] } - | sxStaticParamList TK_SEMICOL sxStaticParam + | StaticParamList TK_SEMICOL StaticParam { $3::$1 } ; -sxStaticParam: - TK_TYPE sxIdent +StaticParam: + TK_TYPE Ident { {it=(StaticParamType (Lxm.id $2)); src=$2} } - | TK_CONST sxIdent TK_COLON sxType + | TK_CONST Ident TK_COLON Type { {it=(StaticParamConst (Lxm.id $2 , $4)); src=$2} } - | TK_NODE sxIdent sxParams TK_RETURNS sxParams + | TK_NODE Ident Params TK_RETURNS Params { let invars = clocked_ids_to_var_infos VarInput $3 in let outvars = clocked_ids_to_var_infos VarOutput $5 in @@ -588,7 +588,7 @@ sxStaticParam: ) in Lxm.flagit xn $2 } - | TK_FUNCTION sxIdent sxParams TK_RETURNS sxParams + | TK_FUNCTION Ident Params TK_RETURNS Params { let invars = clocked_ids_to_var_infos VarInput $3 in let outvars = clocked_ids_to_var_infos VarOutput $5 in @@ -604,49 +604,49 @@ sxStaticParam: /* Le "." à la fin des noeuds est une fioriture historique, On accepte donc '.' ';' ou rien du tout ! */ -sxOptEndNode: +OptEndNode: TK_DOT {} - | sxOptSemicol + | OptSemicol {} ; /* Aucune difference entre params d'entrée et les autres */ /* params de sortie */ -sxParams: +Params: /* rien */ TK_OPEN_PAR TK_CLOSE_PAR { [] } | - TK_OPEN_PAR sxVarDeclList sxOptSemicol TK_CLOSE_PAR + TK_OPEN_PAR VarDeclList OptSemicol TK_CLOSE_PAR /* WARNING ! il faut remettre la liste à l'endroit */ { (List.rev $2) } ; /* variables locales */ -sxLocals: /* empty */ +Locals: /* empty */ { [] } - | TK_VAR sxVarDeclList TK_SEMICOL + | TK_VAR VarDeclList TK_SEMICOL /* WARNING ! il faut remettre la liste à l'endroit */ { (List.rev $2) } ; /* liste de déclarations de vars typées et clockées */ -sxVarDeclList: sxVarDecl +VarDeclList: VarDecl { [$1] } - | sxVarDeclList TK_SEMICOL sxVarDecl + | VarDeclList TK_SEMICOL VarDecl { $3::$1 } ; /* déclaration de vars éventuellement clockées */ -sxVarDecl: +VarDecl: /* Pas de clock : sous-entendu sur la base exemple: x, ..., z : type */ - sxTypedIdents + TypedIdents { ([$1], Base) } @@ -655,7 +655,7 @@ sxVarDecl: Clock explicite sur UNE seule liste d'idents typés exemple: x, ..., z : type when clock */ - sxTypedIdents TK_WHEN sxClockExpr + TypedIdents TK_WHEN ClockExpr { ([$1], $3) } @@ -664,7 +664,7 @@ sxVarDecl: Clock explicite sur PLUSIEURS listes d'idents typés exemple: (x,..,z : t1 ; a,...,b : t2) when clock */ - TK_OPEN_PAR sxTypedIdentsList TK_CLOSE_PAR TK_WHEN sxClockExpr + TK_OPEN_PAR TypedIdentsList TK_CLOSE_PAR TK_WHEN ClockExpr /* WARNING ! il faut remettre la liste à l'endroit */ { ( (List.rev $2), $5 ) @@ -675,28 +675,28 @@ sxVarDecl: /* Retourne un couple (assertions list, equations list) */ -sxBody: +Body: TK_LET TK_TEL { ([], []) } - | TK_LET sxEquationList TK_TEL + | TK_LET EquationList TK_TEL /* WARNING ! il faut remettre les listes à l'endroit */ { (List.rev (fst $2) , List.rev (snd $2)) } ; /* Equations */ -sxEquationList: sxEquation +EquationList: Equation { $1 } - | sxEquationList sxEquation + | EquationList Equation { ( (fst $2) @ (fst $1) , (snd $2) @ (snd $1) ) } ; -sxEquation: TK_ASSERT sxExpression TK_SEMICOL +Equation: TK_ASSERT Expression TK_SEMICOL { ( [ {src = $1; it = $2} ] , [] ) } - | sxLeft TK_EQ sxExpression TK_SEMICOL + | Left TK_EQ Expression TK_SEMICOL { ( [] , [ {src = $2; it = ($1, $3) } ] ) } @@ -705,127 +705,127 @@ sxEquation: TK_ASSERT sxExpression TK_SEMICOL /* partie gauche d'equation */ -sxLeft: sxLeftItemList +Left: LeftItemList /* WARNING ! il faut remettre la liste à l'endroit */ { (List.rev $1) } - | TK_OPEN_PAR sxLeftItemList TK_CLOSE_PAR + | TK_OPEN_PAR LeftItemList TK_CLOSE_PAR /* WARNING ! il faut remettre la liste à l'endroit */ { (List.rev $2) } ; -sxLeftItemList: sxLeftItem +LeftItemList: LeftItem { [$1] } - | sxLeftItemList TK_COMA sxLeftItem + | LeftItemList TK_COMA LeftItem { $3::$1 } ; -sxLeftItem: sxIdent +LeftItem: Ident { LeftVar ( {src = $1; it = Lxm.id $1} ) } - | sxFieldLeftItem + | FieldLeftItem { $1 } - | sxTableLeftItem + | TableLeftItem { $1 } ; -sxFieldLeftItem: sxLeftItem TK_DOT sxIdent +FieldLeftItem: LeftItem TK_DOT Ident { LeftField ($1 , {src = $3; it = Lxm.id $3} ) } ; -sxTableLeftItem: - sxLeftItem TK_OPEN_BRACKET sxExpression TK_CLOSE_BRACKET +TableLeftItem: + LeftItem TK_OPEN_BRACKET Expression TK_CLOSE_BRACKET { LeftArray ($1 , {src = $2; it = $3}) } - | sxLeftItem TK_OPEN_BRACKET sxSelect TK_CLOSE_BRACKET + | LeftItem TK_OPEN_BRACKET Select TK_CLOSE_BRACKET { LeftSlice ($1, $3 ) } ; /* partie droite d'equation (expression) */ -sxExpression: +Expression: /* zéroaires */ - sxConstant { $1 } - | sxIdentRef { leafexp $1.src (IDENT_n $1.it) } + Constant { $1 } + | IdentRef { leafexp $1.src (IDENT_n $1.it) } /* unaires */ - | TK_NOT sxExpression { unexp_predef $1 NOT_n $2 } - | TK_MINUS sxExpression %prec TK_UMINUS + | TK_NOT Expression { unexp_predef $1 NOT_n $2 } + | TK_MINUS Expression %prec TK_UMINUS { unexp_predef $1 UMINUS_n $2 } - | TK_PRE sxExpression { unexp $1 PRE_n $2 } - | TK_CURRENT sxExpression { unexp $1 CURRENT_n $2 } - | TK_INT sxExpression { unexp_predef $1 REAL2INT_n $2 } - | TK_REAL sxExpression { unexp_predef $1 INT2REAL_n $2 } + | TK_PRE Expression { unexp $1 PRE_n $2 } + | TK_CURRENT Expression { unexp $1 CURRENT_n $2 } + | TK_INT Expression { unexp_predef $1 REAL2INT_n $2 } + | TK_REAL Expression { unexp_predef $1 INT2REAL_n $2 } /* binaires */ - | sxExpression TK_WHEN sxClockExpr { unexp $2 (WHEN_n $3) $1 } - - | sxExpression TK_FBY sxExpression { binexp $2 FBY_n $1 $3 } - | sxExpression TK_ARROW sxExpression { binexp $2 ARROW_n $1 $3 } - | sxExpression TK_AND sxExpression { binexp_predef $2 AND_n $1 $3 } - | sxExpression TK_OR sxExpression { binexp_predef $2 OR_n $1 $3 } - | sxExpression TK_XOR sxExpression { binexp_predef $2 XOR_n $1 $3 } - | sxExpression TK_IMPL sxExpression { binexp_predef $2 IMPL_n $1 $3 } - | sxExpression TK_EQ sxExpression { binexp_predef $2 EQ_n $1 $3 } - | sxExpression TK_NEQ sxExpression { binexp_predef $2 NEQ_n $1 $3 } - | sxExpression TK_LT sxExpression { binexp_predef $2 LT_n $1 $3 } - | sxExpression TK_LTE sxExpression { binexp_predef $2 LTE_n $1 $3 } - | sxExpression TK_GT sxExpression { binexp_predef $2 GT_n $1 $3 } - | sxExpression TK_GTE sxExpression { binexp_predef $2 GTE_n $1 $3 } - | sxExpression TK_DIV sxExpression { binexp_predef $2 DIV_n $1 $3 } - | sxExpression TK_MOD sxExpression { binexp_predef $2 MOD_n $1 $3 } - | sxExpression TK_MINUS sxExpression { binexp_predef $2 MINUS_n $1 $3 } - | sxExpression TK_PLUS sxExpression { binexp_predef $2 PLUS_n $1 $3 } - | sxExpression TK_SLASH sxExpression { binexp_predef $2 SLASH_n $1 $3 } - | sxExpression TK_STAR sxExpression { binexp_predef $2 TIMES_n $1 $3 } + | Expression TK_WHEN ClockExpr { unexp $2 (WHEN_n $3) $1 } + + | Expression TK_FBY Expression { binexp $2 FBY_n $1 $3 } + | Expression TK_ARROW Expression { binexp $2 ARROW_n $1 $3 } + | Expression TK_AND Expression { binexp_predef $2 AND_n $1 $3 } + | Expression TK_OR Expression { binexp_predef $2 OR_n $1 $3 } + | Expression TK_XOR Expression { binexp_predef $2 XOR_n $1 $3 } + | Expression TK_IMPL Expression { binexp_predef $2 IMPL_n $1 $3 } + | Expression TK_EQ Expression { binexp_predef $2 EQ_n $1 $3 } + | Expression TK_NEQ Expression { binexp_predef $2 NEQ_n $1 $3 } + | Expression TK_LT Expression { binexp_predef $2 LT_n $1 $3 } + | Expression TK_LTE Expression { binexp_predef $2 LTE_n $1 $3 } + | Expression TK_GT Expression { binexp_predef $2 GT_n $1 $3 } + | Expression TK_GTE Expression { binexp_predef $2 GTE_n $1 $3 } + | Expression TK_DIV Expression { binexp_predef $2 DIV_n $1 $3 } + | Expression TK_MOD Expression { binexp_predef $2 MOD_n $1 $3 } + | Expression TK_MINUS Expression { binexp_predef $2 MINUS_n $1 $3 } + | Expression TK_PLUS Expression { binexp_predef $2 PLUS_n $1 $3 } + | Expression TK_SLASH Expression { binexp_predef $2 SLASH_n $1 $3 } + | Expression TK_STAR Expression { binexp_predef $2 TIMES_n $1 $3 } /* ternaires */ - | TK_IF sxExpression TK_THEN sxExpression TK_ELSE sxExpression + | TK_IF Expression TK_THEN Expression TK_ELSE Expression { ternexp_predef $1 IF_n $2 $4 $6 } - | TK_WITH sxExpression TK_THEN sxExpression TK_ELSE sxExpression + | TK_WITH Expression TK_THEN Expression TK_ELSE Expression { CallByPos( {src = $1 ; it = WITH_n($2, $4, $6) }, Oper [] ) } /* n-aires */ /* WARNING ! il faut remettre la liste à l'endroit */ - | TK_DIESE TK_OPEN_PAR sxExpressionList TK_CLOSE_PAR + | TK_DIESE TK_OPEN_PAR ExpressionList TK_CLOSE_PAR { naryexp_predef $1 DIESE_n (List.rev $3) } - | TK_NOR TK_OPEN_PAR sxExpressionList TK_CLOSE_PAR + | TK_NOR TK_OPEN_PAR ExpressionList TK_CLOSE_PAR { naryexp_predef $1 NOR_n (List.rev $3) } - | sxCallByPosExpression + | CallByPosExpression { $1 } - | TK_OPEN_PAR sxExpList2 TK_CLOSE_PAR + | TK_OPEN_PAR ExpList2 TK_CLOSE_PAR { naryexp $1 TUPLE_n (List.rev $2) } /* Opérations sur les tableaux */ /* -> création à partir d'une liste */ - | TK_OPEN_BRACKET sxExpressionList TK_CLOSE_BRACKET + | TK_OPEN_BRACKET ExpressionList TK_CLOSE_BRACKET { naryexp $1 ARRAY_n (List.rev $2) } /* -> création par exponentiation */ - | sxExpression TK_HAT sxExpression { binexp $2 HAT_n $1 $3 } + | Expression TK_HAT Expression { binexp $2 HAT_n $1 $3 } /* -> concaténation */ - | sxExpression TK_BAR sxExpression { binexp $2 CONCAT_n $1 $3 } + | Expression TK_BAR Expression { binexp $2 CONCAT_n $1 $3 } /* -> accès à un élément */ - | sxExpression TK_OPEN_BRACKET sxExpression TK_CLOSE_BRACKET + | Expression TK_OPEN_BRACKET Expression TK_CLOSE_BRACKET { unexp $2 (ARRAY_ACCES_n $3) $1 } /* -> accès à une tranche */ - | sxExpression TK_OPEN_BRACKET sxSelect TK_CLOSE_BRACKET + | Expression TK_OPEN_BRACKET Select TK_CLOSE_BRACKET { unexp $3.src (ARRAY_SLICE_n $3.it) $1 } /* Acces aux structures */ - | sxExpression TK_DOT sxIdent + | Expression TK_DOT Ident { unexp $2 (STRUCT_ACCESS_n (Lxm.id $3)) $1 } /* Appels par noms */ - | sxCallByNameExpression + | CallByNameExpression { $1 } /* Parenthèses */ - | TK_OPEN_PAR sxExpression TK_CLOSE_PAR + | TK_OPEN_PAR Expression TK_CLOSE_PAR { $2 } ; -sxClockExpr: - | sxIdent TK_OPEN_PAR sxIdent TK_CLOSE_PAR +ClockExpr: + | Ident TK_OPEN_PAR Ident TK_CLOSE_PAR { (make_clock_exp (Lxm.str $1) $3) } - | sxIdent { (make_clock_exp ("True") $1) } - | TK_NOT sxIdent { (make_clock_exp ("False") $2) } - | TK_NOT TK_OPEN_PAR sxIdent TK_CLOSE_PAR + | Ident { (make_clock_exp ("True") $1) } + | TK_NOT Ident { (make_clock_exp ("False") $2) } + | TK_NOT TK_OPEN_PAR Ident TK_CLOSE_PAR { (make_clock_exp ("False") $3) } ; -sxPredefOp: +PredefOp: | TK_NOT { {src=$1; it=Predef_n(NOT_n,[])} } | TK_FBY { {src=$1; it=FBY_n} } | TK_PRE { {src=$1; it=PRE_n} } @@ -849,44 +849,44 @@ sxPredefOp: | TK_SLASH { {src=$1; it=Predef_n(SLASH_n,[]) } } | TK_STAR { {src=$1; it=Predef_n(TIMES_n,[]) } } | TK_IF { {src=$1; it=Predef_n(IF_n,[]) } } - | TK_WHEN sxClockExpr { {src=$1; it=(WHEN_n $2)} } + | TK_WHEN ClockExpr { {src=$1; it=(WHEN_n $2)} } ; /* Appel fonctionnel par position (classique) */ /* NB On a 2 règles à cause des appels échantillonné */ -sxCallByPosExpression: - sxEffectiveNode TK_OPEN_PAR sxExpression TK_CLOSE_PAR +CallByPosExpression: + EffectiveNode TK_OPEN_PAR Expression TK_CLOSE_PAR { naryexp $1.src (CALL_n $1) [$3] } /* WARNING ! il faut remettre la liste à l'endroit */ - | sxEffectiveNode TK_OPEN_PAR sxExpList2 TK_CLOSE_PAR + | EffectiveNode TK_OPEN_PAR ExpList2 TK_CLOSE_PAR { naryexp $1.src (CALL_n $1) (List.rev $3) } ; /* Effective node : une constrcution qui designe un noeud */ -sxEffectiveNode: +EffectiveNode: /* Juste un nom */ - sxIdentRef + IdentRef { {src=$1.src; it=(($1.it, [])) } } /* Un nom + des params statiques */ - | sxIdentRef TK_OPEN_STATIC_PAR sxStaticArgList TK_CLOSE_STATIC_PAR + | IdentRef TK_OPEN_STATIC_PAR StaticArgList TK_CLOSE_STATIC_PAR { {src=$1.src; it=(($1.it, List.rev $3)) } } /* Un operateur prédéfini - | TK_OPERATOR sxPredefOp,[] + | TK_OPERATOR PredefOp,[] { {src=$; it=($2.it, []) } } ; XXX pour l'instant, j'enleve la possibilité d'avoir (operator +(1,2)). On verra ca plus tard */ -sxStaticArgList: - sxStaticArg +StaticArgList: + StaticArg { [$1] } - | sxStaticArgList TK_COMA sxStaticArg + | StaticArgList TK_COMA StaticArg { $3::$1 } /* let's be permissive... */ - | sxStaticArgList TK_SEMICOL sxStaticArg + | StaticArgList TK_SEMICOL StaticArg { $3::$1 } ; @@ -897,21 +897,21 @@ sxStaticArgList: - la nature est compile-time (juste un ident, a résoudre) */ -sxStaticArg: +StaticArg: /* nature explicite */ - | TK_TYPE sxType + | TK_TYPE Type { {src=$1 ; it=StaticArgType $2 } } - | TK_CONST sxExpression + | TK_CONST Expression { {src=$1 ; it=StaticArgConst $2 } } - | TK_NODE sxEffectiveNode + | TK_NODE EffectiveNode { {src=$1 ; it=StaticArgNode (CALL_n $2) } } - | TK_FUNCTION sxEffectiveNode + | TK_FUNCTION EffectiveNode { {src=$1 ; it=StaticArgNode (CALL_n $2) } } - | sxPredefOp + | PredefOp { {src=$1.src; it=StaticArgNode $1.it } } /* un ident OU une expression simple (à résoudre) */ /* c'est au retour qu'on choisit */ - | sxSimpleExp + | SimpleExp { match $1 with | CallByPos (op, x) -> ( @@ -924,20 +924,20 @@ sxStaticArg: assert false } /* un type sans ambiguite */ - | sxSurelyType + | SurelyType { {src=$1.src; it=StaticArgType $1} } /* un node sans ambiguite */ - | sxSurelyNode + | SurelyNode { {src=$1.src; it=StaticArgNode (CALL_n $1)} } ; /* for model arguments (copy-pasted from call by position StaticArg */ -sxByNameStaticArgList: - sxByNameStaticArg +ByNameStaticArgList: + ByNameStaticArg { [$1] } - | sxByNameStaticArgList TK_COMA sxByNameStaticArg + | ByNameStaticArgList TK_COMA ByNameStaticArg { $3::$1 } /* let's be permissive... */ - | sxByNameStaticArgList TK_SEMICOL sxByNameStaticArg + | ByNameStaticArgList TK_SEMICOL ByNameStaticArg { $3::$1 } ; @@ -948,24 +948,24 @@ sxByNameStaticArgList: - la nature est compile-time (juste un ident, a résoudre) */ -sxByNameStaticArg: +ByNameStaticArg: /* nature explicite */ - | TK_TYPE sxIdent TK_EQ sxType + | TK_TYPE Ident TK_EQ Type { (Lxm.id $2, {src=$1 ; it= StaticArgType $4 }) } - | TK_CONST sxIdent TK_EQ sxExpression + | TK_CONST Ident TK_EQ Expression { (Lxm.id $2, {src=$1 ; it= StaticArgConst $4 }) } - | TK_NODE sxIdent TK_EQ sxEffectiveNode + | TK_NODE Ident TK_EQ EffectiveNode { (Lxm.id $2, {src=$1 ; it= StaticArgNode (CALL_n $4) }) } - | TK_FUNCTION sxIdent TK_EQ sxEffectiveNode + | TK_FUNCTION Ident TK_EQ EffectiveNode { (Lxm.id $2, {src=$1 ; it= StaticArgNode (CALL_n $4) }) } - | sxIdent TK_EQ sxPredefOp + | Ident TK_EQ PredefOp { Lxm.id $1, {src=$3.src; it=StaticArgNode $3.it } } /* un ident OU une expression simple (à résoudre) */ /* c'est au retour qu'on choisit */ - | sxIdent TK_EQ sxSimpleExp + | Ident TK_EQ SimpleExp { Lxm.id $1, match $3 with | CallByPos (op, x) -> ( @@ -978,53 +978,53 @@ sxByNameStaticArg: assert false } /* un type sans ambiguite */ - | sxIdent TK_EQ sxSurelyType + | Ident TK_EQ SurelyType { Lxm.id $1, {src=$3.src; it=StaticArgType $3} } /* un node sans ambiguite */ - | sxIdent TK_EQ sxSurelyNode + | Ident TK_EQ SurelyNode { Lxm.id $1, {src=$3.src; it=StaticArgNode (CALL_n $3)} } ; -sxSurelyNode: - | sxIdentRef TK_OPEN_STATIC_PAR sxStaticArgList TK_CLOSE_STATIC_PAR +SurelyNode: + | IdentRef TK_OPEN_STATIC_PAR StaticArgList TK_CLOSE_STATIC_PAR { {src=$1.src; it=($1.it, List.rev $3) } } ; -sxSurelyType: +SurelyType: /* prédéfini */ TK_BOOL { {src=$1; it=Bool_type_exp} } | TK_INT { {src=$1; it=Int_type_exp} } | TK_REAL { {src=$1; it=Real_type_exp} } /* ou tableau immédiat */ - | sxSurelyType TK_HAT sxExpression + | SurelyType TK_HAT Expression { {src=$1.src; it = Array_type_exp ($1 , $3) } } ; -/* sxSimpleExp = statically evaluable exp */ -sxSimpleExp: - sxConstant { $1 } - | sxIdentRef { leafexp $1.src (IDENT_n $1.it) } - | TK_OPEN_PAR sxSimpleExp TK_CLOSE_PAR { $2 } - | TK_NOT sxSimpleExp { unexp_predef $1 NOT_n $2 } - | TK_MINUS sxSimpleExp %prec TK_UMINUS { unexp_predef $1 UMINUS_n $2 } - | sxSimpleExp TK_AND sxSimpleExp { binexp_predef $2 AND_n $1 $3 } - | sxSimpleExp TK_OR sxSimpleExp { binexp_predef $2 OR_n $1 $3 } - | sxSimpleExp TK_XOR sxSimpleExp { binexp_predef $2 XOR_n $1 $3 } - | sxSimpleExp TK_IMPL sxSimpleExp { binexp_predef $2 IMPL_n $1 $3 } - | sxSimpleExp TK_EQ sxSimpleExp { binexp_predef $2 EQ_n $1 $3 } - | sxSimpleExp TK_NEQ sxSimpleExp { binexp_predef $2 NEQ_n $1 $3 } - | sxSimpleExp TK_LT sxSimpleExp { binexp_predef $2 LT_n $1 $3 } - | sxSimpleExp TK_LTE sxSimpleExp { binexp_predef $2 LTE_n $1 $3 } - | sxSimpleExp TK_GT sxSimpleExp { binexp_predef $2 GT_n $1 $3 } - | sxSimpleExp TK_GTE sxSimpleExp { binexp_predef $2 GTE_n $1 $3 } - | sxSimpleExp TK_DIV sxSimpleExp { binexp_predef $2 DIV_n $1 $3 } - | sxSimpleExp TK_MOD sxSimpleExp { binexp_predef $2 MOD_n $1 $3 } - | sxSimpleExp TK_MINUS sxSimpleExp { binexp_predef $2 MINUS_n $1 $3 } - | sxSimpleExp TK_PLUS sxSimpleExp { binexp_predef $2 PLUS_n $1 $3 } - | sxSimpleExp TK_SLASH sxSimpleExp { binexp_predef $2 SLASH_n $1 $3 } - | sxSimpleExp TK_STAR sxSimpleExp { binexp_predef $2 TIMES_n $1 $3 } +/* SimpleExp = statically evaluable exp */ +SimpleExp: + Constant { $1 } + | IdentRef { leafexp $1.src (IDENT_n $1.it) } + | TK_OPEN_PAR SimpleExp TK_CLOSE_PAR { $2 } + | TK_NOT SimpleExp { unexp_predef $1 NOT_n $2 } + | TK_MINUS SimpleExp %prec TK_UMINUS { unexp_predef $1 UMINUS_n $2 } + | SimpleExp TK_AND SimpleExp { binexp_predef $2 AND_n $1 $3 } + | SimpleExp TK_OR SimpleExp { binexp_predef $2 OR_n $1 $3 } + | SimpleExp TK_XOR SimpleExp { binexp_predef $2 XOR_n $1 $3 } + | SimpleExp TK_IMPL SimpleExp { binexp_predef $2 IMPL_n $1 $3 } + | SimpleExp TK_EQ SimpleExp { binexp_predef $2 EQ_n $1 $3 } + | SimpleExp TK_NEQ SimpleExp { binexp_predef $2 NEQ_n $1 $3 } + | SimpleExp TK_LT SimpleExp { binexp_predef $2 LT_n $1 $3 } + | SimpleExp TK_LTE SimpleExp { binexp_predef $2 LTE_n $1 $3 } + | SimpleExp TK_GT SimpleExp { binexp_predef $2 GT_n $1 $3 } + | SimpleExp TK_GTE SimpleExp { binexp_predef $2 GTE_n $1 $3 } + | SimpleExp TK_DIV SimpleExp { binexp_predef $2 DIV_n $1 $3 } + | SimpleExp TK_MOD SimpleExp { binexp_predef $2 MOD_n $1 $3 } + | SimpleExp TK_MINUS SimpleExp { binexp_predef $2 MINUS_n $1 $3 } + | SimpleExp TK_PLUS SimpleExp { binexp_predef $2 PLUS_n $1 $3 } + | SimpleExp TK_SLASH SimpleExp { binexp_predef $2 SLASH_n $1 $3 } + | SimpleExp TK_STAR SimpleExp { binexp_predef $2 TIMES_n $1 $3 } /* ternaires */ - | TK_IF sxSimpleExp TK_THEN sxSimpleExp TK_ELSE sxSimpleExp + | TK_IF SimpleExp TK_THEN SimpleExp TK_ELSE SimpleExp { ternexp_predef $1 IF_n $2 $4 $6 } ; @@ -1033,23 +1033,23 @@ sxSimpleExp: Actuellement, uniquement pour les structures, donc pas de soucis d'échantillonnage */ -sxCallByNameExpression: +CallByNameExpression: /* WARNING ! il faut remettre la liste à l'endroit */ - sxIdentRef TK_OPEN_BRACE sxCallByNameParamList sxOptSemicol TK_CLOSE_BRACE + IdentRef TK_OPEN_BRACE CallByNameParamList OptSemicol TK_CLOSE_BRACE { bynameexp $1.src (STRUCT_n $1.it) (List.rev $3) } /* on peut avoir une liste vide */ - | sxIdentRef TK_OPEN_BRACE TK_CLOSE_BRACE + | IdentRef TK_OPEN_BRACE TK_CLOSE_BRACE { bynameexp $1.src (STRUCT_n $1.it) ([]) } /* COMPATIBILITY : immediate "struct" without the type name - | TK_OPEN_BRACE sxCallByNameParamList sxOptSemicol TK_CLOSE_BRACE + | TK_OPEN_BRACE CallByNameParamList OptSemicol TK_CLOSE_BRACE { bynameexp $1 STRUCT_anonymous_n (List.rev $2) } */ ; -sxCallByNameParamList: - sxCallByNameParam +CallByNameParamList: + CallByNameParam { [$1] } | - sxCallByNameParamList sepVariant sxCallByNameParam + CallByNameParamList sepVariant CallByNameParam { $3::$1 } ; @@ -1062,19 +1062,19 @@ sepVariant: ; -sxCallByNameParam: - sxIdent TK_EQ sxExpression +CallByNameParam: + Ident TK_EQ Expression { ({it=Lxm.id $1;src=$1} , $3) } ; /* WARNING ! : les listes sont crées à l'envers */ -sxExpressionList: sxExpression +ExpressionList: Expression { [$1] } - | sxExpList2 + | ExpList2 { $1 } ; -sxConstant: TK_TRUE +Constant: TK_TRUE { (leafexp $1 (Predef_n(TRUE_n,[]))) } | TK_FALSE { (leafexp $1 (Predef_n(FALSE_n,[]))) } @@ -1085,20 +1085,18 @@ sxConstant: TK_TRUE ; /* WARNING ! : les listes sont crées à l'envers */ -sxExpList2: sxExpressionList TK_COMA sxExpression +ExpList2: ExpressionList TK_COMA Expression { $3::$1 } ; -sxSelect: - sxExpression TK_CDOTS sxExpression sxStep +Select: + Expression TK_CDOTS Expression Step { {it={si_first = $1; si_last = $3 ; si_step = $4 }; src = $2} } -| TK_SLICE_START sxExpression sxStep - { threat_slice_start $1 $2 $3 } ; -sxStep: /* empty */ +Step: /* empty */ { None } - | TK_STEP sxExpression + | TK_STEP Expression { Some $2 } ; /* NB @@ -1107,15 +1105,15 @@ quand il n'y a pas d'ambiguit les ";" sont vus indifferemment commme des séparateurs ou des terminateurs */ -sxOptSemicol : +OptSemicol : /* empty */ {} | TK_SEMICOL {} ; -sxPragma: /* e.g., %ASSUME:toto% */ +Pragma: /* e.g., %ASSUME:toto% */ { [] } /* produces 3 shift reduce conflicts! */ -| TK_PCENT TK_IDENT TK_COLON TK_IDENT TK_PCENT sxPragma +| TK_PCENT TK_IDENT TK_COLON TK_IDENT TK_PCENT Pragma { (Pragma(Lxm.str $2, Lxm.str $4))::$6 } diff --git a/src/syntaxTreeCore.ml b/src/syntaxTreeCore.ml index 03ca9af0..8f2a4762 100644 --- a/src/syntaxTreeCore.ml +++ b/src/syntaxTreeCore.ml @@ -1,4 +1,4 @@ -(** 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. *) diff --git a/src/test/Makefile b/src/test/Makefile index b6c70324..98f6f97a 100644 --- a/src/test/Makefile +++ b/src/test/Makefile @@ -96,7 +96,7 @@ test_ec: 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 ;\ 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; \ diff -u test_ec.res.exp test_ec.res > test_ec.diff || \ (cat test_ec.diff ; echo "cf test_ec.diff"; exit 1) @@ -114,7 +114,7 @@ test_lv4: echo -e "lus2ec /tmp/xx.lus $$node" >> test_lv4.res; \ (lus2ec /tmp/xx.lus $$node >> \ test_lv4.res 2>&1 && echo -n "ok ") \ - || echo " KO!";\ + || echo " KO ($$d)!";\ done; \ done; \ diff -u test_lv4.res.exp test_lv4.res > test_lv4.diff || \ diff --git a/src/test/test.res.exp b/src/test/test.res.exp index cac0669f..c86c89ba 100644 --- a/src/test/test.res.exp +++ b/src/test/test.res.exp @@ -33,6 +33,8 @@ where [options] can be: Generate ec (actually just an alias for '-en -lv4'). -unit Run some (internal) unit tests + --test-lexer Internal option used to test the lexer + -tlex --verbose-level <int> -vl <int> Set the verbose level. -- GitLab