TRENDING NEWS

POPULAR NEWS

How To Generate This Code From Java Using Three Address Code

Java: Trying the print the grid but shows a memory address?

import java.util.Scanner;
import java.util.Random;
public class GridPractice
{
public static void main(String [] args)
{
Scanner in = new Scanner(System.in);
Random generator = new Random();
int[][]grid;
int size = 0;
System.out.println("Enter size of grid: ");
size = in.nextInt();
grid = new int[size][size];

System.out.println();

for(int row = 0; row < size; row++)
{
for(int col = 0; col < size; col++)
{
grid[row][col] = generator.nextInt(100);
}
}
//System.out.println(grid);
}
}

With System.out.println(grid);, it shows a memory address, if i eliminate it, it shows nothing, how do i make it show a grid, say 2 x 3? thanks.

C/c++ program code for generate 3 address code for a given string/code?

shakir you have several questions up which are obviously homework, you need to explain your question better for us to help. address codes could refer to memory addresses, or maybe your talking about street address in a custom map app? to get teh memroy address for a string you can just use & before the variable to get the memory address. so for a string variabled named username whos value is 'shakir' then just use &username to get the memory address

How do I build a three address code (3AC) generator with a given parser (YACC)?

By 3 address code, I assume you mean something of the form, add target, source 1, source 2, for target = source 1 + source 2.The challenge will likely be that you grammar will likely be structured, so that there are expressions that can nest and they will not each have a separate assignment statement, e.g. you can write ”final = a * b + c * d” and there are a lot of intermediate results, and not just final, For each of those intermediate results, you need to generate a “temporary” address, a place to hold it, while the calculation continues.So, the general solution is to generate a temporary address in a function and return that address as the result on the parser stack, using it in the next expression up. Something like the following,expression: expression '+' expression
{ address = newTempaddress();
emit( ”add”, address, $1, $3 );
$$ = address;
}
Since this looks a lot like a home work problem, I am going to stop here, with the note that I would personally use triples rather than three address code, but the constructs are equivalent and one can easily convert one to the other.

2 Important Java codes that I'm having trouble on.?

Assume we import a text file containing the text of the address:

1.) An array[] words contains each word of the Gettysburg Address. Determine how many words have 1 letter, 2 letters, 3 letters, etc. The largest word is 14 letters. Print out a table of possible word lengths and how many words have that lengths.

2.) An array words[] contains each word of the Gettysburg Address. Create another array called vocab[] that contains all of the words that are more than 8 letters long.

If you could, please paste the code here. If not, an explanation on how to do it would be ok. I would like the code itself more because I can analyze and understand much more easily.

Thanks you for your help.

Can we make a new programming language in Java? How?

Yes sure you can.You can use any language infact to create any other language .But for that you need to have fundamental knowledge of compilers and Automata Theory .the comes design of programming languages and once you fixup on that , then comes to writing “The Compiler” part.Every compiler should have 7 subsystem and it need to be implemented.You can use java as you asked.1. Lexical analysis - Take a program and tokenize it.Check for proper valid keywords and similar things based on language specifications.2. Syntax analysis - Check if syntax is correct3. Semantic analysis- Check if meaning of program and statements comply to your langauage rules.4. Intermediate code generation -Intermediate code generation produces intermediate representations for the source program which are of the following forms:o Postfix notationo Three address codeo Syntax tree5. Code optimization- It results in faster running machine code.Mostly depending on architecture of the system.Here you would need knowledge of assembly language6. Code generation- And then final machine code.For sure you need assembly language here.

How do I design a code for parser?

I have pasted my notes, so it is a little badly formatted :) If any part of isn’t clear, just let me know and I’ll correct it :)-- Sax parser unlike a DOM parser, processes the xml on the fly. So it can be used for processing large XML files-- You can create a sax parser, but the user will have to extend it, to parse his own custom xml structure-- So, the Sax parser will consist of 1. a file reader 2. a tokenizer-- The tokenizer or the class reading it will have to recognize the following events--- start tag, end tag, content, end of document etc. and provide callback methods for handling these events--- i.e. they will be abstract methods in the parser, and will be implemented by the user's sub class of the parser.--- The user's sub class will maintain any state regarding which specific tags have been seen, how are they nested etc.--- This is a "push" model in which the parser's method act as the controller and delegate control to the user methods when events are encountered.--- Alternatively, the parser can be implemented as a "pull model" where an abstraction of the parser is provided to the user method------ this parser object is just like an iterator, and each time the user class invokes a "next" method, you get an event and event type------ Based on the event type = START TAG, END TAG, CONTENT, END OF DOCUMENT etc, the user class can decide what to do--- Which approach is better - depends on how much control needs to be given to the user once the data has been read from the file and buffered.

Can somebody write me some pseudo-code for a 2D array Java Nim Project?

if you want an n*m array,with indices that start from zero, allocate a vector with n*m elements. e.g. for a 3 by 7 array, that would be 21 elements numbered 0...20. To access element (i, j) in that array (e.g. in a getter or setter routine, you could first check to make sure i & j are each within bounds. That is i>=0 and i=0 and j

How do I build an expression parser that looks at a piece of code and ensures that the code has balanced parentheses and balanced square brackets?

If you want to check only for balanced parantheses and square brackets use STACK.move from left to right and do the following- If you encounter a opening bracket push it on the stack.If it is closing bracket then-1. If the stack is empty then expression is not balanced.2. If the top element of stack is opening bracket of the different type         then expression is not balanced.3. If the top element of stack is opening bracket of the same type then       pop the top element of the stack.If it is another variable ignore it.If you reach end of the expression-1. If stack is not empty then expression is not balanced.2. If stack is empty then expression is valid.Go to step 1.

TRENDING NEWS