[go: up one dir, main page]

0% found this document useful (0 votes)
19 views2 pages

Token in C

Uploaded by

gananjay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views2 pages

Token in C

Uploaded by

gananjay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Start

tokens = []

current_position = 0

program = "your C program here"

while current_position < length of program:

char = program[current_position]

if char is letter or '_':

identifier = ""

while char is letter or digit or '_':

identifier += char

current_position++

char = program[current_position]

tokens.append(identifier)

elif char is digit:

number = ""

while char is digit:

number += char

current_position++

char = program[current_position]

tokens.append(number)

elif char is '"':

string = '"'

current_position++

char = program[current_position]

while char != '"':

string += char

current_position++
char = program[current_position]

string += '"'

tokens.append(string)

elif char is operator or special symbol:

tokens.append(char)

current_position++

elif char is whitespace:

current_position++

else:

current_position++

End

You might also like