hws/hw06.tex
changeset 898 5075b69142d9
parent 894 4d5058706f1b
child 916 2ab96407f350
equal deleted inserted replaced
897:8074a1abb928 898:5075b69142d9
    66 \item Parser combinators can directly be given a string as
    66 \item Parser combinators can directly be given a string as
    67       input, without the need of a lexer. What are the
    67       input, without the need of a lexer. What are the
    68       advantages to first lex a string and then feed a
    68       advantages to first lex a string and then feed a
    69       sequence of tokens as input to the parser?
    69       sequence of tokens as input to the parser?
    70 
    70 
       
    71 % Reason 1 you can filter out whitespaces and comments, which makes the grammar rules simpler. If you have to make sure that a whitespace comes after a variable say, then your parser rule for variables  gets more complicated. Same with comments which do not contribute anything to the parser tree.
       
    72 % Reason 2) The lexer can already classify tokens, for example as numbers, keywords or identifiers. This again makes the grammar rules more deterministic and as a result faster to parse.
       
    73 % The point is that parser combinators can be used to process strings, but in case of compilers where whitespaces and comments need to be filtered out, the lexing phase is actually quite useful.
       
    74 
       
    75       
    71 \item The injection function for sequence regular expressions is defined
    76 \item The injection function for sequence regular expressions is defined
    72       by three clauses:
    77       by three clauses:
    73 
    78 
    74 \begin{center}
    79 \begin{center}
    75 \begin{tabular}{l@{\hspace{1mm}}c@{\hspace{1mm}}l}
    80 \begin{tabular}{l@{\hspace{1mm}}c@{\hspace{1mm}}l}