2015-07-19 89 views
0

這是使用GNAT IDE的Ada 2012。我在'Ada'程序中收到'value:error'的錯誤輸入

我想測試我的項目,我收到以下錯誤

bad input for 'Value: "x   " 

作爲唯一輸出到控制檯。我認爲這個問題來自這個功能;

function get_next_id(lex: in out Lexical_Analyzer) return Id is 
    tok: Token := get_lookahead_token(lex); 
    tok_type: Token_Type := get_token_type(tok); 
    theId: Id; 
begin 
    match(tok, ID_TOK); 
    get_next_token(lex, tok); 
    theId := create_id(Character'Value(String(get_lexeme(tok)))); -- Problem caused here? 
    return theId; 
end get_next_id; 

我認爲這是導致我的問題,這似乎是試圖把X和下面的白色空間轉換。我如何才能讀取第一個元素?

+0

索引字符串的? – NWS

回答

2

適當解決方案是使用長度的子串1.

declare 
    S : constant String := Get_Lexeme (Tok); 
begin 
    theId := Create_Id (S (S'First)); 
end; 

使用注意事項「第一而不是假定的第一個字符是在索引1

+0

這解決了這個問題謝謝。 –

相關問題