#include<stdio.h>
int main()
{
int a,b;
a=a+b;
printf("%d",a);
return 0;
}
what should be the output if this code is passed through a lexer
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
the lexer just tokenizes the stream to turn a stream of characters into a stream of tokens (that will be parsed with a parser later to obtain a full syntax tree). For your example you would obtain something like:
Of course a lexer by itself can’t do much, it can just split the source into smallest elements possible, checking for syntax errors (like misspelled keywords). You will need something that will combine them to give them a semantic meaning.
Just a side note: some lexers like to group similar kinds of tokens in just one (for example a
KEYWORDtoken that contains all keywords) using a parameter associated with it, while others have a different token for every one likeRETURN_KEYWORK,IF_KEYWORDand so on..