From f7da41e318ff9ab884fd8414973125f3c0e4e003 Mon Sep 17 00:00:00 2001 From: cmfernandez Date: Thu, 1 Oct 2015 10:41:29 -0300 Subject: [PATCH 01/26] Commit Test automaticos y lexema analizer funcionando --- .../analysis/LexicalAnalyzer.java | 187 +++++++++++++++++- .../interpreter/RegexInterpreter.java | 139 +++++++++++++ .../multimedia/shapes4learn/model/Token.java | 26 ++- .../interpreter/RegexInterpreter.java | 4 +- .../interpreter/TestLexicalAnalizer.java | 144 ++++++++++++++ 5 files changed, 495 insertions(+), 5 deletions(-) create mode 100644 src/main/java/edu/maimonides/multimedia/shapes4learn/interpreter/RegexInterpreter.java create mode 100644 src/test/java/edu/maimonides/multimedia/shapes4learn/interpreter/TestLexicalAnalizer.java diff --git a/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/LexicalAnalyzer.java b/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/LexicalAnalyzer.java index ac98a27..769d977 100644 --- a/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/LexicalAnalyzer.java +++ b/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/LexicalAnalyzer.java @@ -1,8 +1,8 @@ package edu.maimonides.multimedia.shapes4learn.analysis; +import java.util.Iterator; import java.util.LinkedList; import java.util.List; - import edu.maimonides.multimedia.shapes4learn.model.Token; /** @@ -16,10 +16,193 @@ public class LexicalAnalyzer { public List analyze(String code) throws LexicalException { + + String[][] reservada = new String[20][20]; + //String[] aux; + boolean validoNum=false; + //boolean validoId=true; + boolean ExpArit=true; + boolean reservada1=false; + boolean id=false; + + // Completo la matriz token (lexemas - clase) + + reservada[0][0] = "create"; reservada[0][1] = "crear"; + + reservada[1][0] = "rectangle"; reservada[1][1] = "ShapeRectangulo"; + + reservada[2][0] = "circle"; reservada[2][1] = "ShapeCirculo"; + + reservada[3][0] = ";"; reservada[3][1] = "fin de sentencia"; + + reservada[4][0] = "setbase"; reservada[4][1] = "setear base"; + + reservada[5][0] = "sethight"; reservada[5][1] = "setear altura"; + + reservada[6][0] = "setcolor"; reservada[6][1] = "setear color"; + + reservada[7][0] = "setradius"; reservada[7][1] = "setear radio"; + + reservada[8][0] = "setposition"; reservada[8][1] = "setear posicion"; + + reservada[9][0] = "shape"; reservada[9][1] = "clase shape"; + + reservada[10][0] = ","; reservada[10][1] = "separador de expresiones"; + + reservada[11][0] = "in"; reservada[11][1] = "'in'"; + List tokens = new LinkedList<>(); - // TODO Implement. + // Separo los lexemas + String delimitadores= "[\\ \\ \\ \\ \\ \\ ]"; + String lexemas[] = code.split(delimitadores); + + //Recorro los lexemas y encuentro las Lexemas reservadas del lenguaje + for(int i=0; i< lexemas.length; i++) { + + Token tempToken = new Token(); + reservada1=false; + validoNum=false; + //boolean validoId=true; + ExpArit=false; + reservada1=false; + id=false; + + //System.out.println("\nPosicion: " + i + " <><> Lexema que ingresa: " + lexemas[i]); + + //System.out.println("Token: "); + + for (int j=0;j<=11;j++) + { + + if (lexemas[i].equals(reservada[j][0])) + { + // Cuando lo encuentro, como se pasa a la linkedlisto token???? + + reservada1=true; + + tempToken.lexema = reservada[j][0]; + tempToken.clase = reservada [j][1]; + } + } + // si no es Lexema reservada + + int x=0; + + // veo si es numero + for (;x iterator = tokens.iterator(); iterator.hasNext();) { + Token token = (Token) iterator.next(); + System.out.println("Lexema: " + token.lexema + " Clase: " + token.clase); + }*/ + return tokens; } } diff --git a/src/main/java/edu/maimonides/multimedia/shapes4learn/interpreter/RegexInterpreter.java b/src/main/java/edu/maimonides/multimedia/shapes4learn/interpreter/RegexInterpreter.java new file mode 100644 index 0000000..ae31791 --- /dev/null +++ b/src/main/java/edu/maimonides/multimedia/shapes4learn/interpreter/RegexInterpreter.java @@ -0,0 +1,139 @@ +package edu.maimonides.multimedia.shapes4learn.interpreter; + +import java.io.IOException; +import java.io.InputStream; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang.StringUtils; + +import edu.maimonides.multimedia.shapes4learn.model.ShapeAmbient; +import edu.maimonides.multimedia.shapes4learn.model.shapes.Rectangle; +import edu.maimonides.multimedia.shapes4learn.model.shapes.Shape; +import edu.maimonides.multimedia.shapes4learn.utils.ColorUtils; +import edu.maimonides.multimedia.shapes4learn.utils.ShapeUtils; + +/** + * Hard-coded, regex-based implementation of {@link Interpreter}, mostly for + * testing purposes. + * + * @author Matias Giorgio. + * + */ +public class RegexInterpreter implements Interpreter { + + private static final String NUMBER_PATTERN = "\\d+"; + private static final String SHAPE_TYPE_PATTERN = "[a-zA-Z]+"; + private static final String CREATE_KEYWORD = "create"; + private static final String SET_COLOR_KEYWORD = "setcolor"; + private static final String SET_BASE_KEYWORD = "setbase"; + + private static final String ID_PATTERN = SHAPE_TYPE_PATTERN; + + private Pattern createPattern; + private Pattern setColorPattern; + private Pattern setbasePatternInRectangle; + + public RegexInterpreter() { + createPattern = Pattern.compile(CREATE_KEYWORD + " (" + SHAPE_TYPE_PATTERN + ") (" + ID_PATTERN + ");", Pattern.CASE_INSENSITIVE); + setColorPattern = Pattern.compile(SET_COLOR_KEYWORD + " \\#([0-9a-fA-F]{6,6}) in shape (" + ID_PATTERN + ");", Pattern.CASE_INSENSITIVE); + setbasePatternInRectangle = Pattern.compile(SET_BASE_KEYWORD + " (" + NUMBER_PATTERN + ") in rectangle (" + ID_PATTERN + ");"); + } + + @Override + public void interpret(String code, ShapeAmbient ambient) throws CodeException { + String[] lines = StringUtils.split(code, "\n"); + + for (String line : lines) { + interpretLine(line, ambient); + } + } + + private void interpretLine(String code, ShapeAmbient ambient) throws CodeException { + code = code.trim(); + + if (code.startsWith(CREATE_KEYWORD)) { + processCreateShape(code, ambient); + } else if (code.startsWith(SET_COLOR_KEYWORD)) { + processSetColor(code, ambient); + } else if (code.startsWith(SET_BASE_KEYWORD)) { + processSetBase(code, ambient); + } else { + throw new CodeException("Unexpected code."); + } + } + + private void processSetBase(String code, ShapeAmbient ambient) throws CodeException { + Matcher matcher = setbasePatternInRectangle.matcher(code); + + if (matcher.find()) { + int base = Integer.parseInt(matcher.group(1)); + String id = matcher.group(2); + + if (ambient.contains(id)) { + Rectangle rectangle = (Rectangle) ambient.get(id); + rectangle.setBase(base); + } else { + throw new CodeException("Id " + id + " does not exist."); + } + } else { + throw new CodeException("Unexpected code"); + } + } + + private void processSetColor(String code, ShapeAmbient ambient) throws CodeException { + Matcher matcher = setColorPattern.matcher(code); + + if (matcher.find()) { + String colorDef = matcher.group(1); + String id = matcher.group(2); + + if (ambient.contains(id)) { + Shape shape = ambient.get(id); + shape.setColor(ColorUtils.color(colorDef)); + } else { + throw new CodeException("Unrecognized identifier"); + } + } else { + throw new CodeException("Unexpected code"); + } + } + + private void processCreateShape(String code, ShapeAmbient ambient) throws CodeException { + Matcher matcher = createPattern.matcher(code); + + if (matcher.find()) { + String type = matcher.group(1); + String id = matcher.group(2); + + Shape shape = createShape(type, id); + if (ambient.contains(id)) { + throw new CodeException("Id " + id + " already exists."); + } else { + ambient.add(shape); + } + } else { + throw new CodeException("Unrecognized identifier"); + } + } + + private Shape createShape(String type, String id) throws CodeException { + switch (type) { + case "shape": + return ShapeUtils.shape(id); + case "rectangle": + return ShapeUtils.rectangle(id); + case "circle": + return ShapeUtils.circle(id); + default: + throw new CodeException("Shape type does not exist"); + } + } + + @Override + public void interpret(InputStream stream, ShapeAmbient ambient) throws CodeException, IOException { + this.interpret(IOUtils.toString(stream), ambient); + } + +} diff --git a/src/main/java/edu/maimonides/multimedia/shapes4learn/model/Token.java b/src/main/java/edu/maimonides/multimedia/shapes4learn/model/Token.java index 9c5f672..7bda945 100644 --- a/src/main/java/edu/maimonides/multimedia/shapes4learn/model/Token.java +++ b/src/main/java/edu/maimonides/multimedia/shapes4learn/model/Token.java @@ -10,6 +10,30 @@ */ public class Token { - // To be implemented. + public String lexema; + public String clase; + + public String getLexema() { + return lexema; + } + public void setLexema(String lexema) { + this.lexema = lexema; + } + public String getClase() { + return clase; + } + public void setClase(String clase) { + this.clase = clase; + } + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("Lexema: "); + sb.append(lexema); + sb.append(" ||| Clase: "); + sb.append(clase); + sb.append("\n"); + return sb.toString(); + } } diff --git a/src/test/java/edu/maimonides/multimedia/shapes4learn/interpreter/RegexInterpreter.java b/src/test/java/edu/maimonides/multimedia/shapes4learn/interpreter/RegexInterpreter.java index ae31791..e4630f1 100644 --- a/src/test/java/edu/maimonides/multimedia/shapes4learn/interpreter/RegexInterpreter.java +++ b/src/test/java/edu/maimonides/multimedia/shapes4learn/interpreter/RegexInterpreter.java @@ -21,7 +21,7 @@ * @author Matias Giorgio. * */ -public class RegexInterpreter implements Interpreter { +/*public class RegexInterpreter implements Interpreter { private static final String NUMBER_PATTERN = "\\d+"; private static final String SHAPE_TYPE_PATTERN = "[a-zA-Z]+"; @@ -136,4 +136,4 @@ public void interpret(InputStream stream, ShapeAmbient ambient) throws CodeExcep this.interpret(IOUtils.toString(stream), ambient); } -} +}*/ diff --git a/src/test/java/edu/maimonides/multimedia/shapes4learn/interpreter/TestLexicalAnalizer.java b/src/test/java/edu/maimonides/multimedia/shapes4learn/interpreter/TestLexicalAnalizer.java new file mode 100644 index 0000000..ce8a99b --- /dev/null +++ b/src/test/java/edu/maimonides/multimedia/shapes4learn/interpreter/TestLexicalAnalizer.java @@ -0,0 +1,144 @@ +package edu.maimonides.multimedia.shapes4learn.interpreter; + +import static org.junit.Assert.*; + +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import org.junit.Test; +import edu.maimonides.multimedia.shapes4learn.analysis.LexicalAnalyzer; +import edu.maimonides.multimedia.shapes4learn.analysis.LexicalException; +import edu.maimonides.multimedia.shapes4learn.model.Token; + +public class TestLexicalAnalizer { + + @Test + public void test() { + + String code1 = "create circle micirculo ; " + + "setradius 5+5 in circle micirculo ; " + + "setcolor #aA1 in shape micirculo ;"; + + //String code1 = "create"; + + List tokenValida = new LinkedList<>(); + + LexicalAnalyzer lex = new LexicalAnalyzer(); + + try { + + List tokens = lex.analyze(code1); + + System.out.println(" TestLexicalAnalizer: \n"); + //Inicializar prueba 1 + Token tok = new Token(); + tok.setLexema("create");tok.setClase("crear");tokenValida.add(tok); + tok = new Token(); + tok.setLexema("circle");tok.setClase("ShapeCirculo");tokenValida.add(tok); + tok = new Token(); + tok.setLexema("micirculo");tok.setClase("ID");tokenValida.add(tok); + tok = new Token(); + tok.setLexema(";");tok.setClase("fin de sentancia");tokenValida.add(tok); + tok = new Token(); + tok.setLexema("setradius");tok.setClase("setear radio");tokenValida.add(tok); + tok = new Token(); + tok.setLexema("5+5");tok.setClase("Expresion Aritmetica");tokenValida.add(tok); + tok = new Token(); + tok.setLexema("in");tok.setClase("'in'");tokenValida.add(tok); + tok = new Token(); + tok.setLexema("circle");tok.setClase("ShapeCirculo");tokenValida.add(tok); + tok = new Token(); + tok.setLexema("micirculo");tok.setClase("ID");tokenValida.add(tok); + tok = new Token(); + tok.setLexema(";");tok.setClase("fin de sentencia");tokenValida.add(tok); + tok = new Token(); + tok.setLexema("setcolor");tok.setClase("setear color");tokenValida.add(tok); + tok = new Token(); + tok.setLexema("#aA1");tok.setClase("color_def");tokenValida.add(tok); + tok = new Token(); + tok.setLexema("in");tok.setClase("'in'");tokenValida.add(tok); + tok = new Token(); + tok.setLexema("shape");tok.setClase("clase shape");tokenValida.add(tok); + tok = new Token(); + tok.setLexema("micirculo");tok.setClase("ID");tokenValida.add(tok); + tok = new Token(); + tok.setLexema(";");tok.setClase("fin de sentancia");tokenValida.add(tok); + + boolean soniguales = false; + + for (int i = 0; i < tokens.size() || i < tokenValida.size(); i++) { + + if (tokens.get(i).getLexema().equals(tokenValida.get(i).getLexema()) + && tokens.get(i).getClase().equals(tokenValida.get(i).getClase())) { + + soniguales=true; + } + } + + for (Iterator iterator = tokens.iterator(); iterator.hasNext();) { + Token token = (Token) iterator.next(); + System.out.println("Lexema: " + token.lexema + " Clase: " + token.clase); + } + + }catch(LexicalException e) { + // TODO Auto-generated catch block + fail("Lanzada excepcion no esperada Tokeb caso 1"); + e.printStackTrace(); + } + + } + + @Test + public void test2() { + + String code1 = "create cir4cle micirculo ; #"; + + List tokenValida = new LinkedList<>(); + + LexicalAnalyzer lex = new LexicalAnalyzer(); + + try { + + List tokens = lex.analyze(code1); + + System.out.println("\n"); + System.out.println(" TestLexicalAnalizer: \n"); + + //Inicializar prueba 2 + Token tok = new Token(); + tok.setLexema("create");tok.setClase("crear");tokenValida.add(tok); + tok = new Token(); + tok.setLexema("cir4cle");tok.setClase("Lexema desconocido");tokenValida.add(tok); + tok = new Token(); + tok.setLexema("micirculo");tok.setClase("ID");tokenValida.add(tok); + tok = new Token(); + tok.setLexema(";");tok.setClase("fin de sentancia");tokenValida.add(tok); + tok = new Token(); + tok.setLexema("#");tok.setClase("Lexema desconocido");tokenValida.add(tok); + + boolean soniguales = false; + + for (int i = 0; i < tokens.size() || i < tokenValida.size(); i++) { + + if (tokens.get(i).getLexema().equals(tokenValida.get(i).getLexema()) + && tokens.get(i).getClase().equals(tokenValida.get(i).getClase())) { + + soniguales=true; + } + } + + + for (Iterator iterator = tokens.iterator(); iterator.hasNext();) { + Token token = (Token) iterator.next(); + System.out.println("Lexema: " + token.lexema + " Clase: " + token.clase); + } + + }catch(LexicalException e) { + // TODO Auto-generated catch block + fail("Lanzada excepcion no esperada Tokeb caso 1"); + e.printStackTrace(); + } + + } + +} From ae2d832ff0b05e51817cabd497a6376e2e7238d5 Mon Sep 17 00:00:00 2001 From: cmfernandez Date: Thu, 1 Oct 2015 11:03:37 -0300 Subject: [PATCH 02/26] Agrego los test automaticos Los borre por error --- .../shapes4learn/interpreter/TestLexicalAnalizer.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/test/java/edu/maimonides/multimedia/shapes4learn/interpreter/TestLexicalAnalizer.java b/src/test/java/edu/maimonides/multimedia/shapes4learn/interpreter/TestLexicalAnalizer.java index ce8a99b..87fb004 100644 --- a/src/test/java/edu/maimonides/multimedia/shapes4learn/interpreter/TestLexicalAnalizer.java +++ b/src/test/java/edu/maimonides/multimedia/shapes4learn/interpreter/TestLexicalAnalizer.java @@ -75,6 +75,8 @@ public void test() { } } + assertTrue("Lexema Correcto ", soniguales); + for (Iterator iterator = tokens.iterator(); iterator.hasNext();) { Token token = (Token) iterator.next(); System.out.println("Lexema: " + token.lexema + " Clase: " + token.clase); @@ -127,6 +129,8 @@ public void test2() { } } + assertTrue("Lexema Correcto ", soniguales); + for (Iterator iterator = tokens.iterator(); iterator.hasNext();) { Token token = (Token) iterator.next(); From c1e4a59537b9fc0d2e5e638aabb65b96aad94647 Mon Sep 17 00:00:00 2001 From: cmfernandez Date: Thu, 1 Oct 2015 11:42:59 -0300 Subject: [PATCH 03/26] Se arregla expresion aritmetica y se agreda un nuevo test asd --- .../analysis/LexicalAnalyzer.java | 22 +++---- .../interpreter/TestLexicalAnalizer.java | 57 +++++++++++++++++++ 2 files changed, 65 insertions(+), 14 deletions(-) diff --git a/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/LexicalAnalyzer.java b/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/LexicalAnalyzer.java index 769d977..f50ae73 100644 --- a/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/LexicalAnalyzer.java +++ b/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/LexicalAnalyzer.java @@ -113,26 +113,20 @@ public List analyze(String code) throws LexicalException { int f=0; char ant='a'; - + for (;(f iterator = tokens.iterator(); iterator.hasNext();) { + Token token = (Token) iterator.next(); + System.out.println("Lexema: " + token.lexema + " Clase: " + token.clase); + } + + }catch(LexicalException e) { + // TODO Auto-generated catch block + fail("Lanzada excepcion no esperada Tokeb caso 1"); + e.printStackTrace(); + } + + } + + @Test + public void test3() { + + String code1 = "setradius (5+5)*3 in circle micirculo ;"; + + List tokenValida = new LinkedList<>(); + + LexicalAnalyzer lex = new LexicalAnalyzer(); + + try { + + List tokens = lex.analyze(code1); + + System.out.println("\n"); + System.out.println(" TestLexicalAnalizer: \n"); + + //Inicializar prueba 3 + Token tok = new Token(); + tok.setLexema("setradius");tok.setClase("setear radio");tokenValida.add(tok); + tok = new Token(); + tok.setLexema("(5+5)*3");tok.setClase("Expresion Aritmetica");tokenValida.add(tok); + tok = new Token(); + tok.setLexema("in");tok.setClase("`in`");tokenValida.add(tok); + tok = new Token(); + tok.setLexema("circle");tok.setClase("ShapeCirculo");tokenValida.add(tok); + tok = new Token(); + tok.setLexema("micirculo");tok.setClase("ID");tokenValida.add(tok); + tok = new Token(); + tok.setLexema(";");tok.setClase("fin de sentancia");tokenValida.add(tok); + + boolean soniguales = false; + + for (int i = 0; i < tokens.size() || i < tokenValida.size(); i++) { + + if (tokens.get(i).getLexema().equals(tokenValida.get(i).getLexema()) + && tokens.get(i).getClase().equals(tokenValida.get(i).getClase())) { + + soniguales=true; + } + } + + assertTrue("Lexema Correcto ", soniguales); + + for (Iterator iterator = tokens.iterator(); iterator.hasNext();) { Token token = (Token) iterator.next(); System.out.println("Lexema: " + token.lexema + " Clase: " + token.clase); From 84a76c290ef7f38acac192c5734ad98c4cf1727b Mon Sep 17 00:00:00 2001 From: cmfernandez Date: Tue, 6 Oct 2015 08:57:01 -0300 Subject: [PATCH 04/26] Implementacion de Interpreter Se implementa la clase para que al correr el programa se ingrese una sentencia o conjunto de sentencias, para ser analizadas de manera lexica. Al finalizar el analisis lexico, muestra por pantalla los tokens (lexema, clase) con o sin errores. --- .classpath | 26 + .gitattributes | 17 + .gitignore | 1 + .metadata/.lock | 0 .metadata/.mylyn/.taskListIndex/segments.gen | Bin 0 -> 20 bytes .metadata/.mylyn/.taskListIndex/segments_1 | Bin 0 -> 32 bytes .metadata/.mylyn/repositories.xml.zip | Bin 0 -> 436 bytes .metadata/.mylyn/tasks.xml.zip | Bin 0 -> 250 bytes .../.root/.indexes/history.version | 1 + .../.root/.indexes/properties.index | Bin 0 -> 57 bytes .../.root/.indexes/properties.version | 1 + .../org.eclipse.core.resources/.root/1.tree | Bin 0 -> 124 bytes .../.safetable/org.eclipse.core.resources | Bin 0 -> 376 bytes .../org.eclipse.core.resources.prefs | 2 + .../.settings/org.eclipse.jdt.ui.prefs | 13 + .../.settings/org.eclipse.m2e.discovery.prefs | 2 + .../org.eclipse.mylyn.context.core.prefs | 2 + .../org.eclipse.mylyn.monitor.ui.prefs | 2 + .../org.eclipse.mylyn.tasks.ui.prefs | 4 + .../.settings/org.eclipse.team.cvs.ui.prefs | 2 + .../.settings/org.eclipse.team.ui.prefs | 2 + .../.settings/org.eclipse.ui.ide.prefs | 5 + .../.settings/org.eclipse.ui.prefs | 2 + .../.settings/org.eclipse.ui.workbench.prefs | 3 + .../org.eclipse.e4.workbench/workbench.xmi | 2009 +++++++++++++++++ .../assumedExternalFilesCache | Bin 0 -> 4 bytes .../org.eclipse.jdt.core/externalFilesCache | Bin 0 -> 4 bytes .../org.eclipse.jdt.core/invalidArchivesCache | Bin 0 -> 4 bytes .../org.eclipse.jdt.core/nonChainingJarsCache | Bin 0 -> 4 bytes .../variablesAndContainers.dat | Bin 0 -> 110 bytes .../org.eclipse.jdt.ui/OpenTypeHistory.xml | 2 + .../QualifiedTypeNameHistory.xml | 2 + .../org.eclipse.jdt.ui/dialog_settings.xml | 10 + .../dialog_settings.xml | 15 + .../26522e0d83a422eed93329ece7565cfc/_0.cfs | Bin 0 -> 297 bytes .../segments.gen | Bin 0 -> 20 bytes .../segments_2 | Bin 0 -> 58 bytes .../write.lock | 0 .../830bc118332e77292949ed1e6d2fabe0/_0.cfs | Bin 0 -> 274 bytes .../segments.gen | Bin 0 -> 20 bytes .../segments_2 | Bin 0 -> 58 bytes .../write.lock | 0 .../d91aba3017ff816c2a31821c02251625/_0.cfs | Bin 0 -> 298 bytes .../segments.gen | Bin 0 -> 20 bytes .../segments_2 | Bin 0 -> 58 bytes .../write.lock | 0 .../org.eclipse.m2e.core/workspaceState.ser | Bin 0 -> 545 bytes .../0.log | 0 .../logback.1.5.1.20150109-1820.xml | 43 + .../dialog_settings.xml | 17 + .../org.eclipse.ui.workbench/workingsets.xml | 4 + .metadata/version.ini | 3 + .project | 23 + .settings/org.eclipse.jdt.core.prefs | 5 + .settings/org.eclipse.m2e.core.prefs | 4 + .../multimedia/shapes4learn/Launcher.java | 6 +- .../analysis/LexicalAnalyzer.java | 4 +- .../controller/InterpreterController.java | 42 + .../shapes4learn/gui/InterpreterFrame.java | 22 +- 59 files changed, 2292 insertions(+), 4 deletions(-) create mode 100644 .classpath create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 .metadata/.lock create mode 100644 .metadata/.mylyn/.taskListIndex/segments.gen create mode 100644 .metadata/.mylyn/.taskListIndex/segments_1 create mode 100644 .metadata/.mylyn/repositories.xml.zip create mode 100644 .metadata/.mylyn/tasks.xml.zip create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.root/.indexes/history.version create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.root/.indexes/properties.index create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.root/.indexes/properties.version create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.root/1.tree create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.safetable/org.eclipse.core.resources create mode 100644 .metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.core.resources.prefs create mode 100644 .metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.ui.prefs create mode 100644 .metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.m2e.discovery.prefs create mode 100644 .metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.mylyn.context.core.prefs create mode 100644 .metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.mylyn.monitor.ui.prefs create mode 100644 .metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.mylyn.tasks.ui.prefs create mode 100644 .metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.team.cvs.ui.prefs create mode 100644 .metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.team.ui.prefs create mode 100644 .metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.ui.ide.prefs create mode 100644 .metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.ui.prefs create mode 100644 .metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.ui.workbench.prefs create mode 100644 .metadata/.plugins/org.eclipse.e4.workbench/workbench.xmi create mode 100644 .metadata/.plugins/org.eclipse.jdt.core/assumedExternalFilesCache create mode 100644 .metadata/.plugins/org.eclipse.jdt.core/externalFilesCache create mode 100644 .metadata/.plugins/org.eclipse.jdt.core/invalidArchivesCache create mode 100644 .metadata/.plugins/org.eclipse.jdt.core/nonChainingJarsCache create mode 100644 .metadata/.plugins/org.eclipse.jdt.core/variablesAndContainers.dat create mode 100644 .metadata/.plugins/org.eclipse.jdt.ui/OpenTypeHistory.xml create mode 100644 .metadata/.plugins/org.eclipse.jdt.ui/QualifiedTypeNameHistory.xml create mode 100644 .metadata/.plugins/org.eclipse.jdt.ui/dialog_settings.xml create mode 100644 .metadata/.plugins/org.eclipse.m2e.core.ui/dialog_settings.xml create mode 100644 .metadata/.plugins/org.eclipse.m2e.core/nexus/26522e0d83a422eed93329ece7565cfc/_0.cfs create mode 100644 .metadata/.plugins/org.eclipse.m2e.core/nexus/26522e0d83a422eed93329ece7565cfc/segments.gen create mode 100644 .metadata/.plugins/org.eclipse.m2e.core/nexus/26522e0d83a422eed93329ece7565cfc/segments_2 create mode 100644 .metadata/.plugins/org.eclipse.m2e.core/nexus/26522e0d83a422eed93329ece7565cfc/write.lock create mode 100644 .metadata/.plugins/org.eclipse.m2e.core/nexus/830bc118332e77292949ed1e6d2fabe0/_0.cfs create mode 100644 .metadata/.plugins/org.eclipse.m2e.core/nexus/830bc118332e77292949ed1e6d2fabe0/segments.gen create mode 100644 .metadata/.plugins/org.eclipse.m2e.core/nexus/830bc118332e77292949ed1e6d2fabe0/segments_2 create mode 100644 .metadata/.plugins/org.eclipse.m2e.core/nexus/830bc118332e77292949ed1e6d2fabe0/write.lock create mode 100644 .metadata/.plugins/org.eclipse.m2e.core/nexus/d91aba3017ff816c2a31821c02251625/_0.cfs create mode 100644 .metadata/.plugins/org.eclipse.m2e.core/nexus/d91aba3017ff816c2a31821c02251625/segments.gen create mode 100644 .metadata/.plugins/org.eclipse.m2e.core/nexus/d91aba3017ff816c2a31821c02251625/segments_2 create mode 100644 .metadata/.plugins/org.eclipse.m2e.core/nexus/d91aba3017ff816c2a31821c02251625/write.lock create mode 100644 .metadata/.plugins/org.eclipse.m2e.core/workspaceState.ser create mode 100644 .metadata/.plugins/org.eclipse.m2e.logback.configuration/0.log create mode 100644 .metadata/.plugins/org.eclipse.m2e.logback.configuration/logback.1.5.1.20150109-1820.xml create mode 100644 .metadata/.plugins/org.eclipse.ui.workbench/dialog_settings.xml create mode 100644 .metadata/.plugins/org.eclipse.ui.workbench/workingsets.xml create mode 100644 .metadata/version.ini create mode 100644 .project create mode 100644 .settings/org.eclipse.jdt.core.prefs create mode 100644 .settings/org.eclipse.m2e.core.prefs create mode 100644 src/main/java/edu/maimonides/multimedia/shapes4learn/controller/InterpreterController.java diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..f619a53 --- /dev/null +++ b/.classpath @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..bdb0cab --- /dev/null +++ b/.gitattributes @@ -0,0 +1,17 @@ +# Auto detect text files and perform LF normalization +* text=auto + +# Custom for Visual Studio +*.cs diff=csharp + +# Standard to msysgit +*.doc diff=astextplain +*.DOC diff=astextplain +*.docx diff=astextplain +*.DOCX diff=astextplain +*.dot diff=astextplain +*.DOT diff=astextplain +*.pdf diff=astextplain +*.PDF diff=astextplain +*.rtf diff=astextplain +*.RTF diff=astextplain diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b83d222 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target/ diff --git a/.metadata/.lock b/.metadata/.lock new file mode 100644 index 0000000..e69de29 diff --git a/.metadata/.mylyn/.taskListIndex/segments.gen b/.metadata/.mylyn/.taskListIndex/segments.gen new file mode 100644 index 0000000000000000000000000000000000000000..63a7ec9a3ce3e4c844ffb7c8dd88e6eb3ff32ef5 GIT binary patch literal 20 QcmezW|NlP*2w;TK07=6G{r~^~ literal 0 HcmV?d00001 diff --git a/.metadata/.mylyn/.taskListIndex/segments_1 b/.metadata/.mylyn/.taskListIndex/segments_1 new file mode 100644 index 0000000000000000000000000000000000000000..d20a054b0355a570278f08fcb3ff062163108ac0 GIT binary patch literal 32 acmezW|NmD82F3ujmfzeAXyBH~BNG6uPY4(Q literal 0 HcmV?d00001 diff --git a/.metadata/.mylyn/repositories.xml.zip b/.metadata/.mylyn/repositories.xml.zip new file mode 100644 index 0000000000000000000000000000000000000000..afd2154e2b049fa4ab0f6b92617a19f4433bcbc8 GIT binary patch literal 436 zcmWIWW@Zs#;Nak35My+5XFvi1Kz31TL4I*&Nq$jgYO!8LZqD0aUw`jpPC(Z8a3_?=IFOdBgl%k>v~xvix?#eZ^M z$8xJJJzDrb2w)bQ5TI(O#$=1`+6 z#sNVdXT8t)pFHEeJ(P>L@bcDxAPqgwGv1zOPM-JP8hYw<_@?cfIX!jGeLJb67s%24 z(uC<%ONX`kv?a@)i-&4eFqA%J*xK?;)w#uJbx`mWkv~GkhAdy-=6p#^yT!;5;LXk< soGWWw0CdL`AP(?mWD;ROxD{CrFG|--P0q(jX;3k{Kkz002QT7dQX_ literal 0 HcmV?d00001 diff --git a/.metadata/.plugins/org.eclipse.core.resources/.safetable/org.eclipse.core.resources b/.metadata/.plugins/org.eclipse.core.resources/.safetable/org.eclipse.core.resources new file mode 100644 index 0000000000000000000000000000000000000000..82e6b89aca6456c95c16f8ccc2e4865da4444ed0 GIT binary patch literal 376 zcmZ?R*xjhShe1S2b=vdAllRFf=Oz}Hq!uZZBqrsg@^UG=6=f>;CzmJ~7%3PSSQ%JY znV2cK`-bQm7+V<_C>R+Sn(}g`q~??)x>giq7A2Ns=I6!d7p3c^Cg)@p6sPKCrIhF; z=NF~g8k(3Go12;%8<`my81QoG>y;Fx0!4Yb4n+L^40b`_=bq}_<;NTb$VJIHsfk4{ lAg^HeKw4r>F)&1MD9f$Psm#+WNi5DT)+^1lg(}AFO8_bQeu)48 literal 0 HcmV?d00001 diff --git a/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.core.resources.prefs b/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..dffc6b5 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +version=1 diff --git a/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.ui.prefs b/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.ui.prefs new file mode 100644 index 0000000..c8fd235 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.ui.prefs @@ -0,0 +1,13 @@ +content_assist_proposals_background=255,255,255 +content_assist_proposals_foreground=0,0,0 +eclipse.preferences.version=1 +fontPropagated=true +org.eclipse.jdt.ui.editor.tab.width= +org.eclipse.jdt.ui.formatterprofiles.version=12 +org.eclipse.jdt.ui.javadoclocations.migrated=true +org.eclipse.jface.textfont=1|Consolas|10.0|0|WINDOWS|1|0|0|0|0|0|0|0|0|1|0|0|0|0|Consolas; +proposalOrderMigrated=true +spelling_locale_initialized=true +tabWidthPropagated=true +useAnnotationsPrefPage=true +useQuickDiffPrefPage=true diff --git a/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.m2e.discovery.prefs b/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.m2e.discovery.prefs new file mode 100644 index 0000000..67b1d96 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.m2e.discovery.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +org.eclipse.m2e.discovery.pref.projects= diff --git a/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.mylyn.context.core.prefs b/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.mylyn.context.core.prefs new file mode 100644 index 0000000..43e97e4 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.mylyn.context.core.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +mylyn.attention.migrated=true diff --git a/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.mylyn.monitor.ui.prefs b/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.mylyn.monitor.ui.prefs new file mode 100644 index 0000000..8d462a6 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.mylyn.monitor.ui.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +org.eclipse.mylyn.monitor.activity.tracking.enabled.checked=true diff --git a/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.mylyn.tasks.ui.prefs b/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.mylyn.tasks.ui.prefs new file mode 100644 index 0000000..5330e43 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.mylyn.tasks.ui.prefs @@ -0,0 +1,4 @@ +eclipse.preferences.version=1 +migrated.task.repositories.secure.store=true +org.eclipse.mylyn.tasks.ui.filters.nonmatching=true +org.eclipse.mylyn.tasks.ui.filters.nonmatching.encouraged=true diff --git a/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.team.cvs.ui.prefs b/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.team.cvs.ui.prefs new file mode 100644 index 0000000..f9e585b --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.team.cvs.ui.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +pref_first_startup=false diff --git a/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.team.ui.prefs b/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.team.ui.prefs new file mode 100644 index 0000000..56cd496 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.team.ui.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +org.eclipse.team.ui.first_time=false diff --git a/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.ui.ide.prefs b/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.ui.ide.prefs new file mode 100644 index 0000000..4c74ce4 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.ui.ide.prefs @@ -0,0 +1,5 @@ +PROBLEMS_FILTERS_MIGRATE=true +eclipse.preferences.version=1 +platformState=1428813606069 +quickStart=false +tipsAndTricks=true diff --git a/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.ui.prefs b/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.ui.prefs new file mode 100644 index 0000000..08076f2 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.ui.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +showIntro=false diff --git a/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.ui.workbench.prefs b/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.ui.workbench.prefs new file mode 100644 index 0000000..6316221 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.ui.workbench.prefs @@ -0,0 +1,3 @@ +ENABLED_DECORATORS=org.eclipse.m2e.core.mavenVersionDecorator\:false,org.eclipse.egit.ui.internal.decorators.GitLightweightDecorator\:true,org.eclipse.jdt.ui.override.decorator\:true,org.eclipse.jdt.ui.interface.decorator\:false,org.eclipse.jdt.ui.buildpath.decorator\:true,org.eclipse.m2e.core.maven2decorator\:true,org.eclipse.mylyn.context.ui.decorator.interest\:true,org.eclipse.mylyn.tasks.ui.decorators.task\:true,org.eclipse.mylyn.team.ui.changeset.decorator\:true,org.eclipse.team.cvs.ui.decorator\:true,org.eclipse.ui.LinkedResourceDecorator\:true,org.eclipse.ui.SymlinkDecorator\:true,org.eclipse.ui.VirtualResourceDecorator\:true,org.eclipse.ui.ContentTypeDecorator\:true,org.eclipse.ui.ResourceFilterDecorator\:false, +PLUGINS_NOT_ACTIVATED_ON_STARTUP=org.eclipse.m2e.discovery; +eclipse.preferences.version=1 diff --git a/.metadata/.plugins/org.eclipse.e4.workbench/workbench.xmi b/.metadata/.plugins/org.eclipse.e4.workbench/workbench.xmi new file mode 100644 index 0000000..574b3f9 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.e4.workbench/workbench.xmi @@ -0,0 +1,2009 @@ + + + + activeSchemeId:org.eclipse.ui.defaultAcceleratorConfiguration + ModelMigrationProcessor.001 + + + + + + topLevel + + + + + persp.actionSet:org.eclipse.mylyn.doc.actionSet + persp.actionSet:org.eclipse.mylyn.tasks.ui.navigation + persp.actionSet:org.eclipse.ui.cheatsheets.actionSet + persp.actionSet:org.eclipse.search.searchActionSet + persp.actionSet:org.eclipse.ui.edit.text.actionSet.annotationNavigation + persp.actionSet:org.eclipse.ui.edit.text.actionSet.navigation + persp.actionSet:org.eclipse.ui.edit.text.actionSet.convertLineDelimitersTo + persp.actionSet:org.eclipse.ui.externaltools.ExternalToolsSet + persp.actionSet:org.eclipse.ui.actionSet.keyBindings + persp.actionSet:org.eclipse.ui.actionSet.openFiles + persp.actionSet:org.eclipse.wb.core.ui.actionset + persp.actionSet:org.eclipse.debug.ui.launchActionSet + persp.actionSet:org.eclipse.jdt.ui.JavaActionSet + persp.actionSet:org.eclipse.jdt.ui.JavaElementCreationActionSet + persp.actionSet:org.eclipse.ui.NavigateActionSet + persp.viewSC:org.eclipse.jdt.ui.PackageExplorer + persp.viewSC:org.eclipse.jdt.ui.TypeHierarchy + persp.viewSC:org.eclipse.jdt.ui.SourceView + persp.viewSC:org.eclipse.jdt.ui.JavadocView + persp.viewSC:org.eclipse.search.ui.views.SearchView + persp.viewSC:org.eclipse.ui.console.ConsoleView + persp.viewSC:org.eclipse.ui.views.ContentOutline + persp.viewSC:org.eclipse.ui.views.ProblemView + persp.viewSC:org.eclipse.ui.views.ResourceNavigator + persp.viewSC:org.eclipse.ui.views.TaskList + persp.viewSC:org.eclipse.ui.views.ProgressView + persp.viewSC:org.eclipse.ui.navigator.ProjectExplorer + persp.viewSC:org.eclipse.ui.texteditor.TemplatesView + persp.viewSC:org.eclipse.pde.runtime.LogView + persp.newWizSC:org.eclipse.jdt.ui.wizards.JavaProjectWizard + persp.newWizSC:org.eclipse.jdt.ui.wizards.NewPackageCreationWizard + persp.newWizSC:org.eclipse.jdt.ui.wizards.NewClassCreationWizard + persp.newWizSC:org.eclipse.jdt.ui.wizards.NewInterfaceCreationWizard + persp.newWizSC:org.eclipse.jdt.ui.wizards.NewEnumCreationWizard + persp.newWizSC:org.eclipse.jdt.ui.wizards.NewAnnotationCreationWizard + persp.newWizSC:org.eclipse.jdt.ui.wizards.NewSourceFolderCreationWizard + persp.newWizSC:org.eclipse.jdt.ui.wizards.NewSnippetFileCreationWizard + persp.newWizSC:org.eclipse.jdt.ui.wizards.NewJavaWorkingSetWizard + persp.newWizSC:org.eclipse.ui.wizards.new.folder + persp.newWizSC:org.eclipse.ui.wizards.new.file + persp.newWizSC:org.eclipse.ui.editors.wizards.UntitledTextFileWizard + persp.perspSC:org.eclipse.jdt.ui.JavaBrowsingPerspective + persp.perspSC:org.eclipse.debug.ui.DebugPerspective + persp.viewSC:org.eclipse.ant.ui.views.AntView + persp.showIn:org.eclipse.egit.ui.RepositoriesView + persp.actionSet:org.eclipse.debug.ui.breakpointActionSet + persp.actionSet:org.eclipse.jdt.debug.ui.JDTDebugActionSet + persp.newWizSC:org.eclipse.jdt.junit.wizards.NewTestCaseCreationWizard + persp.actionSet:org.eclipse.jdt.junit.JUnitActionSet + persp.showIn:org.eclipse.jdt.ui.PackageExplorer + persp.showIn:org.eclipse.team.ui.GenericHistoryView + persp.showIn:org.eclipse.ui.views.ResourceNavigator + persp.showIn:org.eclipse.ui.navigator.ProjectExplorer + persp.viewSC:org.eclipse.mylyn.tasks.ui.views.tasks + persp.newWizSC:org.eclipse.mylyn.tasks.ui.wizards.new.repository.task + persp.viewSC:org.eclipse.wb.core.StructureView + persp.viewSC:org.eclipse.wb.core.PaletteView + + + + newtablook + org.eclipse.e4.primaryNavigationStack + active + + + + + + + + + + newtablook + + + + + + + + + newtablook + + + + newtablook + org.eclipse.e4.secondaryNavigationStack + + + + + + + + newtablook + org.eclipse.e4.secondaryDataStack + + + + + + + + + + + + + + + + + + + + View + categoryTag:Help + + + View + categoryTag:General + + ViewMenu + menuContribution:menu + + + + + View + categoryTag:Help + + + + newtablook + org.eclipse.e4.primaryDataStack + EditorStack + + + + + View + categoryTag:Java + active + activeOnClose + + ViewMenu + menuContribution:menu + + + + + View + categoryTag:Java + + + View + categoryTag:General + + + View + categoryTag:General + + + + View + categoryTag:General + + ViewMenu + menuContribution:menu + + + + + View + categoryTag:Java + + + View + categoryTag:Java + + + View + categoryTag:General + + + View + categoryTag:General + + + View + categoryTag:General + + + View + categoryTag:General + + + + View + categoryTag:General + + ViewMenu + menuContribution:menu + + + + + View + categoryTag:General + + + View + categoryTag:Ant + + + View + categoryTag:Git + + + View + categoryTag:Java + + + + View + categoryTag:Mylyn + + ViewMenu + menuContribution:menu + + + + + View + categoryTag:WindowBuilder + + + View + categoryTag:WindowBuilder + + + + toolbarSeparator + + + + Draggable + + + + toolbarSeparator + + + + Draggable + + + Draggable + + + Draggable + + + toolbarSeparator + + + + Draggable + + + + toolbarSeparator + + + + toolbarSeparator + + + + Draggable + + + stretch + SHOW_RESTORE_MENU + + + Draggable + HIDEABLE + SHOW_RESTORE_MENU + + + + + stretch + + + Draggable + + + Draggable + + + + + TrimStack + + + + + TrimStack + + + TrimStack + + + TrimStack + + + TrimStack + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + platform:win32 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Editor + + + View + categoryTag:Ant + + + View + categoryTag:Debug + + + View + categoryTag:Debug + + + View + categoryTag:Debug + + + View + categoryTag:Debug + + + View + categoryTag:Debug + + + View + categoryTag:Debug + + + View + categoryTag:Debug + + + View + categoryTag:Git + + + View + categoryTag:Git + + + View + categoryTag:Git + + + View + categoryTag:Git + + + View + categoryTag:Git + + + View + categoryTag:General + + + View + categoryTag:Help + + + View + categoryTag:Debug + + + View + categoryTag:Java + + + View + categoryTag:Java + + + View + categoryTag:Java + + + View + categoryTag:Java Browsing + + + View + categoryTag:Java Browsing + + + View + categoryTag:Java Browsing + + + View + categoryTag:Java Browsing + + + View + categoryTag:Java + + + View + categoryTag:General + + + View + categoryTag:Java + + + View + categoryTag:Java + + + View + categoryTag:Maven + + + View + categoryTag:Maven + + + View + categoryTag:Mylyn + + + View + categoryTag:Mylyn + + + View + categoryTag:Mylyn + + + View + categoryTag:Mylyn + + + View + categoryTag:Code Recommenders + + + View + categoryTag:Code Recommenders + + + View + categoryTag:Code Recommenders + + + View + categoryTag:Code Recommenders + + + View + categoryTag:General + + + View + categoryTag:General + + + View + categoryTag:CVS + + + View + categoryTag:CVS + + + View + categoryTag:Team + + + View + categoryTag:Team + + + View + categoryTag:General + + + View + categoryTag:General + + + View + categoryTag:Help + + + View + categoryTag:General + + + View + categoryTag:General + + + View + categoryTag:General + + + View + categoryTag:General + + + View + categoryTag:General + + + View + categoryTag:General + + + View + categoryTag:General + + + View + categoryTag:General + + + View + categoryTag:General + + + View + categoryTag:General + + + View + categoryTag:General + + + View + categoryTag:WindowBuilder + + + View + categoryTag:WindowBuilder + + + View + categoryTag:General + + + View + categoryTag:XML + + + View + categoryTag:XML + + + + glue + move_after:PerspectiveSpacer + SHOW_RESTORE_MENU + + + move_after:Spacer Glue + HIDEABLE + SHOW_RESTORE_MENU + + + glue + move_after:SearchField + SHOW_RESTORE_MENU + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.metadata/.plugins/org.eclipse.jdt.core/assumedExternalFilesCache b/.metadata/.plugins/org.eclipse.jdt.core/assumedExternalFilesCache new file mode 100644 index 0000000000000000000000000000000000000000..593f4708db84ac8fd0f5cc47c634f38c013fe9e4 GIT binary patch literal 4 LcmZQzU|;|M00aO5 literal 0 HcmV?d00001 diff --git a/.metadata/.plugins/org.eclipse.jdt.core/externalFilesCache b/.metadata/.plugins/org.eclipse.jdt.core/externalFilesCache new file mode 100644 index 0000000000000000000000000000000000000000..593f4708db84ac8fd0f5cc47c634f38c013fe9e4 GIT binary patch literal 4 LcmZQzU|;|M00aO5 literal 0 HcmV?d00001 diff --git a/.metadata/.plugins/org.eclipse.jdt.core/invalidArchivesCache b/.metadata/.plugins/org.eclipse.jdt.core/invalidArchivesCache new file mode 100644 index 0000000000000000000000000000000000000000..593f4708db84ac8fd0f5cc47c634f38c013fe9e4 GIT binary patch literal 4 LcmZQzU|;|M00aO5 literal 0 HcmV?d00001 diff --git a/.metadata/.plugins/org.eclipse.jdt.core/nonChainingJarsCache b/.metadata/.plugins/org.eclipse.jdt.core/nonChainingJarsCache new file mode 100644 index 0000000000000000000000000000000000000000..593f4708db84ac8fd0f5cc47c634f38c013fe9e4 GIT binary patch literal 4 LcmZQzU|;|M00aO5 literal 0 HcmV?d00001 diff --git a/.metadata/.plugins/org.eclipse.jdt.core/variablesAndContainers.dat b/.metadata/.plugins/org.eclipse.jdt.core/variablesAndContainers.dat new file mode 100644 index 0000000000000000000000000000000000000000..0edae4b20855dcd5c83bdac184b9ed16afb1b634 GIT binary patch literal 110 zcmZQzU|?c^05&ki?iJ)3@8jvj2;?y`aD#ZkLC!(`{vjX{CI&9AP(RO*cn^PHSC9ZR e16Tu435dtSzz2~A^5IHY8Q6V|;)7fR{22i=Q4xRu literal 0 HcmV?d00001 diff --git a/.metadata/.plugins/org.eclipse.jdt.ui/OpenTypeHistory.xml b/.metadata/.plugins/org.eclipse.jdt.ui/OpenTypeHistory.xml new file mode 100644 index 0000000..a4ee3cb --- /dev/null +++ b/.metadata/.plugins/org.eclipse.jdt.ui/OpenTypeHistory.xml @@ -0,0 +1,2 @@ + + diff --git a/.metadata/.plugins/org.eclipse.jdt.ui/QualifiedTypeNameHistory.xml b/.metadata/.plugins/org.eclipse.jdt.ui/QualifiedTypeNameHistory.xml new file mode 100644 index 0000000..9e390f5 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.jdt.ui/QualifiedTypeNameHistory.xml @@ -0,0 +1,2 @@ + + diff --git a/.metadata/.plugins/org.eclipse.jdt.ui/dialog_settings.xml b/.metadata/.plugins/org.eclipse.jdt.ui/dialog_settings.xml new file mode 100644 index 0000000..9cf5b13 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.jdt.ui/dialog_settings.xml @@ -0,0 +1,10 @@ + +
+
+ + + + + +
+
diff --git a/.metadata/.plugins/org.eclipse.m2e.core.ui/dialog_settings.xml b/.metadata/.plugins/org.eclipse.m2e.core.ui/dialog_settings.xml new file mode 100644 index 0000000..739d14e --- /dev/null +++ b/.metadata/.plugins/org.eclipse.m2e.core.ui/dialog_settings.xml @@ -0,0 +1,15 @@ + +
+
+ + + + + + + + + + +
+
diff --git a/.metadata/.plugins/org.eclipse.m2e.core/nexus/26522e0d83a422eed93329ece7565cfc/_0.cfs b/.metadata/.plugins/org.eclipse.m2e.core/nexus/26522e0d83a422eed93329ece7565cfc/_0.cfs new file mode 100644 index 0000000000000000000000000000000000000000..5a302366b97f292408cc4dca3457bc977af19238 GIT binary patch literal 297 zcmd;JfPhN2cmutX%uFbE4uo3_k*KKCn literal 0 HcmV?d00001 diff --git a/.metadata/.plugins/org.eclipse.m2e.core/nexus/26522e0d83a422eed93329ece7565cfc/write.lock b/.metadata/.plugins/org.eclipse.m2e.core/nexus/26522e0d83a422eed93329ece7565cfc/write.lock new file mode 100644 index 0000000..e69de29 diff --git a/.metadata/.plugins/org.eclipse.m2e.core/nexus/830bc118332e77292949ed1e6d2fabe0/_0.cfs b/.metadata/.plugins/org.eclipse.m2e.core/nexus/830bc118332e77292949ed1e6d2fabe0/_0.cfs new file mode 100644 index 0000000000000000000000000000000000000000..2510e883091094f427acd780011b0c37c60d619a GIT binary patch literal 274 zcmd;JfPhN2cmutX%uFbE4uo3_#gMgu)K}~snQFd`bVsfgLzCHsJmy2t#bC731h<^|xyQfQp Kr=OcY10w)=@Hl$_ literal 0 HcmV?d00001 diff --git a/.metadata/.plugins/org.eclipse.m2e.core/nexus/830bc118332e77292949ed1e6d2fabe0/segments.gen b/.metadata/.plugins/org.eclipse.m2e.core/nexus/830bc118332e77292949ed1e6d2fabe0/segments.gen new file mode 100644 index 0000000000000000000000000000000000000000..225a55b3c336e69bb83a6d5e7d3339a5c525e7e1 GIT binary patch literal 20 QcmezW|NlP*2w;NI07=aR00000 literal 0 HcmV?d00001 diff --git a/.metadata/.plugins/org.eclipse.m2e.core/nexus/830bc118332e77292949ed1e6d2fabe0/segments_2 b/.metadata/.plugins/org.eclipse.m2e.core/nexus/830bc118332e77292949ed1e6d2fabe0/segments_2 new file mode 100644 index 0000000000000000000000000000000000000000..efedb9a600249c841c9a6bf8805d4b03eddf435a GIT binary patch literal 58 qcmezW|Nl=02F3uj)~Y=WKn4gi#T$UA|40DL0ZD>YFuV%pb_W30f*3yl literal 0 HcmV?d00001 diff --git a/.metadata/.plugins/org.eclipse.m2e.core/nexus/830bc118332e77292949ed1e6d2fabe0/write.lock b/.metadata/.plugins/org.eclipse.m2e.core/nexus/830bc118332e77292949ed1e6d2fabe0/write.lock new file mode 100644 index 0000000..e69de29 diff --git a/.metadata/.plugins/org.eclipse.m2e.core/nexus/d91aba3017ff816c2a31821c02251625/_0.cfs b/.metadata/.plugins/org.eclipse.m2e.core/nexus/d91aba3017ff816c2a31821c02251625/_0.cfs new file mode 100644 index 0000000000000000000000000000000000000000..21b99faea8daf05821d5b2db8cdce02a66eb446e GIT binary patch literal 298 zcmd;JfPhN2cmutX%uFbE4uo3_k*ysAo`4O&DbW literal 0 HcmV?d00001 diff --git a/.metadata/.plugins/org.eclipse.m2e.core/nexus/d91aba3017ff816c2a31821c02251625/write.lock b/.metadata/.plugins/org.eclipse.m2e.core/nexus/d91aba3017ff816c2a31821c02251625/write.lock new file mode 100644 index 0000000..e69de29 diff --git a/.metadata/.plugins/org.eclipse.m2e.core/workspaceState.ser b/.metadata/.plugins/org.eclipse.m2e.core/workspaceState.ser new file mode 100644 index 0000000000000000000000000000000000000000..a18b68ea79bdb757ab31178a6082338ad4fe64e6 GIT binary patch literal 545 zcmcJL&q@O^5Qm4BR;`HIig)jt?iLD);J-pqSfR8Jpm95HQ`1d4N!#_})z|O=gx(>Y{HM zVIYj9d)7z_&GbHQO&(tgPdga^9TC+2NIT<3_`i_e=l4f{Jl@Sf-h1v2%gbFPb zy)GZ}vgBb*#fg7cmDF6Tf literal 0 HcmV?d00001 diff --git a/.metadata/.plugins/org.eclipse.m2e.logback.configuration/0.log b/.metadata/.plugins/org.eclipse.m2e.logback.configuration/0.log new file mode 100644 index 0000000..e69de29 diff --git a/.metadata/.plugins/org.eclipse.m2e.logback.configuration/logback.1.5.1.20150109-1820.xml b/.metadata/.plugins/org.eclipse.m2e.logback.configuration/logback.1.5.1.20150109-1820.xml new file mode 100644 index 0000000..e33758c --- /dev/null +++ b/.metadata/.plugins/org.eclipse.m2e.logback.configuration/logback.1.5.1.20150109-1820.xml @@ -0,0 +1,43 @@ + + + + %date [%thread] %-5level %logger{35} - %msg%n + + + OFF + + + + + ${org.eclipse.m2e.log.dir}/0.log + + ${org.eclipse.m2e.log.dir}/%i.log + 1 + 10 + + + 100MB + + + %date [%thread] %-5level %logger{35} - %msg%n + + + + + + WARN + + + + + + + + + + + + + + + diff --git a/.metadata/.plugins/org.eclipse.ui.workbench/dialog_settings.xml b/.metadata/.plugins/org.eclipse.ui.workbench/dialog_settings.xml new file mode 100644 index 0000000..43e24dd --- /dev/null +++ b/.metadata/.plugins/org.eclipse.ui.workbench/dialog_settings.xml @@ -0,0 +1,17 @@ + +
+
+ + + + + + + + + + +
+
+
+
diff --git a/.metadata/.plugins/org.eclipse.ui.workbench/workingsets.xml b/.metadata/.plugins/org.eclipse.ui.workbench/workingsets.xml new file mode 100644 index 0000000..ab6edbc --- /dev/null +++ b/.metadata/.plugins/org.eclipse.ui.workbench/workingsets.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.metadata/version.ini b/.metadata/version.ini new file mode 100644 index 0000000..ed997e9 --- /dev/null +++ b/.metadata/version.ini @@ -0,0 +1,3 @@ +#Fri Oct 02 00:07:25 GMT-03:00 2015 +org.eclipse.core.runtime=2 +org.eclipse.platform=4.4.2.v20150204-1700 diff --git a/.project b/.project new file mode 100644 index 0000000..dda840f --- /dev/null +++ b/.project @@ -0,0 +1,23 @@ + + + shapes4learn + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..ec4300d --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,5 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/.settings/org.eclipse.m2e.core.prefs b/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/src/main/java/edu/maimonides/multimedia/shapes4learn/Launcher.java b/src/main/java/edu/maimonides/multimedia/shapes4learn/Launcher.java index 5ebf13b..e951de3 100644 --- a/src/main/java/edu/maimonides/multimedia/shapes4learn/Launcher.java +++ b/src/main/java/edu/maimonides/multimedia/shapes4learn/Launcher.java @@ -2,6 +2,8 @@ import javax.swing.JOptionPane; +import edu.maimonides.multimedia.shapes4learn.analysis.LexicalAnalyzer; +import edu.maimonides.multimedia.shapes4learn.controller.InterpreterController; import edu.maimonides.multimedia.shapes4learn.gui.InterpreterFrame; import edu.maimonides.multimedia.shapes4learn.interpreter.Interpreter; import edu.maimonides.multimedia.shapes4learn.model.impl.BasicShapeAmbient; @@ -29,7 +31,9 @@ public static void main(String[] args) { } InterpreterFrame frame; try { - frame = new InterpreterFrame(createInterpreter(classname), new BasicShapeAmbient()); + LexicalAnalyzer lexAn = new LexicalAnalyzer(); + + frame = new InterpreterFrame(createInterpreter(classname), new BasicShapeAmbient(), lexAn); frame.init(); frame.setVisible(true); } catch (ClassNotFoundException e) { diff --git a/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/LexicalAnalyzer.java b/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/LexicalAnalyzer.java index f50ae73..131e68f 100644 --- a/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/LexicalAnalyzer.java +++ b/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/LexicalAnalyzer.java @@ -192,10 +192,10 @@ public List analyze(String code) throws LexicalException { // Se imprimien los token (lexema, clase) - /*for (Iterator iterator = tokens.iterator(); iterator.hasNext();) { + for (Iterator iterator = tokens.iterator(); iterator.hasNext();) { Token token = (Token) iterator.next(); System.out.println("Lexema: " + token.lexema + " Clase: " + token.clase); - }*/ + } return tokens; } diff --git a/src/main/java/edu/maimonides/multimedia/shapes4learn/controller/InterpreterController.java b/src/main/java/edu/maimonides/multimedia/shapes4learn/controller/InterpreterController.java new file mode 100644 index 0000000..deb4fc6 --- /dev/null +++ b/src/main/java/edu/maimonides/multimedia/shapes4learn/controller/InterpreterController.java @@ -0,0 +1,42 @@ +package edu.maimonides.multimedia.shapes4learn.controller; + +import java.io.IOException; +import java.io.InputStream; +import java.util.List; + +import edu.maimonides.multimedia.shapes4learn.analysis.LexicalAnalyzer; +import edu.maimonides.multimedia.shapes4learn.analysis.LexicalException; +import edu.maimonides.multimedia.shapes4learn.interpreter.CodeException; +import edu.maimonides.multimedia.shapes4learn.interpreter.Interpreter; +import edu.maimonides.multimedia.shapes4learn.model.ShapeAmbient; +import edu.maimonides.multimedia.shapes4learn.model.Token; + +public class InterpreterController implements Interpreter{ + + private LexicalAnalyzer la; + + public InterpreterController(LexicalAnalyzer la) { + super(); + this.la = la; + } + + @Override + public void interpret(String code, ShapeAmbient ambient) + throws CodeException { + try { + List tk = la.analyze(code); + } catch (LexicalException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + + @Override + public void interpret(InputStream stream, ShapeAmbient ambient) + throws CodeException, IOException { + // TODO Auto-generated method stub + + } + +} diff --git a/src/main/java/edu/maimonides/multimedia/shapes4learn/gui/InterpreterFrame.java b/src/main/java/edu/maimonides/multimedia/shapes4learn/gui/InterpreterFrame.java index 044062d..170bb29 100644 --- a/src/main/java/edu/maimonides/multimedia/shapes4learn/gui/InterpreterFrame.java +++ b/src/main/java/edu/maimonides/multimedia/shapes4learn/gui/InterpreterFrame.java @@ -15,6 +15,8 @@ import javax.swing.JSplitPane; import javax.swing.JTextArea; +import edu.maimonides.multimedia.shapes4learn.analysis.LexicalAnalyzer; +import edu.maimonides.multimedia.shapes4learn.controller.InterpreterController; import edu.maimonides.multimedia.shapes4learn.interpreter.CodeException; import edu.maimonides.multimedia.shapes4learn.interpreter.Interpreter; import edu.maimonides.multimedia.shapes4learn.model.ShapeAmbient; @@ -40,9 +42,17 @@ public class InterpreterFrame extends JFrame { private JMenuBar menuBar; - public InterpreterFrame(Interpreter interpreter, ShapeAmbient ambient) { + private LexicalAnalyzer la; + + private InterpreterController ic; + + public InterpreterFrame(Interpreter interpreter, ShapeAmbient ambient, LexicalAnalyzer la) { this.ambient = ambient; this.interpreter = interpreter; + this.la = la; + + ic = new InterpreterController(la); + code = new JTextArea("Code here..."); shapesPanel = new ShapesPanel(); shapesPanel.setAmbient(ambient); @@ -101,8 +111,18 @@ public void actionPerformed(ActionEvent e) { } private class RunActionListener implements ActionListener { + + + + @Override public void actionPerformed(ActionEvent e) { + try { + ic.interpret(getInputCode(), ambient); + } catch (CodeException e2) { + // TODO Auto-generated catch block + e2.printStackTrace(); + } clearConsole(); try { interpreter.interpret(getInputCode(), ambient); From bfee62357d860868f926dd25462799306a1a555a Mon Sep 17 00:00:00 2001 From: cmfernandez Date: Tue, 6 Oct 2015 14:41:41 -0300 Subject: [PATCH 05/26] Correccion lexical analizer Se corrigio el analizador ya que el lexema @123 salia como expresion aritmetica. --- .../shapes4learn/analysis/LexicalAnalyzer.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/LexicalAnalyzer.java b/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/LexicalAnalyzer.java index 131e68f..53ed83a 100644 --- a/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/LexicalAnalyzer.java +++ b/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/LexicalAnalyzer.java @@ -21,7 +21,7 @@ public List analyze(String code) throws LexicalException { //String[] aux; boolean validoNum=false; //boolean validoId=true; - boolean ExpArit=true; + boolean ExpArit=false; boolean reservada1=false; boolean id=false; @@ -64,7 +64,7 @@ public List analyze(String code) throws LexicalException { reservada1=false; validoNum=false; //boolean validoId=true; - ExpArit=false; + ExpArit=true; reservada1=false; id=false; @@ -112,9 +112,9 @@ public List analyze(String code) throws LexicalException { //Expresion aritmetica int f=0; - char ant='a'; - - for (;(f Date: Tue, 13 Oct 2015 10:59:00 -0300 Subject: [PATCH 06/26] Correccion de errores Se corrigio algunos casos donde se asignaba mal la clase, por ejemplo create rectangle abc ; --- .../multimedia/shapes4learn/analysis/LexicalAnalyzer.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/LexicalAnalyzer.java b/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/LexicalAnalyzer.java index 53ed83a..d0c3231 100644 --- a/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/LexicalAnalyzer.java +++ b/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/LexicalAnalyzer.java @@ -64,7 +64,7 @@ public List analyze(String code) throws LexicalException { reservada1=false; validoNum=false; //boolean validoId=true; - ExpArit=true; + reservada1=false; id=false; @@ -180,11 +180,6 @@ public List analyze(String code) throws LexicalException { //Hexadecimal //System.out.println("Entra en hexadecimal el lexema " + lexemas[i]); - - if (lexemas[i].matches("([a-f]|[A-F]|[0-9]|\\s)+") && validoNum==false) { - tempToken.lexema = lexemas[i]; - tempToken.clase = "color_def"; - } //System.out.println("Token lexema: " + i + " " + tempToken.lexema + " Token clase: " + tempToken.clase); tokens.add(i,tempToken); From d92561fb4061d2f758ca753535f455c0d37d756f Mon Sep 17 00:00:00 2001 From: Gianella Kravchik Date: Tue, 13 Oct 2015 19:46:31 -0300 Subject: [PATCH 07/26] CLase 13/10 Correxion analizador color_def --- .../multimedia/shapes4learn/analysis/LexicalAnalyzer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/LexicalAnalyzer.java b/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/LexicalAnalyzer.java index d0c3231..1b5c119 100644 --- a/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/LexicalAnalyzer.java +++ b/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/LexicalAnalyzer.java @@ -169,7 +169,7 @@ public List analyze(String code) throws LexicalException { if ( lexemas[i].charAt(0)=='#') { - if (lexemas[i].substring(1).matches("([a-f]|[A-F]|[0-9]|\\s)+")) { + if (lexemas[i].substring(1).matches("([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$")) { tempToken.lexema = lexemas[i]; tempToken.clase = "color_def"; }else { From 773b4778f9eff3864ce3fb7ada9f53a2c02bb78b Mon Sep 17 00:00:00 2001 From: cmfernandez Date: Fri, 16 Oct 2015 07:36:51 -0300 Subject: [PATCH 08/26] Correcciones de errores en la parte de analisis lexico Se agrego el separador de lexemas enter Se agregaron las clases, operador suma, operador resta, operador division, operador multriplicar, la clase hexadecimal, parentesis apertura y parentesis cierre La clase hexadecimal es la que menos prioridad tiene, por ejemplo si entra ababab aunque sea un hexadecimal se toma como ID, lo mismo para con 123456, se toma como clase Numero Se saca la clase expresion aritmetica, ya que en esta parte no se debe encargar de saber si es o no una exp aritmetica Todos los lexemas se ingresan separados por espacio o enter, por ejemplo (5+5)/2 se debe ingresar ( 5 + 5 ) / 2 No me acuerdo si hay otra cosa... --- .../analysis/LexicalAnalyzer.java | 125 +++++++++++++----- .../interpreter/TestLexicalAnalizer.java | 28 +++- 2 files changed, 113 insertions(+), 40 deletions(-) diff --git a/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/LexicalAnalyzer.java b/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/LexicalAnalyzer.java index 1b5c119..1f695ae 100644 --- a/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/LexicalAnalyzer.java +++ b/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/LexicalAnalyzer.java @@ -21,9 +21,10 @@ public List analyze(String code) throws LexicalException { //String[] aux; boolean validoNum=false; //boolean validoId=true; - boolean ExpArit=false; + boolean Operadores=false; boolean reservada1=false; boolean id=false; + boolean color=false; // Completo la matriz token (lexemas - clase) @@ -54,7 +55,7 @@ public List analyze(String code) throws LexicalException { List tokens = new LinkedList<>(); // Separo los lexemas - String delimitadores= "[\\ \\ \\ \\ \\ \\ ]"; + String delimitadores= "[\\ \\ \\ \\ \\ \\ \\\n]"; String lexemas[] = code.split(delimitadores); //Recorro los lexemas y encuentro las Lexemas reservadas del lenguaje @@ -64,9 +65,10 @@ public List analyze(String code) throws LexicalException { reservada1=false; validoNum=false; //boolean validoId=true; - reservada1=false; id=false; + color=false; + Operadores=false; //System.out.println("\nPosicion: " + i + " <><> Lexema que ingresa: " + lexemas[i]); @@ -88,11 +90,24 @@ public List analyze(String code) throws LexicalException { // si no es Lexema reservada int x=0; + int paso=1; // veo si es numero - for (;x analyze(String code) throws LexicalException { tempToken.lexema = lexemas[i]; tempToken.clase = "Lexema desconocido"; } - } - - - //Expresion aritmetica - - int f=0; - char ant='a'; - - for (;(f analyze(String code) throws LexicalException { tempToken.lexema = lexemas[i]; tempToken.clase = "Lexema desconocido"; } - } + }*/ //ID bien @@ -156,11 +149,13 @@ public List analyze(String code) throws LexicalException { // tokens.add(tempToken); }*/ - if (lexemas[i].matches("([a-z]|[A-Z]|\\s)+") && reservada1==false) { + if (lexemas[i].matches("([a-zA-Z])+") && reservada1==false) { tempToken.lexema = lexemas[i]; tempToken.clase = "ID"; id=true; } + + //System.out.println("Entra en ID el lexema " + tempToken.lexema + tempToken.clase); //color_def @@ -172,19 +167,81 @@ public List analyze(String code) throws LexicalException { if (lexemas[i].substring(1).matches("([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$")) { tempToken.lexema = lexemas[i]; tempToken.clase = "color_def"; + color=true; }else { - tempToken.lexema = lexemas[i]; - tempToken.clase = "Lexema desconocido"; + if (id==false && reservada1==false && validoNum == false) { + + tempToken.lexema = lexemas[i]; + tempToken.clase = "Lexema desconocido"; + + } + } } //Hexadecimal - //System.out.println("Entra en hexadecimal el lexema " + lexemas[i]); + //System.out.println("Entra en hexadecimal el lexema " + lexemas[i]); + + if (lexemas[i].matches("([A-Fa-f0-9])+") && validoNum==false && id==false) { + tempToken.lexema = lexemas[i]; + tempToken.clase = "Hexadecimal"; + }else { + if (id==false && reservada1==false && validoNum == false && color==false) { + + tempToken.lexema = lexemas[i]; + tempToken.clase = "Lexema desconocido"; + + } + } + + //Operadores + + //System.out.println("Entra en Color_def el lexema " + String.valueOf('+').equals(lexemas[i])); + + if (String.valueOf('+').equals(lexemas[i])) + { + tempToken.lexema = lexemas[i]; + tempToken.clase = "Operador suma"; + } + + if (String.valueOf('-').equals(lexemas[i])) + { + tempToken.lexema = lexemas[i]; + tempToken.clase = "Operador resta"; + } + + if (String.valueOf('*').equals(lexemas[i])) + { + tempToken.lexema = lexemas[i]; + tempToken.clase = "Operador multiplicar"; + } + + if (String.valueOf('/').equals(lexemas[i])) + { + tempToken.lexema = lexemas[i]; + tempToken.clase = "Operador dividir"; + } + + // Parentesis + + if (lexemas[i].equals('(')) + { + tempToken.lexema = lexemas[i]; + tempToken.clase = "Parentesis de Apertura"; + } + + if (lexemas[i].equals(')')) + { + tempToken.lexema = lexemas[i]; + tempToken.clase = "Parentesis de Cierre"; + } //System.out.println("Token lexema: " + i + " " + tempToken.lexema + " Token clase: " + tempToken.clase); tokens.add(i,tempToken); } + + // Se imprimien los token (lexema, clase) for (Iterator iterator = tokens.iterator(); iterator.hasNext();) { diff --git a/src/test/java/edu/maimonides/multimedia/shapes4learn/interpreter/TestLexicalAnalizer.java b/src/test/java/edu/maimonides/multimedia/shapes4learn/interpreter/TestLexicalAnalizer.java index 3ac7b2e..c1b92f1 100644 --- a/src/test/java/edu/maimonides/multimedia/shapes4learn/interpreter/TestLexicalAnalizer.java +++ b/src/test/java/edu/maimonides/multimedia/shapes4learn/interpreter/TestLexicalAnalizer.java @@ -16,8 +16,8 @@ public class TestLexicalAnalizer { public void test() { String code1 = "create circle micirculo ; " - + "setradius 5+5 in circle micirculo ; " - + "setcolor #aA1 in shape micirculo ;"; + + "setradius 5 + 5 in circle micirculo ; " + + "setcolor #aA1234 in shape micirculo ;"; //String code1 = "create"; @@ -42,7 +42,11 @@ public void test() { tok = new Token(); tok.setLexema("setradius");tok.setClase("setear radio");tokenValida.add(tok); tok = new Token(); - tok.setLexema("5+5");tok.setClase("Expresion Aritmetica");tokenValida.add(tok); + tok.setLexema("5");tok.setClase("Numero");tokenValida.add(tok); + tok = new Token(); + tok.setLexema("+");tok.setClase("Operador suma");tokenValida.add(tok); + tok = new Token(); + tok.setLexema("5");tok.setClase("Numero");tokenValida.add(tok); tok = new Token(); tok.setLexema("in");tok.setClase("'in'");tokenValida.add(tok); tok = new Token(); @@ -54,7 +58,7 @@ public void test() { tok = new Token(); tok.setLexema("setcolor");tok.setClase("setear color");tokenValida.add(tok); tok = new Token(); - tok.setLexema("#aA1");tok.setClase("color_def");tokenValida.add(tok); + tok.setLexema("#aA1234");tok.setClase("color_def");tokenValida.add(tok); tok = new Token(); tok.setLexema("in");tok.setClase("'in'");tokenValida.add(tok); tok = new Token(); @@ -148,7 +152,7 @@ public void test2() { @Test public void test3() { - String code1 = "setradius (5+5)*3 in circle micirculo ;"; + String code1 = "setradius ( 5 + 5 ) * 3 in circle micirculo ;"; List tokenValida = new LinkedList<>(); @@ -165,7 +169,19 @@ public void test3() { Token tok = new Token(); tok.setLexema("setradius");tok.setClase("setear radio");tokenValida.add(tok); tok = new Token(); - tok.setLexema("(5+5)*3");tok.setClase("Expresion Aritmetica");tokenValida.add(tok); + tok.setLexema("(");tok.setClase("Parentesis de Apertura");tokenValida.add(tok); + tok = new Token(); + tok.setLexema("5");tok.setClase("Numero");tokenValida.add(tok); + tok = new Token(); + tok.setLexema("+");tok.setClase("Operador suma");tokenValida.add(tok); + tok = new Token(); + tok.setLexema("5");tok.setClase("Numero");tokenValida.add(tok); + tok = new Token(); + tok.setLexema(")");tok.setClase("Parentesis de Apertura");tokenValida.add(tok); + tok = new Token(); + tok.setLexema("*");tok.setClase("Operador multiplicar");tokenValida.add(tok); + tok = new Token(); + tok.setLexema("3");tok.setClase("Numero");tokenValida.add(tok); tok = new Token(); tok.setLexema("in");tok.setClase("`in`");tokenValida.add(tok); tok = new Token(); From 86c6718b1702c824549a105fdce018df6130b960 Mon Sep 17 00:00:00 2001 From: cmfernandez Date: Wed, 21 Oct 2015 07:44:26 -0300 Subject: [PATCH 09/26] Modificaciones lexicals y sus tests ',' es la clase "coma" +- clase "Adicion" */ clase "Producto" --- .../analysis/LexicalAnalyzer.java | 20 +++++++++---------- .../interpreter/TestLexicalAnalizer.java | 8 ++++---- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/LexicalAnalyzer.java b/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/LexicalAnalyzer.java index 1f695ae..fb156ed 100644 --- a/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/LexicalAnalyzer.java +++ b/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/LexicalAnalyzer.java @@ -48,9 +48,9 @@ public List analyze(String code) throws LexicalException { reservada[9][0] = "shape"; reservada[9][1] = "clase shape"; - reservada[10][0] = ","; reservada[10][1] = "separador de expresiones"; + reservada[10][0] = ","; reservada[10][1] = "coma"; - reservada[11][0] = "in"; reservada[11][1] = "'in'"; + reservada[11][0] = "in"; reservada[11][1] = "in"; List tokens = new LinkedList<>(); @@ -198,29 +198,29 @@ public List analyze(String code) throws LexicalException { //System.out.println("Entra en Color_def el lexema " + String.valueOf('+').equals(lexemas[i])); - if (String.valueOf('+').equals(lexemas[i])) + if (String.valueOf('+').equals(lexemas[i]) || String.valueOf('-').equals(lexemas[i])) { tempToken.lexema = lexemas[i]; - tempToken.clase = "Operador suma"; + tempToken.clase = "Adicion"; } - if (String.valueOf('-').equals(lexemas[i])) + /* if (String.valueOf('-').equals(lexemas[i])) { tempToken.lexema = lexemas[i]; tempToken.clase = "Operador resta"; - } + }*/ - if (String.valueOf('*').equals(lexemas[i])) + if (String.valueOf('*').equals(lexemas[i]) || String.valueOf('/').equals(lexemas[i])) { tempToken.lexema = lexemas[i]; - tempToken.clase = "Operador multiplicar"; + tempToken.clase = "Producto"; } - if (String.valueOf('/').equals(lexemas[i])) + /*if (String.valueOf('/').equals(lexemas[i])) { tempToken.lexema = lexemas[i]; tempToken.clase = "Operador dividir"; - } + }*/ // Parentesis diff --git a/src/test/java/edu/maimonides/multimedia/shapes4learn/interpreter/TestLexicalAnalizer.java b/src/test/java/edu/maimonides/multimedia/shapes4learn/interpreter/TestLexicalAnalizer.java index c1b92f1..828232d 100644 --- a/src/test/java/edu/maimonides/multimedia/shapes4learn/interpreter/TestLexicalAnalizer.java +++ b/src/test/java/edu/maimonides/multimedia/shapes4learn/interpreter/TestLexicalAnalizer.java @@ -44,7 +44,7 @@ public void test() { tok = new Token(); tok.setLexema("5");tok.setClase("Numero");tokenValida.add(tok); tok = new Token(); - tok.setLexema("+");tok.setClase("Operador suma");tokenValida.add(tok); + tok.setLexema("+");tok.setClase("Adicion");tokenValida.add(tok); tok = new Token(); tok.setLexema("5");tok.setClase("Numero");tokenValida.add(tok); tok = new Token(); @@ -60,7 +60,7 @@ public void test() { tok = new Token(); tok.setLexema("#aA1234");tok.setClase("color_def");tokenValida.add(tok); tok = new Token(); - tok.setLexema("in");tok.setClase("'in'");tokenValida.add(tok); + tok.setLexema("in");tok.setClase("in");tokenValida.add(tok); tok = new Token(); tok.setLexema("shape");tok.setClase("clase shape");tokenValida.add(tok); tok = new Token(); @@ -173,13 +173,13 @@ public void test3() { tok = new Token(); tok.setLexema("5");tok.setClase("Numero");tokenValida.add(tok); tok = new Token(); - tok.setLexema("+");tok.setClase("Operador suma");tokenValida.add(tok); + tok.setLexema("+");tok.setClase("Adicion");tokenValida.add(tok); tok = new Token(); tok.setLexema("5");tok.setClase("Numero");tokenValida.add(tok); tok = new Token(); tok.setLexema(")");tok.setClase("Parentesis de Apertura");tokenValida.add(tok); tok = new Token(); - tok.setLexema("*");tok.setClase("Operador multiplicar");tokenValida.add(tok); + tok.setLexema("*");tok.setClase("Producto");tokenValida.add(tok); tok = new Token(); tok.setLexema("3");tok.setClase("Numero");tokenValida.add(tok); tok = new Token(); From 3a69725522f026522ad0139702808809e1a8eea8 Mon Sep 17 00:00:00 2001 From: cmfernandez Date: Wed, 28 Oct 2015 07:43:50 -0300 Subject: [PATCH 10/26] SyntacticAnalyzer Se agrega la clase SyntacticAnalizer --- .../analysis/SyntacticAnalyzer.java | 398 +++++++++++++++++- 1 file changed, 395 insertions(+), 3 deletions(-) diff --git a/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/SyntacticAnalyzer.java b/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/SyntacticAnalyzer.java index 66ef34c..7b45fa6 100644 --- a/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/SyntacticAnalyzer.java +++ b/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/SyntacticAnalyzer.java @@ -1,7 +1,8 @@ package edu.maimonides.multimedia.shapes4learn.analysis; +import java.util.Iterator; +import java.util.LinkedList; import java.util.List; - import edu.maimonides.multimedia.shapes4learn.model.AST; import edu.maimonides.multimedia.shapes4learn.model.Token; @@ -15,14 +16,405 @@ */ public class SyntacticAnalyzer { + private String sentencia; + private String lookahead; + private Token token; + private Iterator iterator; + public SyntacticAnalyzer() { } public AST analyze(List tokens) throws SyntacticException { + + List sentencias = new LinkedList<>(); AST ast = new AST(); - // TODO Implement. - + sentencia = new String(); + + + for (Iterator iterator = tokens.iterator(); iterator.hasNext();) { + Token token = (Token) iterator.next(); + + if ((token.lexema.charAt(0) == ';')){ + + sentencias.add(sentencia + ';'); + + sentencia = new String(); + + + }else{ + sentencia = sentencia.concat(' ' +token.lexema); + + + + } + + } + + for (Iterator iterator = sentencias.iterator(); iterator.hasNext();) { + String sent = iterator.next(); + System.out.println("Setencia: " + sent); + + } + + checkSent(tokens); + + + return ast; } + +public void checkSent(List tokens){ + + for (iterator = tokens.iterator(); iterator.hasNext();) { + + token = (Token) iterator.next(); + + lookahead = token.getClase(); + + //Cambiar clase + + + + if (lookahead == "crear"){ + checkCreate(lookahead); + } + + + if (lookahead == "setear color"){ + checkSetColor(lookahead); + } + + if (lookahead == "setear base"){ + checkSetBase(lookahead); + } + + if (lookahead == "setear altura"){ + checkSetHeight(lookahead); + } + + if(lookahead == "setear radio"){ + checkRadio(lookahead); + } + + if(lookahead == "setear posicion"){ + checkPosition(lookahead); + } + } + + } + + +// setposition [expression],[expression] in shape [id] ; + +private void checkPosition(String string) { + System.out.println("setposition [expression],[expression] in shape [id] ;"); + matchSetPosition(string); + checkExpresion(lookahead); + matchComa(lookahead); + checkExpresion(lookahead); + matchIn(lookahead); + matchShape(lookahead); + matchId(lookahead); + matchFin(lookahead); + + +} + + +// setradius [expression] in circle [id] ; + +private boolean matchComa(String string) { + if(string == "separador de expresiones"){ + System.out.println("Es Coma"); + token = (Token) iterator.next(); + lookahead = token.getClase(); + return true; + } + System.out.println("No es Coma. Error"); + System.out.close(); + return false; + +} + +private boolean matchSetPosition(String string) { + if(string == "setear posicion"){ + System.out.println("Es setPosition"); + token = (Token) iterator.next(); + lookahead = token.getClase(); + return true; + } + System.out.printf("Vino %s, se esperaba setPosition.", string); + System.out.close(); + return false; + +} + +private void checkRadio(String string) { + System.out.println("setradius [expression] in circle [id] ;"); + matchSetRadio(string); + checkExpresion(lookahead); + matchIn(lookahead); + matchCircle(lookahead); + matchId(lookahead); + matchFin(lookahead); + +} + +private boolean matchSetRadio(String string) { + if(string == "setear radio"){ + System.out.println("Es setRadio"); + token = (Token) iterator.next(); + lookahead = token.getClase(); + return true; + } + System.out.printf("Vino %s, se esperaba setRadio.", string); + System.out.close(); + return false; + + } + + // setcolor [color_def] in shape [id]; + + private void checkSetColor(String string) { + + System.out.println("setcolor [color_def] in shape [id] ;"); + matchSetColor(string); + matchColorDef(lookahead); + matchIn(lookahead); + matchShape(lookahead); + matchId(lookahead); + matchFin(lookahead); + + } + + private boolean matchShape(String string) { + if(string == "clase shape"){ + System.out.println("Es shape"); + token = (Token) iterator.next(); + lookahead = token.getClase(); + return true; + } + System.out.printf("Vino %s, se esperaba 'shape'", string); + System.out.close(); + return false; + + + } + + private boolean matchIn(String string) { + if(string == "'in'"){ + System.out.println("Es in"); + token = (Token) iterator.next(); + lookahead = token.getClase(); + return true; + } + System.out.printf("Vino %s, se esperaba 'in'", string); + System.out.close(); + return false; + + + } + + +// setheight [expression] in rectangle [id] ; + + private void checkSetHeight(String string) { + System.out.println("setheight [expression] in rectangle [id] ;"); + matchSetHeight(string); + checkExpresion(lookahead); + matchIn(lookahead); + matchRectangle(lookahead); + matchId(lookahead); + matchFin(lookahead); + + } + + + + private boolean matchSetHeight(String string) { + if(string == "setear altura"){ + System.out.println("Es setHeight"); + token = (Token) iterator.next(); + lookahead = token.getClase(); + return true; + } + System.out.printf("Vino %s, se esperaba setHeight.", string); + System.out.close(); + return false; + + } + +// setbase [expression] in rectangle [id] ; + + private void checkSetBase(String string) { + + System.out.println("setbase [expression] in rectangle [id] ;"); + matchSetBase(string); + checkExpresion(lookahead); + matchIn(lookahead); + matchRectangle(lookahead); + matchId(lookahead); + matchFin(lookahead); + + } + + private boolean matchSetBase(String string) { + if(string == "setear base"){ + System.out.println("Es setBase"); + token = (Token) iterator.next(); + lookahead = token.getClase(); + return true; + } + System.out.printf("Vino %s, se esperaba setBase.", string); + System.out.close(); + return false; + + } + + private void checkExpresion(String string) { + + if (string == "Numero"){ + System.out.println("Es numero"); + token = (Token) iterator.next(); + lookahead = token.getClase(); + checkExpresion(lookahead); + } + + + + + } + + private void matchFin(String string) { + + if (string == "fin de sentencia"){ + + if (iterator.hasNext()){ + + System.out.println("[;] Fin de sentencia"); + } + else { + System.out.println("[;] Fin de sentencia"); + System.out.println("Terminaron las sentencias a analizar"); + + } + } + + } + + private boolean matchSetColor(String string) { + if(string == "setear color"){ + System.out.println("Es setColor"); + token = (Token) iterator.next(); + lookahead = token.getClase(); + return true; + } + System.out.printf("Vino %s, se esperaba setcolor \n", string); + System.out.close(); + return false; + + } + + private boolean matchColorDef(String string) { + if(string == "color_def"){ + System.out.println("Es un color"); + token = (Token) iterator.next(); + lookahead = token.getClase(); + return true; + } + System.out.printf("Vino %s, se esperaba un color del tipo #AAA111 \n", string); + System.out.close(); + return false; + + + } + +// create rectangle|circle [id]; + + private void checkCreate(String string) { + matchCreate(string); + checkShape(lookahead); + matchId(lookahead); + matchFin(lookahead); + + } + + + + private boolean matchId(String string) { + + if(string == "ID"){ + System.out.println("Es ID."); + token = (Token) iterator.next(); + lookahead = token.getClase(); + return true; + } else { + System.out.printf("Vino %s, se esperaba un ID valido \n ", string); + System.out.close(); + return false; + } + + } + + private void checkShape(String string) { + + if (string == "ShapeCirculo"){ + System.out.println("Es circle"); + matchCircle(lookahead); + + }else { + if (string == "ShapeRectangulo"){ + System.out.println("Es rectangle"); + matchRectangle(lookahead); + + } else { + System.out.printf("Vino %s, se esperaba una figura \n ", string); + System.out.close(); + + } + + + } + + } + + private boolean matchRectangle(String string) { + if(string == "ShapeRectangulo"){ + token = (Token) iterator.next(); + lookahead = token.getClase(); + return true; + } else { + System.out.printf("Vino %s, se esperaba un rectangulo \n ", string); + System.out.close(); + return false; + } + + } + + private boolean matchCircle(String string) { + if(string == "ShapeCirculo"){ + token = (Token) iterator.next(); + lookahead = token.getClase(); + return true; + } + + System.out.close(); + return false; + + + } + + private boolean matchCreate(String string) { + if(string == "crear"){ + System.out.println("Es create"); + token = (Token) iterator.next(); + lookahead = token.getClase(); + return true; + } + System.out.printf("Vino %s, se esperaba 'create' \n ", string); + System.out.close(); + return false; + + } } \ No newline at end of file From 6e6c75a65be1c94add801b4938fffd9bd4113ec5 Mon Sep 17 00:00:00 2001 From: Gianella Kravchik Date: Mon, 2 Nov 2015 22:25:44 -0300 Subject: [PATCH 11/26] Arreglo de TP2, launcher+ controller + frame --- .../multimedia/shapes4learn/Launcher.java | 5 ++++- .../controller/InterpreterController.java | 18 ++++++++++++++++-- .../shapes4learn/gui/InterpreterFrame.java | 9 +++++++-- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/main/java/edu/maimonides/multimedia/shapes4learn/Launcher.java b/src/main/java/edu/maimonides/multimedia/shapes4learn/Launcher.java index e951de3..3ffcb09 100644 --- a/src/main/java/edu/maimonides/multimedia/shapes4learn/Launcher.java +++ b/src/main/java/edu/maimonides/multimedia/shapes4learn/Launcher.java @@ -3,6 +3,7 @@ import javax.swing.JOptionPane; import edu.maimonides.multimedia.shapes4learn.analysis.LexicalAnalyzer; +import edu.maimonides.multimedia.shapes4learn.analysis.SyntacticAnalyzer; import edu.maimonides.multimedia.shapes4learn.controller.InterpreterController; import edu.maimonides.multimedia.shapes4learn.gui.InterpreterFrame; import edu.maimonides.multimedia.shapes4learn.interpreter.Interpreter; @@ -33,7 +34,9 @@ public static void main(String[] args) { try { LexicalAnalyzer lexAn = new LexicalAnalyzer(); - frame = new InterpreterFrame(createInterpreter(classname), new BasicShapeAmbient(), lexAn); + SyntacticAnalyzer synAn = new SyntacticAnalyzer(); + + frame = new InterpreterFrame(createInterpreter(classname), new BasicShapeAmbient(), lexAn, synAn ); frame.init(); frame.setVisible(true); } catch (ClassNotFoundException e) { diff --git a/src/main/java/edu/maimonides/multimedia/shapes4learn/controller/InterpreterController.java b/src/main/java/edu/maimonides/multimedia/shapes4learn/controller/InterpreterController.java index deb4fc6..e40304a 100644 --- a/src/main/java/edu/maimonides/multimedia/shapes4learn/controller/InterpreterController.java +++ b/src/main/java/edu/maimonides/multimedia/shapes4learn/controller/InterpreterController.java @@ -6,30 +6,44 @@ import edu.maimonides.multimedia.shapes4learn.analysis.LexicalAnalyzer; import edu.maimonides.multimedia.shapes4learn.analysis.LexicalException; +import edu.maimonides.multimedia.shapes4learn.analysis.SyntacticAnalyzer; +import edu.maimonides.multimedia.shapes4learn.analysis.SyntacticException; import edu.maimonides.multimedia.shapes4learn.interpreter.CodeException; import edu.maimonides.multimedia.shapes4learn.interpreter.Interpreter; +import edu.maimonides.multimedia.shapes4learn.model.AST; import edu.maimonides.multimedia.shapes4learn.model.ShapeAmbient; import edu.maimonides.multimedia.shapes4learn.model.Token; public class InterpreterController implements Interpreter{ private LexicalAnalyzer la; + private List tk; + private SyntacticAnalyzer sa; - public InterpreterController(LexicalAnalyzer la) { + public InterpreterController(LexicalAnalyzer la, SyntacticAnalyzer sa) { super(); this.la = la; + this.sa = sa; } @Override public void interpret(String code, ShapeAmbient ambient) throws CodeException { try { - List tk = la.analyze(code); + tk = la.analyze(code); } catch (LexicalException e) { // TODO Auto-generated catch block e.printStackTrace(); } + try { + AST ast = sa.analyze(tk); + } catch (SyntacticException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } @Override diff --git a/src/main/java/edu/maimonides/multimedia/shapes4learn/gui/InterpreterFrame.java b/src/main/java/edu/maimonides/multimedia/shapes4learn/gui/InterpreterFrame.java index 170bb29..2a5f035 100644 --- a/src/main/java/edu/maimonides/multimedia/shapes4learn/gui/InterpreterFrame.java +++ b/src/main/java/edu/maimonides/multimedia/shapes4learn/gui/InterpreterFrame.java @@ -16,6 +16,8 @@ import javax.swing.JTextArea; import edu.maimonides.multimedia.shapes4learn.analysis.LexicalAnalyzer; +import edu.maimonides.multimedia.shapes4learn.analysis.SyntacticAnalyzer; +import edu.maimonides.multimedia.shapes4learn.analysis.SyntacticException; import edu.maimonides.multimedia.shapes4learn.controller.InterpreterController; import edu.maimonides.multimedia.shapes4learn.interpreter.CodeException; import edu.maimonides.multimedia.shapes4learn.interpreter.Interpreter; @@ -45,13 +47,16 @@ public class InterpreterFrame extends JFrame { private LexicalAnalyzer la; private InterpreterController ic; + + private SyntacticAnalyzer sa; - public InterpreterFrame(Interpreter interpreter, ShapeAmbient ambient, LexicalAnalyzer la) { + public InterpreterFrame(Interpreter interpreter, ShapeAmbient ambient, LexicalAnalyzer la, SyntacticAnalyzer sa) { this.ambient = ambient; this.interpreter = interpreter; this.la = la; + this.sa = sa; - ic = new InterpreterController(la); + ic = new InterpreterController(la, sa); code = new JTextArea("Code here..."); shapesPanel = new ShapesPanel(); From dd41ff4cd091f7ad9e16e458635648d1ce0a1cd8 Mon Sep 17 00:00:00 2001 From: Gianella Kravchik Date: Mon, 2 Nov 2015 22:26:49 -0300 Subject: [PATCH 12/26] Arreglos en el analyzer: Se agregan sentencias informativas. --- .../multimedia/shapes4learn/analysis/SyntacticAnalyzer.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/SyntacticAnalyzer.java b/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/SyntacticAnalyzer.java index 7b45fa6..0898976 100644 --- a/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/SyntacticAnalyzer.java +++ b/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/SyntacticAnalyzer.java @@ -3,6 +3,7 @@ import java.util.Iterator; import java.util.LinkedList; import java.util.List; + import edu.maimonides.multimedia.shapes4learn.model.AST; import edu.maimonides.multimedia.shapes4learn.model.Token; @@ -74,6 +75,9 @@ public void checkSent(List tokens){ //Cambiar clase + System.out.println("\n"); + System.out.println("---- Comienza el análisis de una sentencia -----\n"); + System.out.println("\n"); if (lookahead == "crear"){ @@ -333,6 +337,7 @@ private boolean matchColorDef(String string) { // create rectangle|circle [id]; private void checkCreate(String string) { + System.out.println("Se espera: create rectangle|circle [id]"); matchCreate(string); checkShape(lookahead); matchId(lookahead); From b7086707c8cede36cf0441bd7e0f854fb35a9749 Mon Sep 17 00:00:00 2001 From: cmfernandez Date: Wed, 11 Nov 2015 07:56:17 -0300 Subject: [PATCH 13/26] AST create Lo de la clase de ayer 10/11 --- .../analysis/SyntacticAnalyzer.java | 52 +++++++++++++++---- .../multimedia/shapes4learn/model/AST.java | 19 +++++++ 2 files changed, 60 insertions(+), 11 deletions(-) diff --git a/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/SyntacticAnalyzer.java b/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/SyntacticAnalyzer.java index 0898976..55ce1fd 100644 --- a/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/SyntacticAnalyzer.java +++ b/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/SyntacticAnalyzer.java @@ -16,11 +16,13 @@ * */ public class SyntacticAnalyzer { - + + private int linea=0; private String sentencia; private String lookahead; private Token token; private Iterator iterator; + private AST raiz = new AST(); public SyntacticAnalyzer() { } @@ -28,7 +30,6 @@ public SyntacticAnalyzer() { public AST analyze(List tokens) throws SyntacticException { List sentencias = new LinkedList<>(); - AST ast = new AST(); sentencia = new String(); @@ -62,7 +63,7 @@ public AST analyze(List tokens) throws SyntacticException { - return ast; + return raiz; } public void checkSent(List tokens){ @@ -79,7 +80,8 @@ public void checkSent(List tokens){ System.out.println("---- Comienza el análisis de una sentencia -----\n"); System.out.println("\n"); - + linea++; + if (lookahead == "crear"){ checkCreate(lookahead); } @@ -123,6 +125,8 @@ private void checkPosition(String string) { matchFin(lookahead); + + } @@ -337,13 +341,36 @@ private boolean matchColorDef(String string) { // create rectangle|circle [id]; private void checkCreate(String string) { + System.out.println("Se espera: create rectangle|circle [id]"); - matchCreate(string); - checkShape(lookahead); + AST create = new AST(); + create.setLinea(linea); + create.setToken(token); + + matchCreate(string); + + AST shape = checkShape(lookahead); + create.addChild(shape); + + AST id = new AST(); + id.setLinea(linea); + id.setToken(token); matchId(lookahead); + + create.addChild(id); + matchFin(lookahead); - } + raiz.addChild(create); + String a = raiz.getChild(0).getToken().getLexema(); + String b = raiz.getChild(0).getChild(0).getToken().getLexema(); + String c = raiz.getChild(0).getChild(1).getToken().getLexema(); + + System.out.printf("- 1: %s", a); + System.out.printf("- 2: %s", b); + System.out.printf("- 3: %s", c); + } + @@ -362,25 +389,28 @@ private boolean matchId(String string) { } - private void checkShape(String string) { + private AST checkShape(String string) { + + AST figura = new AST(); + figura.setLinea(linea); + figura.setToken(token); if (string == "ShapeCirculo"){ System.out.println("Es circle"); matchCircle(lookahead); - }else { if (string == "ShapeRectangulo"){ System.out.println("Es rectangle"); matchRectangle(lookahead); - + } else { System.out.printf("Vino %s, se esperaba una figura \n ", string); System.out.close(); } - } + return figura; } diff --git a/src/main/java/edu/maimonides/multimedia/shapes4learn/model/AST.java b/src/main/java/edu/maimonides/multimedia/shapes4learn/model/AST.java index 91aed7c..a67acba 100644 --- a/src/main/java/edu/maimonides/multimedia/shapes4learn/model/AST.java +++ b/src/main/java/edu/maimonides/multimedia/shapes4learn/model/AST.java @@ -12,6 +12,25 @@ * */ public class AST { + + public Token token; + public int linea; + + public Token getToken() { + return token; + } + + public void setToken(Token token) { + this.token = token; + } + + public int getLinea() { + return linea; + } + + public void setLinea(int linea) { + this.linea = linea; + } /** * The {@link AST} children. From 0bb9dcf38adeea9743cfea3e8efdbc77a17c45d8 Mon Sep 17 00:00:00 2001 From: cmfernandez Date: Wed, 11 Nov 2015 14:18:15 -0300 Subject: [PATCH 14/26] Setcolor Arbol de setcolor y su "impresion" --- .../analysis/SyntacticAnalyzer.java | 38 ++++++++++++++++++- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/SyntacticAnalyzer.java b/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/SyntacticAnalyzer.java index 55ce1fd..a73bb6a 100644 --- a/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/SyntacticAnalyzer.java +++ b/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/SyntacticAnalyzer.java @@ -187,13 +187,45 @@ private boolean matchSetRadio(String string) { private void checkSetColor(String string) { System.out.println("setcolor [color_def] in shape [id] ;"); - matchSetColor(string); + + AST setcolor = new AST(); + setcolor.setLinea(linea); + setcolor.setToken(token); + + matchSetColor(string); + + AST color_def = new AST(); + color_def.setLinea(linea); + color_def.setToken(token); + + setcolor.addChild(color_def); + matchColorDef(lookahead); + matchIn(lookahead); matchShape(lookahead); + + AST id = new AST(); + id.setLinea(linea); + id.setToken(token); + + setcolor.addChild(id); + matchId(lookahead); matchFin(lookahead); + raiz.addChild(setcolor); + String a = raiz.getChild(1).getToken().getLexema(); + String b = raiz.getChild(1).getChild(0).getToken().getLexema(); + String c = raiz.getChild(1).getChild(1).getToken().getLexema(); + + System.out.printf("Muestro arbol de set color: "); + + System.out.printf("- 1: %s", a); + System.out.printf("- 2: %s", b); + System.out.printf("- 3: %s", c); + + } private boolean matchShape(String string) { @@ -211,7 +243,7 @@ private boolean matchShape(String string) { } private boolean matchIn(String string) { - if(string == "'in'"){ + if(string == "in"){ System.out.println("Es in"); token = (Token) iterator.next(); lookahead = token.getClase(); @@ -365,6 +397,8 @@ private void checkCreate(String string) { String a = raiz.getChild(0).getToken().getLexema(); String b = raiz.getChild(0).getChild(0).getToken().getLexema(); String c = raiz.getChild(0).getChild(1).getToken().getLexema(); + + System.out.printf("Muestro arbol de crear: "); System.out.printf("- 1: %s", a); System.out.printf("- 2: %s", b); From 3ca3169c43ae30a89a3c4360b0c2c67f9ba785dc Mon Sep 17 00:00:00 2001 From: cmfernandez Date: Wed, 18 Nov 2015 08:11:51 -0300 Subject: [PATCH 15/26] Avances MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Se armo el árbol y comenzó con el análisis semántico --- .../analysis/LexicalAnalyzer.java | 2 +- .../analysis/SyntacticAnalyzer.java | 299 +++++++++++++++++- .../multimedia/shapes4learn/model/Figura.java | 32 ++ 3 files changed, 323 insertions(+), 10 deletions(-) create mode 100644 src/main/java/edu/maimonides/multimedia/shapes4learn/model/Figura.java diff --git a/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/LexicalAnalyzer.java b/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/LexicalAnalyzer.java index fb156ed..18c0c19 100644 --- a/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/LexicalAnalyzer.java +++ b/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/LexicalAnalyzer.java @@ -38,7 +38,7 @@ public List analyze(String code) throws LexicalException { reservada[4][0] = "setbase"; reservada[4][1] = "setear base"; - reservada[5][0] = "sethight"; reservada[5][1] = "setear altura"; + reservada[5][0] = "setheight"; reservada[5][1] = "setear altura"; reservada[6][0] = "setcolor"; reservada[6][1] = "setear color"; diff --git a/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/SyntacticAnalyzer.java b/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/SyntacticAnalyzer.java index a73bb6a..d95ed57 100644 --- a/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/SyntacticAnalyzer.java +++ b/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/SyntacticAnalyzer.java @@ -1,10 +1,12 @@ package edu.maimonides.multimedia.shapes4learn.analysis; +import java.util.ArrayList; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import edu.maimonides.multimedia.shapes4learn.model.AST; +import edu.maimonides.multimedia.shapes4learn.model.Figura; import edu.maimonides.multimedia.shapes4learn.model.Token; /** @@ -23,6 +25,7 @@ public class SyntacticAnalyzer { private Token token; private Iterator iterator; private AST raiz = new AST(); + private ArrayList figuras; //pasar al semantico public SyntacticAnalyzer() { } @@ -60,13 +63,86 @@ public AST analyze(List tokens) throws SyntacticException { } checkSent(tokens); - - + System.out.println("\n Valida Arbol"); + validarArbol(raiz); return raiz; } +private void validarArbol(AST raiz2) { + // TODO Auto-generated method stub + System.out.println("\n"); + System.out.println("--- Comienza Analisis semantico ----- "); + System.out.println("\n"); + + + + for (Iterator it = raiz2.listChildren().iterator(); it.hasNext();) { + + AST arbol = it.next(); + + String lexema = arbol.getToken().getClase(); + String tipo = arbol.getChild(0).getToken().getLexema(); + String id = arbol.getChild(1).getToken().getLexema(); + + + + if (lexema.equals("crear")) + { + System.out.println("Entra por create"); + + Figura figuraNueva = new Figura(); + + if(figuras.isEmpty()){ + figuraNueva.setClase(tipo); + figuraNueva.setId(id); + figuras.add(figuraNueva); + + System.out.println("Se creo una figura"); + } + + else + + { + for (Iterator iterator = figuras.iterator(); iterator.hasNext();) { + + + + if(iterator.next().getId().equals(id)){ + + System.out.println("Ya existe ese ID para otra figura"); + System.exit(0); + + } + + figuraNueva.setClase(tipo); + figuraNueva.setId(id); + System.out.println("Se creo una figura"); + } + + figuras.add(figuraNueva); + } + + } + + + + } + + for (Iterator iterator = figuras.iterator(); iterator.hasNext();) { + Figura fig = iterator.next(); + System.out.println("\n"); + + System.out.printf(" Figura: %s Clase %s", fig.getId() , fig.getClase()); + + } + + + } + public void checkSent(List tokens){ + + figuras = new ArrayList<>(); for (iterator = tokens.iterator(); iterator.hasNext();) { @@ -107,13 +183,14 @@ public void checkSent(List tokens){ checkPosition(lookahead); } } + } // setposition [expression],[expression] in shape [id] ; -private void checkPosition(String string) { +/*private void checkPosition(String string) { System.out.println("setposition [expression],[expression] in shape [id] ;"); matchSetPosition(string); checkExpresion(lookahead); @@ -127,12 +204,12 @@ private void checkPosition(String string) { -} +}*/ // setradius [expression] in circle [id] ; -private boolean matchComa(String string) { +/*private boolean matchComa(String string) { if(string == "separador de expresiones"){ System.out.println("Es Coma"); token = (Token) iterator.next(); @@ -143,6 +220,78 @@ private boolean matchComa(String string) { System.out.close(); return false; +}*/ + +private void checkPosition(String string) { + +System.out.println("setposition [expression],[expression] in shape [id] ;"); + AST setposition = new AST(); + setposition.setLinea(linea); + setposition.setToken(token); + + matchSetPosition(string); + + AST position_def = new AST(); + position_def.setLinea(linea); + position_def.setToken(token); + + setposition.addChild(position_def); + + checkExpresion(lookahead); + + matchComa(lookahead); + + AST position_def2 = new AST(); + position_def2.setLinea(linea); + position_def2.setToken(token); + + setposition.addChild(position_def2); + + checkExpresion(lookahead); + + matchIn(lookahead); + matchShape(lookahead); + + AST id = new AST(); + id.setLinea(linea); + id.setToken(token); + + setposition.addChild(id); + + matchId(lookahead); + matchFin(lookahead); + + raiz.addChild(setposition); + + String a = raiz.getChild(0).getToken().getLexema(); + String b = raiz.getChild(0).getChild(0).getToken().getLexema(); + String c = raiz.getChild(0).getChild(1).getToken().getLexema(); + String d = raiz.getChild(0).getChild(2).getToken().getLexema(); + + + System.out.printf("Muestro arbol de set posición: "); + + System.out.printf(" - 1: %s", a); + System.out.printf(" - 2: %s", b); + System.out.printf(" - 3: %s", c); + System.out.printf(" - 4: %s", d); + + + } + +private boolean matchComa(String coma) { + // TODO Auto-generated method stub + + if(coma == "coma"){ + System.out.println("Es coma"); + token = (Token) iterator.next(); + lookahead = token.getClase(); + return true; + } + System.out.printf("Vino %s, se esperaba coma.", coma); + System.out.close(); + return false; + } private boolean matchSetPosition(String string) { @@ -159,6 +308,49 @@ private boolean matchSetPosition(String string) { } private void checkRadio(String string) { + +System.out.println("setradius [expression] in circle [id] ;"); + AST setradio = new AST(); + setradio.setLinea(linea); + setradio.setToken(token); + + matchSetRadio(string); + + AST radio_def = new AST(); + radio_def.setLinea(linea); + radio_def.setToken(token); + + setradio.addChild(radio_def); + + checkExpresion(lookahead); + + matchIn(lookahead); + matchCircle(lookahead); + + AST id = new AST(); + id.setLinea(linea); + id.setToken(token); + + setradio.addChild(id); + + matchId(lookahead); + matchFin(lookahead); + + raiz.addChild(setradio); + String a = raiz.getChild(0).getToken().getLexema(); + String b = raiz.getChild(0).getChild(0).getToken().getLexema(); + String c = raiz.getChild(0).getChild(1).getToken().getLexema(); + + System.out.printf("Muestro arbol de set radio: "); + + System.out.printf(" - 1: %s", a); + System.out.printf(" - 2: %s", b); + System.out.printf(" - 3: %s", c); + + + } + +/*private void checkRadio(String string) { System.out.println("setradius [expression] in circle [id] ;"); matchSetRadio(string); checkExpresion(lookahead); @@ -167,7 +359,7 @@ private void checkRadio(String string) { matchId(lookahead); matchFin(lookahead); -} +}*/ private boolean matchSetRadio(String string) { if(string == "setear radio"){ @@ -260,15 +452,60 @@ private boolean matchIn(String string) { // setheight [expression] in rectangle [id] ; private void checkSetHeight(String string) { + System.out.println("setheight [expression] in rectangle [id] ;"); + + AST setheight = new AST(); + setheight.setLinea(linea); + setheight.setToken(token); + + matchSetHeight(string); + + AST height_def = new AST(); + height_def.setLinea(linea); + height_def.setToken(token); + + setheight.addChild(height_def); + + checkExpresion(lookahead); + + matchIn(lookahead); + matchRectangle(lookahead); + + AST id = new AST(); + id.setLinea(linea); + id.setToken(token); + + setheight.addChild(id); + + matchId(lookahead); + matchFin(lookahead); + + raiz.addChild(setheight); + String a = raiz.getChild(0).getToken().getLexema(); + String b = raiz.getChild(0).getChild(0).getToken().getLexema(); + String c = raiz.getChild(0).getChild(1).getToken().getLexema(); + + System.out.printf("Muestro arbol de set height: "); + + System.out.printf("- 1: %s", a); + System.out.printf("- 2: %s", b); + System.out.printf("- 3: %s", c); + + + } + + /*private void checkSetHeight(String string) { + System.out.println("setheight [expression] in rectangle [id] ;"); + matchSetHeight(string); checkExpresion(lookahead); matchIn(lookahead); matchRectangle(lookahead); matchId(lookahead); matchFin(lookahead); - - } + + }*/ @@ -289,6 +526,48 @@ private boolean matchSetHeight(String string) { private void checkSetBase(String string) { + System.out.println("setbase [expression] in rectangle [id] ;"); + AST setbase = new AST(); + setbase.setLinea(linea); + setbase.setToken(token); + + matchSetBase(string); + + AST base_def = new AST(); + base_def.setLinea(linea); + base_def.setToken(token); + + setbase.addChild(base_def); + + checkExpresion(lookahead); + + matchIn(lookahead); + matchRectangle(lookahead); + + AST id = new AST(); + id.setLinea(linea); + id.setToken(token); + + setbase.addChild(id); + + matchId(lookahead); + matchFin(lookahead); + + raiz.addChild(setbase); + String a = raiz.getChild(0).getToken().getLexema(); + String b = raiz.getChild(0).getChild(0).getToken().getLexema(); + String c = raiz.getChild(0).getChild(1).getToken().getLexema(); + + System.out.printf("Muestro arbol de set base: "); + + System.out.printf(" - 1: %s", a); + System.out.printf(" - 2: %s", b); + System.out.printf(" - 3: %s", c); + + } + + /*private void checkSetBase(String string) { + System.out.println("setbase [expression] in rectangle [id] ;"); matchSetBase(string); checkExpresion(lookahead); @@ -297,7 +576,7 @@ private void checkSetBase(String string) { matchId(lookahead); matchFin(lookahead); - } + }*/ private boolean matchSetBase(String string) { if(string == "setear base"){ @@ -387,6 +666,7 @@ private void checkCreate(String string) { AST id = new AST(); id.setLinea(linea); id.setToken(token); + matchId(lookahead); create.addChild(id); @@ -403,6 +683,7 @@ private void checkCreate(String string) { System.out.printf("- 1: %s", a); System.out.printf("- 2: %s", b); System.out.printf("- 3: %s", c); + } diff --git a/src/main/java/edu/maimonides/multimedia/shapes4learn/model/Figura.java b/src/main/java/edu/maimonides/multimedia/shapes4learn/model/Figura.java new file mode 100644 index 0000000..b8b834f --- /dev/null +++ b/src/main/java/edu/maimonides/multimedia/shapes4learn/model/Figura.java @@ -0,0 +1,32 @@ +package edu.maimonides.multimedia.shapes4learn.model; + +public class Figura { + + public String id; + public String clase; + + + + public String getId() { + return id; + } + + + + public void setId(String id) { + this.id = id; + } + + + + public String getClase() { + return clase; + } + + + + public void setClase(String clase) { + this.clase = clase; + } + +} From 37292bfa4ab2161967a2c3cbdba0fbc962015df9 Mon Sep 17 00:00:00 2001 From: Gianella Kravchik Date: Mon, 23 Nov 2015 21:42:34 -0300 Subject: [PATCH 16/26] =?UTF-8?q?Arreglos=20An=C3=A1lisis=20Sintactico?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../analysis/LexicalAnalyzer.java | 9 +- .../analysis/SyntacticAnalyzer.java | 137 +++++++++++++++++- 2 files changed, 134 insertions(+), 12 deletions(-) diff --git a/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/LexicalAnalyzer.java b/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/LexicalAnalyzer.java index 18c0c19..31d0d46 100644 --- a/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/LexicalAnalyzer.java +++ b/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/LexicalAnalyzer.java @@ -14,7 +14,6 @@ * */ public class LexicalAnalyzer { - public List analyze(String code) throws LexicalException { String[][] reservada = new String[20][20]; @@ -224,16 +223,16 @@ public List analyze(String code) throws LexicalException { // Parentesis - if (lexemas[i].equals('(')) + if (String.valueOf('(').equals(lexemas[i]) ) { tempToken.lexema = lexemas[i]; - tempToken.clase = "Parentesis de Apertura"; + tempToken.clase = "Parentesis A"; } - if (lexemas[i].equals(')')) + if (String.valueOf(')').equals(lexemas[i]) ) { tempToken.lexema = lexemas[i]; - tempToken.clase = "Parentesis de Cierre"; + tempToken.clase = "Parentesis C"; } //System.out.println("Token lexema: " + i + " " + tempToken.lexema + " Token clase: " + tempToken.clase); diff --git a/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/SyntacticAnalyzer.java b/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/SyntacticAnalyzer.java index d95ed57..be30cbe 100644 --- a/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/SyntacticAnalyzer.java +++ b/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/SyntacticAnalyzer.java @@ -592,18 +592,141 @@ private boolean matchSetBase(String string) { } private void checkExpresion(String string) { + System.out.println("CHECK EXPRESION"); - if (string == "Numero"){ - System.out.println("Es numero"); - token = (Token) iterator.next(); - lookahead = token.getClase(); - checkExpresion(lookahead); - } + checkTermino(string); + checkTerminoR(lookahead); + - +} + +private void checkTerminoR(String string) { + System.out.println("CHECK TERMINO R"); + if (!matchLamda(string)){ + + if(!matchAdicion(string)){ + checkFactor(string); + } + else{ + checkTerminoR(lookahead);} + } else { + matchLamda(string); + } + + +} + +private boolean matchLamda(String string) { + if(string == "in" || string == "coma" ){ + System.out.println("Termino expresion."); + + return true; + } else { + if(matchCierroP(string)){ + return true; + }else{ + System.out.printf("Vino %s, se esperaba termino expresion \n ", string); + return false; + } + } +} + +private void checkFactor(String string) { + System.out.println("CHECK FACTOR"); + if (string == "Numero"){ + matchNumero(string);} + else{ + if(matchAbroP(string)){ + checkExpresion(lookahead); + // matchCierroP(lookahead); + }else{ + matchCierroP(string); + } + + } + +} + +private boolean matchNumero(String string) { + if(string == "Numero"){ + System.out.println("Es Numero."); + token = (Token) iterator.next(); + lookahead = token.getClase(); + return true; + } else { + System.out.printf("Vino %s, se esperaba un numero valido \n ", string); + System.out.close(); + return false; + } + +} + +private boolean matchAdicion(String string) { + if(string == "Adicion"){ + System.out.println("Es Adicion."); + token = (Token) iterator.next(); + lookahead = token.getClase(); + return true; + } else { + return false; + } + +} + + + +private void checkTermino(String string) { + System.out.println("CHECK TERMINO"); + checkFactor(string); + checkFactorR(lookahead); + +} + +private void checkFactorR(String string) { + System.out.println("CHECK FACTOR R"); + + if (!matchLamda(string)){ + + if(matchAbroP(string)){ + checkExpresion(lookahead); +// matchCierroP(lookahead); + } } + + + +} + +private boolean matchCierroP(String string) { + if(string == "Parentesis C"){ + System.out.println("Es cierre parentesis"); + token = (Token) iterator.next(); + lookahead = token.getClase(); + return true; + } + System.out.printf("Vino %s, se esperaba ')'. \n", string); + + return false; + +} +//setbase ( 4 ) in rectangle id ; + +private boolean matchAbroP(String string) { + if(string == "Parentesis A"){ + System.out.println("Es abro parentesis"); + token = (Token) iterator.next(); + lookahead = token.getClase(); + return true; + } + System.out.printf("Vino %s, se esperaba '('. \n", string); + + return false; + +} + + private void matchFin(String string) { From e0794dd306b35a400d097e591259aec005bdb84f Mon Sep 17 00:00:00 2001 From: Gianella Kravchik Date: Sat, 28 Nov 2015 11:24:47 -0300 Subject: [PATCH 17/26] =?UTF-8?q?Listo=20An=C3=A1lisis=20Syntactico=20-=20?= =?UTF-8?q?Falta=20Arbol=20Exp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Contiene método para futuro Analisis Semantico --- .../analysis/LexicalAnalyzer.java | 2 +- .../analysis/SyntacticAnalyzer.java | 366 +++++++----------- 2 files changed, 147 insertions(+), 221 deletions(-) diff --git a/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/LexicalAnalyzer.java b/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/LexicalAnalyzer.java index 31d0d46..9945b70 100644 --- a/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/LexicalAnalyzer.java +++ b/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/LexicalAnalyzer.java @@ -158,7 +158,7 @@ public List analyze(String code) throws LexicalException { //color_def - //System.out.println("Entra en Color_def el lexema " + lexemas[i]); + //System.out.println("Entra en Color_def el lexema " + lexemas[i].charAt(0)); if ( lexemas[i].charAt(0)=='#') diff --git a/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/SyntacticAnalyzer.java b/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/SyntacticAnalyzer.java index be30cbe..814b7b8 100644 --- a/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/SyntacticAnalyzer.java +++ b/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/SyntacticAnalyzer.java @@ -25,6 +25,7 @@ public class SyntacticAnalyzer { private Token token; private Iterator iterator; private AST raiz = new AST(); + private AST expG = new AST(); private ArrayList figuras; //pasar al semantico public SyntacticAnalyzer() { @@ -56,14 +57,14 @@ public AST analyze(List tokens) throws SyntacticException { } - for (Iterator iterator = sentencias.iterator(); iterator.hasNext();) { - String sent = iterator.next(); - System.out.println("Setencia: " + sent); + // for (Iterator iterator = sentencias.iterator(); iterator.hasNext();) { + // String sent = iterator.next(); + //System.out.println("Setencia: " + sent); - } + //} checkSent(tokens); - System.out.println("\n Valida Arbol"); + validarArbol(raiz); return raiz; @@ -71,11 +72,39 @@ public AST analyze(List tokens) throws SyntacticException { private void validarArbol(AST raiz2) { // TODO Auto-generated method stub + + + System.out.println("--- Árboles ----- "); System.out.println("\n"); - System.out.println("--- Comienza Analisis semantico ----- "); - System.out.println("\n"); + for (Iterator it = raiz2.listChildren().iterator(); it.hasNext();) { + AST arbol = it.next(); + + String lexema = arbol.getToken().getClase(); + + System.out.println(" " + lexema); + + String s = new String(); + + for(int a = 0 ; a < arbol.listChildren().size(); a++ ){ + + String tipo = arbol.getChild(a).getToken().getLexema(); + + + s = s + tipo + " " ; + + } + System.out.println(s); + System.out.println("\n"); + + } + + System.out.println("--- Fin Árboles ----- "); + System.out.println("\n"); + System.out.println("\n"); + System.out.println("--- Comienza Analisis semantico ----- "); + System.out.println("\n"); for (Iterator it = raiz2.listChildren().iterator(); it.hasNext();) { @@ -89,8 +118,6 @@ private void validarArbol(AST raiz2) { if (lexema.equals("crear")) { - System.out.println("Entra por create"); - Figura figuraNueva = new Figura(); if(figuras.isEmpty()){ @@ -98,7 +125,7 @@ private void validarArbol(AST raiz2) { figuraNueva.setId(id); figuras.add(figuraNueva); - System.out.println("Se creo una figura"); + } else @@ -110,14 +137,14 @@ private void validarArbol(AST raiz2) { if(iterator.next().getId().equals(id)){ - System.out.println("Ya existe ese ID para otra figura"); + System.out.printf("Ya existe el ID \"%s\" para otra figura", id); System.exit(0); } figuraNueva.setClase(tipo); figuraNueva.setId(id); - System.out.println("Se creo una figura"); + System.out.println("Se creo una figura."); } figuras.add(figuraNueva); @@ -133,7 +160,7 @@ private void validarArbol(AST raiz2) { Figura fig = iterator.next(); System.out.println("\n"); - System.out.printf(" Figura: %s Clase %s", fig.getId() , fig.getClase()); + System.out.printf(" Figura creada: %s Clase %s", fig.getId() , fig.getClase()); } @@ -152,11 +179,10 @@ public void checkSent(List tokens){ //Cambiar clase - System.out.println("\n"); - System.out.println("---- Comienza el análisis de una sentencia -----\n"); - System.out.println("\n"); + linea++; + System.out.println("\n"); if (lookahead == "crear"){ checkCreate(lookahead); @@ -188,43 +214,10 @@ public void checkSent(List tokens){ } -// setposition [expression],[expression] in shape [id] ; - -/*private void checkPosition(String string) { - System.out.println("setposition [expression],[expression] in shape [id] ;"); - matchSetPosition(string); - checkExpresion(lookahead); - matchComa(lookahead); - checkExpresion(lookahead); - matchIn(lookahead); - matchShape(lookahead); - matchId(lookahead); - matchFin(lookahead); - - - - -}*/ - - -// setradius [expression] in circle [id] ; - -/*private boolean matchComa(String string) { - if(string == "separador de expresiones"){ - System.out.println("Es Coma"); - token = (Token) iterator.next(); - lookahead = token.getClase(); - return true; - } - System.out.println("No es Coma. Error"); - System.out.close(); - return false; - -}*/ private void checkPosition(String string) { -System.out.println("setposition [expression],[expression] in shape [id] ;"); + AST setposition = new AST(); setposition.setLinea(linea); setposition.setToken(token); @@ -263,33 +256,20 @@ private void checkPosition(String string) { raiz.addChild(setposition); - String a = raiz.getChild(0).getToken().getLexema(); - String b = raiz.getChild(0).getChild(0).getToken().getLexema(); - String c = raiz.getChild(0).getChild(1).getToken().getLexema(); - String d = raiz.getChild(0).getChild(2).getToken().getLexema(); - - - System.out.printf("Muestro arbol de set posición: "); - - System.out.printf(" - 1: %s", a); - System.out.printf(" - 2: %s", b); - System.out.printf(" - 3: %s", c); - System.out.printf(" - 4: %s", d); } private boolean matchComa(String coma) { - // TODO Auto-generated method stub - + if(coma == "coma"){ - System.out.println("Es coma"); + //System.out.println("Es coma"); token = (Token) iterator.next(); lookahead = token.getClase(); return true; } System.out.printf("Vino %s, se esperaba coma.", coma); - System.out.close(); + System.exit(0); return false; } @@ -302,14 +282,14 @@ private boolean matchSetPosition(String string) { return true; } System.out.printf("Vino %s, se esperaba setPosition.", string); - System.out.close(); + System.exit(0); return false; } private void checkRadio(String string) { -System.out.println("setradius [expression] in circle [id] ;"); +System.out.println("Se espera: setradius [expression] in circle [id] ;"); AST setradio = new AST(); setradio.setLinea(linea); setradio.setToken(token); @@ -317,6 +297,7 @@ private void checkRadio(String string) { matchSetRadio(string); AST radio_def = new AST(); + radio_def.setLinea(linea); radio_def.setToken(token); @@ -337,29 +318,10 @@ private void checkRadio(String string) { matchFin(lookahead); raiz.addChild(setradio); - String a = raiz.getChild(0).getToken().getLexema(); - String b = raiz.getChild(0).getChild(0).getToken().getLexema(); - String c = raiz.getChild(0).getChild(1).getToken().getLexema(); - - System.out.printf("Muestro arbol de set radio: "); - - System.out.printf(" - 1: %s", a); - System.out.printf(" - 2: %s", b); - System.out.printf(" - 3: %s", c); } -/*private void checkRadio(String string) { - System.out.println("setradius [expression] in circle [id] ;"); - matchSetRadio(string); - checkExpresion(lookahead); - matchIn(lookahead); - matchCircle(lookahead); - matchId(lookahead); - matchFin(lookahead); - -}*/ private boolean matchSetRadio(String string) { if(string == "setear radio"){ @@ -369,7 +331,7 @@ private boolean matchSetRadio(String string) { return true; } System.out.printf("Vino %s, se esperaba setRadio.", string); - System.out.close(); + System.exit(0); return false; } @@ -378,7 +340,7 @@ private boolean matchSetRadio(String string) { private void checkSetColor(String string) { - System.out.println("setcolor [color_def] in shape [id] ;"); + System.out.println("Se espera: setcolor [color_def] in shape [id] ;"); AST setcolor = new AST(); setcolor.setLinea(linea); @@ -407,15 +369,7 @@ private void checkSetColor(String string) { matchFin(lookahead); raiz.addChild(setcolor); - String a = raiz.getChild(1).getToken().getLexema(); - String b = raiz.getChild(1).getChild(0).getToken().getLexema(); - String c = raiz.getChild(1).getChild(1).getToken().getLexema(); - - System.out.printf("Muestro arbol de set color: "); - - System.out.printf("- 1: %s", a); - System.out.printf("- 2: %s", b); - System.out.printf("- 3: %s", c); + } @@ -428,7 +382,7 @@ private boolean matchShape(String string) { return true; } System.out.printf("Vino %s, se esperaba 'shape'", string); - System.out.close(); + System.exit(0); return false; @@ -442,7 +396,7 @@ private boolean matchIn(String string) { return true; } System.out.printf("Vino %s, se esperaba 'in'", string); - System.out.close(); + System.exit(0); return false; @@ -453,7 +407,7 @@ private boolean matchIn(String string) { private void checkSetHeight(String string) { - System.out.println("setheight [expression] in rectangle [id] ;"); + System.out.println("Se espera: setheight [expression] in rectangle [id] ;"); AST setheight = new AST(); setheight.setLinea(linea); @@ -482,31 +436,11 @@ private void checkSetHeight(String string) { matchFin(lookahead); raiz.addChild(setheight); - String a = raiz.getChild(0).getToken().getLexema(); - String b = raiz.getChild(0).getChild(0).getToken().getLexema(); - String c = raiz.getChild(0).getChild(1).getToken().getLexema(); - - System.out.printf("Muestro arbol de set height: "); - - System.out.printf("- 1: %s", a); - System.out.printf("- 2: %s", b); - System.out.printf("- 3: %s", c); + } - - /*private void checkSetHeight(String string) { - System.out.println("setheight [expression] in rectangle [id] ;"); - - matchSetHeight(string); - checkExpresion(lookahead); - matchIn(lookahead); - matchRectangle(lookahead); - matchId(lookahead); - matchFin(lookahead); - }*/ - private boolean matchSetHeight(String string) { @@ -517,7 +451,7 @@ private boolean matchSetHeight(String string) { return true; } System.out.printf("Vino %s, se esperaba setHeight.", string); - System.out.close(); + System.exit(0); return false; } @@ -526,57 +460,27 @@ private boolean matchSetHeight(String string) { private void checkSetBase(String string) { - System.out.println("setbase [expression] in rectangle [id] ;"); - AST setbase = new AST(); - setbase.setLinea(linea); - setbase.setToken(token); + System.out.println("Se espera: setbase [expression] in rectangle [id] ;"); matchSetBase(string); - AST base_def = new AST(); - base_def.setLinea(linea); - base_def.setToken(token); - - setbase.addChild(base_def); checkExpresion(lookahead); + + matchIn(lookahead); matchRectangle(lookahead); + - AST id = new AST(); - id.setLinea(linea); - id.setToken(token); - - setbase.addChild(id); + matchId(lookahead); matchFin(lookahead); - raiz.addChild(setbase); - String a = raiz.getChild(0).getToken().getLexema(); - String b = raiz.getChild(0).getChild(0).getToken().getLexema(); - String c = raiz.getChild(0).getChild(1).getToken().getLexema(); - - System.out.printf("Muestro arbol de set base: "); - - System.out.printf(" - 1: %s", a); - System.out.printf(" - 2: %s", b); - System.out.printf(" - 3: %s", c); } - /*private void checkSetBase(String string) { - - System.out.println("setbase [expression] in rectangle [id] ;"); - matchSetBase(string); - checkExpresion(lookahead); - matchIn(lookahead); - matchRectangle(lookahead); - matchId(lookahead); - matchFin(lookahead); - - }*/ private boolean matchSetBase(String string) { if(string == "setear base"){ @@ -586,62 +490,61 @@ private boolean matchSetBase(String string) { return true; } System.out.printf("Vino %s, se esperaba setBase.", string); - System.out.close(); + System.exit(0); return false; } private void checkExpresion(String string) { - System.out.println("CHECK EXPRESION"); - + //System.out.println("CHECK EXPRESION"); + checkTermino(string); checkTerminoR(lookahead); - } private void checkTerminoR(String string) { - System.out.println("CHECK TERMINO R"); - if (!matchLamda(string)){ - - if(!matchAdicion(string)){ - checkFactor(string); - } - else{ - checkTerminoR(lookahead);} - } else { - matchLamda(string); - } - -} - -private boolean matchLamda(String string) { - if(string == "in" || string == "coma" ){ - System.out.println("Termino expresion."); +// System.out.println("CHECK TERMINO R"); + if(!matchAdicion(string)){ - return true; - } else { - if(matchCierroP(string)){ - return true; - }else{ - System.out.printf("Vino %s, se esperaba termino expresion \n ", string); - return false; + checkFactor(string); + } - } + else{ + + checkTermino(lookahead); + + + checkTerminoR(lookahead); + + } + + } private void checkFactor(String string) { - System.out.println("CHECK FACTOR"); + + + + //System.out.println("CHECK FACTOR"); if (string == "Numero"){ - matchNumero(string);} + + + + matchNumero(string); + + } else{ if(matchAbroP(string)){ + + + checkExpresion(lookahead); - // matchCierroP(lookahead); - }else{ - matchCierroP(string); + + matchCierroP(lookahead); + } } @@ -655,19 +558,32 @@ private boolean matchNumero(String string) { lookahead = token.getClase(); return true; } else { - System.out.printf("Vino %s, se esperaba un numero valido \n ", string); - System.out.close(); + return false; } } private boolean matchAdicion(String string) { + if(string == "Adicion"){ System.out.println("Es Adicion."); token = (Token) iterator.next(); lookahead = token.getClase(); return true; + + } + return false; + +} + +private boolean matchProducto(String string) { + if(string == "Producto"){ + + System.out.println("Es Producto."); + token = (Token) iterator.next(); + lookahead = token.getClase(); + return true; } else { return false; } @@ -677,37 +593,55 @@ private boolean matchAdicion(String string) { private void checkTermino(String string) { - System.out.println("CHECK TERMINO"); + //System.out.println("CHECK TERMINO"); checkFactor(string); checkFactorR(lookahead); } private void checkFactorR(String string) { - System.out.println("CHECK FACTOR R"); - - if (!matchLamda(string)){ + //System.out.println("CHECK FACTOR R"); + if(matchAbroP(string)){ + + + checkExpresion(lookahead); -// matchCierroP(lookahead); - } + matchCierroP(lookahead); + + } + else { + + if(matchProducto(string)) + { + + + checkFactor(lookahead); + checkFactorR(lookahead); + } + else { + matchNumero(string); + + + } + + + + } - - } private boolean matchCierroP(String string) { if(string == "Parentesis C"){ - System.out.println("Es cierre parentesis"); token = (Token) iterator.next(); lookahead = token.getClase(); return true; } System.out.printf("Vino %s, se esperaba ')'. \n", string); - + System.exit(0); return false; } @@ -715,12 +649,10 @@ private boolean matchCierroP(String string) { private boolean matchAbroP(String string) { if(string == "Parentesis A"){ - System.out.println("Es abro parentesis"); token = (Token) iterator.next(); lookahead = token.getClase(); return true; } - System.out.printf("Vino %s, se esperaba '('. \n", string); return false; @@ -738,7 +670,9 @@ private void matchFin(String string) { } else { System.out.println("[;] Fin de sentencia"); + System.out.println("\n"); System.out.println("Terminaron las sentencias a analizar"); + System.out.println("\n"); } } @@ -753,7 +687,7 @@ private boolean matchSetColor(String string) { return true; } System.out.printf("Vino %s, se esperaba setcolor \n", string); - System.out.close(); + System.exit(0); return false; } @@ -766,7 +700,7 @@ private boolean matchColorDef(String string) { return true; } System.out.printf("Vino %s, se esperaba un color del tipo #AAA111 \n", string); - System.out.close(); + System.exit(0); return false; @@ -797,15 +731,7 @@ private void checkCreate(String string) { matchFin(lookahead); raiz.addChild(create); - String a = raiz.getChild(0).getToken().getLexema(); - String b = raiz.getChild(0).getChild(0).getToken().getLexema(); - String c = raiz.getChild(0).getChild(1).getToken().getLexema(); - - System.out.printf("Muestro arbol de crear: "); - System.out.printf("- 1: %s", a); - System.out.printf("- 2: %s", b); - System.out.printf("- 3: %s", c); } @@ -821,7 +747,7 @@ private boolean matchId(String string) { return true; } else { System.out.printf("Vino %s, se esperaba un ID valido \n ", string); - System.out.close(); + System.exit(0); return false; } @@ -843,7 +769,7 @@ private AST checkShape(String string) { } else { System.out.printf("Vino %s, se esperaba una figura \n ", string); - System.out.close(); + System.exit(0); } @@ -859,7 +785,7 @@ private boolean matchRectangle(String string) { return true; } else { System.out.printf("Vino %s, se esperaba un rectangulo \n ", string); - System.out.close(); + System.exit(0); return false; } @@ -886,7 +812,7 @@ private boolean matchCreate(String string) { return true; } System.out.printf("Vino %s, se esperaba 'create' \n ", string); - System.out.close(); + System.exit(0); return false; } From 52160c3ee482f4251ace891dfb09f2555936628c Mon Sep 17 00:00:00 2001 From: cmfernandez Date: Tue, 1 Dec 2015 07:54:30 -0300 Subject: [PATCH 18/26] Armando arbol Faltaria imprimirlo, principalmente chequear las exp aritmeticas. --- .../analysis/SyntacticAnalyzer.java | 176 +++++++++++++----- 1 file changed, 127 insertions(+), 49 deletions(-) diff --git a/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/SyntacticAnalyzer.java b/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/SyntacticAnalyzer.java index 814b7b8..e4c7c69 100644 --- a/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/SyntacticAnalyzer.java +++ b/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/SyntacticAnalyzer.java @@ -17,6 +17,8 @@ * @author Matias Giorgio * */ + + public class SyntacticAnalyzer { private int linea=0; @@ -27,7 +29,7 @@ public class SyntacticAnalyzer { private AST raiz = new AST(); private AST expG = new AST(); private ArrayList figuras; //pasar al semantico - + public SyntacticAnalyzer() { } @@ -462,22 +464,30 @@ private void checkSetBase(String string) { System.out.println("Se espera: setbase [expression] in rectangle [id] ;"); - matchSetBase(string); - - - checkExpresion(lookahead); - + AST setbase = new AST(); + setbase.setLinea(linea); + setbase.setToken(token); + + matchSetBase(string); + + setbase.addChild(checkExpresion(lookahead)); - - matchIn(lookahead); - matchRectangle(lookahead); + matchIn(lookahead); + + matchRectangle(lookahead); - + AST id = new AST(); + id.setLinea(linea); + id.setToken(token); + + + setbase.addChild(id); + + matchId(lookahead); + matchFin(lookahead); - matchId(lookahead); - matchFin(lookahead); - + raiz.addChild(setbase); } @@ -495,59 +505,114 @@ private boolean matchSetBase(String string) { } - private void checkExpresion(String string) { + private AST checkExpresion(String string) { //System.out.println("CHECK EXPRESION"); - checkTermino(string); - checkTerminoR(lookahead); + AST tnode = checkTermino(string); + AST trnode = checkTerminoR(lookahead); - + return createNodo(tnode,trnode); } -private void checkTerminoR(String string) { +private AST createNodo(AST tnode, AST trnode) { + + AST op = new AST(); + + AST nodeI = tnode; -// System.out.println("CHECK TERMINO R"); - if(!matchAdicion(string)){ + //System.out.println(tnode.getToken().getLexema() + " " + trnode.getToken().getLexema()); + if (trnode != null){ + if (trnode.getToken().getClase()=="Adicion"){ - checkFactor(string); - } - else{ + op.setToken(trnode.getToken()); + op.setLinea(trnode.getLinea()); + + + System.out.println(tnode.getChild(0).getToken().getLexema()); + AST nodeD = trnode.getChild(0); + + op.addChild(nodeI); + op.addChild(nodeD); + + return op; + + } + + if (trnode.getToken().getClase()=="Producto"){ + + + op.setToken(trnode.getToken()); + op.setLinea(trnode.getLinea()); + AST nodeD = trnode.getChild(0); + + op.addChild(nodeI); + op.addChild(nodeD); + + return op; + + } + } + return nodeI; + } + +private AST checkTerminoR(String string) { + + AST fnode = new AST(); + + + System.out.println("CHECK TERMINO R"); + if(matchAdicion(string)){ - checkTermino(lookahead); + AST tnode = checkTermino(lookahead); + AST trnode = checkTerminoR(lookahead); + return createNodo(tnode, trnode); + } + else{ + + if (string=="Numero" || string == "Parentesis A") { + fnode = checkFactor(string); + return fnode; + }else { + return null; + } - checkTerminoR(lookahead); - } + + } + + } -private void checkFactor(String string) { - - - - //System.out.println("CHECK FACTOR"); +private AST checkFactor(String string) { + + AST fnode = new AST(); + System.out.println("CHECK FACTOR"); if (string == "Numero"){ - + fnode.setLinea(linea); + fnode.setToken(token); + matchNumero(string); } else{ if(matchAbroP(string)){ - - - - checkExpresion(lookahead); + + fnode = checkExpresion(lookahead); matchCierroP(lookahead); } + + } + return fnode; } @@ -558,7 +623,7 @@ private boolean matchNumero(String string) { lookahead = token.getClase(); return true; } else { - + return false; } @@ -582,7 +647,7 @@ private boolean matchProducto(String string) { System.out.println("Es Producto."); token = (Token) iterator.next(); - lookahead = token.getClase(); + lookahead = token.getClase(); return true; } else { return false; @@ -590,24 +655,32 @@ private boolean matchProducto(String string) { } +//EXP +//TERM = 4*4 +//TERMR+4 -private void checkTermino(String string) { - //System.out.println("CHECK TERMINO"); - checkFactor(string); - checkFactorR(lookahead); +private AST checkTermino(String string) { + System.out.println("CHECK TERMINO"); + AST fnode = checkFactor(string); //4 + AST frnode = checkFactorR(lookahead); //*4 + + + return createNodo(fnode, frnode); } -private void checkFactorR(String string) { - //System.out.println("CHECK FACTOR R"); +private AST checkFactorR(String string) { + System.out.println("CHECK FACTOR R"); + AST frnode = new AST(); + frnode = null; if(matchAbroP(string)){ - checkExpresion(lookahead); + frnode = checkExpresion(lookahead); matchCierroP(lookahead); @@ -619,12 +692,15 @@ private void checkFactorR(String string) { { - checkFactor(lookahead); - checkFactorR(lookahead); + AST fnode = checkFactor(lookahead); + frnode = checkFactorR(lookahead); + return createNodo(fnode, frnode); } else { - matchNumero(string); - + if(matchNumero(string)){ + frnode.setLinea(linea); + frnode.setToken(token); + } } @@ -632,6 +708,8 @@ private void checkFactorR(String string) { } + return frnode; + } private boolean matchCierroP(String string) { From 8d21debe345288bb126add847db0f82d61dac196 Mon Sep 17 00:00:00 2001 From: cmfernandez Date: Tue, 1 Dec 2015 13:43:05 -0300 Subject: [PATCH 19/26] Imprimir Arbol --- .../analysis/SyntacticAnalyzer.java | 96 ++++++++++++++----- 1 file changed, 72 insertions(+), 24 deletions(-) diff --git a/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/SyntacticAnalyzer.java b/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/SyntacticAnalyzer.java index e4c7c69..f5f838c 100644 --- a/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/SyntacticAnalyzer.java +++ b/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/SyntacticAnalyzer.java @@ -72,38 +72,86 @@ public AST analyze(List tokens) throws SyntacticException { return raiz; } -private void validarArbol(AST raiz2) { - // TODO Auto-generated method stub + public void validarArbol(AST raiz2){ + + + + System.out.println("--- Árboles ----- "); + + System.out.println("\n"); + + + + for (Iterator it = raiz2.listChildren().iterator(); it.hasNext();) { - - System.out.println("--- Árboles ----- "); - System.out.println("\n"); - - for (Iterator it = raiz2.listChildren().iterator(); it.hasNext();) { - AST arbol = it.next(); - - String lexema = arbol.getToken().getClase(); - - System.out.println(" " + lexema); - - String s = new String(); - for(int a = 0 ; a < arbol.listChildren().size(); a++ ){ + + AST arbol = it.next(); + + + + String lexema = arbol.getToken().getClase(); + + + + System.out.println(" " + lexema); + + + + String s = new String(); + - String tipo = arbol.getChild(a).getToken().getLexema(); + + if (arbol.listChildren().size() != 0 ){ - s = s + tipo + " " ; + + + + for(int a = 0 ; a < arbol.listChildren().size(); a++ ){ + - } - System.out.println(s); - System.out.println("\n"); - + + if (arbol.getChild(a).listChildren().size() != 0 ){ + + + + validarArbol(arbol); + + + + } else { + + + + String tipo = arbol.getChild(a).getToken().getLexema(); + + + + s = s + tipo + " " ; + + + + + + System.out.println(s); + + System.out.println("\n"); + + } + + + + } + + } + + System.out.println("--- Fin Árboles ----- "); + + System.out.println("\n"); + } - System.out.println("--- Fin Árboles ----- "); - System.out.println("\n"); - System.out.println("\n"); System.out.println("--- Comienza Analisis semantico ----- "); System.out.println("\n"); From 64f4533be69f401c541bc2d2e9bbc548c702b415 Mon Sep 17 00:00:00 2001 From: gianellak Date: Tue, 1 Dec 2015 14:53:21 -0300 Subject: [PATCH 20/26] Update SyntacticAnalyzer.java Prints + Correccion If --- .../analysis/SyntacticAnalyzer.java | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/SyntacticAnalyzer.java b/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/SyntacticAnalyzer.java index f5f838c..bf2dc97 100644 --- a/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/SyntacticAnalyzer.java +++ b/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/SyntacticAnalyzer.java @@ -76,17 +76,20 @@ public void validarArbol(AST raiz2){ - System.out.println("--- Árboles ----- "); + System.out.println("--- Ãrboles ----- "); System.out.println("\n"); +// SETBASE +// + RECTANGLE +//4 4 - for (Iterator it = raiz2.listChildren().iterator(); it.hasNext();) { + for (Iterator it = raiz2.listChildren().iterator(); it.hasNext();) { //SETBASE.LIST = 2 - +List = 2 - 4 - AST arbol = it.next(); + AST arbol = it.next(); //SETBASE - "+" - 4 @@ -94,7 +97,8 @@ public void validarArbol(AST raiz2){ - System.out.println(" " + lexema); + System.out.println(" " + lexema); // PRINT: SETBASE - Adicion - Numero + System.out.println("Hijos: " + raiz2.listChildren().size());// Print: 2 - 2 - 0 @@ -102,7 +106,7 @@ public void validarArbol(AST raiz2){ - if (arbol.listChildren().size() != 0 ){ + if (arbol.listChildren().size() != 0 ){ // SI = 2 - SI = 2 - NO @@ -112,7 +116,7 @@ public void validarArbol(AST raiz2){ - if (arbol.getChild(a).listChildren().size() != 0 ){ + if (arbol.getChild(a).listChildren().size() != 0 ){ //SI = 2 - SI = 2 @@ -120,7 +124,9 @@ public void validarArbol(AST raiz2){ - } else { + } + + } else { @@ -142,11 +148,11 @@ public void validarArbol(AST raiz2){ - } + } - System.out.println("--- Fin Árboles ----- "); + System.out.println("--- Fin Ãrboles ----- "); System.out.println("\n"); @@ -942,4 +948,4 @@ private boolean matchCreate(String string) { return false; } -} \ No newline at end of file +} From fe05807fca06df31d368eee60679b14a16998a14 Mon Sep 17 00:00:00 2001 From: gianellak Date: Wed, 2 Dec 2015 10:21:42 -0300 Subject: [PATCH 21/26] Update SyntacticAnalyzer.java Modificacion en la muestra del arbol --- .../analysis/SyntacticAnalyzer.java | 65 ++++++++----------- 1 file changed, 26 insertions(+), 39 deletions(-) diff --git a/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/SyntacticAnalyzer.java b/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/SyntacticAnalyzer.java index bf2dc97..0b574a2 100644 --- a/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/SyntacticAnalyzer.java +++ b/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/SyntacticAnalyzer.java @@ -97,8 +97,8 @@ public void validarArbol(AST raiz2){ - System.out.println(" " + lexema); // PRINT: SETBASE - Adicion - Numero - System.out.println("Hijos: " + raiz2.listChildren().size());// Print: 2 - 2 - 0 + System.out.println(" " + lexema); + System.out.println("Hijos: " + arbol.listChildren().size()); @@ -106,51 +106,38 @@ public void validarArbol(AST raiz2){ - if (arbol.listChildren().size() != 0 ){ // SI = 2 - SI = 2 - NO - - - - - - for(int a = 0 ; a < arbol.listChildren().size(); a++ ){ - - - - if (arbol.getChild(a).listChildren().size() != 0 ){ //SI = 2 - SI = 2 - - - - validarArbol(arbol); - + if (arbol.listChildren().size() != 0 ){ + for(int a = 0 ; a < arbol.listChildren().size(); a++ ) + { - - } - } else { - - - - String tipo = arbol.getChild(a).getToken().getLexema(); + String tipo = arbol.getChild(a).getToken().getLexema(); - - - s = s + tipo + " " ; - - - - + s = s + tipo + " " ; + } + System.out.println(s); System.out.println("\n"); - - } - - - - - } + + for(int a = 0 ; a < arbol.listChildren().size(); a++ ) + { + + if (arbol.getChild(a).listChildren().size() != 0 ){ + validarArbol(arbol); + } + else{ + String tipo = arbol.getChild(a).getToken().getLexema(); + System.out.println(tipo + " "); + System.out.println("\n"); + } + + } + + } + } System.out.println("--- Fin Ãrboles ----- "); From c2713e9d8fc2a0dbcdbf0c03ca0378672f3ff801 Mon Sep 17 00:00:00 2001 From: cmfernandez Date: Wed, 2 Dec 2015 11:49:41 -0300 Subject: [PATCH 22/26] UP --- .../analysis/SyntacticAnalyzer.java | 89 +++++++++---------- 1 file changed, 41 insertions(+), 48 deletions(-) diff --git a/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/SyntacticAnalyzer.java b/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/SyntacticAnalyzer.java index f5f838c..95880f8 100644 --- a/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/SyntacticAnalyzer.java +++ b/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/SyntacticAnalyzer.java @@ -76,17 +76,20 @@ public void validarArbol(AST raiz2){ - System.out.println("--- Árboles ----- "); + System.out.println("--- Arboles ----- "); System.out.println("\n"); +// SETBASE +// + RECTANGLE +//4 4 - for (Iterator it = raiz2.listChildren().iterator(); it.hasNext();) { + for (Iterator it = raiz2.listChildren().iterator(); it.hasNext();) { //SETBASE.LIST = 2 - +List = 2 - 4 - AST arbol = it.next(); + AST arbol = it.next(); //SETBASE - "+" - 4 @@ -95,6 +98,7 @@ public void validarArbol(AST raiz2){ System.out.println(" " + lexema); + System.out.println("Hijos: " + arbol.listChildren().size()); @@ -102,59 +106,48 @@ public void validarArbol(AST raiz2){ - if (arbol.listChildren().size() != 0 ){ - - - - - - for(int a = 0 ; a < arbol.listChildren().size(); a++ ){ - - - - if (arbol.getChild(a).listChildren().size() != 0 ){ - + if (arbol.listChildren().size() != 0 ){ + for(int a = 0 ; a < arbol.listChildren().size(); a++ ) + { - - validarArbol(arbol); - + String tipo = arbol.getChild(a).getToken().getLexema(); - } else { - - - - String tipo = arbol.getChild(a).getToken().getLexema(); - - - - s = s + tipo + " " ; - - - - + s = s + tipo + " " ; + } + System.out.println(s); System.out.println("\n"); + + + for(int a = 0 ; a < arbol.listChildren().size(); a++ ) + { + + if (arbol.getChild(a).listChildren().size() != 0 ){ + validarArbol(arbol); + } + else{ + String tipo = arbol.getChild(a).getToken().getLexema(); + System.out.println(tipo + " "); + System.out.println("\n"); + } + + } + + } + } - } - - - - } - - } - - System.out.println("--- Fin Árboles ----- "); + System.out.println("--- Fin Arboles ----- "); System.out.println("\n"); - } - System.out.println("\n"); - System.out.println("--- Comienza Analisis semantico ----- "); - System.out.println("\n"); + + System.out.println ("\n"); + System.out.println ("--- Comienza Analisis semantico ----- "); + System.out.println ("\n"); for (Iterator it = raiz2.listChildren().iterator(); it.hasNext();) { @@ -206,16 +199,16 @@ public void validarArbol(AST raiz2){ } - for (Iterator iterator = figuras.iterator(); iterator.hasNext();) { - Figura fig = iterator.next(); + for (Iterator iterator1 = figuras.iterator(); iterator.hasNext();) { + Figura fig = iterator1.next(); System.out.println("\n"); System.out.printf(" Figura creada: %s Clase %s", fig.getId() , fig.getClase()); } - } + public void checkSent(List tokens){ @@ -942,4 +935,4 @@ private boolean matchCreate(String string) { return false; } -} \ No newline at end of file +} From 1ba0b4a178e51e3eb8d7c812f2b5c97e3966d456 Mon Sep 17 00:00:00 2001 From: gianellak Date: Wed, 2 Dec 2015 12:02:40 -0300 Subject: [PATCH 23/26] Update SyntacticAnalyzer.java Agrego validacion al ciclo de print. --- .../analysis/SyntacticAnalyzer.java | 26 +++++++------------ 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/SyntacticAnalyzer.java b/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/SyntacticAnalyzer.java index 35bc210..0fe97ed 100644 --- a/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/SyntacticAnalyzer.java +++ b/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/SyntacticAnalyzer.java @@ -76,11 +76,8 @@ public void validarArbol(AST raiz2){ -<<<<<<< HEAD - System.out.println("--- Arboles ----- "); -======= - System.out.println("--- Ãrboles ----- "); ->>>>>>> origin/master + System.out.println("--- Arboles ----- "); + System.out.println("\n"); @@ -89,11 +86,11 @@ public void validarArbol(AST raiz2){ //4 4 - for (Iterator it = raiz2.listChildren().iterator(); it.hasNext();) { //SETBASE.LIST = 2 - +List = 2 - 4 + for (Iterator it = raiz2.listChildren().iterator(); it.hasNext();) { - AST arbol = it.next(); //SETBASE - "+" - 4 + AST arbol = it.next(); @@ -130,24 +127,21 @@ public void validarArbol(AST raiz2){ { if (arbol.getChild(a).listChildren().size() != 0 ){ + System.out.println("Valido arbol de raiz: " + a), validarArbol(arbol); } - else{ - String tipo = arbol.getChild(a).getToken().getLexema(); - System.out.println(tipo + " "); - System.out.println("\n"); - } + // else{ + // String tipo = arbol.getChild(a).getToken().getLexema(); + // System.out.println(tipo + " "); + // System.out.println("\n"); + // } } } } -<<<<<<< HEAD - System.out.println("--- Fin Arboles ----- "); -======= System.out.println("--- Fin Ãrboles ----- "); ->>>>>>> origin/master System.out.println("\n"); From aea6341193b247a1b4259083df34809f2a88ff0a Mon Sep 17 00:00:00 2001 From: Gianella Kravchik Date: Thu, 3 Dec 2015 20:26:34 -0300 Subject: [PATCH 24/26] Arreglos Varios en Expresion + Prints --- .settings/org.eclipse.core.resources.prefs | 2 + .../analysis/SyntacticAnalyzer.java | 154 +++++++++++------- 2 files changed, 99 insertions(+), 57 deletions(-) create mode 100644 .settings/org.eclipse.core.resources.prefs diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..1c4f5c4 --- /dev/null +++ b/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding//src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/SyntacticAnalyzer.java=UTF-8 diff --git a/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/SyntacticAnalyzer.java b/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/SyntacticAnalyzer.java index 0fe97ed..a15f68e 100644 --- a/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/SyntacticAnalyzer.java +++ b/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/SyntacticAnalyzer.java @@ -99,16 +99,13 @@ public void validarArbol(AST raiz2){ System.out.println(" " + lexema); - System.out.println("Hijos: " + arbol.listChildren().size()); - - - - String s = new String(); - + + String s = " "; - if (arbol.listChildren().size() != 0 ){ + for(int a = 0 ; a < arbol.listChildren().size(); a++ ) + { @@ -120,38 +117,25 @@ public void validarArbol(AST raiz2){ System.out.println(s); - System.out.println("\n"); - - for(int a = 0 ; a < arbol.listChildren().size(); a++ ) + { - - if (arbol.getChild(a).listChildren().size() != 0 ){ - System.out.println("Valido arbol de raiz: " + a), - validarArbol(arbol); - } - // else{ - // String tipo = arbol.getChild(a).getToken().getLexema(); - // System.out.println(tipo + " "); - // System.out.println("\n"); - // } - - } - - } - } + validohijo(arbol.getChild(a)); + } + } - System.out.println("--- Fin Ãrboles ----- "); + System.out.println("--- Fin �rboles ----- "); System.out.println("\n"); - + } + } - System.out.println ("\n"); - System.out.println ("--- Comienza Analisis semantico ----- "); - System.out.println ("\n"); + //System.out.println ("\n"); + //System.out.println ("--- Comienza Analisis semantico ----- "); + //System.out.println ("\n"); - for (Iterator it = raiz2.listChildren().iterator(); it.hasNext();) { + /**for (Iterator it = raiz2.listChildren().iterator(); it.hasNext();) { AST arbol = it.next(); @@ -199,19 +183,64 @@ public void validarArbol(AST raiz2){ - } + }**/ - for (Iterator iterator1 = figuras.iterator(); iterator.hasNext();) { +/** for (Iterator iterator1 = figuras.iterator(); iterator.hasNext();) { Figura fig = iterator1.next(); System.out.println("\n"); System.out.printf(" Figura creada: %s Clase %s", fig.getId() , fig.getClase()); - } + }**/ + - } + private void validohijo(AST arbol) { + + + + + + //System.out.println("\n"); + String s = new String(); + + for(int a = 0 ; a < arbol.listChildren().size(); a++ ) + + { + + System.out.println("Valido " + arbol.getToken().getLexema() + " " + arbol.getChild(a).listChildren().size()); + + if (arbol.getChild(a).listChildren().size() != 0 ){ + //System.out.println("Valido arbol de raiz: " + a); + String tipo = arbol.getChild(a).getToken().getLexema(); + + s = s + tipo + " " ; + + System.out.println("Valido" + arbol.getChild(a).getToken().getLexema()); + + validohijo(arbol.getChild(a)); + } + else{ + String tipo = arbol.getChild(a).getToken().getLexema(); + + s = s + tipo + " " ; + + + } + + } + + if (s != null){ + System.out.println(s); + } + + + + + + } + public void checkSent(List tokens){ figuras = new ArrayList<>(); @@ -565,36 +594,38 @@ private AST createNodo(AST tnode, AST trnode) { //System.out.println(tnode.getToken().getLexema() + " " + trnode.getToken().getLexema()); if (trnode != null){ - if (trnode.getToken().getClase()=="Adicion"){ + + System.out.println("Es distinto de null: " + trnode.getToken().getClase()); + + if (trnode.getToken().getClase()=="Adicion"){ - op.setToken(trnode.getToken()); - op.setLinea(trnode.getLinea()); + op.setToken(trnode.getToken()); + op.setLinea(trnode.getLinea()); - System.out.println(tnode.getChild(0).getToken().getLexema()); - AST nodeD = trnode.getChild(0); + AST nodeD = trnode; - op.addChild(nodeI); - op.addChild(nodeD); + op.addChild(nodeI); + op.addChild(nodeD); - return op; + return op; - } + } - if (trnode.getToken().getClase()=="Producto"){ + if (trnode.getToken().getClase()=="Producto"){ - op.setToken(trnode.getToken()); - op.setLinea(trnode.getLinea()); - AST nodeD = trnode.getChild(0); - - op.addChild(nodeI); - op.addChild(nodeD); - - return op; - - } + op.setToken(trnode.getToken()); + op.setLinea(trnode.getLinea()); + AST nodeD = trnode.getChild(0); + + op.addChild(nodeI); + op.addChild(nodeD); + + return op; + + } } return nodeI; } @@ -602,19 +633,28 @@ private AST createNodo(AST tnode, AST trnode) { private AST checkTerminoR(String string) { AST fnode = new AST(); - + fnode.setLinea(linea); + fnode.setToken(token); System.out.println("CHECK TERMINO R"); if(matchAdicion(string)){ + AST tnode = checkTermino(lookahead); AST trnode = checkTerminoR(lookahead); - return createNodo(tnode, trnode); + AST opnode = new AST(); + opnode = createNodo(tnode, trnode); + + fnode.addChild(opnode); + + return fnode; + } else{ if (string=="Numero" || string == "Parentesis A") { + fnode = checkFactor(string); return fnode; }else { From c74d90511db2c6da3a5e7d6aa90d8ad16d9afe98 Mon Sep 17 00:00:00 2001 From: Gianella Kravchik Date: Thu, 3 Dec 2015 21:24:54 -0300 Subject: [PATCH 25/26] Print Arbol completo - Pendiente revisar Producto. --- .../analysis/SyntacticAnalyzer.java | 55 ++++++++++++------- 1 file changed, 36 insertions(+), 19 deletions(-) diff --git a/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/SyntacticAnalyzer.java b/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/SyntacticAnalyzer.java index a15f68e..694a7e1 100644 --- a/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/SyntacticAnalyzer.java +++ b/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/SyntacticAnalyzer.java @@ -29,6 +29,7 @@ public class SyntacticAnalyzer { private AST raiz = new AST(); private AST expG = new AST(); private ArrayList figuras; //pasar al semantico + private String s1 = " "; public SyntacticAnalyzer() { } @@ -98,9 +99,9 @@ public void validarArbol(AST raiz2){ - System.out.println(" " + lexema); + System.out.println(" " + lexema); - String s = " "; + String s = " "; if (arbol.listChildren().size() != 0 ){ @@ -115,7 +116,7 @@ public void validarArbol(AST raiz2){ } - System.out.println(s); + System.out.println(s1 + s); for(int a = 0 ; a < arbol.listChildren().size(); a++ ) @@ -124,7 +125,7 @@ public void validarArbol(AST raiz2){ } } - System.out.println("--- Fin �rboles ----- "); + System.out.println("--- Fin arboles ----- "); System.out.println("\n"); } @@ -203,38 +204,46 @@ private void validohijo(AST arbol) { //System.out.println("\n"); - String s = new String(); + s1 = s1 + " "; + String s = " "; for(int a = 0 ; a < arbol.listChildren().size(); a++ ) { - System.out.println("Valido " + arbol.getToken().getLexema() + " " + arbol.getChild(a).listChildren().size()); + //System.out.println("Valido " + arbol.getToken().getLexema() + "Hijos: " + arbol.listChildren().size()); if (arbol.getChild(a).listChildren().size() != 0 ){ //System.out.println("Valido arbol de raiz: " + a); String tipo = arbol.getChild(a).getToken().getLexema(); - s = s + tipo + " " ; - - System.out.println("Valido" + arbol.getChild(a).getToken().getLexema()); + s = s + tipo + " " ; - validohijo(arbol.getChild(a)); + //System.out.println("Valido si es distinto de cero: " + arbol.getChild(a).getToken().getLexema()); + } + + else{ String tipo = arbol.getChild(a).getToken().getLexema(); - s = s + tipo + " " ; + //System.out.println("Valido si es cero: " + arbol.getChild(a).getToken().getLexema()); + + s = s + tipo + " "; } } - if (s != null){ - System.out.println(s); - } + System.out.println(s1 + s); + + for(int a = 0 ; a < arbol.listChildren().size(); a++ ) + + { + validohijo(arbol.getChild(a)); + } @@ -580,8 +589,8 @@ private boolean matchSetBase(String string) { private AST checkExpresion(String string) { //System.out.println("CHECK EXPRESION"); - AST tnode = checkTermino(string); - AST trnode = checkTerminoR(lookahead); + AST tnode = checkTermino(string); // 4 + AST trnode = checkTerminoR(lookahead); // + 4 return createNodo(tnode,trnode); } @@ -607,6 +616,9 @@ private AST createNodo(AST tnode, AST trnode) { AST nodeD = trnode; op.addChild(nodeI); + + nodeD = trnode.getChild(0); + op.addChild(nodeD); return op; @@ -641,9 +653,11 @@ private AST checkTerminoR(String string) { AST tnode = checkTermino(lookahead); + AST trnode = checkTerminoR(lookahead); AST opnode = new AST(); + opnode = createNodo(tnode, trnode); fnode.addChild(opnode); @@ -756,7 +770,7 @@ private AST checkTermino(String string) { private AST checkFactorR(String string) { System.out.println("CHECK FACTOR R"); AST frnode = new AST(); - frnode = null; + if(matchAbroP(string)){ @@ -766,7 +780,7 @@ private AST checkFactorR(String string) { frnode = checkExpresion(lookahead); matchCierroP(lookahead); - + return frnode; } else { @@ -780,9 +794,10 @@ private AST checkFactorR(String string) { return createNodo(fnode, frnode); } else { - if(matchNumero(string)){ frnode.setLinea(linea); frnode.setToken(token); + if(matchNumero(string)){ + return frnode; } } @@ -791,6 +806,8 @@ private AST checkFactorR(String string) { } + frnode = null; + return frnode; } From d56d13c7b43a0a9687cc9bccc7246233dfb42e37 Mon Sep 17 00:00:00 2001 From: Gianella Kravchik Date: Thu, 10 Dec 2015 21:46:54 -0300 Subject: [PATCH 26/26] Fin Analisis Sint. - Falta arreglar print arbol --- .../analysis/SyntacticAnalyzer.java | 56 +++++++++---------- 1 file changed, 25 insertions(+), 31 deletions(-) diff --git a/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/SyntacticAnalyzer.java b/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/SyntacticAnalyzer.java index 694a7e1..dc5b018 100644 --- a/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/SyntacticAnalyzer.java +++ b/src/main/java/edu/maimonides/multimedia/shapes4learn/analysis/SyntacticAnalyzer.java @@ -630,9 +630,15 @@ private AST createNodo(AST tnode, AST trnode) { op.setToken(trnode.getToken()); op.setLinea(trnode.getLinea()); - AST nodeD = trnode.getChild(0); + +// AST nodeD = trnode.getChild(0); + + AST nodeD = trnode; op.addChild(nodeI); + + nodeD = trnode.getChild(0); + op.addChild(nodeD); return op; @@ -768,48 +774,36 @@ private AST checkTermino(String string) { } private AST checkFactorR(String string) { + System.out.println("CHECK FACTOR R"); - AST frnode = new AST(); + AST frnode = new AST(); + frnode.setLinea(linea); + frnode.setToken(token); - if(matchAbroP(string)){ - + if(matchProducto(string)) + { + AST fnode = checkFactor(lookahead); + AST fnode2 = checkFactorR(lookahead); + AST opnode = new AST(); - frnode = checkExpresion(lookahead); - matchCierroP(lookahead); + opnode = createNodo(fnode, fnode2); + frnode.addChild(opnode); return frnode; - } - else { + }else { + if(string=="Numero" || string == "Parentesis A"){ - if(matchProducto(string)) - { - - - AST fnode = checkFactor(lookahead); - frnode = checkFactorR(lookahead); - return createNodo(fnode, frnode); - } - else { - frnode.setLinea(linea); - frnode.setToken(token); - if(matchNumero(string)){ - return frnode; - } - - } + frnode = checkExpresion(string); + return frnode; - - + }else{ + return null; } - - frnode = null; - - return frnode; - + } } private boolean matchCierroP(String string) {