User:Ed Davis: Difference between revisions

Content added Content deleted
No edit summary
No edit summary
Line 1: Line 1:
From [https://en.wikipedia.org/wiki/Lexical_analysis Wikipedia]

Lexical analysis is the process of converting a sequence of characters (such as in a
Lexical analysis is the process of converting a sequence of characters (such as in a
computer program or web page) into a sequence of tokens (strings with an identified
computer program or web page) into a sequence of tokens (strings with an identified
Line 22: Line 20:
! Characters !! Common name !! Name
! Characters !! Common name !! Name
|-
|-
| '*' || multiply || Mul
| * || multiply || Mul
|-
|-
| '/' || divide || Div
| / || divide || Div
|-
|-
| '+' || plus || Add
| + || plus || Add
|-
|-
| '-' || minus and unary minus || Sub and Uminus
| - || minus and unary minus || Sub and Uminus
|-
|-
| '<' || less than || Lss
| < || less than || Lss
|-
|-
| '<=' || less than or equal || Leq
| <= || less than or equal || Leq
|-
|-
| '>' || greater than || Gtr
| > || greater than || Gtr
|-
|-
| '!=' || not equal || Neq
| != || not equal || Neq
|-
|-
| '=' || assign || Assign
| = || assign || Assign
|-
|-
| '&&' || and || And
| && || and || And
|}
|}


Line 49: Line 47:
! Characters !! Common name !! Name
! Characters !! Common name !! Name
|-
|-
| '(' || left parenthesis || Lparen
| ( || left parenthesis || Lparen
|-
|-
| ')' || right parenthesis || Rparen
| ) || right parenthesis || Rparen
|-
|-
| '{' || left brace || Lbrace
| { || left brace || Lbrace
|-
|-
| '}' || right brace || Rbrace
| } || right brace || Rbrace
|-
|-
| ';' || semi colon || Semi
| ; || semi colon || Semi
|-
|-
| ',' || comma || Comma
| , || comma || Comma
|}
|}


Line 68: Line 66:
! Characters !! Name
! Characters !! Name
|-
|-
| "if" || If
| if || If
|-
|-
| "while" || While
| while || While
|-
|-
| "print" || Print
| print || Print
|-
|-
| "putc" || Putc
| putc || Putc
|}
|}


Line 105: Line 103:
;Program output
;Program output


Output of the program should be the line and column where the
Output of the program should be:

found token starts, followed by the Token name. For tokens
* the word line, followed by:
Integer, Ident and String, the Integer, identifier, or string
* the line number where the token starts, followed by:
should follow.
* the abbreviation col, followed by:
* the column number where the token starts, followed by:
* the token name.
* If the token name is one of Integer, Ident or String, the
actual value of the same should follow.


;Test Cases
;Test Cases
Line 184: Line 187:
* Unrecognized character. Example: |
* Unrecognized character. Example: |


;Reference
Refer additional questions to the C and Python implementations.

The C and Python versions can be considered reference implementations.

;Implementations


=={{header|C}}==
=={{header|C}}==