Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cs444
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
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
Xun Yang
cs444
Commits
8f682989
Commit
8f682989
authored
5 years ago
by
Xun Yang
Browse files
Options
Downloads
Patches
Plain Diff
push
parent
33ee5d17
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Scanning.py
+18
-21
18 additions, 21 deletions
Scanning.py
test.joos
+4
-0
4 additions, 0 deletions
test.joos
with
22 additions
and
21 deletions
Scanning.py
+
18
−
21
View file @
8f682989
import
re
# regex
import
re
# regex
import
string
import
string
# class ScanDFA():
# class ScanDFA():
# scans the input line by line, and char by char for each line
# scans the input line by line, and char by char for each line
# explicitly recognize whitespace when scanning, but discard whitespace tokens at the end
# explicitly recognize whitespace when scanning, but discard whitespace tokens at the end
##################### Token ##########################################
# A Token is a pair (name, lexeme)
class
Token
(){
def
__init__
(
self
,
name
,
lex
):
self
.
name
=
name
self
.
lex
=
lex
}
################# Joos Token Names in 5 categoeis ##########################
################# Joos Token Names in 5 categoeis ##########################
JoosTokens
=
set
([
JoosTokens
=
set
([
# Literals:
# Literals:
'
INT
'
,
'
INT
'
,
# Operants:
# Operants:
'
+
'
,
'
+
'
,
# Separators:
# Separators:
'
L(
'
,
'
L(
'
,
# Keywords:
# Keywords:
'
ID
'
,
''
,
'
SQL
'
,
'
Git
'
,
'
Tableau
'
,
'
SAS
'
,
'
ID
'
,
''
,
'
SQL
'
,
'
Git
'
,
'
Tableau
'
,
'
SAS
'
,
])
])
##################### Token ##########################################
# A Token is a pair (name, lexeme)
class
Token
(){
def
__init__
(
self
,
name
,
lex
):
self
.
name
=
name
self
.
lex
=
lex
}
##################### Transition function ############################
##################### Transition function ############################
...
@@ -50,6 +42,14 @@ def JoosTransition(input, state):
...
@@ -50,6 +42,14 @@ def JoosTransition(input, state):
##################### Other DFA elements ##############################
##################### Other DFA elements ##############################
JoosAccept
=
JoosTokens
.
union
({
'
WHITESPACE
'
,
'
COMMENT
'
})
JoosStates
=
JoosAccept
.
union
({
'
START
'
})
#TODO: add intermediate states here
JoosAlphabet
=
set
(
string
.
ascii_lowercase
)
.
union
(
set
(
string
.
ascii_uppercase
))
.
union
(
set
(
string
.
digits
))
.
union
(
set
(
list
(
"
.;,{}()[]<>!+-*/=
''
\"\\
"
))),
#TODO: add operand and separator characters to alphabet
######################### DFA #######################################
######################### DFA #######################################
class
DFA
():
class
DFA
():
def
__init__
(
self
,
states
,
alphabet
,
transition
,
start
,
accepting
):
def
__init__
(
self
,
states
,
alphabet
,
transition
,
start
,
accepting
):
...
@@ -69,10 +69,7 @@ class DFA ():
...
@@ -69,10 +69,7 @@ class DFA ():
JoosDFA
=
DFA
(
JoosDFA
=
DFA
(
states
=
JoosTokens
,
states
=
JoosTokens
,
alphabet
=
set
(
string
.
ascii_lowercase
)
alphabet
=
JoosAlphabet
,
.
union
(
set
(
string
.
ascii_uppercase
))
.
union
(
set
(
list
(
"
.;,{}()[]<>!+-*/=
''
\"\\
"
))),
#TODO: add operand and separator characters to alphabet
start
=
'
START
'
,
start
=
'
START
'
,
accept
=
JoosTokens
,
accept
=
JoosTokens
,
transition
=
JoosTransition
transition
=
JoosTransition
...
@@ -104,5 +101,5 @@ def scan(input):
...
@@ -104,5 +101,5 @@ def scan(input):
# TODO: handle edge cases (e.g. check int range, error on ++
# TODO: handle edge cases (e.g. check int range, error on ++
# remove whitespace and comments
# remove whitespace and comments
tokens
=
filter
(
lambda
t
:
t
.
name
not
in
(
"
WHITESPACE
"
,
"
COMMENT
"
),
tokens
)
tokens
=
filter
(
lambda
t
:
t
.
name
not
in
(
"
WHITESPACE
"
,
"
COMMENT
"
),
tokens
)
return
tokens
return
tokens
This diff is collapsed.
Click to expand it.
test.joos
0 → 100644
+
4
−
0
View file @
8f682989
public class A {
public A() {}
protected boolean x;
}
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