User:Ed Davis: Difference between revisions
Content added Content deleted
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
{{task}} |
{{task}}Lexical Analyzer |
||
Lexical Analyzer |
|||
---------------- |
|||
From [https://en.wikipedia.org/wiki/Lexical_analysis Wikipedia] |
From [https://en.wikipedia.org/wiki/Lexical_analysis Wikipedia] |
||
Line 10: | Line 8: | ||
or scanner (though "scanner" is also used to refer to the first stage of a lexer). |
or scanner (though "scanner" is also used to refer to the first stage of a lexer). |
||
;The Task |
|||
Create a lexical analyzer for the Tiny programming language. The |
Create a lexical analyzer for the Tiny programming language. The |
||
Line 16: | Line 14: | ||
output to a file and/or stdout. |
output to a file and/or stdout. |
||
;Specification |
|||
The various token types are denoted below. |
The various token types are denoted below. |
||
;Operators |
|||
{| class="wikitable" |
{| class="wikitable" |
||
Line 47: | Line 45: | ||
|} |
|} |
||
;Symbols |
|||
{| class="wikitable" |
{| class="wikitable" |
||
Line 66: | Line 64: | ||
|} |
|} |
||
;Keywords |
|||
{| class="wikitable" |
{| class="wikitable" |
||
Line 81: | Line 79: | ||
|} |
|} |
||
;Other entities |
|||
{| class="wikitable" |
{| class="wikitable" |
||
Line 103: | Line 101: | ||
'''Comments''' /* ... */ (multi-line) |
'''Comments''' /* ... */ (multi-line) |
||
;Complete list of token names |
|||
'''EOI, Print, Putc, If, While, Lbrace, Rbrace, Lparen, Rparen, Uminus, Mul, Div, Add, Sub, Lss, Gtr, Leq, Neq, And, Semi, Comma, Assign, Integerk, Stringk, Ident''' |
'''EOI, Print, Putc, If, While, Lbrace, Rbrace, Lparen, Rparen, Uminus, Mul, Div, Add, Sub, Lss, Gtr, Leq, Neq, And, Semi, Comma, Assign, Integerk, Stringk, Ident''' |
||
;Program output |
|||
Output of the program should be the line and column where the |
Output of the program should be the line and column where the |
||
Line 114: | Line 112: | ||
should follow. |
should follow. |
||
;Test Cases |
|||
<lang c> |
<lang c> |
||
Line 123: | Line 121: | ||
</lang> |
</lang> |
||
;Output |
|||
{| class="wikitable" |
{| class="wikitable" |
||
Line 148: | Line 146: | ||
</lang> |
</lang> |
||
;Output |
|||
{| class="wikitable" |
{| class="wikitable" |
||
Line 177: | Line 175: | ||
|} |
|} |
||
;Diagnostics |
|||
The following error conditions should be caught: |
The following error conditions should be caught: |
||