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 string
# class ScanDFA():
# 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
##################### 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 ##########################
JoosTokens = set([
# Literals:
'INT',
# Operants:
'+',
# Separators:
'L(',
# Keywords:
'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 ############################
......@@ -50,6 +42,14 @@ def JoosTransition(input, state):
##################### 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 #######################################
class DFA ():
def __init__(self, states, alphabet, transition, start, accepting):
......@@ -69,10 +69,7 @@ class DFA ():
JoosDFA = DFA(
states = JoosTokens,
alphabet = set(string.ascii_lowercase)
.union(set(string.ascii_uppercase))
.union(set(list(".;,{}()[]<>!+-*/=''\"\\"))),
#TODO: add operand and separator characters to alphabet
alphabet = JoosAlphabet,
start = 'START',
accept = JoosTokens,
transition = JoosTransition
......@@ -104,5 +101,5 @@ def scan(input):
# TODO: handle edge cases (e.g. check int range, error on ++
# 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
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