-
Notifications
You must be signed in to change notification settings - Fork 4
/
EssexToken.py
executable file
·48 lines (41 loc) · 1.7 KB
/
EssexToken.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#=========================================================================
# This is OPEN SOURCE SOFTWARE governed by the Gnu General Public
# License (GPL) version 3, as described at www.opensource.org.
# Copyright (C)2016 William H. Majoros (martiandna@gmail.com).
#=========================================================================
from __future__ import (absolute_import, division, print_function,
unicode_literals, generators, nested_scopes, with_statement)
from builtins import (bytes, dict, int, list, object, range, str, ascii,
chr, hex, input, next, oct, open, pow, round, super, filter, map, zip)
######################################################################
# Represents a token in a Essex file --- either a parenthesis or a
# literal (a literal is anything other than a parenthesis: a tag/ident-
# ifier, number, or string). Note that the scanner can't differentiate
# between a tag and a datum, so the parser must do this.
#
# Attributes:
# tokenType : one of "(", ")", or "L" (literal)
# lexeme : string
# Methods:
# token=EssexToken(type,lexeme)
# type=token.getType()
# string=token.getLexeme()
# bool=token.sOpenParen()
# bool=token.isCloseParen()
# bool=token.isLiteral()
######################################################################
class EssexToken:
def __init__(self,type,lexeme=None):
self.type=type
if(lexeme is not None and len(lexeme)>0):
self.lexeme=lexeme
def getType(self):
return self.type
def getLexeme(self):
return self.lexeme
def isOpenParen(self):
return self.type=="("
def isCloseParen(self):
return self.type==")"
def isLiteral(self):
return self.type=="L"