Starting from:
$35

$29

Project #1 Solution




Hand-in Policy: Source code should be handed in via Moodle with file name “student_id.cl”. No late submission will be accepted.




Collaboration Policy: No collaboration is permitted. Any cheating (copying someone else’s work in any form) will result in a grade of -100 for the first offense and -200 for the subsequent ones. Grading: Each project will be graded on the scale 100.










G++ Language Lexer (100 points): Given the description of the G++ language (G++Syntax.pdf) you are asked to implement the lexer that does the tokenization of a given G++ program in a file.




You are expected to submit the file “student_id.cl” with a function called “lexer”. This function should




take a file name and perform lexical analysis of the program contained within this file. The output of




the function should be the tokens in a list. Sample input and output is provided below.




Sample Input:
Sample Output: (There may be mistake(s))




(deffun sumup (x)
(("operator" "(") ("keyword" "deffun")
(if (equal x 0)
("identifier" "sumup") ("operator" "(")
1
("identifier" "x") ("operator" ")") ("operator"
(+ x (sumup (- x 1)))
"(") ("keyword" "if") ("operator" "(") ("keyword"
)
"equal") ("identifier" "x") ("integer" "0")
)
("operator" ")") ("integer" "1") ("operator" "(")


("operator" "+") ("identifier" "x") ("operator"


"(") ("identifier" "sumup") ("operator" "(")


("operator" "-") ("identifier" "x") ("integer" "1")


("operator" ")") ("operator" ")") ("operator" ")")


("operator" ")") ("operator" ")")



Grading: Full score would require the lexer code to implement the proper regular expression or DFA for identifiers as well as integer values. You may not use available Common Lisp code for regular expression finding. 20 points will be taken away for those not implementing a proper DFA or regular expression reader. There are important points regarding to grading. You should be careful about these.




Missing lexer function



The lexer function with less or more arguments



Reading from file



Output format



No output/output not in list



Wrong/missing lexical analysis



Wrong/missing tokenizing



Wrong/missing order of tokens



Syntax/runtime error of any kind (0 points)

More products