If it's how to display the name of the token, simply move the name of the token to lexeme when you recognize the token type.
BTW, you have a missing ; at line 12.
PLEASE USE CODE TAGS (the <> formatting button) when posting code. http://v2.cplusplus.com/articles/jEywvCM9/
It makes it easier to read your code and it also makes it easier to respond to your post.
hi, abstractionAnon tanx, here is the question
1. Modify the front.c to include the name of the token/Lexeme after the analysis
2. The analyzer does not accept assignment operation. Expand the analyzer to accept the assignment operation.
here is the given file that contains aritmetic expressions: a=a+b+(c*d)
now i need to include the name of the token/lexeme, then the analyzer should accept assignment operation. because this code thus not accept assignment operation.
this is the incomplete output of this code that we need to modify
Next token is: 11, next lexeme is a
Next token is: -1, next lexeme is =
sample file given that contains arithmetic expressions: (sum+47) / total
the output for this is:
Next token is: 25 Next lexeme is (
Next token is: 11 Next lexeme is sum
Next token is: 21 Next lexeme is +
Next token is: 10 Next lexeme is 47
Next token is: 26 Next lexeme is )
Next token is: 24 Next lexeme is /
Next token is 11 Next lexeme is total
Next token is: -1 Next lexeme is EOF
--------------
now if being modified, and include the name of the token/lexeme the output i need, would be like this:
Next token is: LEFT_PAREN Next lexeme is (
Next token is: IDENT Next lexeme is sum
Next token is: ADD_OP Next lexeme is +
Next token is: INT_LIT Next lexeme is 47
Next token is: RIGHT_PAREN Next lexeme is )
Next token is: DIV_OP Next lexeme is /
Next token is IDENT Next lexeme is total
Next token is: -1 Next lexeme is EOF
i don't think if "-1" need the name of the token. because it is not define at the beginning of the Token codes. thanx
hi, Luke do you have a sample code on how to include the name of the token/lexeme after the analysis?. I already solved my #2 question on how to accept the assignment operation of the lexical analyzer.
here is our File that contains arithmetic operations :
a=a+b+(c*d)
here is the output that we want :
Next token is: IDENT Next lexeme is a
Next token is: ASSIGN_OP Next lexeme is =
Next token is: IDENT Next lexeme is a
Next token is: ADD_OP Next lexeme is +
Next token is: IDENT Next lexeme is b
Next token is: ADD_OP Next lexeme is +
Next token is LEFT_PAREN Next lexeme is (
Next token is: IDENT Next lexeme is c
Next token is: MULT_OP Next lexeme is *
Next token is: IDENT Next lexeme is d
Next token is: RIGHT_PAREN Next lexeme is )
Next token is: INT_LIT Next lexeme is EOF