List of usage examples for org.antlr.v4.runtime.misc ParseCancellationException ParseCancellationException
public ParseCancellationException(Throwable cause)
From source file:boa.compiler.BoaCompiler.java
License:Apache License
public static void main(final String[] args) throws IOException { CommandLine cl = processCommandLineOptions(args); if (cl == null) return;//from w w w .j a va2s.c o m final ArrayList<File> inputFiles = BoaCompiler.inputFiles; // get the name of the generated class final String className = getGeneratedClass(cl); // get the filename of the jar we will be writing final String jarName; if (cl.hasOption('o')) jarName = cl.getOptionValue('o'); else jarName = className + ".jar"; // make the output directory final File outputRoot = new File(new File(System.getProperty("java.io.tmpdir")), UUID.randomUUID().toString()); final File outputSrcDir = new File(outputRoot, "boa"); if (!outputSrcDir.mkdirs()) throw new IOException("unable to mkdir " + outputSrcDir); // find custom libs to load final List<URL> libs = new ArrayList<URL>(); if (cl.hasOption('l')) for (final String lib : cl.getOptionValues('l')) libs.add(new File(lib).toURI().toURL()); final File outputFile = new File(outputSrcDir, className + ".java"); final BufferedOutputStream o = new BufferedOutputStream(new FileOutputStream(outputFile)); try { final List<String> jobnames = new ArrayList<String>(); final List<String> jobs = new ArrayList<String>(); boolean isSimple = true; final List<Program> visitorPrograms = new ArrayList<Program>(); SymbolTable.initialize(libs); for (int i = 0; i < inputFiles.size(); i++) { final File f = inputFiles.get(i); try { final BoaLexer lexer = new BoaLexer(new ANTLRFileStream(f.getAbsolutePath())); lexer.removeErrorListeners(); lexer.addErrorListener(new LexerErrorListener()); final CommonTokenStream tokens = new CommonTokenStream(lexer); final BoaParser parser = new BoaParser(tokens); parser.removeErrorListeners(); parser.addErrorListener(new BaseErrorListener() { @Override public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) throws ParseCancellationException { throw new ParseCancellationException(e); } }); final BoaErrorListener parserErrorListener = new ParserErrorListener(); final Start p = parse(tokens, parser, parserErrorListener); if (cl.hasOption("ast")) new ASTPrintingVisitor().start(p); final String jobName = "" + i; try { if (!parserErrorListener.hasError) { new TypeCheckingVisitor().start(p, new SymbolTable()); final TaskClassifyingVisitor simpleVisitor = new TaskClassifyingVisitor(); simpleVisitor.start(p); LOG.info(f.getName() + ": task complexity: " + (!simpleVisitor.isComplex() ? "simple" : "complex")); isSimple &= !simpleVisitor.isComplex(); new InheritedAttributeTransformer().start(p); new LocalAggregationTransformer().start(p); // if a job has no visitor, let it have its own method // also let jobs have own methods if visitor merging is disabled if (!simpleVisitor.isComplex() || cl.hasOption("nv") || inputFiles.size() == 1) { new VisitorOptimizingTransformer().start(p); if (cl.hasOption("pp")) new PrettyPrintVisitor().start(p); if (cl.hasOption("ast")) new ASTPrintingVisitor().start(p); final CodeGeneratingVisitor cg = new CodeGeneratingVisitor(jobName); cg.start(p); jobs.add(cg.getCode()); jobnames.add(jobName); } // if a job has visitors, fuse them all together into a single program else { p.getProgram().jobName = jobName; visitorPrograms.add(p.getProgram()); } } } catch (final TypeCheckException e) { parserErrorListener.error("typecheck", lexer, null, e.n.beginLine, e.n.beginColumn, e.n2.endColumn - e.n.beginColumn + 1, e.getMessage(), e); } } catch (final Exception e) { System.err.print(f.getName() + ": compilation failed: "); e.printStackTrace(); } } final int maxVisitors; if (cl.hasOption('v')) maxVisitors = Integer.parseInt(cl.getOptionValue('v')); else maxVisitors = Integer.MAX_VALUE; if (!visitorPrograms.isEmpty()) try { for (final Program p : new VisitorMergingTransformer().mergePrograms(visitorPrograms, maxVisitors)) { new VisitorOptimizingTransformer().start(p); if (cl.hasOption("pp")) new PrettyPrintVisitor().start(p); if (cl.hasOption("ast")) new ASTPrintingVisitor().start(p); final CodeGeneratingVisitor cg = new CodeGeneratingVisitor(p.jobName); cg.start(p); jobs.add(cg.getCode()); jobnames.add(p.jobName); } } catch (final Exception e) { System.err.println("error fusing visitors - falling back: " + e); e.printStackTrace(); for (final Program p : visitorPrograms) { new VisitorOptimizingTransformer().start(p); if (cl.hasOption("pp")) new PrettyPrintVisitor().start(p); if (cl.hasOption("ast")) new ASTPrintingVisitor().start(p); final CodeGeneratingVisitor cg = new CodeGeneratingVisitor(p.jobName); cg.start(p); jobs.add(cg.getCode()); jobnames.add(p.jobName); } } if (jobs.size() == 0) throw new RuntimeException("no files compiled without error"); final ST st = AbstractCodeGeneratingVisitor.stg.getInstanceOf("Program"); st.add("name", className); st.add("numreducers", inputFiles.size()); st.add("jobs", jobs); st.add("jobnames", jobnames); st.add("combineTables", CodeGeneratingVisitor.combineAggregatorStrings); st.add("reduceTables", CodeGeneratingVisitor.reduceAggregatorStrings); st.add("splitsize", isSimple ? 64 * 1024 * 1024 : 10 * 1024 * 1024); o.write(st.render().getBytes()); } finally { o.close(); } compileGeneratedSrc(cl, jarName, outputRoot, outputFile); }
From source file:boa.compiler.BoaCompiler.java
License:Apache License
public static void parseOnly(final String[] args) throws IOException { CommandLine cl = processParseCommandLineOptions(args); if (cl == null) return;/* w ww . j av a 2 s .c o m*/ final ArrayList<File> inputFiles = BoaCompiler.inputFiles; // find custom libs to load final List<URL> libs = new ArrayList<URL>(); if (cl.hasOption('l')) for (final String lib : cl.getOptionValues('l')) libs.add(new File(lib).toURI().toURL()); final List<String> jobnames = new ArrayList<String>(); final List<String> jobs = new ArrayList<String>(); boolean isSimple = true; final List<Program> visitorPrograms = new ArrayList<Program>(); SymbolTable.initialize(libs); for (int i = 0; i < inputFiles.size(); i++) { final File f = inputFiles.get(i); try { final BoaLexer lexer = new BoaLexer(new ANTLRFileStream(f.getAbsolutePath())); lexer.removeErrorListeners(); lexer.addErrorListener(new LexerErrorListener()); final CommonTokenStream tokens = new CommonTokenStream(lexer); final BoaParser parser = new BoaParser(tokens); parser.removeErrorListeners(); parser.addErrorListener(new BaseErrorListener() { @Override public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) throws ParseCancellationException { throw new ParseCancellationException(e); } }); final BoaErrorListener parserErrorListener = new ParserErrorListener(); final Start p = parse(tokens, parser, parserErrorListener); if (cl.hasOption("ast")) new ASTPrintingVisitor().start(p); final String jobName = "" + i; try { if (!parserErrorListener.hasError) { new TypeCheckingVisitor().start(p, new SymbolTable()); final TaskClassifyingVisitor simpleVisitor = new TaskClassifyingVisitor(); simpleVisitor.start(p); LOG.info(f.getName() + ": task complexity: " + (!simpleVisitor.isComplex() ? "simple" : "complex")); isSimple &= !simpleVisitor.isComplex(); new InheritedAttributeTransformer().start(p); new LocalAggregationTransformer().start(p); // if a job has no visitor, let it have its own method // also let jobs have own methods if visitor merging is disabled if (!simpleVisitor.isComplex() || cl.hasOption("nv") || inputFiles.size() == 1) { new VisitorOptimizingTransformer().start(p); if (cl.hasOption("pp")) new PrettyPrintVisitor().start(p); if (cl.hasOption("ast")) new ASTPrintingVisitor().start(p); final CodeGeneratingVisitor cg = new CodeGeneratingVisitor(jobName); cg.start(p); jobs.add(cg.getCode()); jobnames.add(jobName); } // if a job has visitors, fuse them all together into a single program else { p.getProgram().jobName = jobName; visitorPrograms.add(p.getProgram()); } } } catch (final TypeCheckException e) { parserErrorListener.error("typecheck", lexer, null, e.n.beginLine, e.n.beginColumn, e.n2.endColumn - e.n.beginColumn + 1, e.getMessage(), e); } } catch (final Exception e) { System.err.print(f.getName() + ": parsing failed: "); e.printStackTrace(); } } }
From source file:br.beholder.memelang.model.visitor.BipGeneratorVisitor.java
private void geradorData() { this.header.append(".data\n"); for (Identificador identificador : tabelaSimbolos) { if (!identificador.isFuncao()) { if (identificador.getTipo() != Identificador.Tipo.INTEIRO) { throw new ParseCancellationException(identificador.getTipo() + " NOT SUPPORTED BY BIPIDE"); }/* w w w .j a va2s . com*/ this.header.append("\t"); this.header.append(AssemblyName.findAN(this.anlist, identificador)); this.header.append(" : "); for (int i = 0; i < identificador.getQtdArmazenada(); i++) { if (i == identificador.getQtdArmazenada() - 1) { this.header.append("0\n"); } else { this.header.append("0 , "); } } } } }
From source file:br.beholder.memelang.model.visitor.BipGeneratorVisitor.java
private void resolveOpBitwise(Op_bitwiseContext opBit, Val_finalContext valctx) { // System.out.println("Entrou " + valctx.getText()); if (valctx.CONSTINTEIRO() != null) { if (opBit.BITAND() != null) { comando("ANDI", valctx.CONSTINTEIRO().getSymbol().getText()); } else if (opBit.BITOR() != null) { comando("ORI", valctx.CONSTINTEIRO().getSymbol().getText()); } else if (opBit.BITXOR() != null) { comando("XORI", valctx.CONSTINTEIRO().getSymbol().getText()); } else if (opBit.BITSHIFTLEFT() != null) { comando("SLL", valctx.CONSTINTEIRO().getSymbol().getText()); } else if (opBit.BITSHIFTRIGHT() != null) { comando("SRL", valctx.CONSTINTEIRO().getSymbol().getText()); } else if (opBit.BITNOT() != null) { comando("NOT", "0"); }//from w ww . ja v a 2 s. c o m return; } //Carrega valor de um ID if (valctx.ID() != null) { if (valctx.multidimensional() != null) { //Carregar valor de vetor int tempNum = getOneTemp(); comando("STO", "temp" + tempNum); for (ExpressaoContext exp : valctx.multidimensional().expressao()) { visitExpressao(exp); } comando("STO", "$indr"); comando("LDV", findAN(valctx.ID().getSymbol().getText()).toString()); tempNum = getOneTemp(); comando("STO", "temp" + tempNum); comando("LD", "temp" + (tempNum - 1)); if (opBit.BITAND() != null) { comando("AND", "temp" + tempNum); } else if (opBit.BITNOT() != null) { comando("NOT", "0"); } else if (opBit.BITOR() != null) { comando("OR", "temp" + tempNum); } else if (opBit.BITSHIFTLEFT() != null) { comando("SLL", "temp" + tempNum); } else if (opBit.BITSHIFTRIGHT() != null) { comando("SRL", "temp" + tempNum); } else if (opBit.BITXOR() != null) { comando("XOR", "temp" + tempNum); } releaseTheTemp(); releaseTheTemp(); return; } else { //Carregar valor de variavel String varName = findAN(valctx.ID().getText()).toString(); if (opBit.BITAND() != null) { comando("AND", varName); } else if (opBit.BITNOT() != null) { comando("NOT", "0"); } else if (opBit.BITOR() != null) { comando("OR", varName); } else if (opBit.BITSHIFTLEFT() != null) { comando("SLL", varName); } else if (opBit.BITSHIFTRIGHT() != null) { comando("SRL", varName); } else if (opBit.BITXOR() != null) { comando("XOR", varName); } return; } } //Chama funo if (valctx.chamadaFuncao() != null) { int tempNum = getOneTemp(); comando("STO", "temp" + tempNum); visitChamadaFuncao(valctx.chamadaFuncao()); tempNum = getOneTemp(); comando("STO", "temp" + tempNum); comando("LD", "temp" + (tempNum - 1)); if (opBit.BITAND() != null) { comando("AND", "temp" + tempNum); } else if (opBit.BITNOT() != null) { comando("NOT", "0"); } else if (opBit.BITOR() != null) { comando("OR", "temp" + tempNum); } else if (opBit.BITSHIFTLEFT() != null) { comando("SLL", "temp" + tempNum); } else if (opBit.BITSHIFTRIGHT() != null) { comando("SRL", "temp" + tempNum); } else if (opBit.BITXOR() != null) { comando("XOR", "temp" + tempNum); } releaseTheTemp(); releaseTheTemp(); return; } //Resolve outra expresso if (valctx.expressao() != null) { int tempNum = getOneTemp(); comando("STO", "temp" + tempNum); visitExpressao(valctx.expressao()); tempNum = getOneTemp(); comando("STO", "temp" + tempNum); comando("LD", "temp" + (tempNum - 1)); if (opBit.BITAND() != null) { comando("AND", "temp" + tempNum); } else if (opBit.BITNOT() != null) { comando("NOT", "0"); } else if (opBit.BITOR() != null) { comando("OR", "temp" + tempNum); } else if (opBit.BITSHIFTLEFT() != null) { comando("SLL", "temp" + tempNum); } else if (opBit.BITSHIFTRIGHT() != null) { comando("SRL", "temp" + tempNum); } else if (opBit.BITXOR() != null) { comando("XOR", "temp" + tempNum); } releaseTheTemp(); releaseTheTemp(); return; } throw new ParseCancellationException("Outras operaes no identificadas" + valctx.getText()); }
From source file:br.beholder.memelang.model.visitor.BipGeneratorVisitor.java
private void resolveOpAritmeticaMaisOuNegacaoMenos(MemelangParser.Val_finalContext valctx, boolean operacaoMais) { //ADD ou SUB valor inteiro imediato // System.out.println("Exp " + valctx.getText()); if (valctx.CONSTINTEIRO() != null) { if (operacaoMais) { comando("ADDI", valctx.CONSTINTEIRO().getSymbol().getText()); } else {/*ww w .j a v a 2 s. c o m*/ comando("SUBI", valctx.CONSTINTEIRO().getSymbol().getText()); } return; } //Carrega valor de um ID if (valctx.ID() != null) { if (valctx.multidimensional() != null) { //Carregar valor de vetor int tempNum = getOneTemp(); comando("STO", "temp" + tempNum); for (ExpressaoContext exp : valctx.multidimensional().expressao()) { visitExpressao(exp); } comando("STO", "$indr"); comando("LDV", findAN(valctx.ID().getSymbol().getText()).toString()); tempNum = getOneTemp(); comando("STO", "temp" + tempNum); comando("LD", "temp" + (tempNum - 1)); if (operacaoMais) { comando("ADD", "temp" + tempNum); } else { comando("SUB", "temp" + tempNum); } releaseTheTemp(); releaseTheTemp(); return; } else { //Carregar valor de variavel String varName = findAN(valctx.ID().getText()).toString(); if (operacaoMais) { comando("ADD", varName); } else { comando("SUB", varName); } return; } } //Chama funo if (valctx.chamadaFuncao() != null) { int tempNum = getOneTemp(); comando("STO", "temp" + tempNum); visitChamadaFuncao(valctx.chamadaFuncao()); tempNum = getOneTemp(); comando("STO", "temp" + tempNum); comando("LD", "temp" + (tempNum - 1)); if (operacaoMais) { comando("ADD", "temp" + tempNum); } else { comando("SUB", "temp" + tempNum); } releaseTheTemp(); releaseTheTemp(); return; } //Resolve outra expresso if (valctx.expressao() != null) { int tempNum = getOneTemp(); comando("STO", "temp" + tempNum); visitExpressao(valctx.expressao()); tempNum = getOneTemp(); comando("STO", "temp" + tempNum); comando("LD", "temp" + (tempNum - 1)); if (operacaoMais) { comando("ADD", "temp" + tempNum); } else { comando("SUB", "temp" + tempNum); } releaseTheTemp(); releaseTheTemp(); return; } throw new ParseCancellationException("Outras operaes no identificadas" + valctx.getText()); }
From source file:br.beholder.memelang.model.visitor.SemanticVisitor.java
public Tipo visitExpressaoLoop(MemelangParser.ExpressaoContext ctx) { if (ctx == null) { return null; }//from w w w . j a v a 2 s . c om Stack<Identificador.Tipo> pilhaTipoExpressaoLoop = new Stack<>(); Stack<Operation> pilhaOperacaoLoop = new Stack<>(); for (MemelangParser.OperationsContext opCont : ctx.operations()) { pilhaOperacaoLoop.push(verificarTipoOperacao(opCont)); } for (int i = 0; i < ctx.val_final().size(); i++) { String valFinal = ctx.val_final(i).getText(); Tipo tipoExpParenteses = null; if (ctx.val_final(i).multidimensional() != null) { valFinal = ctx.val_final(i).ID().getText(); } if (ctx.val_final(i).chamadaFuncao() != null) { valFinal = ctx.val_final(i).chamadaFuncao().ID().getText(); } if (ctx.val_final(i).PARENTESEABRE() != null) { pilhaTipoExpressaoLoop.push(visitExpressaoLoop(ctx.val_final(i).expressao())); continue; } if (Identificador.getId(valFinal, tabelaSimbolos, escopoAtual) != null) { Identificador id = Identificador.getId(valFinal, tabelaSimbolos, escopoAtual); if (ctx.val_final(i).multidimensional() != null) { Tipo posicaoVetor = visitExpressaoLoop(ctx.val_final(i).multidimensional().expressao(0)); if (posicaoVetor != Tipo.INTEIRO) { this.semanticErrors.add(new ParseCancellationException( "Tentando acessar posio de vetor com tipo no inteiro na Linha: " + ctx.start.getLine() + " Coluna: " + ctx.start.getCharPositionInLine())); } visitMultidimensional(ctx.val_final(i).multidimensional(), posicaoVetor); } else { multidimensional = 0; } if (!id.isInicializada()) { this.semanticErrors.add(new ParseCancellationException( "Vriavel " + id.getNome() + " no inicializada Linha: " + ctx.start.getLine() + " Coluna: " + ctx.start.getCharPositionInLine())); } if (id.getDimensoes() != multidimensional) { this.semanticErrors.add(new ParseCancellationException( "Dimenses incorreta do vetor " + id.getNome() + " . Ele possui " + id.getDimensoes() + " dimenses e foi usada " + multidimensional + " Linha: " + ctx.start.getLine() + " Coluna: " + ctx.start.getCharPositionInLine())); } id.setUsada(true); pilhaTipoExpressaoLoop.push(id.getTipo()); } else if (verificarTipoConstante(ctx.val_final(i)) == null && tipoExpParenteses == null) { this.semanticErrors.add( new ParseCancellationException("Vriavel " + valFinal + " no existe neste escopo Linha: " + ctx.start.getLine() + " Coluna: " + ctx.start.getCharPositionInLine())); } else { if (tipoExpParenteses != null) { pilhaTipoExpressaoLoop.push(tipoExpParenteses); } pilhaTipoExpressaoLoop.push(verificarTipoConstante(ctx.val_final(i))); } } verificarCompatibilidadeOperacao(ctx, pilhaTipoExpressaoLoop, pilhaOperacaoLoop); if (pilhaTipoExpressaoLoop.empty()) { return null; } return pilhaTipoExpressaoLoop.peek(); }
From source file:br.beholder.memelang.model.visitor.SemanticVisitor.java
@Override public Object visitExpressao(MemelangParser.ExpressaoContext ctx) { if (ctx == null) { return null; }//from ww w. j a v a 2 s. co m this.pilhaOperacao.clear(); this.pilhaTipoExpressao.clear(); for (MemelangParser.OperationsContext opCont : ctx.operations()) { this.pilhaOperacao.push(verificarTipoOperacao(opCont)); } for (int i = 0; i < ctx.val_final().size(); i++) { String valFinal = ctx.val_final(i).getText(); if (ctx.val_final(i).multidimensional() != null) { valFinal = ctx.val_final(i).ID().getText(); } if (ctx.val_final(i).chamadaFuncao() != null) { visitChamadaFuncao(ctx.val_final(i).chamadaFuncao()); valFinal = ctx.val_final(i).chamadaFuncao().ID().getText(); } if (ctx.val_final(i).PARENTESEABRE() != null) { this.pilhaTipoExpressao.push(visitExpressaoLoop(ctx.val_final(i).expressao())); continue; } if (Identificador.getId(valFinal, tabelaSimbolos, escopoAtual) != null) { Identificador id = Identificador.getId(valFinal, tabelaSimbolos, escopoAtual); if (ctx.val_final(i).multidimensional() != null) { Tipo posicaoVetor = visitExpressaoLoop(ctx.val_final(i).multidimensional().expressao(0)); if (posicaoVetor != Tipo.INTEIRO) { this.semanticErrors.add(new ParseCancellationException( "Tentando acessar posio de vetor com tipo no inteiro na Linha: " + ctx.start.getLine() + " Coluna: " + ctx.start.getCharPositionInLine())); } visitMultidimensional(ctx.val_final(i).multidimensional(), posicaoVetor); } else { multidimensional = 0; } if (!id.isInicializada()) { this.semanticErrors.add(new ParseCancellationException( "Vriavel " + id.getNome() + " no inicializada Linha: " + ctx.start.getLine() + " Coluna: " + ctx.start.getCharPositionInLine())); } if (id.getDimensoes() != multidimensional) { this.semanticErrors.add(new ParseCancellationException( "Dimenses incorreta do vetor " + id.getNome() + " . Ele possui " + id.getDimensoes() + " dimenses e foi usada " + multidimensional + " Linha: " + ctx.start.getLine() + " Coluna: " + ctx.start.getCharPositionInLine())); } id.setUsada(true); this.pilhaTipoExpressao.push(id.getTipo()); } else if (verificarTipoConstante(ctx.val_final(i)) == null) { this.semanticErrors.add( new ParseCancellationException("Vriavel " + valFinal + " no existe neste escopo Linha: " + ctx.start.getLine() + " Coluna: " + ctx.start.getCharPositionInLine())); } else { this.pilhaTipoExpressao.push(verificarTipoConstante(ctx.val_final(i))); } } verificarCompatibilidadeOperacao(ctx, this.pilhaTipoExpressao, this.pilhaOperacao); return null; // return super.visitExpressao(ctx); //To change body of generated methods, choose Tools | Templates. }
From source file:br.beholder.memelang.model.visitor.SemanticVisitor.java
public void verificarCompatibilidadeOperacao(MemelangParser.ExpressaoContext ctx, Stack<Tipo> pilhaTipoExpressao, Stack<Operation> pilhaOperacao) { if (pilhaOperacao.empty() || pilhaTipoExpressao.size() != pilhaOperacao.size() + 1) { return;/* w ww. jav a 2 s .co m*/ } int resultExp; Tipo tipo1, tipo2; Operation op; while (!pilhaOperacao.empty()) { tipo1 = pilhaTipoExpressao.pop(); tipo2 = pilhaTipoExpressao.pop(); op = pilhaOperacao.pop(); int resulExp = SemanticTable.resultType(tipo1, tipo2, op); if (resulExp == SemanticTable.ERR) { this.semanticErrors.add(new ParseCancellationException("Tentando realizar uma " + op.name() + " entre " + tipo1.name() + " e " + tipo2.name() + " na linha " + ctx.start.getLine())); return; } pilhaTipoExpressao.push(SemanticTable.getCodeType(resulExp)); } }
From source file:br.beholder.memelang.model.visitor.SemanticVisitor.java
@Override public Object visitParametros(MemelangParser.ParametrosContext ctx) { for (int i = 0; i < ctx.parametro().size(); i++) { String idName = ctx.parametro(i).ID().getSymbol().getText(); if (Escopo.verificaSeExisteNoEscopo(idName, tabelaSimbolos, escopoAtual)) { this.semanticErrors.add(new ParseCancellationException( "Declarao de Vriavel " + idName + " j existe neste escopo Linha: " + ctx.start.getLine() + " Coluna: " + ctx.start.getCharPositionInLine())); }//from www .j a va2s . c om multidimensional = 0; qtdMultidimensional = 1; if (ctx.parametro(i).multidimensional() != null) { visitMultidimensional(ctx.parametro(i).multidimensional()); } visitTipo(ctx.parametro(i).tipo()); Identificador id = new Identificador(idName, tipoAtual, true, false, escopoAtual, true, ctx.parametro(i).REFERENCIA() != null, i + 1, multidimensional, // S aceita unidimensional como parametro... false); tabelaSimbolos.add(id); } return null; }
From source file:br.beholder.memelang.model.visitor.SemanticVisitor.java
/** * Passe a ele o idNome da funo que ele te retornara o escopo que a funo * criou.//from w w w . j a va 2 s . com * * @param idName * @return */ private Escopo getEscopoDaFuncao(String idName) { Escopo escopo = null; for (Identificador identificador : tabelaSimbolos) { if (identificador.getNome().equals(idName)) { escopo = identificador.getEscopo(); break; } } if (escopo == null) { this.semanticErrors.add(new ParseCancellationException("Escopo no encontrado")); } for (Escopo subEscopo : escopo.getSubEscopos()) { if (subEscopo.getNome().equals(idName)) { return subEscopo; } } return null; }