next up previous contents
Next: The Dynamic Structure Up: Syntax and Data Structure Previous: Implementation

The Lexical Analyzer

The lexical analyzer is not a DFA. At the development phase the lex program of the UNIX system was used, but later, the code this system has generated was found to be large in size. Therefore, a hand coded functional equivalent has been substituted. This is the reason why most of the functions have names that are used by the lex+yacc utilities. The hand coded lexical analyzer, is not as fast as a DFA, but the difference in timing is very minor.

The design philosophy of the lexical analyzer is consulting a series of functions each of which are sensible to a certain lexical pattern type. For example, the function isid() is sensible to identifiers. If the current parsing pointer curpos points to a position where an identifier starts, then upon a call to isid() three actions will be taken by this function:

  1. The input string is scanned until the end of the identifier is found.
  2. curpos is advanced to the first unused character.
  3. A return value of 1 is passed back to the caller.
If the pattern that was currently pointed by curpos was not an identifier then a call to isid() would not alter the value of curpos and the return-value would be 0.

The main function of the lexical analyzing process is yylex(), when this function is called, functions like isstring(), isid(), isfpointer(), etc. are called until one of them succeeds (that means return a 1). When this happens the matched pattern is copied into the array yytex by a call to the function storetext(). If the parsed pattern is a delimiter then a global variable delimflag is set to 1.



Gokturk UCOLUK
Fri Nov 1 21:52:13 EET 1996