4.Input Matching in lex


BASIC PRINCIPLES.
(1) When the generated scanner is run, it analyses its input looking for strings which match any of its patterns.
(2) If the current input can be matched by several expressions, then the ambiguity is resolved by the following rules.
     (2.1) The longest match is preferred.
     (2.2) The rule given first is preferred.
(3) Once the match is determined,
    (3.1) the text corresponding to it is available in the global character pointer yytext its length is yyleng and the current line number is yylineno,
    (3.2) and the action corresponding to the matched pattern is then executed,
    (3.3) and then the remaining input is scanned for another match.
Note that yytext can be defined in two different ways: either as a character pointer or as a character array. You can control which definition flex uses by including one of the special directives %pointer or %array in the first (definitions) section of your flex input.

Comments

Popular posts from this blog

KTU Compiler Lab CSL411

13.Precedence and conflict resolution in yacc

1.Introducion to lex/flex