public bool Matches(Token t) { if (matchedTokenType != null) return t.Type == matchedTokenType; else return t.Lexeme == matchedString; }
// or from a nonterminal and a token, in which case we need to check // all the terminals for the given nonterminal and see if one matches the token public ISymbol[] Get(Nonterminal var, Token token) { Dictionary<Terminal, ISymbol[]> tableRow = table[var]; foreach (Terminal term in tableRow.Keys) if (term.Matches(token)) return tableRow[term]; return null; }
public ReadStmt(string identifier, Token token) : base(token) { this.identifier = identifier; }
public PrintStmt(Expression expr, Token token) : base(token) { this.expr = expr; }
public ForStmt(string identifier, Expression startVal, Expression endVal, IEnumerable<Statement> block, Token token) : base(token) { this.identifier = identifier; this.startVal = startVal; this.endVal = endVal; this.block = block; }
public LexicalError(Token t) : base(t) { }
public RuntimeError(Token t, string description) : base(t) { this.description = description; }
// recall the last valid token private Token TakeToken() { Token t = lastToken; lastToken = null; row = endRow; col = endCol; startRow = endRow; startCol = endCol; return t; }
public ValueExpr(Value value, Token token) : base(token) { this.value = value; }
public UnaryOp(char op, Expression expr, Token token) : base(token) { this.op = op; this.expr = expr; }
public IdentifierExpr(string identifier, Token token) : base(token) { this.identifier = identifier; }
// Every expression contains token to identify location in code Expression(Token token) { this.token = token; }
public BinaryOp(Expression lhs, char op, Expression rhs, Token token) : base(token) { this.op = op; this.lhs = lhs; this.rhs = rhs; }
public SyntaxError(Token t) : base(t) { }
// resets the automaton to its initial state public void Reset() { row = 0; col = 0; endRow = 0; endCol = 0; startRow = 0; startCol = 0; tokenBuffer = new Queue<Token>(); lastToken = null; position = start; }
// remember the last valid token private void StoreToken(TokenType type) { lastToken = type.CreateToken(charBuffer, startRow, startCol); endRow = row; endCol = col; }
public AssignStmt(string identifier, Expression expr, Token token) : base(token) { this.identifier = identifier; this.expr = expr; }
// Every statement contains token to identify location in code Statement(Token token) { this.token = token; }
public DeclarationStmt(string identifier, ValueType type, Token token, Expression initialValue) : this(identifier, type, token) { this.initialValue = initialValue; }
// just checks if a token should be yielded by the generator private bool IsRelevant(Token t, bool EOFisRelevant) { return (t.Type.TokenPriority != TokenType.Priority.Whitespace && (t.Type != TokenType.EOF || EOFisRelevant)); }
public DeclarationStmt(string identifier, ValueType type, Token token) : base(token) { this.identifier = identifier; this.type = type; }
public SemanticError(Token t, string description) : base(t) { this.description = description; }
protected Error(Token t) { this.t = t; }