Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pascal-compiler
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Harbor Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Lior Spach
pascal-compiler
Commits
86a192a5
Commit
86a192a5
authored
9 years ago
by
Lior Spach
Browse files
Options
Downloads
Patches
Plain Diff
3/3
parent
e6edbfbe
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/scala/TabelaSimb.scala
+54
-0
54 additions, 0 deletions
src/main/scala/TabelaSimb.scala
with
54 additions
and
0 deletions
src/main/scala/TabelaSimb.scala
0 → 100644
+
54
−
0
View file @
86a192a5
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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment