MAJ terminée. Nous sommes passés en version 14.6.2 . Pour consulter les "releases notes" associées c'est ici :

https://about.gitlab.com/releases/2022/01/11/security-release-gitlab-14-6-2-released/
https://about.gitlab.com/releases/2022/01/04/gitlab-14-6-1-released/

Commit e6102caa authored by VIGNET Pierre's avatar VIGNET Pierre
Browse files

[lib][antlr] Update grammar definitions for antlr4; #2

parent a8898ef7
......@@ -43,10 +43,7 @@ parser grammar sigexpr_compiler;
options{
language = Python;
ASTLabelType = CommonTree;
k=2;
tokenVocab = sigexpr_lexer;
output = AST;
}
@header{
......@@ -54,7 +51,18 @@ from cadbiom.models.biosignal.sig_expr import *
import string
}
// auxiliary methods
// put extra attributes in members is equivalent of @init{} in antlr3
@members{
# Extra attributes
self.state_events = []
self.free_clocks = []
self.state_only = False
self.state_only_in_bool = False
self.catch_free_clocks = False
self.deep = -1
self.message = ""
self.error_reporter = None
def set_error_reporter(self, err):
self.error_reporter = err
......@@ -163,16 +171,7 @@ def check_included(self, exp1,exp2):
}
// Compiler options and internals
@init{
self.state_events = []
self.free_clocks = []
self.state_only = False
self.state_only_in_bool = False
self.catch_free_clocks = False
self.deep = -1
self.message = ""
self.error_reporter = None
}
// RULES {$exp = $exp1.exp}
sig_expression[tab_symb] returns [exp]
......@@ -184,7 +183,7 @@ sig_expression[tab_symb] returns [exp]
sig_expression1[tab_symb] returns [exp]
: exp1=sig_exp[tab_symb] {$exp = $exp1.exp}
(DEFAULT^ exp2=sig_exp[tab_symb]
(DEFAULT exp2=sig_exp[tab_symb]
{$exp = SigDefaultExpr($exp, $exp2.exp)}
)*
// void expressions = default to True
......@@ -193,40 +192,41 @@ sig_expression1[tab_symb] returns [exp]
sig_exp[tab_symb] returns [exp]
: exp1=sig_bool[tab_symb] {$exp = $exp1.exp}
(WHEN^
(WHEN
{st_only_save = self.state_only; self.state_only = self.state_only_in_bool}
exp2=sig_bool[tab_symb]
{$exp = SigWhenExpr($exp, $exp2.exp)
self.state_only = st_only_save}
{
$exp = SigWhenExpr($exp, $exp2.exp)
self.state_only = st_only_save}
)*
;
sig_bool[tab_symb] returns [exp]
: exp1=sig_bool_and[tab_symb] {$exp = $exp1.exp }
(OR^ exp2=sig_bool_and[tab_symb]
(OR exp2=sig_bool_and[tab_symb]
{$exp = SigSyncBinExpr("or", $exp, $exp2.exp)}
)*
;
sig_bool_and[tab_symb] returns [exp]
: exp1=sig_primary[tab_symb] {$exp = $exp1.exp }
(AND^ exp2=sig_primary[tab_symb]
(AND exp2=sig_primary[tab_symb]
{$exp = SigSyncBinExpr("and",$exp, $exp2.exp)}
)*
;
sig_primary[tab_symb] returns [exp]
: NOT^ nexp=sig_primary[tab_symb]
: NOT nexp=sig_primary[tab_symb]
{$exp = SigNotExpr($nexp.exp)} // TODO
| cexp=sig_constant
{$exp = $cexp.exp}
| EVENT PG! exps=sig_expression1[tab_symb] PD!
| EVENT PG exps=sig_expression1[tab_symb] PD
{$exp = SigEventExpr($exps.exp)}
| WHEN PG! expw=sig_expression1[tab_symb] PD!
| WHEN PG expw=sig_expression1[tab_symb] PD
{$exp = SigWhenExpr(SigConstExpr(True),$expw.exp)}
| i7=IDENT UP
......@@ -250,13 +250,13 @@ sig_constant returns [exp]
;
sig_constraint[tab_symb] returns [exp]
: SYNC^ PG! el=exp_list[tab_symb] PD!
: SYNC PG el=exp_list[tab_symb] PD
{$exp = self.check_sync($el.expl)}
| EXC^ PG! el = exp_list[tab_symb] PD!
| EXC PG el = exp_list[tab_symb] PD
{$exp = self.check_exclus($el.expl)}
| INC^ PG! e3=sig_expression1[tab_symb] COM! e4=sig_exp[tab_symb] PD!
| INC PG e3=sig_expression1[tab_symb] COM e4=sig_exp[tab_symb] PD
{$exp = self.check_included($e3.exp, $e4.exp)}
;
......
......@@ -43,12 +43,11 @@ lexer grammar sigexpr_lexer;
options {
language= Python;
k = 3;
}
WS : (' '|'\t'|'\n'){$channel = HIDDEN;};
WS : (' '|'\t'|'\n') -> channel(HIDDEN);
COMMENT : '//'(~'\n')*'\n'{$channel = HIDDEN;};
COMMENT : '//'(~'\n')*'\n' -> channel(HIDDEN);
// keywords
DEFAULT : 'default' ;
......
......@@ -7,34 +7,33 @@ grammar condexp;
options {
language= Python;
k = 3;
}
@header{
}
// RULES
// returns the set of ids in boolean expression
sig_bool returns [idents]
@init{idents = set([])}
@init{$idents = set()}
: id1=sig_bool1 DOL {$idents = id1}
| DOL
;
sig_bool1 returns [idents]
@init{idents = set([])}
@init{$idents = set()}
: id1=sig_bool_and {$idents = id1}
(OR id2=sig_bool_and {$idents = $idents | id2}
)*
;
sig_bool_and returns [idents]
@init{idents = set([])}
@init{$idents = set()}
: id1=sig_primary {$idents = id1}
(AND id2=sig_primary {$idents = $idents | id2}
)*
;
sig_primary returns [idents]
@init{idents = set([])}
@init{$idents = set()}
: NOT id1=sig_primary
{$idents = id1}
......@@ -49,15 +48,15 @@ sig_primary returns [idents]
;
sig_constant returns [idents]
@init{idents = set([])}
: T {$idents = set([])}
| F {$idents = set([])}
@init{$idents = set()}
: T {$idents = set()}
| F {$idents = set()}
;
//lexer
WS : (' '|'\t'|'\n'){$channel = HIDDEN;};
WS : (' '|'\t'|'\n') -> channel(HIDDEN);
COMMENT : '//'(~'\n')*'\n'{$channel = HIDDEN;};
COMMENT : '//'(~'\n')*'\n' -> channel(HIDDEN);
// keywords
AND : 'and' ;
......
......@@ -7,8 +7,6 @@ grammar cadlang;
options {
language= Python;
//k = 3;
output = AST; // hack
}
@lexer::members{
......@@ -30,7 +28,7 @@ def displayExceptionMessage(self, e):
}
@members{
@parser::members{
def set_error_reporter(self, err):
self.error_reporter = err
......@@ -207,13 +205,12 @@ def check_end(self):
// boolean expressions in conditions
cad_model[model]
@init{
self.model = model
self.macro_pile = []
self.symb_tab = dict()}
:
self.model = model
self.macro_pile = []
self.symb_tab = dict()} :
{self.current_macro = self.model.get_root()}
(NAME id=IDENT {self.model.name = $id.text})?
(NAME id_dec=IDENT {self.model.name = $id_dec.text})?
(macro|transition|dec)+
{self.check_end()}
(txt=constraints {self.model.constraints = $txt.text})?
......@@ -222,8 +219,8 @@ cad_model[model]
dec :{type = 'S'}
id=IDENT (m=modifier {type = self.modif_code($m.text)})? SC
{self.check_ident_dec(id.text, type, id.line)}
id_dec=IDENT (m=modifier {type = self.modif_code($m.text)})? SC
{self.check_ident_dec($id_dec.text, type, $id_dec.line)}
;
transition :
......@@ -246,18 +243,18 @@ modifier :
guard returns [guard_component]
:
(h=sig_expression)? LB (bt=bool_exp) RB (id2=IDENT)?
{if h and id2: $guard_component = ($h.text, $bt.text, $id2.text)
elif h: $guard_component = ($h.text, $bt.text, None)
elif id2: $guard_component = (None, $bt.text, $id2.text)
else: $guard_component = (None, $bt.text, None)}
;
{
if $h.ctx and $id2: $guard_component = ($h.text, $bt.text, $id2.text)
elif $h.ctx: $guard_component = ($h.text, $bt.text, None)
elif $id2: $guard_component = (None, $bt.text, $id2.text)
else: $guard_component = (None, $bt.text, None)};
note :
TEXT
|
;
macro @init{id2 = None}
macro @init{id2 = None} // refactor note: usefull for this function?
:
MACRO id1=IDENT
{self.enter_macro($id1.text, $id1.line)}
......@@ -269,21 +266,21 @@ macro @init{id2 = None}
sig_expression returns [text]
: exp1=sig_exp {$text = $exp1.text}
(DEFAULT^ exp2=sig_exp
(DEFAULT exp2=sig_exp
{$text = $text + ' default '+ $exp2.text}
)*
;
sig_exp returns [text]
: exp1=sig_exp_primary {$text = $exp1.text}
(WHEN^ exp2=bool_exp
(WHEN exp2=bool_exp
{$text = $text + ' when '+ $exp2.text}
)*
;
sig_exp_primary returns [text]
: id=IDENT
{$text = $id.text}
: id_dec=IDENT
{$text = $id_dec.text}
| LP se=sig_expression RP
{$text = '('+$se.text+')'}
;
......@@ -305,7 +302,7 @@ bool_primary returns [text]
| b2=bool_constant {$text = $b2.text}
| id=IDENT {$text = $id.text}
| id_dec=IDENT {$text = $id_dec.text}
| LP b3=bool_exp RP {$text = '('+$b3.text+')'}
......@@ -317,9 +314,7 @@ bool_constant returns [text]
;
constraints returns [text]
@init {
SEP = ';'
}
@init {SEP = ';'}
: CONST t1=const_exp {$text = $t1.text+SEP}
(t2=const_exp {$text = $text+'\n'+$t2.text+SEP})* ENDCONST
;
......@@ -335,7 +330,7 @@ const_exp returns [text]
exp_list returns [text]
: t1=sig_expression {$text = $t1.text}
(COM t2=sig_expression { $text = $text +', '+$t2.text})*
(COM t2=sig_expression {$text = $text +', '+$t2.text})*
;
......@@ -343,9 +338,9 @@ exp_list returns [text]
//lexer
WS : (' '|'\t'|'\n'){$channel = HIDDEN;};
WS : (' '|'\t'|'\n') -> channel(HIDDEN);
COMMENT : '//'(~'\n')*'\n'{$channel = HIDDEN;};
COMMENT : '//'(~'\n')*'\n' -> channel(HIDDEN);
// keywords
AND : 'and' ;
......
......@@ -7,7 +7,6 @@ grammar pintlang;
options {
language= Python;
// k = 3;
}
@lexer::members{
......@@ -25,10 +24,10 @@ def displayExceptionMessage(self, e):
self.error_reporter.display('',msg)
}
@header{
@parser::header{
from cadbiom.models.guard_transitions.chart_model import ChartModel
}
@members{
@parser::members{
def set_error_reporter(self, err):
self.error_reporter = err
......@@ -159,21 +158,21 @@ def tt_translate_lcond(self, id_list, lval_list, line_txt):
// RULES
pintspec[model_name] @init{
self.model = ChartModel(model_name)
self.symb_tab = dict()
self.clock_cpt = 0
self.clock_list = []}
self.model = ChartModel(model_name)
self.symb_tab = dict()
self.clock_cpt = 0
self.clock_list = []}
: (process|action|cooper)* EOF
;
process
: PROC id=IDENT i=INT
{self.check_process($id.text, int($i.text), id.line)}
: PROC id_dec=IDENT i=INT
{self.check_process($id_dec.text, int($i.text), $id_dec.line)}
;
action
: fid=IDENT flev=INT ARROW cid=IDENT lev1=INT lev2=INT
{self.check_action($fid.text, int($flev.text), $cid.text, int($lev1.text), int($lev2.text), fid.line)}
{self.check_action($fid.text, int($flev.text), $cid.text, int($lev1.text), int($lev2.text), $fid.line)}
;
cooper
......@@ -182,24 +181,27 @@ cooper
coop_lhs returns [transition, id_list, condition]
: il=sort_list
{$id_list = il}
rc=rcoop_lhs[il]
{$transition = $rc.transition
$condition = $rc.condition }
// Refactor note: Before antlr3 sort_list returned a list,
// now its a localctx with an id_list inside which must be used here.
{$id_list = $il.id_list}
rc=rcoop_lhs[$id_list]
{
$transition = $rc.transition
$condition = $rc.condition}
;
rcoop_lhs [ids] returns [transition, condition]
: kw=IN_KW tt=tt_condition cond=tail_logexp
{$condition = self.tt_translate_lcond(ids, $tt.l_cond, 'line '+str(kw.line)+':') + $cond.cond}
| ARROW id=IDENT i1=INT i2=INT
{$transition = self.check_transition($id.text, int($i1.text), int($i2.text), $id.line)}
{$condition = self.tt_translate_lcond(ids, $tt.l_cond, 'line '+str($kw.line)+':') + $cond.cond}
| ARROW id_dec=IDENT i1=INT i2=INT
{$transition = self.check_transition($id_dec.text, int($i1.text), int($i2.text), $id_dec.line)}
;
coop_rhs[tr, il, cond]
: tt=tt_condition
{self.check_tt_rhs(tr,il, $tt.l_cond, )}
| id=IDENT cc=COM i1=INT COM i2=INT
{self.check_tr_rhs(cond, $id.text, int($i1.text), int($i2.text), cc.line)}
| id_dec=IDENT cc=COM i1=INT COM i2=INT
{self.check_tr_rhs(cond, $id_dec.text, int($i1.text), int($i2.text), $cc.line)}
;
sort_list returns [id_list]
......@@ -223,9 +225,16 @@ tail_logexp returns [cond]
| AND tt1=tt_logexp
{$cond = ' and ' + $tt1.cond}
| OR tt2=tt_logexp
{$cond = ' and ' + $tt1.cond}
//{$cond = ' and ' + $tt1.cond} // refactor note: maybe a problem here ? bad copy/paste ?
// replaced by:
{$cond = ' or ' + $tt2.cond}
| tt_primary
{$cond = $tt1.cond}
// refactor note: tt1 doesn't exist here
// old version: tt1 was initialized by None and put in cond variable
// Pb: tail_logexp() is expected to return a string used in rcoop_lhs()
// {$cond = $tt1.cond}
// replaced by:
{$cond = ""}
;
tt_logexp returns [cond]
......@@ -242,7 +251,7 @@ tt_primary returns [cond]
: NOT tt1=tt_primary
{$cond = 'not (' + $tt1.cond + ')'}
| st=sort_list kw=IN_KW tt2=tt_condition
{$cond = self.tt_translate_lcond($st.id_list, $tt2.l_cond, 'line '+str(kw.line)+':')}
{$cond = self.tt_translate_lcond($st.id_list, $tt2.l_cond, 'line '+str($kw.line)+':')}
| LP tt3=tt_logexp RP
{$cond = '('+$tt3.cond+')'}
;
......@@ -251,9 +260,9 @@ tt_primary returns [cond]
//lexer
WS : (' '|'\t'|'\n'){$channel = HIDDEN;};
WS : (' '|'\t'|'\n') -> channel(HIDDEN);
COMMENT : '//'(~'\n')*'\n'{$channel = HIDDEN;};
COMMENT : '//'(~'\n')*'\n' -> channel(HIDDEN);
// keywords
PROC : 'process' ;
......
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