zl90 / Cornell-CS4120

I'm taking Cornell University's "Introduction to Compilers" course
5 stars 0 forks source link

Handle broken rules in the flex_input.l file #3

Closed zl90 closed 1 year ago

zl90 commented 1 year ago
zl90 commented 1 year ago

There were three problems with my lex input file:

  1. I wasn't properly escaping the " quotation marks. They need to be escaped in the file like so: \".
  2. I had a general rule for matching "any character": . which simply increments the col_num counter. This rule needs to be defined AFTER all my other rules, or else it seems to override the actions of my other rules.
  3. I wasn't incrementing col_num properly. To do that, I needed to access the flex variable yyleng which represents the length of the matched string. It's used like so: col_num += yyleng;.