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
9241bfbe
Commit
9241bfbe
authored
10 years ago
by
Lior Spach
Browse files
Options
Downloads
Patches
Plain Diff
c1
parent
a1a9aeb7
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
compiler/LexerHelper.scala
+44
-0
44 additions, 0 deletions
compiler/LexerHelper.scala
with
44 additions
and
0 deletions
compiler/LexerHelper.scala
0 → 100644
+
44
−
0
View file @
9241bfbe
package
lexer
class
LexerHelper
extends
Definicoes
{
//Acoes
def
erro
(
msg
:
String
)
=
{
println
(
"Erro: "
+
msg
);
sys
.
exit
(
1
)
}
//TAKES
def
takeOp
(
input
:
List
[
Char
],
acc
:
String
=
""
)
:
String
=
input
match
{
case
Nil
=>
acc
case
op
::
rest
if
ehOp
(
op
)
=>
takeOp
(
rest
,
acc
+
op
)
case
notOp
::
rest
if
!
ehOp
(
notOp
)
=>
acc
}
def
take
(
input
:
List
[
Char
],
acc
:
String
=
""
)
:
String
=
{
def
isNotASeparatorNorOperator
:
Boolean
=
!
(
ehSeparador
(
input
.
head
)
||
ehOp
(
input
.
head
))
input
match
{
case
in
::
_
if
ehLetra
(
in
)
||
ehNum
(
in
)
=>
take
(
input
.
tail
,
acc
+
in
)
case
_
=>
acc
}
}
//CASOS
def
casoLetra
(
input
:
List
[
Char
])
:
Token
=
{
val
palavra
=
take
(
input
)
val
forwardInput
=
input
.
drop
(
palavra
.
size
)
val
valido
=
palavra
.
forall
{
ch
=>
ehLetra
(
ch
)
||
ehNum
(
ch
)
}
val
tipo
=
if
(
ehPalavraReservada
(
palavra
))
"reservada"
else
"identificador"
Token
(
palavra
,
tipo
)
}
def
casoOp
(
input
:
List
[
Char
])
:
Token
=
{
val
fullOp
=
takeOp
(
input
)
fullOp
match
{
case
":"
=>
Token
(
":"
,
"dois pontos"
)
case
op
if
operadorValido
(
fullOp
)
=>
Token
(
fullOp
,
"operador"
)
case
_
=>
erro
(
"operador invalido"
+
fullOp
)
}
}
}
\ 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