view python/ppci/common.py @ 251:6ed3d3a82a63

Added another c3 example. First import attempt
author Windel Bouwman
date Mon, 29 Jul 2013 20:23:13 +0200
parents e41e4109addd
children 1c7c1e619be8
line wrap: on
line source

from collections import namedtuple

# Token is used in the lexical analyzer:
class Token:
    def __init__(self, typ, val, loc=None):
        self.typ = typ
        self.val = val
        if loc is None:
            loc = SourceLocation(0, 0, 0)
        assert type(loc) is SourceLocation
        self.loc = loc
    def __repr__(self):
        return 'Token({0}, {1})'.format(self.typ, self.val)

class SourceLocation:
    def __init__(self, row, col, ln):
        self.row = row
        self.col = col
        self.length = ln
        self.filename = ''

    def __repr__(self):
        return '{}, {}'.format(self.row, self.col)

SourceRange = namedtuple('SourceRange', ['p1', 'p2'])