User:Ed Davis: Difference between revisions
no edit summary
No edit summary |
No edit summary |
||
Line 10:
or scanner (though "scanner" is also used to refer to the first stage of a lexer).
Create a lexical analyzer for the Tiny programming language. The
program should read input from a file and/or stdin, and write
output to a file and/or stdout.
===Operators===
{| class="wikitable"
Line 43 ⟶ 45:
|}
===Symbols===
{| class="wikitable"
Line 61 ⟶ 63:
| ',' || comma || Comma
|}
===Keywords===
{| class="wikitable"▼
|-▼
! Characters !! Name▼
|-▼
| "if" || If▼
|-▼
| "while" || While▼
|-▼
| "print" || Print▼
|-▼
| "putc" || Putc▼
|}▼
===Other entities===
{| class="wikitable"
Line 74 ⟶ 93:
| string literal || ".*" || String
|}
Notes: For char literals, '\n' is supported as a new line
Line 81 ⟶ 99:
supported.
▲{| class="wikitable"
▲|-
Assign, Integerk, Stringk, Ident'''
▲! Characters !! Name
▲|-
▲| "if" || If
▲|-
▲| "while" || While
▲|-
▲| "print" || Print
▲|-
▲| "putc" || Putc
▲|}
===Program output===
▲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
Output of the program should be the line and column where the
Line 109 ⟶ 114:
should follow.
===Test Cases===▼
▲Test Cases
<lang c>
Line 120 ⟶ 123:
</lang>
===Output===
{| class="wikitable"
Line 146 ⟶ 148:
</lang>
===Output===
{| class="wikitable"
Line 176 ⟶ 177:
|}
===Diagnostics
The following error conditions should be caught:
* Empty character constant. Example: ''
* Unknown escape sequence. Example: '\r'
* Multi-character constant. Example: 'xx'
* End-of-file in comment. Closing comment characters not found.
* End-of-file while scanning string literal. Closing string character not found.
* End-of-line while scanning string literal. Closing string character not found before end-of-line.
* Unrecognized character. Example: |
Refer additional questions to the C and Python implementations.
|