From 8f682989c6be9982bc9837f9aa76fe24f8fefec9 Mon Sep 17 00:00:00 2001 From: Xun Yang <x299yang@uwaterloo.ca> Date: Mon, 27 Jan 2020 22:18:48 -0500 Subject: [PATCH] push --- Scanning.py | 39 ++++++++++++++++++--------------------- test.joos | 4 ++++ 2 files changed, 22 insertions(+), 21 deletions(-) create mode 100644 test.joos diff --git a/Scanning.py b/Scanning.py index 83bbc0d..e220862 100644 --- a/Scanning.py +++ b/Scanning.py @@ -1,38 +1,30 @@ 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 diff --git a/test.joos b/test.joos new file mode 100644 index 0000000..2ce35b4 --- /dev/null +++ b/test.joos @@ -0,0 +1,4 @@ +public class A { + public A() {} + protected boolean x; +} -- GitLab