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
dfc1f89b
Commit
dfc1f89b
authored
10 years ago
by
Lior Spach
Browse files
Options
Downloads
Patches
Plain Diff
Lexer novo, ainda em versão script.
parent
7eec21ff
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
compiler/Lexer.scala
+41
-17
41 additions, 17 deletions
compiler/Lexer.scala
with
41 additions
and
17 deletions
compiler/Lexer.scala
+
41
−
17
View file @
dfc1f89b
import
io.
{
Source
,
BufferedSource
}
#!/
usr
/
bin
/
scala
!#
println
(
"started..."
)
case
class
Token
(
val
value
:
String
,
val
func
:
String
)
case
class
Atomo
(
val
valor
:
Str
in
g
,
val
token
:
String
)
val
palavrasReservadas
=
List
(
"beg
in
"
,
"end"
,
"function"
,
"procedure"
,
"var"
,
"program"
)
object
Lexer
{
def
getTokens
(
stream
:
Iterator
[
Char
])
:
List
[
atomo
]
=
{
var
proximo
:
Char
=
''
var
acc
=
""
// Conjuntos
val
num
=
(
c
:
Char
)
=>
(
'0'
to
'9'
).
contains
(
c
)
val
op
=
(
c
:
Char
)
=>
"+-*/=:"
.
contains
(
c
)
val
letra
=
(
c
:
Char
)
=>
(
'a'
to
'z'
).
contains
(
c
)
||
(
'A'
to
'Z'
).
contains
(
c
)
||
c
==
'_'
val
espacoLinTab
=
(
c
:
Char
)
=>
c
==
' '
||
c
==
'\t'
||
c
==
'\n'
val
palavraReservada
=
(
s
:
String
)
=>
palavrasReservadas
.
contains
(
s
)
def
PROX
=
if
(
stream
.
hasNext
)
proximo
=
stream
.
next
def
ADD
=
acc
+
proximo
//Acoes
val
erro
=
(
msg
:
String
)
=>
{
println
(
"Erro: "
+
msg
);
sys
.
exit
(
1
)}
PROX
proximo
match
{
//TODO: Pattern Matching
case
' '
||
'\t'
||
'\n'
=>
case
letra
=>
case
numero
=>
case
simbolo_especial
=>
}
def
atomo
(
str
:
String
)
{
val
iter
=
str
.
iterator
while
(
iter
.
hasNext
)
{
def
take
(
iter
:
Iterator
[
Char
])
=
iter
.
takeWhile
{(
c
)
=>
!
espacoLinTab
(
c
)}.
mkString
iter
.
dropWhile
(
espacoLinTab
)
val
c
=
iter
.
next
var
acc
=
""
println
(
c
match
{
case
c
if
num
(
c
)
=>
acc
=
c
+
take
(
iter
)
if
(
acc
.
exists
{(
c
)
=>
!
num
(
c
)}
)
erro
(
acc
+
" nao eh numero"
)
(
acc
,
"numero"
)
case
c
if
op
(
c
)
=>
(
c
,
"op"
)
case
c
if
letra
(
c
)
=>
(
c
,
"letra"
)
acc
=
c
+
take
(
iter
)
if
(
acc
.
exists
{(
c
)
=>
!(
num
(
c
)
||
letra
(
c
))
}
)
erro
(
acc
+
" nao eh identificador valido"
)
if
(
palavraReservada
(
acc
))
(
acc
,
"reservado"
)
else
(
acc
,
"identificador"
)
case
c
if
espacoLinTab
(
c
)
=>
/*pula*/
case
erroCh
=>
erro
(
erroCh
+
""
)
}
)
}
}
while
(
true
)
atomo
(
readLine
)
\ 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