2 votes 2 votes printf("Hello); In the statement given above,is there any lexical error or not ? Compiler Design compiler-design lexical-analysis descriptive + – Purvi Agrawal asked Mar 10, 2017 retagged Jun 21, 2022 by Lakshman Bhaiya Purvi Agrawal 1.2k views answer comment Share Follow See 1 comment See all 1 1 comment reply utk0203 commented Mar 10, 2017 reply Follow Share But "Hello -> is not a valid token? 0 votes 0 votes Please log in or register to add a comment.
4 votes 4 votes Yes, there is a lexical error. "Hello); is NOT a valid string literal. nadeshseen answered Sep 4, 2019 nadeshseen comment Share Follow See all 0 reply Please log in or register to add a comment.
1 votes 1 votes The above statement has no Lexical error. If you think about a lexer as a finite state machine that accepts valid input strings, then errors are going to be any input strings that do not result in that finite state machine reaching an accepting state. vishwa ratna answered Mar 10, 2017 vishwa ratna comment Share Follow See all 7 Comments See all 7 7 Comments reply Purvi Agrawal commented Mar 10, 2017 reply Follow Share but printf here does not contain the valid string literal,so can we make a valid dfa for this ? 0 votes 0 votes rude commented Mar 10, 2017 reply Follow Share @Purvi yes but that's a matter of check for Syntax analysis, not the lexical analysis. 0 votes 0 votes Purvi Agrawal commented Mar 10, 2017 reply Follow Share It is definitely a syntax error but I am not able to understand that if lexical analyser work is to produce valid lexemes and this is not a valid lexeme then how can we make a dfa for this and if dfa could not be made then how it is not a lexical error ? 1 votes 1 votes Venkat Sai commented Oct 7, 2017 reply Follow Share @ Purvl Agarwal the dfa for lexical analyser which accepts literals must have a matching " " and if there is no matching end " then this will not end up in an accepting state and hence this will result in LEXICAL ERROR as the dfa will be looping on all the symbols till ; and will be waiting for a end " which it will never find hence no token can be generated for this hence this is a lexical error . 3 votes 3 votes set2018 commented Oct 7, 2017 reply Follow Share Venkat Sai it means it is not a valid token thts why lexical error 1 votes 1 votes Venkat Sai commented Oct 7, 2017 reply Follow Share yeah its not a valid token and hence a lexical error as this continues till the end of the program is considered as the same literal as there is no closing " and this cannot be tokenised 1 votes 1 votes Purvi Agrawal commented Oct 7, 2017 reply Follow Share Okay..Thanku 0 votes 0 votes Please log in or register to add a comment.