0% found this document useful (0 votes)
3 views

CC Assignment-1

The document outlines the compilation process of a Java program, detailing steps from writing source code to execution via the Java Virtual Machine. It also explains the roles of Lex and Yacc in compiler construction, with Lex handling lexical analysis and Yacc managing syntactic analysis. Additionally, it provides regular expressions for defining various literals in the C programming language, including integer, floating-point, character, and string literals.

Uploaded by

vansh4835
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

CC Assignment-1

The document outlines the compilation process of a Java program, detailing steps from writing source code to execution via the Java Virtual Machine. It also explains the roles of Lex and Yacc in compiler construction, with Lex handling lexical analysis and Yacc managing syntactic analysis. Additionally, it provides regular expressions for defining various literals in the C programming language, including integer, floating-point, character, and string literals.

Uploaded by

vansh4835
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

1. Discuss the compilation process of a Java program in detail.

Sol-: An application written in Java must go through multiple steps of compilation. Here's
a quick rundown:

1. Writing Java Source Code: Using a text editor or an Integrated Development


Environment (IDE), the process begins with writing the Java source code.

2. Compiling the Code: The Java compiler (javac) is used to build the Java source
code, resulting in bytecode (.class files).

3. Java Virtual Machine (JVM) and Bytecode: The machine cannot execute the
intermediate binary code that is created as bytecode directly. It is understood by the
Java Virtual Machine (JVM), which comprises a Java interpreter that transforms the
bytecode to the target computer machine code.

4.Execution: When the programme runs, the just-in-time (JIT) compiler transforms
the program's bytecode into machine code, which is subsequently executed.
The Java compilation process is run in two stages: first, in a virtual machine (JVM)
tailored for each operating system, and subsequently, through an OS-independent
compiler.

2. Write Short note on LEX & YACC

Lex (LEXical analyzer generator):


Lex generates lexical analyzers, which are parts of compilers that separate input into tokens.
With a set of regular expressions as input, Lex creates a C programme that searches for
patterns in the input and executes commands when one is detected. Usually, the resulting C
programme is utilised by a compiler's lexical analyzer.

Using regular expressions to specify patterns and assigning actions to each pattern are
standard workflow steps. After that, Lex creates a programme that goes through the input,
finds these patterns, and starts the related processes. To create full compilers, Lex is
frequently used in conjunction with Yacc (Yet Another Compiler Compiler).

Yacc (Yet Another Compiler Compiler):


One tool for creating parsers is called Yacc. A parser examines a program's syntax and breaks
it down into an easily processed hierarchical structure. Yacc creates a C parser given an input
formal grammar. It is frequently used in tandem with Lex, where Yacc does syntactic analysis
and Lex handles lexical analysis.

The syntax of the computer language is described by a context-free grammar that is defined
by the programmer in Yacc. The formation of various language constructions and their
relationships are outlined in the grammar rules. A parser that can identify the linguistic
constructions specified by the grammar is produced by Yacc.
Combining Yacc and Lex gives developers a strong toolkit for creating interpreters and
compilers. Tokenization and lexical analysis are handled by Lex, and syntactic analysis is
handled by Yacc. When combined, they make it easier to create compilers for programming
languages by streamlining the process of producing the parts required to process the source
code.

3. Construct a DFA for the following language over given alphabets and find its regular
expression.

A. L= { an bm c k|n , m, k ≥ 1}

B. L= {na ( w ) mod 2=0∧nb ( w ) mod 3=0|where

' ' w
n a ( w )∧n b ( w ) is a number of a s∧no . of b s∈ ={a , b }}
Σ
a b c

→ q₀ ────→ qₐ ────→ qₐ

│ │ │

↓ ↓ ↓

q₃ ────→ qₙ⁺¹ ────→ qₙ⁺¹

│ │ │

└─────── ──────── ─┘

5. Write regular expression for defining literals in C language.


Integer Literals:

Integer literals in C can be represented in decimal, octal, or hexadecimal format.


Decimal: [0-9]+
Octal: 0[0-7]+
Hexadecimal: 0[xX][0-9a-fA-F]+
The combined regular expression for integer literals in C is:
Floating-Point Literals:

Floating-point literals in C can be represented in various forms, such as 1.0, 1e10, etc.
[0-9]*\.[0-9]+([eE][-+]?[0-9]+)?
This regular expression covers decimal points and the optional exponent part.
Character Literals:

Character literals are enclosed in single quotes, and they can represent a single character.
\'([^\']|(\\[\'"\\nrtbf0]))\'
This regular expression allows for escape sequences like \', \", \\, \n, \r, \t, \b, and \f.

String literals are enclosed in double quotes and can represent a sequence of characters.
\"([^\"]|(\\[\'"\\nrtbf0]))*\"
This regular expression allows for escape sequences similar to character literals.

You might also like