From 7e7ecf8375f5073597b58c892d448030b4ba8426 Mon Sep 17 00:00:00 2001 From: Sophie Coudert <sophie.coudert@telecom-paris.fr> Date: Tue, 30 Apr 2024 16:54:23 +0200 Subject: [PATCH] add draft files for parser and lexer --- .../tosysmlv2/javacup/AvatarFromSysML.jcup | 100 +++++++ .../tosysmlv2/javacup/AvatarFromSysML.jflex | 260 ++++++++++++++++++ 2 files changed, 360 insertions(+) create mode 100644 src/main/java/avatartranslator/tosysmlv2/javacup/AvatarFromSysML.jcup create mode 100644 src/main/java/avatartranslator/tosysmlv2/javacup/AvatarFromSysML.jflex diff --git a/src/main/java/avatartranslator/tosysmlv2/javacup/AvatarFromSysML.jcup b/src/main/java/avatartranslator/tosysmlv2/javacup/AvatarFromSysML.jcup new file mode 100644 index 0000000000..6d14487393 --- /dev/null +++ b/src/main/java/avatartranslator/tosysmlv2/javacup/AvatarFromSysML.jcup @@ -0,0 +1,100 @@ + +package avatartranslator.fromsml; +import java_cup.runtime.*; +parser code {: + + + interface Ident { + public String getSysMLname(); + public String getAvatarName(); + } + class UniIdent implements Ident { + private String sysMLname; + public UniIdent(String _sysMLname){ sysMLname = _sysMLname; } + public String getSysMLname(){ return sysMLname; } + public String getAvatarName(){ return sysMLname; } + } + class BiIdent implements Ident { + private String avatarName; + private String sysMLname; + public BiIdent(String _sysMLname, String _avatarName){ + sysMLname = _sysMLname; + avatarName = _avatarName; + } + public String getSysMLname(){ return sysMLname; } + public String getAvatarName(){ return avatarName; } + } + + public BiIdent identFromDATATYPENAME(String _ident){ + return new BiIdent(_ident.substring(1,_ident.length - 2), _ident.substring(5,_ident.length - 2)); + } + public BiIdent identFromATTRIBUTENAME(String _ident){ + return new BiIdent(_ident.substring(1,_ident.length - 2), _ident.substring(2,_ident.length - 2)); + } + public BiIdent identFromSIGNALNAMENAME(String _ident){ + return new BiIdent(_ident.substring(1,_ident.length - 2), _ident.substring(6,_ident.length - 2)); + } + public BiIdent identFromSTANDARDSTATENAME(String _ident){ + return new BiIdent(_ident.substring(1,_ident.length - 2), _ident.substring(14,_ident.length - 2)); + } + public BiIdent identFromBLOCKNAME(String _ident){ + return new BiIdent(_ident.substring(1,_ident.length - 2), _ident.substring(6,_ident.length - 2)); + } + public UniIdent identFromString(String _ident){ + return new UniIdent(_ident.substring(1,_ident.length - 2)); + } +:} + +/* Terminals (tokens returned by the scanner). */ +terminal LB, RB; + +terminal Ident DATATYPENAME, BLOCKNAME, ATTRIBUTENAME, RELATIONNAME, CHANNELPRENAME, SIGNALNAMENAME, CHANNELNAME, MESSAGENAME, STANDARDSTATENAME, STARTSTATENAME, STOPSTATENAME, RANDOMSTATENAME, COUNTSTATENAME, SENDSTATENAME, RECEIVESTATENAME, PRESENDSTATENAME, PRERECEIVESTATENAME, SETTIMERSTATENAME, RESETTIMERSTATENAME, EXPIRETIMERSTATENAME, PRESETTIMERSTATENAME, PRERESETTIMERSTATENAME, PREEXPIRETIMERSTATENAME, TIMERBLOCKNAME, TIMERRELATIONNAME, SETTIMERCHANNELNAME, RESETTIMERCHANNELNAME, EXPIRETIMERCHANNELNAME, AVATARNAME; + +terminal ABOUT, ABSTRACT, ACCEPT, ACTION, ACTOR, AFTER, ALIAS, ALL, ALLOCATE, ALLOCATION, ANALYSIS, AND, AS, ASSERT, ASSIGN, ASSOC, ASSUME, AT, ATTRIBUTE, BIND, BINDING, BLOCK, BY, CALC, CASE, COMMENT, CONCERN, CONNECT, CONNECTION, CONSTRAINT, DECIDE, DEF, DEFAULT, DEFINED, DEPENDENCY, DERIVED, DO, DOC, ELSE, END, ENTRY, ENUM, EVENT, EXHIBIT, EXIT, EXPOSE, FILTER, FIRST, FLOW, FOR, FORK, FRAME, FROM, HASTYPE, IF, IMPLIES, IMPORT, IN, INCLUDE, INDIVIDUAL, INOUT, INTERFACE, ISTYPE, ITEM, JOIN, LANGUAGE, LOOP, MERGE, MESSAGE, METADATA, NONUNIQUE, NOT, OBJECTIVE, OCCURRENCE, OF, OR, ORDERED, OUT, PACKAGE, PARALLEL, PART, PERFORM, PORT, PRIVATE, PROTECTED, PUBLIC, READONLY, REDEFINES, REF, REFERENCES, RENDER, RENDERING, REP, REQUIRE, REQUIREMENT, RETURN, SATISFY, SEND, SNAPSHOT, SPECIALIZES, STAKEHOLDER, STATE, SUBJECT, SUBSETS, SUCCESSION, THEN, TIMESLICE, TO, TRANSITION, UNTIL, USE, VARIANT, VARIATION, VERIFICATION, VERIFY, VIA, VIEW, VIEWPOINT, WHEN, WHILE, XOR + + +/* Non terminals */ +non terminal featureList + +non terminal IBSExpressions<Spec,Comp,State,SpecState,CompState>.Expr expr; +non terminal Integer iexpr, bexpr; + +/* Precedences croissantes (probably useless for the current grammar) */ +precedence left OR; +precedence left AND; + +model ::= PACKAGE AVATARNAME LB featureList RB | PACKAGE AVATARNAME LB RB; +featureList ::= feature | feature featureList; + +feature ::= + | datatypeDecl + | relationDecl + | channelDecl + | signalBind + | messageDecl + | blockDecl + | blockAlias +; +datatypeDecl ::= datatypeDeclHEADER datatypeDeclBODY; +relationDecl ::= syncRelDecl | nbfRelDecl |bfRelDecl; +syncRelDecl ::= syncRelDeclHEADER syncRelDeclBODY; +nbfRelDecl ::= nbfRelDeclHEADER fifofRelDeclBODY; +bfRelDecl ::= bfRelDeclHEADER fifoRelDeclBODY; +channelDecl ::= syncChDecl | nbfChDecl |bfChDecl; +syncChDecl ::= syncChDeclHEADER syncChDeclBODY; +nbfChDecl ::= nbfChDeclHEADER fifofChDeclBODY; +bfChDecl ::= bfChDeclHEADER fifoChDeclBODY; + | signalBind + | messageDecl + | blockDecl + | blockAlias + + +expr ::= + PARSE_BOOL bexpr:e {: RESULT = lexer.getExpressions().getBExpr(e.intValue()); + lexer.getExpressions().freeBool(e.intValue()); :} + | PARSE_INT iexpr:e {: RESULT = lexer.getExpressions().getIExpr(e.intValue()); + lexer.getExpressions().freeInt(e.intValue()); :} +; + +Spec ::= Blocs Interconnections diff --git a/src/main/java/avatartranslator/tosysmlv2/javacup/AvatarFromSysML.jflex b/src/main/java/avatartranslator/tosysmlv2/javacup/AvatarFromSysML.jflex new file mode 100644 index 0000000000..4f658742ef --- /dev/null +++ b/src/main/java/avatartranslator/tosysmlv2/javacup/AvatarFromSysML.jflex @@ -0,0 +1,260 @@ +package avatartranslator.fromsmlv2; +import java_cup.runtime.*; +import java.util.HashSet; + +%% + +%class AvatarSysmlLex + +%public +%unicode +%cup +%eofval{ + return new java_cup.runtime.Symbol(AvatarSysmlLex#symb.EOF); +%eofval} + +%yylexthrow Exception + +%{ +fonctions +%} + +Space = [\ \n\r\t\f] +Natural = 0 | [1-9][0-9]* + +AvIdent = ("_"[a-zA-Z0-9] | [a-zA-Z]) ("_"[a-zA-Z0-9] | [a-zA-Z0-9])* ("_")? +dataTypeName = "'@dt:" AvIdent "'" +blockName = "'@blk:" AvIdent "'" +attributeName = "'$" AvIdent "'" +fieldName = "'" AvIdent "'" +relationName = ("'@BF" | "'@NBF" | "'@SYN") Natural ":" AvIdent "-" AvIdent "'" +channelPreName = AvIdent "." AvIdent (">"|"<") AvIdent "." AvIdent +signalName = "'@sig:" AvIdent "'" +channelNname = ("'@syn" | "'@bf" | "'@nbf") ":" channelPreName "'" +messageName = "'@MSG:" AvIdent "." AvIdent "'" +startStateName = "'@st:start'" +stopStateName = "'@st:stop'" +standardStateName = "'@st:standard." AvIdent "'" +randomStateName = "'@st:random." Natural "'" +countStateName = "'@st:count." AvIdent "." Natural "'" +sendStateName = "'@st:send." AvIdent "." Natural "'" +receiveStateName = "'@st:receive." AvIdent "." Natural "'" +presendStateName = "'@st:presend." AvIdent "." Natural "'" +prereceiveStateName = "'@st:prereceive." AvIdent "." Natural "'" +setTimerStateName = "'@st:set." AvIdent "." Natural "'" +resetTimerStateName = "'@st:reset." AvIdent "." Natural "'" +expireTimerStateName = "'@st:expire." AvIdent "." Natural "'" +presetTimerStateName = "'@st:preset." AvIdent "." Natural "'" +preresetTimerStateName = "'@st:prereset." AvIdent "." Natural "'" +preexpireTimerStateName = "'@st:preexpire." AvIdent "." Natural "'" +timerBlockName = "'@tmr:" AvIdent "'" +timerRelationName = "'@TMRRel:" AvIdent "'" +setTimerChannelName = "'@ch:set." AvIdent "'" +resetTimerChannelName = "'@ch:reset." AvIdent "'" +expireTimerChannelName = "'@ch:expire." AvIdent "'" + +%state INTBOOL + {Space} { break; } + "true" { return new Symbol(XX#Symb.BOOL, Integer.valueOf(exprC.make_bConst(true))); } + "false" { return new Symbol(XX#Symb.BOOL, Integer.valueOf(exprC.make_bConst(false))); } + {Natural} { try { return new Symbol(XX#Symb.INT, Integer.valueOf(exprC.make_iConst(Integer.parseInt(yytext()))));} + catch (NumberFormatException nfe) { throw new Exception ("Lexer : Integer Format : " + yytext()); } + } + "+" { return new Symbol(XX#Symb.PLUS); } + "-" { return new Symbol(XX#Symb.MINUS); } + "*" { return new Symbol(XX#Symb.MULT); } + "/" { return new Symbol(XX#Symb.DIV); } + "%" { return new Symbol(XX#Symb.MOD); } + "&" { return new Symbol(XX#Symb.AND); } + "|" { return new Symbol(XX#Symb.OR); } + "==" { return new Symbol(XX#Symb.EQ); } + "!=" { return new Symbol(XX#Symb.DIF); } + "<" { return new Symbol(XX#Symb.LT); } + ">" { return new Symbol(XX#Symb.GT); } + "<=" { return new Symbol(XX#Symb.LEQ); } + ">=" { return new Symbol(XX#Symb.GEQ); } + "(" { return new Symbol(XX#Symb.LPAR); } + ")" { return new Symbol(XX#Symb.RPAR); } + "{" { return new Symbol(XX#Symb.LBRAC); } + "}" { return new Symbol(XX#Symb.RBRAC); } + "," { return new Symbol(XX#Symb.COMMA); } + ";" { return new Symbol(XX#Symb.SEMICOLON); } + ":" { return new Symbol(XX#Symb.COLON); } + "." { return new Symbol(XX#Symb.POINT); } + "=" { return new Symbol(XX#Symb.EQUAL); } + ":=" { return new Symbol(XX#Symb.GETS); } + + '@lossy' + '@max_size' + '@private' + '@relation' + '@block1' + '@block2' + '@pool' + '@request' + '@state_action' + '@index' + '@payload' + '@channel' + + + + "about" { return new Symbol(XX#Symb.ABOUT); } + "abstract" { return new Symbol(XX#Symb.ABSTRACT); } + "accept" { return new Symbol(XX#Symb.ACCEPT); } + "action" { return new Symbol(XX#Symb.ACTION); } + "actor" { return new Symbol(XX#Symb.ACTOR); } + "after" { return new Symbol(XX#Symb.AFTER); } + "alias" { return new Symbol(XX#Symb.ALIAS); } + "all" { return new Symbol(XX#Symb.ALL); } + "allocate" { return new Symbol(XX#Symb.ALLOCATE); } + "allocation" { return new Symbol(XX#Symb.ALLOCATION); } + "analysis" { return new Symbol(XX#Symb.ANALYSIS); } + "and" { return new Symbol(XX#Symb.AND); } + "as" { return new Symbol(XX#Symb.AS); } + "assert" { return new Symbol(XX#Symb.ASSERT); } + "assign" { return new Symbol(XX#Symb.ASSIGN); } + "assoc" { return new Symbol(XX#Symb.ASSOC); } + "assume" { return new Symbol(XX#Symb.ASSUME); } + "at" { return new Symbol(XX#Symb.AT); } + "attribute" { return new Symbol(XX#Symb.ATTRIBUTE); } + "bind" { return new Symbol(XX#Symb.BIND); } + "binding" { return new Symbol(XX#Symb.BINDING); } + "block" { return new Symbol(XX#Symb.BLOCK); } + "by" { return new Symbol(XX#Symb.BY); } + "calc" { return new Symbol(XX#Symb.CALC); } + "case" { return new Symbol(XX#Symb.CASE); } + "comment" { return new Symbol(XX#Symb.COMMENT); } + "concern" { return new Symbol(XX#Symb.CONCERN); } + "connect" { return new Symbol(XX#Symb.CONNECT); } + "connection" { return new Symbol(XX#Symb.CONNECTION); } + "constraint" { return new Symbol(XX#Symb.CONSTRAINT); } + "decide" { return new Symbol(XX#Symb.DECIDE); } + "def" { return new Symbol(XX#Symb.DEF); } + "default" { return new Symbol(XX#Symb.DEFAULT); } + "defined" { return new Symbol(XX#Symb.DEFINED); } + "dependency" { return new Symbol(XX#Symb.DEPENDENCY); } + "derived" { return new Symbol(XX#Symb.DERIVED); } + "do" { return new Symbol(XX#Symb.DO); } + "doc" { return new Symbol(XX#Symb.DOC); } + "else" { return new Symbol(XX#Symb.ELSE); } + "end" { return new Symbol(XX#Symb.END); } + "entry" { return new Symbol(XX#Symb.ENTRY); } + "enum" { return new Symbol(XX#Symb.ENUM); } + "event" { return new Symbol(XX#Symb.EVENT); } + "exhibit" { return new Symbol(XX#Symb.EXHIBIT); } + "exit" { return new Symbol(XX#Symb.EXIT); } + "expose" { return new Symbol(XX#Symb.EXPOSE); } + "filter" { return new Symbol(XX#Symb.FILTER); } + "first" { return new Symbol(XX#Symb.FIRST); } + "flow" { return new Symbol(XX#Symb.FLOW); } + "for" { return new Symbol(XX#Symb.FOR); } + "fork" { return new Symbol(XX#Symb.FORK); } + "frame" { return new Symbol(XX#Symb.FRAME); } + "from" { return new Symbol(XX#Symb.FROM); } + "hastype" { return new Symbol(XX#Symb.HASTYPE); } + "if" { return new Symbol(XX#Symb.IF); } + "implies" { return new Symbol(XX#Symb.IMPLIES); } + "import" { return new Symbol(XX#Symb.IMPORT); } + "in" { return new Symbol(XX#Symb.IN); } + "include" { return new Symbol(XX#Symb.INCLUDE); } + "individual" { return new Symbol(XX#Symb.INDIVIDUAL); } + "inout" { return new Symbol(XX#Symb.INOUT); } + "interface" { return new Symbol(XX#Symb.INTERFACE); } + "istype" { return new Symbol(XX#Symb.ISTYPE); } + "item" { return new Symbol(XX#Symb.ITEM); } + "join" { return new Symbol(XX#Symb.JOIN); } + "language" { return new Symbol(XX#Symb.LANGUAGE); } + "loop" { return new Symbol(XX#Symb.LOOP); } + "merge" { return new Symbol(XX#Symb.MERGE); } + "message" { return new Symbol(XX#Symb.MESSAGE); } + "metadata" { return new Symbol(XX#Symb.METADATA); } + "nonunique" { return new Symbol(XX#Symb.NONUNIQUE); } + "not" { return new Symbol(XX#Symb.NOT); } + "objective" { return new Symbol(XX#Symb.OBJECTIVE); } + "occurrence" { return new Symbol(XX#Symb.OCCURRENCE); } + "of" { return new Symbol(XX#Symb.OF); } + "or" { return new Symbol(XX#Symb.OR); } + "ordered" { return new Symbol(XX#Symb.ORDERED); } + "out" { return new Symbol(XX#Symb.OUT); } + "package" { return new Symbol(XX#Symb.PACKAGE); } + "parallel" { return new Symbol(XX#Symb.PARALLEL); } + "part" { return new Symbol(XX#Symb.PART); } + "perform" { return new Symbol(XX#Symb.PERFORM); } + "port" { return new Symbol(XX#Symb.PORT); } + "private" { return new Symbol(XX#Symb.PRIVATE); } + "protected" { return new Symbol(XX#Symb.PROTECTED); } + "public" { return new Symbol(XX#Symb.PUBLIC); } + "readonly" { return new Symbol(XX#Symb.READONLY); } + "redefines" { return new Symbol(XX#Symb.REDEFINES); } + "ref" { return new Symbol(XX#Symb.REF); } + "references" { return new Symbol(XX#Symb.REFERENCES); } + "render" { return new Symbol(XX#Symb.RENDER); } + "rendering" { return new Symbol(XX#Symb.RENDERING); } + "rep" { return new Symbol(XX#Symb.REP); } + "require" { return new Symbol(XX#Symb.REQUIRE); } + "requirement" { return new Symbol(XX#Symb.REQUIREMENT); } + "return" { return new Symbol(XX#Symb.RETURN); } + "satisfy" { return new Symbol(XX#Symb.SATISFY); } + "send" { return new Symbol(XX#Symb.SEND); } + "snapshot" { return new Symbol(XX#Symb.SNAPSHOT); } + "specializes" { return new Symbol(XX#Symb.SPECIALIZES); } + "stakeholder" { return new Symbol(XX#Symb.STAKEHOLDER); } + "state" { return new Symbol(XX#Symb.STATE); } + "subject" { return new Symbol(XX#Symb.SUBJECT); } + "subsets" { return new Symbol(XX#Symb.SUBSETS); } + "succession" { return new Symbol(XX#Symb.SUCCESSION); } + "then" { return new Symbol(XX#Symb.THEN); } + "timeslice" { return new Symbol(XX#Symb.TIMESLICE); } + "to" { return new Symbol(XX#Symb.TO); } + "transition" { return new Symbol(XX#Symb.TRANSITION); } + "until" { return new Symbol(XX#Symb.UNTIL); } + "use" { return new Symbol(XX#Symb.USE); } + "variant" { return new Symbol(XX#Symb.VARIANT); } + "variation" { return new Symbol(XX#Symb.VARIATION); } + "verification" { return new Symbol(XX#Symb.VERIFICATION); } + "verify" { return new Symbol(XX#Symb.VERIFY); } + "via" { return new Symbol(XX#Symb.VIA); } + "view" { return new Symbol(XX#Symb.VIEW); } + "viewpoint" { return new Symbol(XX#Symb.VIEWPOINT); } + "when" { return new Symbol(XX#Symb.WHEN); } + "while" { return new Symbol(XX#Symb.WHILE); } + "xor" { return new Symbol(XX#Symb.XOR); } + + dataTypeName { return new Symbol(XX#Symb.DATATYPENAME, identFromDATATYPENAME(yytext())); } + blockName { return new Symbol(XX#Symb.BLOCKNAME, identFromBLOCKNAME(yytext())); } + attributeName { return new Symbol(XX#Symb.ATTRIBUTENAME, identFromATTRIBUTENAME(yytext())); } + relationName { return new Symbol(XX#Symb.RELATIONNAME, identFromString(yytext())); } + channelPreName { return new Symbol(XX#Symb.CHANNELPRENAME, identFromString(yytext())); } + signalName { return new Symbol(XX#Symb.SIGNALNAME, identFromSIGNALNAME(yytext())); } + channelNname { return new Symbol(XX#Symb.CHANNELNAME, identFromString(yytext())); } + messageName { return new Symbol(XX#Symb.MESSAGENAME, identFromString(yytext())); } + startStateName { return new Symbol(XX#Symb.CHANNELPRENAME, identFromString(yytext())); } + stopStateName { return new Symbol(XX#Symb.STARTSTATENAME, identFromString(yytext())); } + standardStateName { return new Symbol(XX#Symb.STANDARDSTATENAME, identFromSTANDARDSTATENAME(yytext())); } + randomStateName { return new Symbol(XX#Symb.RANDOMSTATENAME, identFromString(yytext())); } + countStateName { return new Symbol(XX#Symb.COUNTSTATENAME, identFromString(yytext())); } + sendStateName { return new Symbol(XX#Symb.SENDSTATENAME, identFromString(yytext())); } + receiveStateName { return new Symbol(XX#Symb.RECEIVESTATENAME, identFromString(yytext())); } + presendStateName { return new Symbol(XX#Symb.PRESENDSTATENAME, identFromString(yytext())); } + prereceiveStateName { return new Symbol(XX#Symb.PRERECEIVESTATENAME, identFromString(yytext())); } + setTimerStateName { return new Symbol(XX#Symb.SETTIMERSTATENAME, identFromString(yytext())); } + resetTimerStateName { return new Symbol(XX#Symb.RESETTIMERSTATENAME, identFromString(yytext())); } + expireTimerStateName { return new Symbol(XX#Symb.EXPIRETIMERSTATENAME, identFromString(yytext())); } + presetTimerStateName { return new Symbol(XX#Symb.PRESETTIMERSTATENAME, identFromString(yytext())); } + preresetTimerStateName { return new Symbol(XX#Symb.PRERESETTIMERSTATENAME, identFromString(yytext())); } + preexpireTimerStateName { return new Symbol(XX#Symb.PREEXPIRETIMERSTATENAME, identFromString(yytext())); } + timerBlockName { return new Symbol(XX#Symb.TIMERBLOCKNAME, identFromTIMERBLOCKNAME(yytext())); } + timerRelationName { return new Symbol(XX#Symb.TIMERRELATIONNAME, identFromString(yytext())); } + setTimerChannelName { return new Symbol(XX#Symb.SETTIMERCHANNELNAME, identFromString(yytext())); } + resetTimerChannelName { return new Symbol(XX#Symb.RESETTIMERCHANNELNAME, identFromString(yytext())); } + expireTimerChannelName { return new Symbol(XX#Symb.EXPIRETIMERCHANNELNAME, identFromString(yytext())); } + fieldName { return new Symbol(XX#Symb.AVATARNAME, identFromString(yytext())); } + AvIdent { return new Symbol(XX#Symb.AVATARNAME, yytext()); } + + + +%% + "method" { return new Symbol(AvatarSysmlLex#symb.METHOD; } + "\t" { return new Symbol(AvatarSysmlLex#symb.DEC; } + -- GitLab