Note: The question needs to be answered in "C Programming Languange ". And after the question find 3 pages for needed informations.
1
i. Save your program under the extension ".l" l stands for lex
the next command to be executed is " flex <programname.l>
for example if your program name is sample.l
then execute flex sample.l
this will create a file lex.yy.c
As the extension indicates it is a 'C ' file
To compile lex.yy.c type gcc lex.yy.c
to run the program ./a.out
ii) rule number 2 is for identifiers it should start with alphabet followed by any number of alphabets or digits
r3- for exponential number with optional sign bit. we can have negative numbers
r4 is for integers with optional negative sign
r5 is for hexadecimal number
r6 is for binary number in the format 0101,1010 but without any decimal point
iii)
%option noyywrap
%{
#include<stdio.h>
%}
%%
[0-9]
{printf("Valid Identifier");}
-?[0-9]+(\.[0-9]+)?([eE][+|-]?[0-9]+)?
{printf("Valid
exponent");}
[0-9a-fA-F]+[hH] {printf("hex
number");}
[01]\.?[01]*[bB]
{printf("binary");}
-?[0-9]+
{printf("number");}
[\t\n]
;
%%
int main ()
{
int tcode;
do{
tcode= yylex();
printf("enter the value");
printf ("token type %d \"%s\"\n", tcode, yytext);
} while(tcode);
}
rule for binary has been slightly modified to include '.'
when the input is 1.1b1.10b245hi
what we get is binary binary hex
Note: The question needs to be answered in "C Programming Languange ". And after the question fin...
SUBROUTINES Example 2: May 2006 Question 2 The main program uses a subroutine located at address 3000,- Read the program and answer the following questions. (a) What is the address of the instruction DCR E in the main program?[3 marks] (b) What instructions need to be written in the subroutine and give the address of the instructions? [3 marks] List the contents of the stack, the PC, and the stack pointer after (i) Execution of CALL instruction in the main...
LC-3 Programming Help!! The Stack Protocol The following outline is the protocol for passing arguments to a function and returning values. Everything is stored on the runtime stack so that space is used only when the function is executing. As a result the actual address of arguments and locals may change from call to call. However, the layout of the stack frame (activation record) is constant. Thus, the offests from the frame pointer (FP) to the parameters/locals are constant. All...
Subroutines in MIPS Determines the minimum of two integers Functions within the MIPS slides describe how one can use subroutines (also called procedures, functions, and methods) in MIPS. Because of the importance of subroutines in modern programming, most hardware designers include mechanisms to help programmers. In a high-level language like C or Java, most of the details of subroutine calling are hidden from the programmer. MIPS has special registers to send information to and from a subroutine. The registers $a0,...
In C++ Implement a queue data structure using two stacks. Remember a queue has enqueue and dequeue functions. You could use either the array or linked list implementation for stacks and queues. Source for stack array: --------------------------------------------------- #include<iostream> #define SIZE 100 #define NO_ELEMENT -999999 using namespace std; class Stack { int arr[SIZE]; // array to store Stack elements int top; public: Stack() { top = -1; } void push(int); // push an element into Stack int pop(); // pop the...
Need help about C PROGRAMMING,, pls use only C LANGUAGE.., yea so im doing this exercise as a practice for c programming, could someone do this as well so i could compare if my code makes makes sense and to see and help correct the errors im getting right now.. Any helpful help would be appreciated.. Pointers &Pointer arithmetic Memory allocation and freeing Main topics: Exercise This lab is designed to give you practice working with pointers and memory allocation...
C++ Please ensure code is fully working, will rate Question to be answered: Repeat Exercise 1 for the class linkedStackType question one: Two stacks of the same type are the same if they have the same number of elements and their elements at the corresponding positions are the same. Overload the relational operator == for the class stackType that returns true if two stacks of the same type are the same, false otherwise. Also, write the definition...
C++ Create an array-based implementation of a stack. Each element of the stack should store a string. The stack class should include 3 private member variables (maximum stack size, top of the stack index, and a pointer to the array that holds the stack elements). Public member methods should include a constructor (with an argument of stack maximum size that is used to create a dynamic array), a destructor (that deletes the dynamic array), a push method (argument is a...
LC3 stack (factorial) I need help in writing factorial in Lc3 language by using stack.. ; Begin reserved section: do not change ANYTHING in reserved section! .ORIG x3000 BR Main ; Parameter and result Param .FILL x0004 Result .BLKW 1 ; Constants Stack .FILL x4000 One .FILL #1 MinusOne .FILL #-1 ; End reserved section: do not change ANYTHING in reserved section! ;------------------------------------------------------------------------------- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; int Factorial(int N) ; Returns N! (must be a recursive function) ; Factorial ;__________________...
HI USING C++ CAN YOU PLEASE PROGRAM THIS ASSIGNMENT AND ADD COMMENTS: stackARRAY: #include<iostream> #define SIZE 100 #define NO_ELEMENT -999999 using namespace std; class Stack { int arr[SIZE]; // array to store Stack elements int top; public: Stack() { top = -1; } void push(int); // push an element into Stack int pop(); // pop the top element from Stack int topElement(); // get the top element void display(); // display Stack elements from top to bottom }; void Stack...
QUESTION: ADT stack: resizable array-based implementation for Ch4 programming problem 4 "maintain the stacks's top entry at the end of the array" at array index N-1 where the array is currently allocated to hold up to N entries. MAKE SURE YOU IMPLEMENT the functions: bool isEmpty() const; bool push(const ItemType& newEntry); bool pop(); in ArrayStackP4.cpp //FILE StackInterface.h #ifndef STACK_INTERFACE_ #define STACK_INTERFACE_ template<class ItemType> class StackInterface { public: /** Sees whether this stack is empty. @return True if the...