private bool Accept(Token.Types excepted) { if (CurrentToken.Type == excepted) { AcceptedToken = CurrentToken; NextToken(); return true; } return false; }
private bool Accept(Token.Types[] excepted) { if (Array.IndexOf(excepted, CurrentToken.Type) != -1) { AcceptedToken = CurrentToken; NextToken(); return true; } return false; }
private void Process(Token t) { if (exptFuCallFlag) ExcpectFunctionCall(t); else if (opBlockFlag) { if (t.type == Token.Type.Operator && t.lexema == "}") { opBlockFlag = false; this.pStack.Push(newblock); } else { newblock.Append(t); } } else switch (t.type) { case Token.Type.Indexer: pStack.Push(int.Parse(t.lexema)); CallFunction(new Id("~indexer")); break; case Token.Type.Operator: ProcessOperator(t.lexema); break; case Token.Type.FunctionCall: CallFunction(new Id(t.lexema)); break; case Token.Type.String: pStack.Push(t.lexema); break; case Token.Type.Double: pStack.Push(Double.Parse(t.lexema)); break; case Token.Type.Integer: pStack.Push(Double.Parse(t.lexema)); break; case Token.Type.IdHead: pStack.Push(new Id(t.lexema)); break; case Token.Type.IdSingle: pStack.Push(new Id(t.lexema)); break; case Token.Type.IdTail: Id before = (Id)pStack.Peek(); before.AddPath(t.lexema); break; case Token.Type.EOS: break; } }
private Token Match(Token.Types excepted) { if (CurrentToken.Type != excepted) { if (excepted == Token.Types.LineTerm) return new Token(Token.Types.LineTerm, CurrentToken.Line, CurrentToken.Column); throw new ParserException(String.Format("Expected {0}, got {1} instead at line {2} column {3}.", excepted, CurrentToken.Type, CurrentToken.Line, CurrentToken.Column)); } Token match = CurrentToken; NextToken(); return match; }
public void Append(Token t) { if (t.type == Token.Type.Operator && t.lexema == "{") { flag = true; newblock = new Opcodes(); } if (flag) { if (t.type == Token.Type.Operator && t.lexema == "}") { flag = false; this.ops.AddLast(newblock); } else newblock.Append(t); } else ops.AddLast(t); }
private BinaryExpr CreateBinaryExpr(Token token = null) { if (token == null) { token = AcceptedToken; } BinaryExpr expr = new BinaryExpr(token.Line, token.Column); switch(token.Type) { case Token.Types.OpPlus: expr.Op = Operator.Plus; break; case Token.Types.OpMinus: expr.Op = Operator.Minus; break; case Token.Types.OpMultiply: expr.Op = Operator.Times; break; case Token.Types.OpDivide: expr.Op = Operator.Divide; break; case Token.Types.OpLess: expr.Op = Operator.Less; break; case Token.Types.OpEquals: expr.Op = Operator.Equals; break; case Token.Types.OpAnd: expr.Op = Operator.And; break; } return expr; }
void BreakCarry(Token.Type with) { if (carryType == Token.Type.EOS) { carryType = with; return; } if (carryType == Token.Type.IdTail && with!=Token.Type.IdTail) carryType = Token.Type.IdEnd; if (carryType == Token.Type.IdHead && with != Token.Type.IdTail) carryType = Token.Type.IdSingle; output.AddLast(new Token(carry, carryType)); carry = ""; carryType = with; }
private void ReadNextToken() { currentToken = scanner.GetNextToken (); if ((Token.Types)currentToken.Type == Token.Types.ERROR) { throw new LexicalError ("malformed token \"" + currentToken.Lexeme + "\"", currentToken.Row, currentToken.Column); } }
private Token Match(Token.Types type) { if ((Token.Types)currentToken.Type == type) { Token current = currentToken; ReadNextToken (); return current; } throw new SyntaxError ("invalid token " + currentToken.Type + ", expected: " + type, currentToken.Row, currentToken.Column); }
private void NextToken() { CurrentToken = Scanner.GetNextToken(); }
public Parser(Scanner scanner, ErrorHandler errors) { Scanner = scanner; Errors = errors; CurrentToken = Scanner.GetNextToken(); }
void ExcpectFunctionCall(Token t) { if (t.type == Token.Type.IdSingle) { CallFunction(new Id(t.lexema)); exptFuCallFlag = false; } else if (t.type == Token.Type.IdHead) { pStack.Push(new Id(t.lexema)); } else if (t.type == Token.Type.IdTail) { Id before = (Id)pStack.Peek(); before.AddPath(t.lexema); } else if (t.type == Token.Type.IdEnd) { Id before = (Id)pStack.Pop(); before.AddPath(t.lexema); CallFunction(before); exptFuCallFlag = false; } else throw new Exception("invalid function call"); }
public Token(string lexema, Token.Type type) { this.type = type; this.lexema = lexema; }
public Node(Token token) { Name = token.Lexeme; Row = token.Row; Column = token.Column; }