Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

CS 401/501 Exam: Tokens vs Lexemes, RegEx, BNF Grammar, Parsing & Attribute Grammar, Exams of Programming Languages

Sample questions for an exam in computer science, covering topics such as the difference between tokens and lexemes, regular expressions, bnf grammar, parsing, and attribute grammar. Questions include explaining the difference between tokens and lexemes, identifying lexemes that match regular expressions, writing a bnf grammar for a simple language, performing left factoring, writing a recursive descent parser, and using attribute grammar.

Typology: Exams

2009/2010

Uploaded on 04/12/2010

koofers-user-hd0
koofers-user-hd0 🇺🇸

10 documents

1 / 2

Toggle sidebar

Related documents


Partial preview of the text

Download CS 401/501 Exam: Tokens vs Lexemes, RegEx, BNF Grammar, Parsing & Attribute Grammar and more Exams Programming Languages in PDF only on Docsity! CS 401/501 EXAM #1 SAMPLE QUESTIONS 1. Explain the difference between a token and a lexeme. (5%) 2. For each regular expression below provide a brief description what kind of lexemes are going to match with a pattern and provide some examples of lexemes (at least 3). [pr]?ink [a-z][a-z0-9]* [1-9][0-9][0-9] /\*[^\*]+\*/ ([a-c][0-9])+ (10%) 3. Write a BNF grammar for a language, in which programs always start with the keyword “print” followed by arithmetic expression (+ or -). The later is optionally followed by a declaration part, starting with the keyword “where” and a list of pairs “id=num” which are separated with “,”. Few examples: print 10 print a+10 where a=1 print a+b-c where a=2, b=4, c=21 (20%) 4. Perform left factoring on the production B ::= spring A | spring num C (5%) 5. Write a recursive descent parser for the following LL(1) grammar. Assume the existence of a scanning procedure GET_TOKEN which sets a global string variable TOKEN to the token type of the next token. P ::= D begin S end D ::= var V V::= T V | ε T ::= int id ; | real id ; S ::= id := num S | ε Draw a parse tree for the sentence: var int i; int j; begin end (25+5%) 6. Write an attribute grammar for a following grammar: Eq ::= Sum = Sum Sum ::= Prod AddOp Sum | Prod Prod ::= Fact MulOp Prod | Fact Fact ::= ( Sum ) | num AddOp ::= + | - MulOp ::= * | /
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved