Jump to content

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).
 
;==The Task==
 
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.
 
;==Specification==
 
===Operators===
operators:
 
{| class="wikitable"
Line 43 ⟶ 45:
|}
 
===Symbols===
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.
 
comments:'''Comments''' /* ... */ (multi-line)
 
====Complete list of token names:====
keywords:
 
'''EOI, Print, Putc, If, While, Lbrace, Rbrace, Lparen, Rparen, Uminus, Mul, Div, Add,
{| class="wikitable"
Uminus, Mul, Div, Add, Sub, Lss, Gtr, Leq, Neq, And, Semi, Comma, Assign, Integerk, Stringk, Ident
|-
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.
155

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.