public void WhenWeTokenize() { Token currentToken = _lexer.GetNextToken(); while (currentToken.Type != TokenType.EOF) { _tokenList.Add(currentToken); currentToken = _lexer.GetNextToken(); } _tokenList.Add(currentToken); }
public void Parse() { _currentToken = _lexer.GetNextToken(); E(); if (_currentToken.Type != TokenTypes.Eof) { throw new SyntaxException("Se esperaba EOF"); } }
public Parser(Lexer.Lexer lexer) { _lexer = lexer; _token = _lexer.GetNextToken(); }
public void NextToken() { _token = _lexer.GetNextToken(); }
private SentenceNode Sentence() { if (currentToken.Type == TokenTypes.Int || currentToken.Type == TokenTypes.String) { var type = currentToken.Type; currentToken = lexer.GetNextToken(); if (currentToken.Type == TokenTypes.Id) { string name = currentToken.Lexeme; currentToken = lexer.GetNextToken(); var dimensions = Dimensions(); if (currentToken.Type == TokenTypes.Eos) { currentToken = lexer.GetNextToken(); return(new DeclarationNode { Type = type, Value = name, Dimensions = dimensions }); } } } else if (currentToken.Type == TokenTypes.Read) { currentToken = lexer.GetNextToken(); if (currentToken.Type == TokenTypes.Id) { string name = currentToken.Lexeme; currentToken = lexer.GetNextToken(); if (currentToken.Type == TokenTypes.Eos) { currentToken = lexer.GetNextToken(); return(new ReadNode() { Id = name }); } } } else if (currentToken.Type == TokenTypes.Print) { currentToken = lexer.GetNextToken(); var exp = E(); if (currentToken.Type == TokenTypes.Eos) { currentToken = lexer.GetNextToken(); return(new PrintNode { Expression = exp }); } } else if (currentToken.Type == TokenTypes.Id) { var idNode = Id(); if (currentToken.Type == TokenTypes.Equal) { currentToken = lexer.GetNextToken(); var exp = E(); if (currentToken.Type == TokenTypes.Eos) { currentToken = lexer.GetNextToken(); return(new AssignNode { Id = idNode, Expression = exp }); } } else if (currentToken.Type == TokenTypes.Id) { var name = currentToken.Lexeme; currentToken = lexer.GetNextToken(); if (currentToken.Type == TokenTypes.Eos) { currentToken = lexer.GetNextToken(); return(new StructNode { Value = name, StructType = idNode.Value }); } } } else if (currentToken.Type == TokenTypes.Struct) { currentToken = lexer.GetNextToken(); return(DeclareStruct()); } throw new SyntaxErrorException(); }