Talk:Compiler/lexical analyzer: Difference between revisions

Content added Content deleted
(new section →‎Token Names)
Line 120: Line 120:
</ol>
</ol>
--[[User:Smls|Smls]] ([[User talk:Smls|talk]]) 16:35, 15 August 2016 (UTC)
--[[User:Smls|Smls]] ([[User talk:Smls|talk]]) 16:35, 15 August 2016 (UTC)

==Token names==

Some more bikeshedding. I hope you don't mind it - it's just that once the task goes out of draft status and gets many solutions, it will be very annoying to make changes, so now is the time to get it in as good a shape as possible.

What caught my eye regarding the token names is, that the extensive use of uncommon abbreviations makes them less "user-friendly" to deal with than they could be. For this task, itself, it doesn't matter too much, but when it gets to syntax analysis, I image people who will try to write solutions will find themselves saying like "Huh, 'Lss Ident Semi', what tokens were those again?" and having to look it up. How would you feel about renaming them to the following slightly more verbose but friendlier names?

{| class="wikitable" style="display:inline-table"
|-
! Old !! New
|-
| <tt>Mul</tt> || <tt>OP_MULTIPLY</tt>
|-
| <tt>Div</tt> || <tt>OP_DIVIDE</tt>
|-
| <tt>Add</tt> || <tt>OP_ADD</tt>
|-
| <tt>Sub</tt> || <tt>OP_SUBTRACT</tt>
|-
| <tt>Lss</tt> || <tt>OP_LESSEQUAL</tt>
|-
| <tt>Leq</tt> || <tt>OP_LESS</tt>
|-
| <tt>Gtr</tt> || <tt>OP_GREATER</tt>
|-
| <tt>Neq</tt> || <tt>OP_NOTEQUAL</tt>
|-
| <tt>Assign</tt> || <tt>OP_ASSIGN</tt>
|-
| <tt>And</tt> || <tt>OP_AND</tt>
|}

{| class="wikitable" style="display:inline-table"
|-
! Old !! New
|-
| <tt>If</tt> || <tt>KEYWORD_IF</tt>
|-
| <tt>While</tt> || <tt>KEYWORD_WHILE</tt>
|-
| <tt>Print</tt> || <tt>KEYWORD_PRINT</tt>
|-
| <tt>Putc</tt> || <tt>KEYWORD_PUTC</tt>
|}

{| class="wikitable" style="display:inline-table"
|-
! Old !! New
|-
| <tt>Lparen</tt> || <tt>LEFTPAREN</tt>
|-
| <tt>Rparen</tt> || <tt>RIGHTPAREN</tt>
|-
| <tt>Lbrace</tt> || <tt>LEFTBRACE</tt>
|-
| <tt>Rbrace</tt> || <tt>RIGHTBRACE</tt>
|-
| <tt>Semi</tt> || <tt>SEMICOLON</tt>
|-
| <tt>Comma</tt> || <tt>COMMA</tt>
|}

{| class="wikitable" style="display:inline-table"
|-
! Old !! New
|-
| <tt>Ident</tt> || <tt>IDENTIFIER</tt>
|-
| <tt>Integer</tt> || <tt>INTEGER</tt>
|-
| <tt>String</tt> || <tt>STRING</tt>
|}
--[[User:Smls|Smls]] ([[User talk:Smls|talk]]) 17:04, 15 August 2016 (UTC)