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

3/3

parent e6edbfbe
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)
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],
nvLex:Int, rotEntrada:String) extends Entrada(id)
case class Param(override val id:String, desloc: Int, byRef:Boolean, nvLex:Int) extends Entrada(id)
case class Var(override val id:String, desloc: Int, nvLex:Int) extends Entrada(id)
case class Label(override val id:String, rotulo:String, nvLex:Int, var used:Boolean = false, var put:Boolean = false) extends Entrada(id)
object TabelaSimb {
private var table = List[Entrada]()
def hasNext = table.size>0
def top = table.head
def drop = table = table.tail
def getTable = table
def setTable(t:List[Entrada]) = table = t
def getById(id:String) = {
table.find { e => e.id == id }
}
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
case _ => false
}.get
}
@annotation.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
case (f:Funcao) :: xs => if (f.nvLex>nvLex) numVarsLocais(nvLex,count,xs) else count
case _ => count
}
def insere(e:Entrada) {
table = e :: table
}
def insere(lst:List[Entrada]) {
table = lst.reverse ::: table
}
def print = table.reverse foreach println
}
\ No newline at end of file
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