COP 5021 Lecture -*- Outline -*- * Overview of XText ** What is XText? ------------------------------------------ XTEXT OVERVIEW XText is a framework for building DSLs It has built-in ways to do: - lexical analysis - parsing - AST validation - Code generation (or interpretation) Integrated with Xtend, an extension of Java ------------------------------------------ Q: What is an AST? An Abstract Syntax Tree ------------------------------------------ ABSTRACT SYNTAX TREES = OBJECT STRUCTURES input: x := x+1 AST: [AssignS | v: * | aexp: * | label: * ] / | v [AExpression | left: * | op: * | right: * ] [EString | * ] / | | | v v v v [VarRefExpr | vname: ] "+" [NumLitExp | num: * ] [String | 1 | * ] | / v v 1 [CharBuf | 'x' ] ------------------------------------------ ** basic tool usage ------------------------------------------ TYPICAL USAGE OF THE TOOLS 0. Create an XText project choose language name, file suffix, etc. 1. Create Lang.xtext in src folder 2. Generate XText artifacts right click on the .xtext file, select Run As... select Generate XText Artifacts 3. Run as Eclipse application to test right click on the main project (edu.ucf.cs.whilelang.WhileLang) select Run As... select Eclipse Application and/or run JUnit tests right click on the ....tests project select Run As... select JUnit Test 4. Edit to enhance the language 5. Repeat the above... ------------------------------------------ ------------------------------------------ 5 PROJECTS for the language named "WhileLang" edu.ucf.cs.whilelang.WhileLang > src > edu.ucf.cs.whilelang > WhileLang.xtext > ... > edu.ucf.cs.whilelang.generator > WhileLangGenerator.xtend > ... > edu.ucf.cs.whilelang.validation > WhileLangValidator.xtend > ... > ... edu.ucf.cs.whilelang.WhileLang.ide edu.ucf.cs.whilelang.WhileLang.tests > src > edu.ucf.cs.whilelang.tests > ... edu.ucf.cs.whilelang.WhileLang.ui edu.ucf.cs.whilelang.WhileLang.ui.tests ------------------------------------------ Q: What converts the user's input into an AST? The parser ** installation ------------------------------------------ INSTALLATION OF XTEXT TO FOLLOW ALONG 1. Install Java (8 or 9) http://www.oracle.com/technetwork/java/index.html (download Java SE) 2. Install Eclipse http://www.eclipse.org/downloads/packages/ eclipse-ide-java-and-dsl-developers/oxygen2 (use the package for Java and DSL Developers, which includes XText and XTend) or search the Eclipse Marketplace for XText and install that and add org.eclipse.xtext to required bundles 3. Install Eclipse Plug-in Development Environment (PDE) search the Marketplace 4. Clone the WhileLang project from Github git clone https://github.com/leavens/WhileLang.git in Eclipse File > Import ... select Git, clone URI import modules as subprojects ------------------------------------------ if necessary, change the JRE System Library to Alternate JRE by changing the buildpath settings in each project right click on project select Properties select Libraries remove JRE System Lib from the list then add it back with Add Library select JRE System Library select alternate JRE I also changed access restriction errors into warnings