Skip to content
Snippets Groups Projects
Commit 8f682989 authored by Xun Yang's avatar Xun Yang
Browse files

push

parent 33ee5d17
No related branches found
No related tags found
No related merge requests found
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
public class A {
public A() {}
protected boolean x;
}
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