Compiler/lexical analyzer: Difference between revisions

Content deleted Content added
Ed Davis (talk | contribs)
m Better regular expressions for character and string literals.
Ed Davis (talk | contribs)
m Updated definition of whitespace.
Line 96: Line 96:


;White space
;White space

* Zero or more whitespace characters or comments are allowed between any two tokens, with the exceptions noted below.
* "longest token matching" is used to resolve conflicts (e.g., in order to match '''<=''' as a single token rather than the two tokens '''<''' and '''=''').
* Whitespace is only required in the following situations:
** To distinguish between keywords:
*** ifprint - is recognized as an identifier, instead of the keywords '''if''' and '''print'''.
** To distinguish between keywords and integers:
*** 42fred - is an invalid number or invalid identifier.
* Whitespace is not allowed between:
** Multi-character operators: These cannot be recognized unless they occur without embedded whitespace: '''&&''' '''<='''.


The following programs are equivalent:
The following programs are equivalent:
Line 512: Line 522:
}
}
</lang>
</lang>



Output from test case 3:
Output from test case 3:
Line 547: Line 556:
</pre>
</pre>
</b>
</b>



=={{header|Euphoria}}==
=={{header|Euphoria}}==
Line 798: Line 806:
</pre>
</pre>
</b>
</b>



=={{header|Flex}}==
=={{header|Flex}}==