Micro Compiler Portfolio

Total Page:16

File Type:pdf, Size:1020Kb

Micro Compiler Portfolio Montana State University Micro Compiler Portfolio Matt Johnerson Michael Shihrer CSCI 468 ­ Compilers 1 Program 2 Expression.java 2 IRNode.java 2 Listener.java 4 Main.java 10 Micro.java 11 Micro.g4 12 Scope.java 14 Symbol.java 16 SymbolTable.java 17 TinyGenerator.java 19 Teamwork 22 Design Pattern 23 Technical Writing 23 UML Diagram 24 Design Trade­Offs 24 Software Development Life Cycle 25 2 1. Program The program’s source code and final submission is located on github. It can be viewed at https://github.com/shihrer/csci468 under the release tagged “Step4”. In order to build and ​ execute the code, the ANTLR v4.5.2 runtime is needed. This can be located at http://www.antlr.org/. ​ a. Expression.java package com.csci468.micro; ​ ​ ​ ​ ​ class Expression { ​ ​ private String name; ​ ​ ​ ​ private String type; ​ ​ ​ ​ Expression(String name, String type) { ​ ​ ​ ​ ​ this.name = name; ​ ​ ​ ​ ​ this.type = type; ​ ​ ​ ​ ​ } ​ String getType() { ​ ​ return this.type; ​ ​ ​ ​ } ​ String getName() { ​ ​ return this.name; ​ ​ ​ ​ } ​ @Override ​ public String toString() { ​ ​ ​ return this.name; ​ ​ ​ ​ } ​ } b. IRNode.java package com.csci468.micro; ​ ​ ​ ​ ​ class IRNode { ​ ​ //Data fields ​ private String _opcode; ​ ​ ​ ​ private Expression _operand1; ​ ​ ​ ​ private Expression _operand2; ​ ​ ​ ​ private Expression _result; ​ ​ ​ ​ IRNode(String OPCode, Expression OP1, Expression OP2, Expression Result) { ​ ​ ​ ​ ​ ​ ​ ​ ​ if (OP1 != null && !OPCode.equals("STR")) { ​ ​ ​ ​ ​ ​ ​ ​ switch (OP1.getType()) { ​ ​ ​ ​ case "INT": ​ ​ ​ this._opcode = OPCode + "I"; ​ ​ ​ ​ ​ ​ 3 break; ​ ​ case "FLOAT": ​ ​ ​ this._opcode = OPCode + "R"; ​ ​ ​ ​ ​ ​ break; ​ ​ default: ​ ​ this._opcode = OPCode + "S"; ​ ​ ​ ​ ​ ​ break; ​ ​ } ​ } else { ​ ​ this._opcode = OPCode; ​ ​ ​ ​ ​ } ​ this._operand1 = OP1; ​ ​ ​ ​ ​ this._operand2 = OP2; ​ ​ ​ ​ ​ this._result = Result; ​ ​ ​ ​ ​ } ​ String getIRCode() { ​ ​ StringBuilder irCode = new StringBuilder(); ​ ​ ​ ​ ​ ​ irCode.append("; "); ​ ​ ​ ​ ​ ​ irCode.append(_opcode).append(" "); ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ if (_operand1 != null) ​ ​ ​ ​ ​ ​ irCode.append(_operand1).append(" "); ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ if (_operand2 != null) ​ ​ ​ ​ ​ ​ irCode.append(_operand2).append(" "); ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ if (_result != null) ​ ​ ​ ​ ​ ​ irCode.append(_result).append(" "); ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ return irCode.toString(); ​ ​ ​ ​ ​ ​ } ​ String getOpcode() { ​ ​ return _opcode; ​ ​ ​ } ​ Expression getOP1() { ​ ​ return _operand1; ​ ​ ​ } ​ Expression getOP2() { ​ ​ return _operand2; ​ ​ ​ } ​ Expression getResult() { ​ ​ return _result; ​ ​ ​ } ​ @Override ​ public String toString() { ​ ​ ​ return getIRCode(); ​ ​ ​ ​ } ​ 4 } c. Listener.java package com.csci468.micro; ​ ​ ​ ​ ​ import java.util.LinkedList; ​ ​ ​ ​ ​ import java.util.Stack; ​ ​ ​ ​ ​ /** * Michael Shihrer * Matthew Johnerson * 26 March 2016 */ class Listener extends MicroBaseListener { ​ ​ ​ ​ // Count variables ​ private int scopeCount = 1; ​ ​ ​ ​ ​ private int labelCount = 0; ​ ​ ​ ​ ​ private int variableCount = 0; ​ ​ ​ ​ ​ private SymbolTable microSymbolTable; ​ ​ ​ ​ // Code generation objects ​ private LinkedList<IRNode> IRNodes; ​ ​ ​ ​ ​ ​ ​ private Stack<Integer> labelStack; ​ ​ ​ ​ ​ ​ ​ private Stack<Expression> expressionStack = new Stack<>(); ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ private Stack<Stack<Expression>> stackStack = new Stack<>(); ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ // Constructor requires IRNodes list ​ Listener(LinkedList<IRNode> IRNodes) { ​ ​ ​ ​ ​ ​ microSymbolTable = new SymbolTable(); ​ ​ ​ ​ ​ ​ this.IRNodes = IRNodes; ​ ​ ​ ​ ​ this.labelStack = new Stack<>(); ​ ​ ​ ​ ​ ​ ​ ​ } ​ @Override ​ public void enterFuncDecl(MicroParser.FuncDeclContext ctx) { ​ ​ ​ ​ ​ ​ ​ //Create new scope ​ microSymbolTable.createScope(ctx.ID().toString()); ​ ​ ​ ​ ​ ​ ​ ​ ​ Expression result = new Expression(ctx.ID().getText(), "STR"); ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ IRNodes.add(new IRNode("LABEL", null, null, result)); ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ } ​ @Override ​ public void exitFuncDecl(MicroParser.FuncDeclContext ctx) { ​ ​ ​ ​ ​ ​ ​ //Pop scope ​ destroyScope(); ​ ​ ​ } ​ 5 @Override ​ public void exitVarDecl(MicroParser.VarDeclContext ctx) { ​ ​ ​ ​ ​ ​ ​ String ids = ctx.idList().getText(); ​ ​ ​ ​ ​ ​ ​ for (String id : ids.split(",")) { ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ Expression result = new Expression(id, ctx.varType().toString()); ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ IRNodes.add(new IRNode("VAR", null, null, result)); ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ } ​ } @Override ​ public void enterParamDecl(MicroParser.ParamDeclContext ctx) { ​ ​ ​ ​ ​ ​ ​ //Add parameter to scope ​ microSymbolTable.createSymbol(ctx.ID().toString(), ​ ​ ​ ​ ​ ​ ​ ​ ​ ctx.varType().getText()); ​ ​ ​ ​ ​ } ​ @Override ​ public void enterIfStmt(MicroParser.IfStmtContext ctx) { ​ ​ ​ ​ ​ ​ ​ createBlockScope(); ​ ​ ​ } ​ @Override ​ public void exitIfStmt(MicroParser.IfStmtContext ctx) { ​ ​ ​ ​ ​ ​ ​ int curLabel = labelStack.pop(); ​ ​ ​ ​ ​ ​ ​ ​ Expression result = new Expression("label" + curLabel, "STR"); ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ IRNodes.add(new IRNode("LABEL", null, null, result)); ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ destroyScope(); ​ ​ } ​ @Override public void enterWhileStmt(MicroParser.WhileStmtContext ctx) { ​ ​ ​ ​ ​ ​ Expression result = new Expression("label" + labelCount, "STR"); ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ IRNodes.add(new IRNode("LABEL", null, null, result)); ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ labelStack.push(labelCount); ​ ​ ​ ​ ​ ​ ​ labelCount++; ​ ​ ​ createBlockScope(); ​ ​ } @Override public void exitWhileStmt(MicroParser.WhileStmtContext ctx) { ​ ​ ​ ​ ​ ​ int curLabel = labelStack.pop(); ​ ​ ​ ​ ​ ​ ​ ​ int jumpLabel = labelStack.pop(); ​ ​ ​ ​ ​ ​ ​ ​ Expression jumpResult = new Expression("label" + jumpLabel, "STR"); ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ Expression labelResult = new Expression("label" + curLabel, "STR"); ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ IRNodes.add(new IRNode("JUMP", null, null, jumpResult)); ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ IRNodes.add(new IRNode("LABEL", null, null, labelResult)); ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ } 6 @Override public void enterElse(MicroParser.ElseContext ctx) { ​ ​ ​ ​ ​ ​ createBlockScope(); ​ ​ ​ int curLabel = labelStack.pop(); ​ ​ ​ ​ ​ ​ ​ ​ Expression jumpResult = new Expression("label" + labelCount, "STR"); ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ Expression labelResult = new Expression("label" + curLabel, "STR"); ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ IRNodes.add(new IRNode("JUMP", null, null, jumpResult)); ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ IRNodes.add(new IRNode("LABEL", null, null, labelResult)); ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ labelStack.push(labelCount); ​ ​ ​ ​ ​ ​ ​ labelCount++; ​ ​ ​ } @Override public void exitElse(MicroParser.ElseContext ctx) { ​ ​ ​ ​ ​ ​ destroyScope(); ​ ​ ​ } @Override public void exitReadStmt(MicroParser.ReadStmtContext ctx) { ​ ​ ​ ​ ​ ​ String ids = ctx.idList().getText(); ​ ​ ​ ​ ​ ​ ​ for (String id : ids.split(",")) { ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ Expression readResult = new Expression(id, ​ ​ ​ ​ ​ ​ microSymbolTable.getSymbol(id).getType()); ​ ​ ​ ​ ​ ​ ​ ​ IRNodes.add(new IRNode("READ", readResult, null, null)); ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ } ​ } private void createBlockScope() { ​ ​ //Create new scope ​ microSymbolTable.createScope(scopeCount); ​ ​ ​ ​ ​ ​ ​ scopeCount++; ​ ​ ​ } private Scope destroyScope() { ​ ​ return microSymbolTable.destroyScope(); ​ ​ ​ ​ ​ ​ } @Override public void enterStringDecl(MicroParser.StringDeclContext ctx) { ​ ​ ​ ​ ​ ​ //Create an entry in the current scope ​ String name = ctx.ID().toString(); ​ ​ ​ ​ ​ ​ ​ String value = ctx.STRINGLITERAL().toString(); ​ ​ ​ ​ ​ ​ String type = ctx.STRING().toString(); ​ ​ ​ ​ ​ ​ microSymbolTable.createSymbol(name, type, value); ​ ​ ​ ​ ​ ​ ​ } @Override 7 public void enterVarDecl(MicroParser.VarDeclContext ctx) { ​ ​ ​ ​ ​ ​ String varType = ctx.varType().getText(); ​ ​ ​ ​ ​ ​ ​ // Create an entry in the current scope ​ String names = ctx.idList().getText(); ​ ​ ​ ​ ​ ​ ​ String[] tokens = names.split(","); ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ for (String s : tokens) { ​ ​ ​ ​ ​ ​ microSymbolTable.createSymbol(s, varType); ​ ​ ​ ​ ​ ​ ​ } ​ } @Override public void exitAssignExpr(MicroParser.AssignExprContext ctx) { ​ ​ ​ ​ ​ ​ //Clear out expression stack, just make sure there's nothing extra to ​ evaluate. while (expressionStack.size() > 1) { ​ ​ ​ ​ ​ ​ ​ ​ buildExpression(); ​ ​ ​ } ​ String OPCode = "STORE"; ​ ​ ​ ​ String ID = ctx.ID().toString(); ​ ​ ​ ​ ​ ​ Expression storeResult = new Expression(ID, ​ ​ ​ ​ ​ microSymbolTable.getSymbol(ID).getType()); ​ ​ ​ ​ ​ ​ ​ ​ // Avoid popping if the stack is empty ​ if (expressionStack.size() > 0) { ​ ​ ​ ​ ​ ​ ​ ​ Expression OP1 = expressionStack.pop(); ​ ​ ​ ​ ​ ​ ​ IRNodes.add(new IRNode(OPCode, OP1, null, storeResult)); ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ } ​ } @Override public void exitCond(MicroParser.CondContext ctx) { ​ ​ ​ ​ ​ ​ //Compare the results of the expressions ​ Expression op1; ​ Expression op2; if (expressionStack.size() > 1) { ​ ​ ​ ​ ​ ​ ​ ​ op1 = expressionStack.pop(); ​ ​ ​ ​ ​ ​ ​ op2 = expressionStack.pop(); ​ ​ ​ ​ ​ ​ Expression compareResult = new Expression("label" + labelCount, "STR"); ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ StringBuilder OPCode = new StringBuilder(); ​ ​ ​ ​ ​ switch (ctx.COMPOP().toString()) { ​ ​ ​ ​ ​ ​ case ">": ​ ​ ​ OPCode.append("LE"); ​ ​ ​ ​ ​ ​ ​ break; ​ ​ case ">=": ​ ​ ​ OPCode.append("LT"); ​ ​ ​ ​ ​ ​ ​ 8 break; ​ ​ case "<": ​ ​ ​ OPCode.append("GE"); ​ ​ ​ ​ ​ ​ ​ break; ​ ​ case "<=": ​ ​ ​ OPCode.append("GT"); ​ ​ ​ ​ ​ ​ ​ break; ​ ​ case "!=": ​ ​ ​ OPCode.append("EQ"); ​ ​ ​ ​ ​ ​ ​ break; ​ ​ case "=": ​ ​ ​ OPCode.append("NE"); ​ ​ ​ ​ ​ ​ ​ break; ​ ​ } ​ IRNodes.add(new
Recommended publications
  • Unravel Data Systems Version 4.5
    UNRAVEL DATA SYSTEMS VERSION 4.5 Component name Component version name License names jQuery 1.8.2 MIT License Apache Tomcat 5.5.23 Apache License 2.0 Tachyon Project POM 0.8.2 Apache License 2.0 Apache Directory LDAP API Model 1.0.0-M20 Apache License 2.0 apache/incubator-heron 0.16.5.1 Apache License 2.0 Maven Plugin API 3.0.4 Apache License 2.0 ApacheDS Authentication Interceptor 2.0.0-M15 Apache License 2.0 Apache Directory LDAP API Extras ACI 1.0.0-M20 Apache License 2.0 Apache HttpComponents Core 4.3.3 Apache License 2.0 Spark Project Tags 2.0.0-preview Apache License 2.0 Curator Testing 3.3.0 Apache License 2.0 Apache HttpComponents Core 4.4.5 Apache License 2.0 Apache Commons Daemon 1.0.15 Apache License 2.0 classworlds 2.4 Apache License 2.0 abego TreeLayout Core 1.0.1 BSD 3-clause "New" or "Revised" License jackson-core 2.8.6 Apache License 2.0 Lucene Join 6.6.1 Apache License 2.0 Apache Commons CLI 1.3-cloudera-pre-r1439998 Apache License 2.0 hive-apache 0.5 Apache License 2.0 scala-parser-combinators 1.0.4 BSD 3-clause "New" or "Revised" License com.springsource.javax.xml.bind 2.1.7 Common Development and Distribution License 1.0 SnakeYAML 1.15 Apache License 2.0 JUnit 4.12 Common Public License 1.0 ApacheDS Protocol Kerberos 2.0.0-M12 Apache License 2.0 Apache Groovy 2.4.6 Apache License 2.0 JGraphT - Core 1.2.0 (GNU Lesser General Public License v2.1 or later AND Eclipse Public License 1.0) chill-java 0.5.0 Apache License 2.0 Apache Commons Logging 1.2 Apache License 2.0 OpenCensus 0.12.3 Apache License 2.0 ApacheDS Protocol
    [Show full text]
  • Adaptive LL(*) Parsing: the Power of Dynamic Analysis
    Adaptive LL(*) Parsing: The Power of Dynamic Analysis Terence Parr Sam Harwell Kathleen Fisher University of San Francisco University of Texas at Austin Tufts University [email protected] [email protected] kfi[email protected] Abstract PEGs are unambiguous by definition but have a quirk where Despite the advances made by modern parsing strategies such rule A ! a j ab (meaning “A matches either a or ab”) can never as PEG, LL(*), GLR, and GLL, parsing is not a solved prob- match ab since PEGs choose the first alternative that matches lem. Existing approaches suffer from a number of weaknesses, a prefix of the remaining input. Nested backtracking makes de- including difficulties supporting side-effecting embedded ac- bugging PEGs difficult. tions, slow and/or unpredictable performance, and counter- Second, side-effecting programmer-supplied actions (muta- intuitive matching strategies. This paper introduces the ALL(*) tors) like print statements should be avoided in any strategy that parsing strategy that combines the simplicity, efficiency, and continuously speculates (PEG) or supports multiple interpreta- predictability of conventional top-down LL(k) parsers with the tions of the input (GLL and GLR) because such actions may power of a GLR-like mechanism to make parsing decisions. never really take place [17]. (Though DParser [24] supports The critical innovation is to move grammar analysis to parse- “final” actions when the programmer is certain a reduction is time, which lets ALL(*) handle any non-left-recursive context- part of an unambiguous final parse.) Without side effects, ac- free grammar. ALL(*) is O(n4) in theory but consistently per- tions must buffer data for all interpretations in immutable data forms linearly on grammars used in practice, outperforming structures or provide undo actions.
    [Show full text]
  • Lexing and Parsing with ANTLR4
    Lab 2 Lexing and Parsing with ANTLR4 Objective • Understand the software architecture of ANTLR4. • Be able to write simple grammars and correct grammar issues in ANTLR4. EXERCISE #1 Lab preparation Ï In the cap-labs directory: git pull will provide you all the necessary files for this lab in TP02. You also have to install ANTLR4. 2.1 User install for ANTLR4 and ANTLR4 Python runtime User installation steps: mkdir ~/lib cd ~/lib wget http://www.antlr.org/download/antlr-4.7-complete.jar pip3 install antlr4-python3-runtime --user Then in your .bashrc: export CLASSPATH=".:$HOME/lib/antlr-4.7-complete.jar:$CLASSPATH" export ANTLR4="java -jar $HOME/lib/antlr-4.7-complete.jar" alias antlr4="java -jar $HOME/lib/antlr-4.7-complete.jar" alias grun='java org.antlr.v4.gui.TestRig' Then source your .bashrc: source ~/.bashrc 2.2 Structure of a .g4 file and compilation Links to a bit of ANTLR4 syntax : • Lexical rules (extended regular expressions): https://github.com/antlr/antlr4/blob/4.7/doc/ lexer-rules.md • Parser rules (grammars) https://github.com/antlr/antlr4/blob/4.7/doc/parser-rules.md The compilation of a given .g4 (for the PYTHON back-end) is done by the following command line: java -jar ~/lib/antlr-4.7-complete.jar -Dlanguage=Python3 filename.g4 or if you modified your .bashrc properly: antlr4 -Dlanguage=Python3 filename.g4 2.3 Simple examples with ANTLR4 EXERCISE #2 Demo files Ï Work your way through the five examples in the directory demo_files: Aurore Alcolei, Laure Gonnord, Valentin Lorentz. 1/4 ENS de Lyon, Département Informatique, M1 CAP Lab #2 – Automne 2017 ex1 with ANTLR4 + Java : A very simple lexical analysis1 for simple arithmetic expressions of the form x+3.
    [Show full text]
  • Creating Custom DSL Editor for Eclipse Ian Graham Markit Risk Analytics
    Speaking Your Language Creating a custom DSL editor for Eclipse Ian Graham 1 Speaking Your Language | © 2012 Ian Graham Background highlights 2D graphics, Fortran, Pascal, C Unix device drivers/handlers – trackball, display devices Smalltalk Simulation Sensor “data fusion” electronic warfare test-bed for army CASE tools for telecommunications Java Interactive visual tools for QC of seismic processing Seismic processing DSL development tools Defining parameter constraints and doc of each seismic process in XML Automating help generation (plain text and HTML) Smart editor that leverages DSL definition Now at Markit using custom language for financial risk analysis Speaking Your Language | © 2012 Ian Graham Overview Introduction: Speaking Your Language What is a DSL? What is Eclipse? Demo: Java Editor Eclipse architecture Implementing an editor Implementing a simple editor Demo Adding language awareness to your editor Demo Learning from Eclipse examples Resources Speaking Your Language | © 2012 Ian Graham Introduction: Speaking Your Language Goal illustrate power of Eclipse platform Context widening use of Domain Specific Languages Focus editing support for custom languages in Eclipse Speaking Your Language | © 2012 Ian Graham Recipe Editor 5 Text Editor Recipes | © 2006 IBM | Made available under the EPL v1.0 What is a DSL? Domain Specific Language - a simplified language for specific problem domain Specialized programming language E.g. Excel formula, SQL, seismic processing script Specification language
    [Show full text]
  • Conflict Resolution in a Recursive Descent Compiler Generator
    LL(1) Conflict Resolution in a Recursive Descent Compiler Generator Albrecht Wöß, Markus Löberbauer, Hanspeter Mössenböck Johannes Kepler University Linz, Institute of Practical Computer Science, Altenbergerstr. 69, 4040 Linz, Austria {woess,loeberbauer,moessenboeck}@ssw.uni-linz.ac.at Abstract. Recursive descent parsing is restricted to languages whose grammars are LL(1), i.e., which can be parsed top-down with a single lookahead symbol. Unfortunately, many languages such as Java, C++, or C# are not LL(1). There- fore recursive descent parsing cannot be used or the parser has to make its deci- sions based on semantic information or a multi-symbol lookahead. In this paper we suggest a systematic technique for resolving LL(1) conflicts in recursive descent parsing and show how to integrate it into a compiler gen- erator (Coco/R). The idea is to evaluate user-defined boolean expressions, in order to allow the parser to make its parsing decisions where a one symbol loo- kahead does not suffice. Using our extended compiler generator we implemented a compiler front end for C# that can be used as a framework for implementing a variety of tools. 1 Introduction Recursive descent parsing [16] is a popular top-down parsing technique that is sim- ple, efficient, and convenient for integrating semantic processing. However, it re- quires the grammar of the parsed language to be LL(1), which means that the parser must always be able to select between alternatives with a single symbol lookahead. Unfortunately, many languages such as Java, C++ or C# are not LL(1) so that one either has to resort to bottom-up LALR(1) parsing [5, 1], which is more powerful but less convenient for semantic processing, or the parser has to resolve the LL(1) con- flicts using semantic information or a multi-symbol lookahead.
    [Show full text]
  • A Simple, Possibly Correct LR Parser for C11 Jacques-Henri Jourdan, François Pottier
    A Simple, Possibly Correct LR Parser for C11 Jacques-Henri Jourdan, François Pottier To cite this version: Jacques-Henri Jourdan, François Pottier. A Simple, Possibly Correct LR Parser for C11. ACM Transactions on Programming Languages and Systems (TOPLAS), ACM, 2017, 39 (4), pp.1 - 36. 10.1145/3064848. hal-01633123 HAL Id: hal-01633123 https://hal.archives-ouvertes.fr/hal-01633123 Submitted on 11 Nov 2017 HAL is a multi-disciplinary open access L’archive ouverte pluridisciplinaire HAL, est archive for the deposit and dissemination of sci- destinée au dépôt et à la diffusion de documents entific research documents, whether they are pub- scientifiques de niveau recherche, publiés ou non, lished or not. The documents may come from émanant des établissements d’enseignement et de teaching and research institutions in France or recherche français ou étrangers, des laboratoires abroad, or from public or private research centers. publics ou privés. 14 A simple, possibly correct LR parser for C11 Jacques-Henri Jourdan, Inria Paris, MPI-SWS François Pottier, Inria Paris The syntax of the C programming language is described in the C11 standard by an ambiguous context-free grammar, accompanied with English prose that describes the concept of “scope” and indicates how certain ambiguous code fragments should be interpreted. Based on these elements, the problem of implementing a compliant C11 parser is not entirely trivial. We review the main sources of difficulty and describe a relatively simple solution to the problem. Our solution employs the well-known technique of combining an LALR(1) parser with a “lexical feedback” mechanism. It draws on folklore knowledge and adds several original as- pects, including: a twist on lexical feedback that allows a smooth interaction with lookahead; a simplified and powerful treatment of scopes; and a few amendments in the grammar.
    [Show full text]
  • An Insight Into ANTLR(Antlr)/Jedit/Netbeans/Eclipse/Java/JVM/Jikesrvm/Osgi As Bio- Informatics Platform in the Context of DNA/RN
    An Insight into ANTLR(antlr)/jEdit/NetBeans/Eclipse/Java/JVM/JikesRVM/OSGi as Bio- informatics Platform in the Context of DNA/RNA Sequencing & Gene Chip Design – A Simple & Interesting Suggestion towards Interfacing Nano-Bio Systems /IoT Hardware & Software/ HPC Environments. Nirmal/ [email protected] [I] Introduction & Inspiration : https://www.osapublishing.org/boe/viewmedia.cfm?uri=boe-1-5-1302&seq=0 http://www.scienpress.com/Upload/JAMB/Vol%202_2_6.pdf https://pubs.rsc.org/en/content/articlelanding/2015/cc/c4cc10047f#!divAbstract https://www.ncbi.nlm.nih.gov/pmc/articles/PMC5522603/ https://www.ncbi.nlm.nih.gov/pmc/articles/PMC6163985/ https://www.mdpi.com/2077-0383/8/1/6/htm https://www.sciencedirect.com/science/article/pii/S030100821530099X https://pubs.acs.org/doi/abs/10.1021/ac0487449 http://www.globalhealthprimer.emory.edu/targets-technologies/nucleic-acid-based-diagnostics.html https://en.wikipedia.org/wiki/DNA_nanotechnology https://explained.ai/ - Good information. https://arxiv.org/pdf/1802.01528.pdf - The Matrix Calculus You Need For Deep Learning . https://en.wikipedia.org/wiki/DNA_microarray https://learn.genetics.utah.edu/content/labs/microarray/ https://en.wikipedia.org/wiki/Patrick_O._Brown https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4479227/ https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4011503/ http://www.cs.mun.ca/~harold/Courses/Old/CS6754.W06/Diary/ng1030.pdf http://textofvideo.nptel.ac.in/102101054/lec33.pdf https://www.m2-automation.com/ https://genome.cshlp.org/content/13/3/467.full https://www.comsol.co.in/paper/download/364251/jindal_presentation.pdf http://www.ipcsit.com/vol2/38-A313.pdf [II] Informatics Framework & Implementation : Figure I – Our Total Idea as mentioned in our TITLE.
    [Show full text]
  • Third Party Licenses Visual Investigator
    Third Party Licenses and Information This page contains information regarding any third party code included with your SAS software, including applicable third party software notices and/or additional terms and conditions. SAS Visual Investigator 10.7 Component Applicable License(s) @uirouter/angularjs 1.0.20 MIT License @uirouter/core 5.0.21 MIT License @uirouter/dsr 1.0.3 MIT License @uirouter/sticky-states 1.5.0 MIT License ACE 1.2.3 BSD 3-clause "New" or "Revised" License akka-actor 2.4.17 Apache License 2.0 Angular 1.7.9 MIT License Animal Sniffer Annotations 1.18 MIT License ANTLR 2.7.7 ANTLR Software Rights Notice ANTLR 3.5.2 BSD 3-clause "New" or "Revised" License ANTLR 4.5.3 BSD 3-clause "New" or "Revised" License ANTLR 4 Tool 4.5 BSD 3-clause "New" or "Revised" License ANTLR 4 Tool 4.5.3 BSD 3-clause "New" or "Revised" License Apache Commons BeanUtils 1.9.4 Apache License 2.0 Apache Commons Codec 1.11 Apache License 2.0 Apache Commons Codec 1.9 Apache License 2.0 Apache Commons Collections 3.2.2 Apache License 2.0 Apache Commons Collections 4.1 Apache License 2.0 Apache Commons Collections 4.3 Apache License 2.0 Apache Commons Collections commons-commons-collections-4.4 Apache License 2.0 Apache Commons Compress 1.19 Apache License 2.0 Apache Commons Configuration 1.8 Apache License 2.0 Apache Commons CSV 1.4 Apache License 2.0 Apache Commons DBCP 1.4 Apache License 2.0 Apache Commons Digester 2.1 Apache License 1.1 Apache Commons Email 1.5 Apache License 2.0 Apache Commons FileUpload 1.3.3 Apache License 2.0 Apache Commons Lang
    [Show full text]
  • ANTLR Reference Manual ANTLR Reference Manual ANTLR Jguru Credits Project Lead Terence Parr
    ANTLR Reference Manual ANTLR Reference Manual ANTLR jGuru Credits Project Lead Terence Parr Support from jGuru.com Your View of the Java Universe Help with initial coding John Lilly, Empathy Software C++ code generator by Peter Wells and Ric Klaren Sather code generator by Mika Illouz Infrastructure support from Perforce: The world's best source code control system Substantial intellectual effort donated by John Mitchell Scott Stanchfield Jim Coker Monty Zukowski (Streams, translation) Chapman Flack (UNICODE, streams) ParseView parser debugger by Scott Stanchfield ANTLR Version 2.7.1 Version: $Id: //depot/code/org.antlr/main/main/doc/index.html#8 $ October 1, 2000 Check out the ANTLR FAQ at jguru.com! Check out the Bug Database (ok, so it's out of date) Check out http://www.ANTLR.org ParseView debugger is available. (for prior versions) http://www.antlr.org/doc/ (1 of 7) [8/10/2001 10:45:13 AM] ANTLR Reference Manual If you are looking for the previous main version (PCCTS 1.33) of ANTLR rather than the Java/C++/Sather version (2.x), see Getting started with PCCTS. Download ANTLR 2.7.1. ANTLR 2.7.1 release notes ANTLR Meta-Language ● Meta-Language Vocabulary ● Header Section ● Parser Class Definitions ● Lexical Analyzer Class Definitions ● Tree-parser Class Definitions ● Options Section ● Tokens Section ● Grammar Inheritance ● Rule Definitions ● Atomic Production elements ● Simple Production elements ● Production Element Operators ● Token Classes ● Predicates ● Element Labels ● EBNF Rule Elements ● Interpretation Of Semantic Actions ● Semantic
    [Show full text]
  • Part 1: Introduction
    Part 1: Introduction By: Morteza Zakeri PhD Student Iran University of Science and Technology Winter 2020 Agenda • What is ANTLR? • History • Motivation • What is New in ANTLR v4? • ANTLR Components: How it Works? • Getting Started with ANTLR v4 February 2020 Introduction to ANTLR – Morteza Zakeri 2 What is ANTLR? • ANTLR (pronounced Antler), or Another Tool For Language Recognition, is a parser generator that uses LL(*) for parsing. • ANTLR takes as input a grammar that specifies a language and generates as output source code for a recognizer for that language. • Supported generating code in Java, C#, JavaScript, Python2 and Python3. • ANTLR is recursive descent parser Generator! (See Appendix) February 2020 Introduction to ANTLR – Morteza Zakeri 3 Runtime Libraries and Code Generation Targets • There is no language specific code generators • There is only one tool, written in Java, which is able to generate Lexer and Parser code for all targets, through command line options. • The available targets are the following (2020): • Java, C#, C++, Swift, Python (2 and 3), Go, PHP, and JavaScript. • Read more: • https://github.com/antlr/antlr4/blob/master/doc/targets.md 11 February 2020 Introduction to ANTLR – Morteza Zakeri Runtime Libraries and Code Generation Targets • $ java -jar antlr4-4.8.jar -Dlanguage=CSharp MyGrammar.g4 • https://github.com/antlr/antlr4/tree/master/runtime/CSharp • https://github.com/tunnelvisionlabs/antlr4cs • $ java -jar antlr4-4.8.jar -Dlanguage=Cpp MyGrammar.g4 • https://github.com/antlr/antlr4/blob/master/doc/cpp-target.md • $ java -jar antlr4-4.8.jar -Dlanguage=Python3 MyGrammar.g4 • https://github.com/antlr/antlr4/blob/master/doc/python- target.md 11 February 2020 Introduction to ANTLR – Morteza Zakeri History • Initial release: • February 1992; 24 years ago.
    [Show full text]
  • Xtext User Guide
    Xtext User Guide Xtext User Guide Heiko Behrens, Michael Clay, Sven Efftinge, Moritz Eysholdt, Peter Friese, Jan Köhnlein, Knut Wannheden, Sebastian Zarnekow and contributors Copyright 2008 - 2010 Xtext 1.0 1 1. Overview .................................................................................................................... 1 1.1. What is Xtext? ................................................................................................... 1 1.2. How Does It Work? ............................................................................................ 1 1.3. Xtext is Highly Configurable ................................................................................ 1 1.4. Who Uses Xtext? ................................................................................................ 1 1.5. Who is Behind Xtext? ......................................................................................... 1 1.6. What is a Domain-Specific Language ..................................................................... 2 2. Getting Started ............................................................................................................ 3 2.1. Creating a DSL .................................................................................................. 3 2.1.1. Create an Xtext Project ............................................................................. 3 2.1.2. Project Layout ......................................................................................... 4 2.1.3. Build Your Own Grammar ........................................................................
    [Show full text]
  • ANTLR Reference PDF Manual
    ANTLR Reference Manual Home | Download | News | About ANTLR | Support Latest version is 2.7.3. Download now! » » Home » Download ANTLR Reference Manual » News »Using ANTLR » Documentation ANTLR » FAQ » Articles Reference Manual » Grammars Credits » File Sharing » Code API Project Lead and Supreme Dictator Terence Parr » Tech Support University of San Franciso »About ANTLR Support from » What is ANTLR jGuru.com » Why use ANTLR Your View of the Java Universe » Showcase Help with initial coding » Testimonials John Lilly, Empathy Software » Getting Started C++ code generator by » Software License Peter Wells and Ric Klaren » ANTLR WebLogs C# code generation by »StringTemplate Micheal Jordan, Kunle Odutola and Anthony Oguntimehin. »TML Infrastructure support from Perforce: »PCCTS The world's best source code control system Substantial intellectual effort donated by Loring Craymer Monty Zukowski Jim Coker Scott Stanchfield John Mitchell Chapman Flack (UNICODE, streams) Source changes for Eclipse and NetBeans by Marco van Meegen and Brian Smith ANTLR Version 2.7.3 March 22, 2004 What's ANTLR http://www.antlr.org/doc/index.html (1 of 6)31.03.2004 17:11:46 ANTLR Reference Manual ANTLR, ANother Tool for Language Recognition, (formerly PCCTS) is a language tool that provides a framework for constructing recognizers, compilers, and translators from grammatical descriptions containing Java, C++, or C# actions [You can use PCCTS 1.xx to generate C-based parsers]. Computer language translation has become a common task. While compilers and tools for traditional computer languages (such as C or Java) are still being built, their number is dwarfed by the thousands of mini-languages for which recognizers and translators are being developed.
    [Show full text]