tutorbin

compiler design homework help

Boost your journey with 24/7 access to skilled experts, offering unmatched compiler design homework help

tutorbin

Trusted by 1.1 M+ Happy Students

WhatsApp Support

Get Instant
Online Homework Help
via WhatsApp

Get instant homework help from top tutors—just a WhatsApp message away. 24/7 hw help support for all your academic needs!

A
S
M
R
★★★★★
2M+ students trust TutorBin
Your WhatsApp Number
phone
or
⚡ Instant reply
🔒 100% private
👨‍🏫 Top tutors
🌍 All subjects
*Get instant homework help from top tutors—just a WhatsApp message away. 24/7 support for all your academic needs!
2M+ Students Helped24/7 Live SupportExpert TutorsAll Subjects CoveredInstant Response100% ConfidentialTop Rated ServiceMoney-back Guarantee2M+ Students Helped24/7 Live SupportExpert TutorsAll Subjects CoveredInstant Response100% ConfidentialTop Rated ServiceMoney-back Guarantee

Recently Asked compiler design Questions

Expert help when you need it
  • Q1: CSE340 Project 1: Lexical Analysis The goal of this project is to give you hands-on experience with lexical analysis. You will extend the provided lexical analyzer to support more token types. The next section lists all new token types that you need to implement. 1. Token Types Modify the lexer to support the following 3 token types: REALNUM NUM DOT digit digit* BASE08NUM ((pdigit8 digit8*) + 0) (x) (08) BASE16NUM = ((pdigit16 digit16*) + 0) (x) (16) Where digit16 pdigit16 digit = 012 + 3 + 4 + 5 + 6 + 7+ = = + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 01 + 2 + 3 + 4 + 5 + 6 + pdigit digit8 pdigit8 = 8+ 9+ A + B + C + D + E + F 9 + A + B + C + D + E + F 7+ 8+ 9 1 + 2 + 3 + 4 + 5 + 6 + 7+ 8+ 9 = = 1 + 2 + 3 + 4 + 5 01 + 2 + 3 + 4 + 5 + 6 + 7 + 6 + 7 Note that NUM and DOT are already defined in the lexer, but here are the regular expressions for the sake of completeness: = NUM DOT = "." (pdigit digit*) + 0 Note that DOT is a single dot character, the quotes are used to avoid ambiguity. The list of valid tokens including the existing tokens in the code would be as follows: IF WHILE DO THEN PRINT PLUS MINUS DIV MULT EQUAL COLON COMMA SEMICOLON LBRACE RBRACE LPAREN RPAREN NOTEQUAL GREATER LESS LTEQ GTEQ DOT NUM ID REALNUM BASE08NUM BASE16NUM This list should be used to determine the token if the input matches more than one regular expression. 2. How-To Follow these steps: • Download the lexer.cc, lexer.h, inputbuf.cc and inputbuf.h files accompanying this project description. Note that these files might be a little different than the code you've seen in class or elsewhere. • Add your code to the files to support the token types listed in the previous section. • Compile your code using GCC compiler in Ubuntu 19.04 or higher. You will need to use the g++ command to compile your code in a terminal window. Note that you are required to compile and test your code in Ubuntu 19.04 or higher using the GCC compilers. You are free to use any IDE or text editor on any platform, however, using tools available in Ubuntu 19.04 g++ version 7.5.0 (or tools that you could install on Ubuntu 19.04 could save time in the development/compile/test cycle. See next section for more details on how to compile using GCC. • Test your code to see if it passes the provided test cases. You will need to extract the test cases from the zip file and run the test script test1.sh. More details on this in the next section. Submit your code in Gradescope before the deadline: For this project you need to update lexer.cc and lexer.h. Since inputbuf.h and inputbuf.cc should not be modified, you do not need to upload them to Gradescope. 3. Compile & Test 3.1 Compiling Code with GCC You should compile your programs with the GCC compilers which are available in g++ 7.5.0 in Ubuntu 19.04. The GCC is a collection of compilers for many programming languages. There are separate commands for compiling C and C++ programs: • Use gcc command to compile C programs Use g++ to compile C++ programs Here is an example of how to compile a simple C++ program: $ g++ test_program.cpp If the compilation is successful, gcc will generate an executable file named a.out in the same folder as the program. You can change the output file name by specifying the -o switch: $ g++ test_program.cpp -o hello.out To enable all warning messages of the GCC compiler, use the -Wall switch: $ g++ -Wall test_program.cpp -o hello.out The same options can be used with gcc to compile C programs. We use c++11 on Gradescope to compile the codes; so to make sure your code compiles correctly on Gradescope, use the following option to compile your code with c++11: $ g++ -std=c++11 -Wall_test_program.cpp -o hello.out Compiling projects with multiple files If your program is written in multiple source files that should be linked together, you can compile and link all files together with one command: $ g++ filel.cpp file2.cpp file3.cpp Or you can compile them separately and then link: $ g++ file1.cpp $ g++ file2.cpp $ g++ file3.cpp $ g++ filel.o file2.0 file3.0 The files with the .o extension are object files but are not executable. They are linked together with the last statement and the final executable will be a.out. NOTE: you can replace g++ with gcc in all examples listed above to compile C programs. 3.2 Testing your code with I/O Redirection Your programs should not explicitly open any file. You can only use the standard input e.g. std::cin in C++, getchar(), scanf() in C and standard output e.g. std::cout in C++, putchar(), printf() in C for input/output. However, this restriction does not limit our ability to feed input to the program from files nor does it mean that we cannot save the output of the program in a file. We use a technique called standard IO redirection to achieve this. Suppose we have an executable program a.out, we can run it by issuing the following command in a terminal (the dollar sign is not part of the command): $ ./a.out If the program expects any input, it waits for it to be typed on the keyboard and any output generated by the program will be displayed on the terminal screen. Now to feed input to the program from a file, we can redirect the standard input to a file: $ ./a.out <input_data.txt Now, the program will not wait for keyboard input, but rather read its input from the specified file. We can redirect the output of the program as well: $ ./a.out output_file.txt In this way, no output will be shown in the terminal window, but rather it will be saved to the specified file. Note that programs have access to another standard interface which is called standard error e.g. std::cerr in C++, fprintf(stderr,...) in C.See Answer
  • Q2:1). show the parse steps for "(00) "for the grammar using LR(1) Goal → List List List Pair | Pair Pair →(Pair) 1()See Answer
  • Q3:1.Three Address Code Three Address Code-4 Translate the following program fragment to 3 address code using T1, T2, ... for temporaries and L1, L2, for labels, and upper case letters for variables /* this computes x^n in log_2(n) steps using the following identities */ q^(2n) = (q^2)^n q^(2n+1)= q (q^2)^n p = 1; q = x; while (n> 0) { // invariant p*q^n is constant at this point in the program if (n%2==0){ n = n/2; q = q*q; } else { n = (n-1)/2; q=q+q; } Translation: P=1 Q=X if false (N>0) goto (L1) L1:/nFlow Graphs -4 Consider the following program in 3 address code. 1) find and label the Basic Blocks 2) draw the Flow graph for this program (ideally using graphviz) and 3) find the loops in this program (as sets of basic blocks) Cut/paste your basic block decomposition below and list of loops below and include a link to a movie where you explain how you decomposed the code into basic blocks and how you created the flow graph, and found the loops, and also show the flow graph. i-m-1 j-n t1=4*n v=a[11] L1: L2: i=i+1 t2=4*1 t3=a[12] if t3<v goto (L1) j-j-1 t4=4*j t5=a[t4] if t5>v goto(L2) if ij goto (L3) +6=4*1 x= a[6] t7=4*1 t8=4*j +9=a[18] a[17]=t9 a[t11]=x goto(L1)/n3. Register Allocation LOAD V R STORE RV Consider the machine language with the following instructions which copies the value in stack location V to register R which copies the value in register R to stack location V which is D D+S where S and D are registers ADD 5 D MUL S D SUB SD which is D = D+S which is DD-S DIV S D which is D = D/S and assume that values V1, V2, V3... are in the stack. You can introduce as many new variables V4, VS,.... Compile the following program into this assembly language using A) 4 registers B) 3 registers C) 2 registers and estimate the time required where an arithmetic operation counts as 1 time step but a LOAD or STORE counts as 18 time steps. V1 = (V1-V2)*(V1+V2) + (V1-V3)+(V1+V3) For example, it could start with LOAD V1 R1 LOAD V2 R2 SUB R2 R1 and end by storing some register value into V1 STORE R1 V Cut/paste your answers below (including the assembly code) and record a short movie explaining how you compiled these expression using only two, three, four registers. Don't give all the details, just explain enough so we know your strategy for each of the three cases and we could follow your strategy for a new problem.See Answer
  • Q4: Problem 1. Consider the list of tokens T1 = { "supper", "abcdle" } T2 = { "abd" } SUPPERID = strings that are ID (see below) and that have “supper” as prefix. For example, “supper123”, “supper”, “supperabc” are SUPPERID, but “supper_” is not SUPPERID because "supper_" is not an ID " " 11 ID = Set of strings that consist of a letter or underscore that is followed by zero or more letters and/or digits. For example, ‘_11”, “_1alb” are IDs, but "_ and "a_" are not IDs according to this definition CRAZYID = Set of strings that consist of an ID followed by "_crazy". For example, "a_crazy" is a CRAZYID, but “a_CRAZY", "acrazy" and "a_crazy" (two underscores) are not a CRAZYID NUM=Set of strings that consist of a non-zero digit that is followed by 1 or more digits or the string "0". For this problem, when identifying tokens in the input, we treat & and ! as separators. This means that getToken() should stop when it reaches & or ! and returns the longest matching prefix up to but not including the separator. The separator itself (& or !) cannot be part of a token, so the next token starts after the separators. & and ! are the only separator. Space characters are not separators for this problem. Consider the input: supper22 crazyabc!!&d1_11&_supper_11&123abcdle and the following sequence of calls: t1 = lexer.GetToken(); t2 = lexer.GetToken(); t3 = lexer.peek(1); t4 = lexer.peek(3); t5 = lexer.peek(5); t6 = lexer.peek(7); t7=lexer.GetToken(); t8 = lexer.GetToken(); What are the values of t1, t2, t3, t4, t5, t6, t7 and t8? You are only asked to give the values and not to explain how you obtained them.See Answer
  • Q5:Problem 2. Compute the FIRST and FOLLOW sets for the following grammar. S -> aAB | CD A -> CD | SE | 8 B -> aSB | AS D -> CDd | & E -> eFg F -> Fg | & Show your work. An answer by itself does not count.See Answer
  • Q6:Problem 3. Consider the grammar A->BCD|DCB B -> b B c | c B | b | & C-+cd|c D -+ d Dc | bC where A, B, C, and D are non-terminal, A is the start symbol and b, c and d are tokens. Remember that & represents the empty sequence. Y -> & means that Y does not have to match any tokens or, equivalently, it matches an empty sequence of tokens. 1. Give a parse tree for the sequence of tokens: bccbccbc 2. Give a another (different) parse tree for the sequence of tokens: bccbccbc 3. Is this grammar ambiguous?See Answer

TutorBin Testimonials

I found TutorBin Compiler Design homework help when I was struggling with complex concepts. Experts provided step-wise explanations and examples to help me understand concepts clearly.

Rick Jordon

5

TutorBin experts resolve your doubts without making you wait for long. Their experts are responsive & available 24/7 whenever you need Compiler Design subject guidance.

Andrea Jacobs

5

I trust TutorBin for assisting me in completing Compiler Design assignments with quality and 100% accuracy. Experts are polite, listen to my problems, and have extensive experience in their domain.

Lilian King

5

I got my Compiler Design homework done on time. My assignment is proofread and edited by professionals. Got zero plagiarism as experts developed my assignment from scratch. Feel relieved and super excited.

Joey Dip

5

TutorBin helping students around the globe

TutorBin believes that distance should never be a barrier to learning. Over 500000+ orders and 100000+ happy customers explain TutorBin has become the name that keeps learning fun in the UK, USA, Canada, Australia, Singapore, and UAE.