12.6 Scanner

The Scanner yylex() is included in the yacc source file miniC.y. We did not use lex or flex to generate the Scanner. The Scanner is comparatively straightforward, but the handling of integer and float constants possibly requires some explanation. An integer may be a prefix in a float value, which makes the scanning somewhat tricky.

The Keywords, Built-in function names and proper variables all are detected as IDentifiers by the Scanner, using the regular expression [a–zA–Z_][a–zA–Z_0–9]*. Before the Scanner becomes active, the initializer function in the source file init.c has already inserted the Keywords and Built-in names in the Symbol Table. Thus, the Scanner is able to separate out variable proper from the Keywords and Built-in ...

Get Compilers: Principles and Practice now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.