Skip to content
Snippets Groups Projects
Commit 4952f562 authored by Lior Spach's avatar Lior Spach
Browse files

update TabSimb.scala

parent 43a742fb
No related branches found
No related tags found
No related merge requests found
package other
import scala.annotation.tailrec
abstract class Entrada(val id:String)
class Entrada(val id:String)
case class Funcao (override val id:String, paramInfo:List[Param], desloc:Int,
nvLex:Int, rotEntrada:String) extends Entrada(id)
case class Procedimento(override val id:String, paramInfo:List[Param],
......@@ -26,7 +26,6 @@ object TabelaSimb {
}
def getLastProc(nvLex:Int) = {
print
table.find {
case p:Procedimento => if (p.nvLex==nvLex) true else false
case f:Funcao => if (f.nvLex==nvLex) true else false
......@@ -34,7 +33,19 @@ object TabelaSimb {
}.get
}
@annotation.tailrec
@tailrec
def temParamOuVarComMesmoId(nome:String, rest:List[Entrada] = table):Boolean = { //No escopo da ultima funcao/proc
val e = getById(nome)
rest match {
case (p:Procedimento) :: xs => false
case (f:Funcao) :: xs => false
case (v:Var) :: xs => if (v.id == nome) true else temParamOuVarComMesmoId(nome, xs)
case (p:Param) :: xs => if (p.id == nome) true else temParamOuVarComMesmoId(nome, xs)
case _ => false
}
}
@tailrec
def numVarsLocais(nvLex:Int, count:Int=0, rest:List[Entrada] = table):Int = rest match {
case (v:Var) :: xs => numVarsLocais(nvLex, count+1, xs)
case (p:Procedimento) :: xs => if (p.nvLex>nvLex) numVarsLocais(nvLex,count,xs) else count
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment