9

What is the meaning of yytext[0]? And why should we use in the lex and yacc program? I'm learner so don't mind if it is a silly question.

Brian
  • 3,850
  • 3
  • 21
  • 37
sandy
  • 149
  • 1
  • 2
  • 8

1 Answers1

13

yytext holds the text matched by the current token. So yytext[0] holds the first character of the text matched by the current token. Sometimes you have a rule which can match different texts so you need to get the real text matched like for variable names or you have a rule to match all arithmetic operations.

A good source is the Flex manual.

For beginners the best starting point is trying the sample projects.

rici
  • 234,347
  • 28
  • 237
  • 341
H. Idden
  • 403
  • 3
  • 7