1 Prática: um pretty printer para SOL Giovanny Lucero Departamento de Estatística e Informática Universidade Federal de Sergipe.

Slides:



Advertisements
Similar presentations
TWO STEP EQUATIONS 1. SOLVE FOR X 2. DO THE ADDITION STEP FIRST
Advertisements

LEUCEMIA MIELOIDE AGUDA TIPO 0
Substitution.
CS Data Structures I Chapter 6 Stacks I 2 Topics ADT Stack Stack Operations Using ADT Stack Line editor Bracket checking Special-Palindromes Implementation.
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Basic Java Constructs and Data Types – Nuts and Bolts
Copyright © 2011, Elsevier Inc. All rights reserved. Chapter 4 Author: Julia Richards and R. Scott Hawley.
1 Copyright © 2010, Elsevier Inc. All rights Reserved Fig 2.1 Chapter 2.
1 Chapter 40 - Physiology and Pathophysiology of Diuretic Action Copyright © 2013 Elsevier Inc. All rights reserved.
By D. Fisher Geometric Transformations. Reflection, Rotation, or Translation 1.
Business Transaction Management Software for Application Coordination 1 Business Processes and Coordination.
12 Copyright © 2005, Oracle. All rights reserved. Structuring Code Using Abstract Classes and Interfaces.
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Title Subtitle.
Coordinate Plane Practice The following presentation provides practice in two skillsThe following presentation provides practice in two skills –Graphing.
0 - 0.
ALGEBRAIC EXPRESSIONS
DIVIDING INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
MULTIPLYING MONOMIALS TIMES POLYNOMIALS (DISTRIBUTIVE PROPERTY)
ADDING INTEGERS 1. POS. + POS. = POS. 2. NEG. + NEG. = NEG. 3. POS. + NEG. OR NEG. + POS. SUBTRACT TAKE SIGN OF BIGGER ABSOLUTE VALUE.
MULTIPLICATION EQUATIONS 1. SOLVE FOR X 3. WHAT EVER YOU DO TO ONE SIDE YOU HAVE TO DO TO THE OTHER 2. DIVIDE BY THE NUMBER IN FRONT OF THE VARIABLE.
SUBTRACTING INTEGERS 1. CHANGE THE SUBTRACTION SIGN TO ADDITION
MULT. INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
Addition Facts
ALGEBRAIC EXPRESSIONS
ZMQS ZMQS
Chapter 2-2 A Simple One-Pass Compiler
BT Wholesale October Creating your own telephone network WHOLESALE CALLS LINE ASSOCIATED.
1 / / / /. 2 (Object) (Object) –, 10 (Class) (Class) –, –, – (Variables) [ Data member Field Attribute](, ) – (Function) [ Member function Method Operation.
Procedural Programming in C# Chapters Objectives You will be able to: Describe the most important data types available in C#. Read numeric values.
O X Click on Number next to person for a question.
© S Haughton more than 3?
1 Directed Depth First Search Adjacency Lists A: F G B: A H C: A D D: C F E: C D G F: E: G: : H: B: I: H: F A B C G D E H I.
1 public class Newton { public static double sqrt(double c) { double epsilon = 1E-15; if (c < 0) return Double.NaN; double t = c; while (Math.abs(t - c/t)
Object-Oriented Programming. 2 An object, similar to a real-world object, is an entity with certain properties, and with the ability to react in certain.
Twenty Questions Subject: Twenty Questions
Take from Ten First Subtraction Strategy -9 Click on a number below to go directly to that type of subtraction problems
Linking Verb? Action Verb or. Question 1 Define the term: action verb.
Energy & Green Urbanism Markku Lappalainen Aalto University.
1.A computer game is an example of A.system software; B.a compiler; C.application software; D.hardware; E.none of the above. 2.JVM stands for: A.Java Virtual.
4 If-Statements © 2010 David A Watt, University of Glasgow Accelerated Programming 2 Part I: Python Programming.
Lets play bingo!!. Calculate: MEAN Calculate: MEDIAN
Past Tense Probe. Past Tense Probe Past Tense Probe – Practice 1.
1 Chapter 4 The while loop and boolean operators Samuel Marateck ©2010.
Properties of Exponents
Purpose : To convert this string to a new character array. Return Type : char[ ] Parameters : none Declaration : public char[ ] toCharArray() Returns.
Chapter 5 Test Review Sections 5-1 through 5-4.
Control Structures Selections Repetitions/iterations
1 of 31 Images from Africa. 2 of 31 My little Haitian friend Antoine (1985)
1 of 32 Images from Africa. 2 of 32 My little Haitian friend Antoine (1985)
CSci 1130 Intro to Programming in Java
1 First EMRAS II Technical Meeting IAEA Headquarters, Vienna, 19–23 January 2009.
Addition 1’s to 20.
25 seconds left…...
Test B, 100 Subtraction Facts
11 = This is the fact family. You say: 8+3=11 and 3+8=11
Week 1.
Types of selection structures
We will resume in: 25 Minutes.
1 Ke – Kitchen Elements Newport Ave. – Lot 13 Bethesda, MD.
1 Unit 1 Kinematics Chapter 1 Day
O X Click on Number next to person for a question.
Copyright © 2012 Pearson Education, Inc. Chapter 14: More About Classes.
Introduction to Programming G51PRG University of Nottingham Revision 1
Building Java Programs Chapter 14
1 Identifiers  Identifiers are the words a programmer uses in a program  An identifier can be made up of letters, digits, the underscore character (
Lecture 2: Data Types, Variables, Operators, and Expressions
null, true, and false are also reserved.
An overview of Java, Data types and variables
Presentation transcript:

1 Prática: um pretty printer para SOL Giovanny Lucero Departamento de Estatística e Informática Universidade Federal de Sergipe Compiladores

2 Program(ClassDecs, Statement) ClassDec EmptyClassDec() ClassDeclaration(Symbol name, Symbol superclass, ClassInterf, ClassImp) SequenceClassDec(ClassDec, ClassDec) ClassInterf(VarDec, MethodHeader) ClassImp(VarDec, MethodDec)

3 VarDec EmptyVarDecs() VarDeclaration(Symbol, Type) SequenceVarDec(VarDec, VarDec) Em VarDeclaration não usamos IdList, pois é açucar sintático.

4 MethodHeader EmptyMehtodHeader() FunctionHeader(Symbol, VarDeclararionList, Type) ProcedureHeader(Symbol, VarDeclarationList) ConstructorHeader(VarDeclarationList) SequenceMethodHeader(MehtodHeader, MethodHeader)

5 MethodDec EmptyMethodDec() FunctionDec(Symbol, VarDeclararionList, Type, Expression) ProcedureDec(Symbol, VarDeclarationList, Statement) ConstructorDec(VarDeclarationList, Statement) SequenceMethodDec(MethodDec, MethodDec)

6 Type Primitive() IdType(Symbol) ArrayP(Primitive, int) ArrayO(Symbol, int) Primitivos: integer, character ou boolean Por simplicidade podemos, alternativamente, representar tipos com Strings ou Symbols.

7 Statement BlockStmt(varDecList, Statement) IfStmt(Expression, Statement, Statement) WhileStmt(Expression, Statement) PrintStmt(Expression) CallStmt(Expression target, Symbol name, ExpressionList) AssignStmt(Variable, Expression) SkipStmt() SequenceStmt(Statement, Statement) else condicional é açucar sintático f(x) é um açucar sintático de this.f(x)

8 Expression BlockExp(VarDec, Statement, Expression) BinaryBoolExp(int operand, Expression, Expression) BinaryArithmeticExp(int operand, Expression, Expression) BinaryComparissonExp(int operand, Expression, Expression) UnaryOperationExp(int operand, Expression, Expression)...

9 CallExp(Expression target, Symbol name, ExpressionList) VarExp(Variable) NewObjectExp(Symbol, ExpressionList) NewArrayExp(Type, Expression) IntLiteralExp(int) CharLiteralExp(char) BoolLiteralExp(bool) selfExp() nullExp()

10 Variable IdVar(Symbol) FieldVar(Expression target, Symbol field) ArrayElementVar(Expression target, Expression index)

11 SolVisitor interface SolVisitor { visitProgram(Program p); visitEmptyClassDec(EmptyClassDec dec); visitClassDeclaration(ClassDeclaration dec); visitSequenceClassDec(SequenceClassDec dec);.... visitAssignStmt(AssignStmt stm); }

12 class ClassDeclaration extends ClassDec {.... void accept(SolVisitor visitor) { visitor.visitClassDeclaration(this) } class AssingStmt extends Statement {.... void accept(SolVisitor visitor) { visitor.visitAssingStmt(this); } Sintaxe Abstrata com visitors

13 class AssignStmt extends Statement { Variable var; Expression exp; AssignStm(Variable var, Expression exp) { this.var = var; this.exp = exp; void accept(SolVisitor visitor) { visitor.visitAssingStmt(this); }

14 abstract class ClassDec { void abstract accept(SolVisitor visitor); }

15 Um Pretty Printer public class PrettySol implementes SolVisitor { private int indent = 0; private static int indInc = 3; private void indent() { indent += indInc; } private void unindent() { unindent -= indInc; } private void write(String st) { System.out.print(st); } private void writeln(String st) { System.out.println(st); char [] ws = Arrays.fill(new char[indent], ' '); System.out.print(new String(ws)); }

16 void visitProgram(Program p) { p.classDec.accept(this); writeln(“main”); indent(); p.main.accept(this); }

17 void visitBinaryArithmeticExp (BinaryArithmeticExp exp) { write (“( ”); exp.left.accept(this); switch (exp.operator) { case '+': write(“ + ”); break; case '*': write (“ * ”); break;... } exp.right.accept(this); write(“)”); }

18 void visitAssignStm(AssignStm stm) { stm.var.accept(this); write(" := "); stm.exp.accept(this); write(";") } void visitSequenceStmt(SequenceStmt stm) { stm.stm1.accept(this); writeln(""); stm.stm2.accept(this); }

19 void visitIfStm(IfStm stm) { write("if “); stm.exp.accept(this); writeln(“ then ”); indent(); stm.stm1.accept(this); unindent(); writeln(""); writeln("else "); indent(); stm.stm2.accept(this); unindent(); }