### Example SysML v2 Tool Usage Source: https://github.com/monticore/sysmlv2/blob/master/README.md Examples demonstrating how to invoke the SysML v2 tool. The first example shows how to display the help dialog, and the second shows parsing an input file and pretty-printing the AST. ```bash java -jar MCSysMLv2.jar -h ``` ```bash java -jar MCSysMLv2.jar -i Car.sysml -pp ``` -------------------------------- ### Initialize SysMLv2Mill and Setup Global Scope Source: https://context7.com/monticore/sysmlv2/llms.txt Demonstrates the programmatic initialization of `SysMLv2Mill` and the preparation of the global scope with built-in types. This is essential before performing parsing or symbol table operations. ```java import de.monticore.lang.sysmlv2.SysMLv2Mill; // Step 1: Initialize the Mill (resets all state) SysMLv2Mill.init(); // Step 2: Prepare the global scope with built-in types // (called automatically by SysMLv2Tool.init(), or manually here) SysMLv2Mill.prepareGlobalScope(); // adds nat, String, List, Set, Map, Optional SysMLv2Mill.addStreamType(); // adds Stream with snth, length, times, atTime, ... // Verify built-in types are available assert SysMLv2Mill.globalScope().resolveType("nat").isPresent(); assert SysMLv2Mill.globalScope().resolveType("String").isPresent(); assert SysMLv2Mill.globalScope().resolveType("Stream").isPresent(); assert SysMLv2Mill.globalScope().resolveType("List").isPresent(); // Create a traverser over the full language family var traverser = SysMLv2Mill.traverser(); // Create an inheritance-aware traverser (used during symbol table completion) var inheritanceTraverser = SysMLv2Mill.inheritanceTraverser(); // Create a new artifact scope var artifactScope = SysMLv2Mill.artifactScope(); ``` -------------------------------- ### Build SysML v2 Tool JAR with Gradle Source: https://github.com/monticore/sysmlv2/blob/master/README.md Command to build the executable JAR file for the SysML v2 tool using Gradle. Ensure Java 21 JRE is installed and configured. ```bash ./gradlew :language:shadowJar ``` -------------------------------- ### Define Standard Library Package in SysML v2 Source: https://github.com/monticore/sysmlv2/blob/master/README.md Example of defining a standard library package with imports and aliases in SysML v2 textual notation. This demonstrates basic package structure and type aliasing. ```SysML standard library package 'Vehicles' { import ISQ::TorqueValue; import ScalarValuesliv.*; part def Automobile; alias Car for Automobile; alias Torque for ISQ::TorqueValue; } ``` -------------------------------- ### Derive Type of Stream Constructor Expression in SysMLv2 Source: https://context7.com/monticore/sysmlv2/llms.txt This snippet demonstrates how to use `SysMLDeriver` to derive the type of a stream constructor expression. It also shows an example of a mixed-type stream yielding an 'Obscure' type and how to resolve the generic `EventStream` type. ```java import de.monticore.lang.sysmlv2.SysMLv2Mill; import de.monticore.lang.sysmlv2.SysMLv2Tool; import de.monticore.lang.sysmlv2.types.SysMLDeriver; import de.monticore.lang.sysmlconstraints._ast.ASTConstraintUsage; import de.monticore.lang.sysmlparts._ast.ASTPartUsage; import de.monticore.types.check.TypeCheckResult; SysMLv2Tool tool = new SysMLv2Tool(); tool.init(); // --- Derive type of a stream constructor expression --- String model = "port def F { attribute a: boolean; } " + "part s { port f: F; constraint e { } }"; var ast = SysMLv2Mill.parser().parse_String(model).get(); tool.createSymbolTable(ast); tool.completeSymbolTable(ast); tool.finalizeSymbolTable(ast); ASTPartUsage part = (ASTPartUsage) ast.getSysMLElement(1); ASTConstraintUsage constraint = (ASTConstraintUsage) part.getSysMLElement(1); var expr = constraint.getExpression(); SysMLDeriver deriver = new SysMLDeriver(); TypeCheckResult result = deriver.deriveType(expr); assert result.isPresentResult(); System.out.println(result.getResult().printFullName()); // Output: "Stream.Stream" // --- Mixed-type stream yields Obscure (error case) --- String badModel = "part s { constraint e { } }"; // boolean + int = error var badAst = SysMLv2Mill.parser().parse_String(badModel).get(); tool.createSymbolTable(badAst); tool.completeSymbolTable(badAst); tool.finalizeSymbolTable(badAst); ASTConstraintUsage badConstraint = (ASTConstraintUsage) badAst.getSysMLElement(0); TypeCheckResult badResult = deriver.deriveType(badConstraint.getExpression()); assert badResult.getResult().printFullName().equals("Stream.Stream"); assert !Log.getFindings().isEmpty(); // "Stream Expressions cannot contain multiple types" // --- Resolve generic EventStream type (preferred over plain Stream) --- var eventStream = SysMLv2Mill.globalScope().resolveType("EventStream"); // EventStream implements Stream, has .nth(long n): UntimedStream and .times(long n): EventStream ``` -------------------------------- ### Build and Test Project with Maven Source: https://github.com/monticore/sysmlv2/blob/master/language/README.md Use this command to clean, build, and test all components of the project. ```bash mvn clean install ``` -------------------------------- ### Build and Run Language Server JAR Source: https://context7.com/monticore/sysmlv2/llms.txt Builds the language server JAR using Gradle and provides the command to run it. This server enables IDE features like syntax highlighting and diagnostics. ```bash # Build the language server JAR ./gradlew :language-server:shadowJar # Run the language server (communicates over stdio) java -jar language-server/target/libs/language-server-7.*.*-SNAPSHOT.jar # VSCode launch config (settings.json): # { # "sysmlv2.languageServer.path": "/path/to/language-server-7.x.x-SNAPSHOT.jar", # "sysmlv2.languageServer.javaPath": "/path/to/java21/bin/java" # } ``` -------------------------------- ### SysMLTool Main Method Parameters Source: https://github.com/monticore/sysmlv2/blob/master/language/README.md Illustrates the command-line arguments for the SysMLTool, including model path, disabling CoCos, and specifying library directories. ```java public static void main(String[] args) ``` -------------------------------- ### Build SysML v2 Parser from Source with Gradle Source: https://context7.com/monticore/sysmlv2/llms.txt Instructions for cloning the repository and building the executable shadow JAR using Gradle. Requires Java 21. ```bash # Clone the repository git clone https://github.com/MontiCore/sysmlv2.git cd sysmlv2 ``` ```bash # Build the executable shadow JAR (requires Java 21) ./gradlew :language:shadowJar # Output: language/target/libs/language-7.*.*-SNAPSHOT-mc-tool.jar ``` ```bash # Run all tests ./gradlew test ``` ```bash # Build all modules ./gradlew build ``` ```bash # Skip slow tests during development ./gradlew test -Pdev-skip-slow-tests ``` -------------------------------- ### SysML v2 Parser CLI Tool Usage Source: https://context7.com/monticore/sysmlv2/llms.txt Demonstrates various command-line operations for the SysML v2 parser JAR, including downloading, showing help, parsing files, pretty-printing, processing directories, and running extended checks. ```bash # Download the tool wget https://www.monticore.de/download/MCSysMLv2.jar ``` ```bash # Show help java -jar MCSysMLv2.jar -h ``` ```bash # Parse a file and print version java -jar MCSysMLv2.jar -v java -jar MCSysMLv2.jar -i Car.sysml ``` ```bash # Parse and pretty-print to stdout java -jar MCSysMLv2.jar -i Car.sysml -pp ``` ```bash # Parse and pretty-print to a file java -jar MCSysMLv2.jar -i Car.sysml -pp Car_out.sysml ``` ```bash # Parse an entire directory of .sysml files java -jar MCSysMLv2.jar -i models/ ``` ```bash # Parse with an artifact path for imported symbols java -jar MCSysMLv2.jar -i Car.sysml -path ./symbols ``` ```bash # Run extended checks for MontiBelle semantic analysis java -jar MCSysMLv2.jar -i Car.sysml -ex ``` ```bash # Serialize to Component Connector symbol table format java -jar MCSysMLv2.jar -i Car.sysml --compcon Car.sym ``` ```bash # Parse only (skip CoCos) java -jar MCSysMLv2.jar -i Car.sysml --nococo ``` ```bash # Parse a directory and log per-file success/failure java -jar MCSysMLv2.jar -i models/ --log_parser_results # Output: [PARSER_LOG]models/Car.sysml::true ``` -------------------------------- ### Build Project without Tests using Maven Source: https://github.com/monticore/sysmlv2/blob/master/language/README.md Use this command to build the project, skipping all tests. ```bash mvn install -DskipTests ``` -------------------------------- ### Programmatic IDE Features via LSP Server Source: https://context7.com/monticore/sysmlv2/llms.txt Demonstrates how to programmatically reconfigure the model root at runtime using the SysMLv2LspServer. The server automatically rebuilds the symbol table and re-runs CoCos on file changes. ```java // The LSP server exposes these IDE features programmatically: // - Syntax highlighting (semantic tokens) // - In-place error reporting (diagnostics from CoCos and parser) // - Auto-completion suggestions (symbol names from symbol table) // - Hover information (symbol type, documentation) // - Document symbols (outline of part defs, port defs, state defs, etc.) // Example: reconfiguring the model root at runtime (e.g., in test) import de.monticore.lang.sysmlv2._lsp.language_access.SysMLv2LspServer; // The server automatically rebuilds the symbol table and re-runs CoCos // on every file change reported by the client (textDocument/didChange) ``` -------------------------------- ### SysMLTool mainForJava Method Source: https://github.com/monticore/sysmlv2/blob/master/language/README.md Demonstrates the `mainForJava` method of SysMLTool, which returns parsed models for further processing. It accepts the same arguments as the main method. ```java public static List mainForJava(String[] args) ``` -------------------------------- ### Build Project with Development Profile (Skip Slow Tests) Source: https://github.com/monticore/sysmlv2/blob/master/language/README.md Activates a Maven profile that skips slow tests, useful for parser development. Use with caution as it skips the SysMLToolTest. ```bash mvn install -Pdev-skip-slow-tests ``` -------------------------------- ### Run SysML v2 Tool CLI Source: https://github.com/monticore/sysmlv2/blob/master/README.md Command-line interface for the SysML v2 tool. Use -h for help. The -i option is mandatory for specifying the input file. ```bash java -jar MCSysMLv2.jar [-h] -i [-path

] [-pp []] [-s []] ``` -------------------------------- ### Run Default and Extended CoCos in SysMLv2 Source: https://context7.com/monticore/sysmlv2/llms.txt This snippet shows how to initialize the SysMLv2 tool, parse a model, and run both default and extended context condition checks. It also demonstrates how to set up a custom checker with specific CoCos. ```java import de.monticore.lang.sysmlv2.SysMLv2Mill; import de.monticore.lang.sysmlv2.SysMLv2Tool; import de.monticore.lang.sysmlv2._ast.ASTSysMLModel; import de.monticore.lang.sysmlv2._cocos.SysMLv2CoCoChecker; import de.monticore.lang.sysmlv2.cocos.*; import de.monticore.lang.sysmlparts._cocos.*; import de.se_rwth.commons.logging.Log; SysMLv2Tool tool = new SysMLv2Tool(); tool.init(); ASTSysMLModel ast = SysMLv2Mill.parser().parse_String("\n part def A;\n part def B : A {\n port i : ~BoolPort;\n constraint c { i == true }\n }\n port def BoolPort { attribute v: boolean; }\n ").get(); tool.createSymbolTable(ast); tool.completeSymbolTable(ast); tool.finalizeSymbolTable(ast); // Default CoCos (transition guards, send/assign type checks) Log.enableFailQuick(false); tool.runDefaultCoCos(ast); // Extended CoCos (MontiBelle-readiness) tool.runAdditionalCoCos(ast); if (Log.getFindings().isEmpty()) { System.out.println("Model is well-formed."); } else { Log.getFindings().forEach(f -> System.out.println(f.getMsg())); } // --- Custom CoCo checker (selective checks) --- var checker = new SysMLv2CoCoChecker(); checker.addCoCo(new ConstraintIsBoolean()); // 0x10xxx: constraint expr must be boolean checker.addCoCo(new RefinementCyclic()); // 0x90xxx: no cyclic refinements checker.addCoCo(new OneCardinality()); // max one cardinality per usage checker.addCoCo(new PortDefinitionExistsCoCo()); // port type must exist checker.addCoCo((SysMLPartsASTPartDefCoCo) new NameCompatible4Isabelle()); // Isabelle-safe names checker.checkAll(ast); // Error code categories (see doc/ERROR_CODES.md): // 0x00xxx CLI, 0x10xxx CoCos, 0x80xxx TypeCheck, 0x90xxx Refinement, 0xFFxxx Verification ``` -------------------------------- ### Orchestrate SysMLv2 Processing Pipeline with SysMLv2Tool Source: https://context7.com/monticore/sysmlv2/llms.txt Use SysMLv2Tool to manage the entire SysMLv2 processing pipeline, from initialization to running checks. It can parse files, strings, and multiple files, build symbol tables, and pretty-print models. ```java import de.monticore.lang.sysmlv2.SysMLv2Tool; import de.monticore.lang.sysmlv2.SysMLv2Mill; import de.monticore.lang.sysmlv2._ast.ASTSysMLModel; import de.se_rwth.commons.logging.Log; Log.init(); SysMLv2Tool tool = new SysMLv2Tool(); tool.init(); // initializes Mill, clears global scope, loads stream symbols, inits TC3 // --- Parse from file --- ASTSysMLModel ast = tool.parse("models/Car.sysml"); // --- Parse from string --- var optAst = SysMLv2Mill.parser().parse_String("part def Wheel;"); ASTSysMLModel ast2 = optAst.get(); // --- Build and complete symbol table --- var artifactScope = tool.createSymbolTable(ast); tool.completeSymbolTable(ast); // Phase 1 & 2: specializations, directions, types tool.finalizeSymbolTable(ast); // Phase 3: OCL/let-in completer // --- Run well-formedness checks --- tool.runDefaultCoCos(ast); // type checks on transitions, send/assign actions tool.runAdditionalCoCos(ast); // MontiBelle-readiness: ConstraintIsBoolean, RefinementCyclic, etc. // --- Pretty-print to stdout --- tool.prettyPrint(ast, null); // --- Pretty-print to file --- tool.prettyPrint(ast, "out/Car_pp.sysml"); // --- Process multiple files with mainForJava --- List models = tool.mainForJava(new String[]{"models/", "-lib=stdlib/"}); // models: all parsed & symbol-table-completed ASTs from models/ directory ``` -------------------------------- ### SysMLv2 Import Resolution Strategies Source: https://context7.com/monticore/sysmlv2/llms.txt Demonstrates explicit and wildcard import resolution. Recursive imports are currently treated as wildcard imports. ```java import de.monticore.lang.sysmlv2.SysMLv2Tool; import de.monticore.lang.sysmlv2.SysMLv2Mill; import de.monticore.lang.sysmlv2._symboltable.ISysMLv2Scope; SysMLv2Tool tool = new SysMLv2Tool(); tool.init(); // --- Explicit import: "import Other::Parent;" --- String parentModel = "package Other { part def Parent; }"; String model1 = "private import Other::Parent; part def Child : Parent;"; ASTSysMLModel parentAst = SysMLv2Mill.parser().parse_String(parentModel).get(); ASTSysMLModel childAst = SysMLv2Mill.parser().parse_String(model1).get(); tool.createSymbolTable(parentAst); tool.completeSymbolTable(parentAst); tool.finalizeSymbolTable(parentAst); tool.createSymbolTable(childAst); tool.completeSymbolTable(childAst); tool.finalizeSymbolTable(childAst); var partDef = (de.monticore.lang.sysmlparts._ast.ASTPartDef) childAst.getSysMLElement(1); var ref = (de.monticore.types.mcbasictypes._ast.ASTMCQualifiedType) partDef.getSpecialization(0).getSuperTypes(0); var resolved = ((ISysMLv2Scope) ref.getEnclosingScope()).resolveType(ref.getNameList().get(0)); assert resolved.isPresent(); assert resolved.get().getFullName().equals("Other.Parent"); // "Other.Parent" resolved via explicit import // --- Wildcard import: "import Other::* ;" --- String model2 = "private import Other::* ; part def Widget : Parent;"; // After tool processing, "Parent" resolves to "Other.Parent" via wildcard // --- FQN resolution without import --- String model3 = "part def Child : Other.Parent;"; // Resolves "Other.Parent" by fully qualified name in the global scope // --- Recursive import (currently unsupported, treated as wildcard) --- // "import Other::**;" — only direct children of Other are resolved ``` -------------------------------- ### Configure GitHub Credentials for Development Source: https://github.com/monticore/sysmlv2/blob/master/visualization/README.md Add your GitHub username and personal access token (PAT) with 'read_registry' rights to your Gradle user properties file. This is required for the project to access the official SysML v2 implementation on GitHub. ```properties githubUser = GITHUB_USERNAME githubToken = GITHUB_PAT ``` -------------------------------- ### Parse SysMLv2 Models, Strings, and Expressions with SysMLv2Parser Source: https://context7.com/monticore/sysmlv2/llms.txt Directly use SysMLv2Parser for parsing single .sysml files, inline string models, or SysML expressions. Ensure to initialize the parser and check for errors after parsing. ```java import de.monticore.lang.sysmlv2.SysMLv2Mill; import de.monticore.lang.sysmlv2._ast.ASTSysMLModel; import de.monticore.lang.sysmlv2._parser.SysMLv2Parser; import de.monticore.expressions.expressionsbasis._ast.ASTExpression; Log.init(); SysMLv2Mill.init(); SysMLv2Parser parser = SysMLv2Mill.parser(); // Parse a .sysml file Optional ast = parser.parse("models/Vehicles.sysml"); assert !parser.hasErrors() : "Parse error"; assert ast.isPresent(); // Parse an inline string model Optional ast2 = parser.parse_String(""" standard library package 'Vehicles' { import ISQ::TorqueValue; import ScalarValues.*; part def Automobile; alias Car for Automobile; } """); assert ast2.isPresent(); // Parse a single SysML expression Optional expr = parser.parse_StringExpression("a.b \subseteq c"); assert expr.isPresent(); // Parse from stdin (used in interactive mode) var reader = new java.io.BufferedReader(new java.io.InputStreamReader(System.in)); Optional astFromStdin = SysMLv2Mill.parser().parse(reader); ``` -------------------------------- ### Build and Resolve SysMLv2 Symbol Tables with Cross-Model Support Source: https://context7.com/monticore/sysmlv2/llms.txt Utilize SysMLv2Tool to create, complete, and finalize symbol tables for SysMLv2 models. Configure an MCPath for cross-model resolution and serialize/deserialize symbol tables. ```java import de.monticore.io.paths.MCPath; import de.monticore.lang.sysmlv2.SysMLv2Tool; import de.monticore.lang.sysmlv2._ast.ASTSysMLModel; import de.monticore.lang.sysmlv2._symboltable.ISysMLv2ArtifactScope; import de.monticore.lang.sysmlparts._symboltable.PartDefSymbol; SysMLv2Tool tool = new SysMLv2Tool(); tool.init(); // Parse two interdependent models ASTSysMLModel libAst = tool.parse("lib/PortDefinitions.sysml"); ASTSysMLModel mainAst = tool.parse("src/Inverter.sysml"); // Build initial symbol tables ISysMLv2ArtifactScope libScope = tool.createSymbolTable(libAst); tool.createSymbolTable(mainAst); // Phase 1+2: specialize, direction, types tool.completeSymbolTable(libAst); tool.completeSymbolTable(mainAst); // Phase 3: OCL/let-in tool.finalizeSymbolTable(mainAst); // --- Cross-model resolution via symbol path --- // Set the symbol path so the global scope can load .sym files MCPath symbolPath = new MCPath(); symbolPath.addEntry(java.nio.file.Paths.get("symbols/")); tool.getGlobalScope().setSymbolPath(symbolPath); // Resolve a part def by FQN across model boundaries Optional partDef = tool.getGlobalScope().resolvePartDef("PortDefinitions.BooleanInput"); assert partDef.isPresent(); // Refinement chain inspection assert partDef.get().getDirectRefinements().size() >= 0; assert partDef.get().getTransitiveRefinements().size() >= 0; // --- Serialize (store) symbol table --- tool.storeSymbols(libScope, "symbols/PortDefinitions.sym"); // --- Deserialize (load) symbol table --- ISysMLv2ArtifactScope loaded = tool.loadSymbols("symbols/PortDefinitions.sym"); ``` -------------------------------- ### Clone MontiCore SysML v2 Repository Source: https://github.com/monticore/sysmlv2/blob/master/README.md Command to clone the MontiCore SysML v2 project from GitHub. This is the first step to building the tool from source. ```bash git clone https://github.com/MontiCore/sysmlv2.git ``` -------------------------------- ### Open Symbol Definition from JAR Source: https://github.com/monticore/sysmlv2/blob/master/doc/TYPECHECK.md This Java code snippet uses JarURLConnection to open the JAR file containing the symbol definition. It includes error handling for potential IOExceptions during the opening process. ```java JarURLConnection conn = null; JarFile jar = null; try { conn = (JarURLConnection) streamDefUrl.openConnection(); jar = conn.getJarFile(); } catch (IOException e) { Log.error("0xPA092 Failed to open symbol definition from JAR URL"); } ``` -------------------------------- ### Pretty Print AST to SysML v2 Text Source: https://context7.com/monticore/sysmlv2/llms.txt Serializes an ASTSysMLModel back into SysML v2 textual syntax. Uses either a convenience method or the full pretty printer directly. ```java import de.monticore.lang.sysmlv2.SysMLv2Mill; import de.monticore.lang.sysmlv2._ast.ASTSysMLModel; import de.monticore.lang.sysmlv2._prettyprint.SysMLv2FullPrettyPrinter; import de.monticore.prettyprint.IndentPrinter; SysMLv2Mill.init(); Optional ast = SysMLv2Mill.parser().parse_String(""" package Vehicles { part def Automobile; alias Car for Automobile; part def Truck : Automobile; } """); assert ast.isPresent(); // --- Using SysMLv2Mill convenience method --- String prettyPrinted = SysMLv2Mill.prettyPrint(ast.get(), true); System.out.println(prettyPrinted); // Output: package Vehicles { part def Automobile; alias Car for Automobile; ... } // --- Using the full pretty printer directly --- SysMLv2FullPrettyPrinter printer = new SysMLv2FullPrettyPrinter(new IndentPrinter()); String output = printer.prettyprint(ast.get()); System.out.println(output); // --- Via SysMLv2Tool (to file or stdout) --- // new SysMLv2Tool().prettyPrint(ast.get(), null); // → stdout // new SysMLv2Tool().prettyPrint(ast.get(), "out.sysml"); // → file ``` -------------------------------- ### Load Stream Symbols from JAR Source: https://github.com/monticore/sysmlv2/blob/master/doc/TYPECHECK.md This Java code attempts to load the 'Stream.symtabdefinitionsym' from the classpath and verifies it's loaded from a JAR. It logs errors if the file is not found or not loaded from a JAR. ```java public void loadStreamSymbolsFromJar() { URL streamDefUrl = SysMLv2Tool.class.getClassLoader().getResource("Stream.symtabdefinitionsym"); if (streamDefUrl == null) { Log.error("0xPA090 Failed to find Stream.symtabdefinitionsym on the classpath."); return; } if (!"jar".equals(streamDefUrl.getProtocol())) { Log.error("0xPA091 Expected Stream.symtabdefinitionsym to be loaded from a JAR"); return; } ``` -------------------------------- ### Add JAR Path and Register Deserializers Source: https://github.com/monticore/sysmlv2/blob/master/doc/TYPECHECK.md This Java code adds the path of the JAR file containing symbol definitions to the global scope's symbol path and registers deserializers for specific symbol types. ```java Path jarPath = Path.of(jar.getName()); SysMLv2Mill.globalScope().getSymbolPath().addEntry(jarPath); SysMLv2Mill.globalScope().putSymbolDeSer("de.monticore.cdbasis._symboltable.CDTypeSymbol", new OOTypeSymbolDeSer()); SysMLv2Mill.globalScope().putSymbolDeSer("de.monticore.cd4codebasis._symboltable.CDMethodSignatureSymbol", new MethodSymbolDeSer()); } ``` -------------------------------- ### Component Connector Serialization for Semantic Analysis Source: https://context7.com/monticore/sysmlv2/llms.txt Extracts PartDefs from SysML v2 models and serializes them as component-connector symbols. This is required for semantic analysis tools like MontiBelle. ```java import de.monticore.lang.componentconnector.SerializationUtil; import de.monticore.lang.sysmlv2.SysMLv2Mill; import de.monticore.lang.sysmlv2.SysMLv2Tool; SysMLv2Tool tool = new SysMLv2Tool(); tool.init(); var ast = tool.parse("models/System.sysml"); tool.createSymbolTable(ast); tool.completeSymbolTable(ast); tool.finalizeSymbolTable(ast); tool.runDefaultCoCos(ast); tool.runAdditionalCoCos(ast); // required for MontiBelle readiness // Setup CC serialization (maps SysML symbols to component-connector symbols) SerializationUtil.setupComponentConnectorSerialization(); // Extract all PartDefs into a new artifact scope var ccArtifact = SysMLv2Mill.artifactScope(); var extractor = new SerializationUtil.PartDefExtractor(ccArtifact); var traverser = tool.getTraverser(); traverser.add4SysMLParts(extractor); ast.accept(traverser); // Serialize to .sym file for downstream MontiBelle / verification tooling tool.storeSymbols(ccArtifact, "output/System.sym"); // System.sym contains: component, port, automaton, and specification symbols // Equivalent CLI command: // java -jar MCSysMLv2.jar -i models/System.sysml -ex --compcon output/System.sym ``` -------------------------------- ### Serialize and Deserialize SysMLv2 Symbol Tables Source: https://context7.com/monticore/sysmlv2/llms.txt Use this to save symbol tables to JSON files for later use, enabling cross-model resolution. Ensure the symbol path is correctly set for deserialization. ```java import de.monticore.lang.sysmlv2.SysMLv2Tool; import de.monticore.lang.sysmlv2._ast.ASTSysMLModel; import de.monticore.lang.sysmlv2._symboltable.ISysMLv2ArtifactScope; import de.monticore.io.paths.MCPath; SysMLv2Tool tool = new SysMLv2Tool(); tool.init(); // Serialize ASTSysMLModel ast = tool.parse("src/RoughPartDef.sysml"); ISysMLv2ArtifactScope scope = tool.createSymbolTable(ast); tool.completeSymbolTable(ast); tool.storeSymbols(scope, "symbols/RoughPartDef.sym"); // Creates: symbols/RoughPartDef.sym (JSON format) // Deserialize in another session SysMLv2Tool tool2 = new SysMLv2Tool(); tool2.init(); ASTSysMLModel refAst = tool2.parse("src/RefinedPart.sysml"); tool2.createSymbolTable(refAst); MCPath path = new MCPath(); path.addEntry(java.nio.file.Paths.get("symbols/")); tool2.getGlobalScope().setSymbolPath(path); // completeSymbolTable will trigger lazy loading of RoughPartDef.sym tool2.completeSymbolTable(refAst); tool2.finalizeSymbolTable(refAst); // The refined part's specializations are now resolved cross-model var refined = tool2.getGlobalScope().resolvePartDef("RefinedPart.A"); assert refined.isPresent(); assert refined.get().getTransitiveRefinements().size() == 2; ``` -------------------------------- ### Add Stream Symbols Dependency Source: https://github.com/monticore/sysmlv2/blob/master/doc/TYPECHECK.md This Gradle code snippet shows how to add the stream-symbols dependency to the 'language' module's build.gradle file. This is necessary for loading stream symbol definitions. ```gradle implementation "de.monticore:stream-symbols:$mc_version" ``` -------------------------------- ### SysML v2 Packages and Imports Source: https://context7.com/monticore/sysmlv2/llms.txt Defines a package 'Vehicles' and imports types from 'ISQ::TorqueValue' and 'ScalarValues'. This sets up the scope for defining parts, ports, and other elements within the package. ```sysml // --- Packages and Imports --- package Vehicles { import ISQ::TorqueValue; import ScalarValues.*; // --- Part Definitions and Usages --- part def Automobile { port engine : ~EnginePort; port wheel[4] : WheelPort; timing delayed; } part def ElectricCar : Automobile; // --- Port Definitions --- port def EnginePort { attribute torque : TorqueValue; } port def WheelPort { attribute rpm : Real; } // --- State Machines --- part def TrafficLight { state def Phases { state red; state green; state yellow; transition first red if timer > 30 then green; transition first green if timer > 25 then yellow; transition first yellow if timer > 5 then red; } exhibit state phases : Phases; } // --- Constraints and Requirements --- requirement def SafetyReq { subject car : Automobile; require constraint { car.wheel[0].rpm < 200 } } // --- Actions --- action def Accelerate { in attribute force : Real; out attribute velocity : Real; } // --- Stream Expressions --- part def SignalProcessor { port input : ~DataPort; constraint dataFlow { .times(3) } } // --- Connections --- part assembly : Automobile { connection connect engine to wheel[0]; } } ``` -------------------------------- ### Build 'times' Function Symbol Source: https://github.com/monticore/sysmlv2/blob/master/doc/TYPECHECK.md This Java code builds a FunctionSymbol for the 'times' function. It defines the function name, return type (Stream), and parameters (k of type Nat). ```java protected FunctionSymbol buildTimesFunction(TypeSymbol streamSymbol, TypeVarSymbol typeVar) { var parameterList = new BasicSymbolsScope(); VariableSymbol parameter = SysMLv2Mill.variableSymbolBuilder().setName( "k").setType(buildNatType()).build(); parameterList.add(typeVar); parameterList.add(parameter); var returnType = SymTypeExpressionFactory.createGenerics(streamSymbol, SymTypeExpressionFactory.createTypeVariable(typeVar)); return SysMLv2Mill.functionSymbolBuilder() .setName("times") .setType(returnType) .setSpannedScope(parameterList) .build(); } ``` -------------------------------- ### Configure SysML Expressions Deriver Source: https://github.com/monticore/sysmlv2/blob/master/doc/TYPECHECK.md Configure the traverser with DeriveSymTypeOfExpression for basis expressions. A reference to the TypeCheckResult instance is passed to DeriveSymTypeOfExpression so it can set its result. Visitors and handlers are then attached to the traverser. ```java public class SysMLExpressionsDeriver extends AbstractDerive { public SysMLExpressionsDeriver() { super(SysMLExpressionsMill.traverser()); DeriveSymTypeOfExpression forBasisExpr = new DeriveSymTypeOfExpression(); forBasisExpr.setTypeCheckResult(typeCheckResult); getTraverser().add4ExpressionsBasis(forBasisExpr); getTraverser().setExpressionsBasisHandler(forBasisExpr); // more DeriveSymTypeOf... follow } } ``` -------------------------------- ### Define Power Expression in Grammar Source: https://github.com/monticore/sysmlv2/blob/master/doc/TYPECHECK.md This Java code defines a grammar rule for power expressions, using the '^' operator. This rule conflicts with the desired syntax for the 'times' function. ```java CalcDefPowerExpression implements Expression = base:Expression "^" exponent:Expression ; ``` -------------------------------- ### Derive Type for ASTExpression Source: https://github.com/monticore/sysmlv2/blob/master/doc/TYPECHECK.md The type check can be invoked on any ASTExpression or ASTLiteral. This is the entry point for performing a type check on constructs of a specific language. ```java TypeCheckResult type = new SysMLExpressionsDeriver().deriveType(someASTExpression); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.