READING AND WRITING FROM A FILE(WRITTEN IN ANOTHER LANGUAGE)

# Comment
INTEGER Declares integer type variable
STRING Declares string type variable
LET Assigns a variable
CALCULATE Performs an arithmetic calculation
PRINT Writes data to the console
PRINTLN As print, but followed by a new line
END Terminates the program
Each line of the program must begin with one of these words, and the language should not be case sensitive.
Tim Brailsford, 2007
G64ICP
COMMENT
Any line beginning with the # character is completely ignored.
Example:
# ignore this line!
INTEGER
The INTEGER reserved word declares an Integer variable, and assigns a default value of 0 to it.
Example:
INTEGER myInt
This example is equivalent to the Java statment "int myInt=0;"
STRING
The STRING reserved word declares a String variable, and assigns an empty string to it.
Example:
STRING myString
This is equivalent to the Java statement "String myString;"
LET
This assigns values to variables (either integers, or strings enclosed
in double quotes).
Examples:
LET myInt=42
LET myString="Hello World!"
CALCULATE
This performs numeric calculations upon values or variables, and assigns the result to a variable (which must have
been declared earlier). Four operators are supported: + *
and / (for addition, subtraction multiplication and
integer division respectively).
Examples:
CALCULATE myInt=2*2
CALCULATE myInt=myInt+24
CALCULATE myInt=intA/intB
PRINT and PRINTLN
These words both print to the console the
only difference being that PRINTLN appends a new line (as does
System.out.println in Java). These can print either text provided as an argument, or variables (string or integer).
Examples:
PRINTLN "Hello World!"
PRINT myString
PRINTLN myInt
END
This terminates the program, and prints a message to that effect.
TPL Example
To the left is an example TPL input file , to
calculate the factorial of 5. This should produce
an output similar to that shown overleaf (except
that calculates the factorial of 10).
# A TPL Program to calculate the factorial of 5
INTEGER myInt
INTEGER factorial
STRING myString
LET mystring="Factorial Program"
LET myInt=5
CALCULATE factorial=myInt*4
CALCULATE factorial=factorial*3
CALCULATE factorial=factorial*2
Tim Brailsford, 2007
G64ICP
PRINTLN mystring
PRINTLN
PRINT "The factorial of "
PRINT myInt
PRINT " is "
PRINTLN factorial
END
Documentation
Document your code by writing instructions explaining how to run it, listing all of the files you have submitted,
and specifying any limitations (eg you might want to say what platforms you would expect it to run on, and what
platforms you have tested it on). This document should be written as a plain text file (ie ASCII � MS Word binary
files are not acceptable) � and this file should be called README.TXT. This file should constitute the user
manual of your program, and should explain exactly how to use your program.
The README file should be the user manual for your language as implemented.
NB:
I want it to read values from the file as given above and execute the answer in the command prompt( as intented in the file above)
Thanks
Alam Ikenna

Hai I have one doubt in doing other peoples homework for them. Why bother?

Similar Messages

  • Reading and writing from a file

    I am trying to read and write to a file so that I may store an array of string and a double in my application, but I have come upon a couple of problems; first when I put my file path into the path constant it will say that the file is not there ever though it is (so I have to force the issue and when the application asks for a file I have to browse and add the files), secondly when I run the program and it reads from the file it does not display the strings or doubles immediately instead I have to hit the submit button and than they finally come up, thirdly when I reset my values in the .txt files and put in my string and double and hit submit the array jumps one spot and starts at the index of 1 (array[1])  if anyone can help I would appreciate it a lot.
    here is my code:
    Harold Timmis
    [email protected]
    Orlando,Fl
    *Kudos always welcome
    Solved!
    Go to Solution.
    Attachments:
    testingfileIO.vi ‏30 KB
    double.txt ‏1 KB
    string.txt ‏1 KB

    Harold Timmis wrote:
    I am trying to read and write to a file so that I may store an array of string and a double in my application, but I have come upon a couple of problems; first when I put my file path into the path constant it will say that the file is not there ever though it is (so I have to force the issue and when the application asks for a file I have to browse and add the files),
    I don't see that behavior at all about forcing the issue.  Why are you using Not a Path constants?  Why not turn those constants into controls you put on your front panel?
    secondly when I run the program and it reads from the file it does not display the strings or doubles immediately instead I have to hit the submit button and than they finally come up,
    Put your array indicators before your event structure rather than after.  Think dataflow.  The code pauses at the event structure waiting for an even to fire.  Only when it does (such as hitting the submit button) does the data get written to the array indicators. 
    thirdly when I reset my values in the .txt files and put in my string and double and hit submit the array jumps one spot and starts at the index of 1 (array[1])  if anyone can help I would appreciate it a lot.
    I don't see this behavior either.  How come your double.txt file has names in it, and your string.txt file has doubles in it?

  • Problem on reading and writing from from a *.txt file

    I get Problem on reading and writing from from a *.txt file. The following is the read() method...
    The software said the DataInputStream is depreciated. Can anyone help me please?
    public void read()
        File file = new File("C://Documents and Settings//Charles//My Documents//Brunel//EE2065//Assignment and Lab//Assignment 4 and Lab 4//data.txt");
        FileInputStream in = null;
        String str = "";
        try
          in = new BufferedReader(file);
          //in = new FileInputStream(file);
          for(;;)
            str = new BufferedReader(in).readLine();
            //str = new DataInputStream(in).readLine();
            if(str == null)
              break;
            System.out.print(str);
        in.close();
        catch(IOException e)
            System.err.println("execution error: " +e);
      }

    Thank you for your reply. I have made some change. However, there is an incompetable type found error.
    in = new BufferedReader(new InputStreamReader(in));The following are all of the code.
    public void read()
        File file = new File("C://Documents and Settings//Charles//My Documents//Brunel//EE2065//Assignment and Lab//Assignment 4 and Lab 4//data.txt");
        FileInputStream in = null;
        //BufferedReader in = null;
        String str = "";
        try
          in = new BufferedReader(new InputStreamReader(in));
          //in = new FileInputStream(file);
          for(;;)
            BufferedReader Bstr = new BufferedReader(new InputStreamReader(in));
            //str = new BufferedReader(in).readLine();
            //str = new DataInputStream(in).readLine();
            if(str == null)
              break;
            System.out.print(str);
        in.close();
        catch(IOException e)
            System.err.println("execution error: " +e);

  • Reading and Writing large Excel file using JExcel API

    hi,
    I am using JExcelAPI for reading and writing excel file. My problem is when I read file with 10000 records and 95 columns (file size about 14MB), I got out of memory error and application is crashed. Can anyone tell me is there any way that I can read large file using JExcelAPI throug streams or in any other way. Jakarta POI is also showing this behaviour.
    Thanks and advance

    Sorry when out of memory error is occurred no stack trace is printed as application is crashed. But I will quote some lines taken from JProfiler where this problem is occurred:
              reader = new FileInputStream(new File(filePath));
              workbook = Workbook.getWorkbook(reader);
              *sheeet = workbook.getSheet(0);* // here out of memory error is occured
               JProfiler tree:
    jxl.Workbook.getWorkBook
          jxl.read.biff.File 
                 jxl.read.biff.CompoundFile.getStream
                       jxl.read.biff.CompoundFile.getBigBlockStream Thanks

  • Very slow painting while reading and writing doubles into file

    for 15MB length file i = 7662080
    for 50MB length file i = 12414368
    Part of Code for writing into file follows like this:
    try{
    fos = new FileOutputStream("Angel.txt");
    File f = new File("Angel.txt");
         if(f.length() >=4)
         f.delete();
    fos = new FileOutputStream("Angel.txt");     
    dos = new DataOutputStream(new BufferedOutputStream(fos,1000000));
    int x=0;
    double y_last, y_new;
    for(int j=0 ;j<i ;j++)
    if(some condition)
    y_new = ....;
    try{
    //previously in vectors
    y_last = y_new;
    vect.add(new Line2D.Double(x, y_last, x, y_new)_;
    dos.writeDouble(y_new);
         }catch(Exception e){System.out.println(e);}
    dos.close();
    fos.close();
    x++;
    }catch(Exception excp){System.out.println(excp);}
    part of code for reading from file follows like this:
    public void paint(Graphics g)
    try{
         double y1, y2 =0;               
         Line2D.Double doub;
         raf = new RandomAccessFile("Angel.txt","r");
         dis = new DataInputStream(new BufferedInputStream(new FileInputStream(raf.getFD(),1000000)));
         raf.seek((rect.x*8));
         for (int i = 0/any value; (i < value as per choice); i++)
              g2.setStroke(new BasicStroke(0)); //2
              y1 = y2;
         y2 =dis.readDouble();
              doub=new Line2D.Double(i,y1,i,y2);
              g2.draw(doub);
    dis.close();
         raf.close();
    }catch(Exception excp){System.out.println(excp);}
    I tried using Object Streams but NotSerializable Exception is thrown as Line2D.Double objects
    are not serialized.
    Any idea to make reading and writing into file specially from MB files faster is appreciated.

    Why are you reading in the file in the paint method ?
    Create your data once before painting.
    I think you should explain what is your goal and what behavior you want.
    Denis

  • How to read and write from XL file

    HI ,
    I wanted to read a data from XL file and write a data in XL file by generating a report .Can any body help me out.Many examples are available on discussion forums but when I try to save and run those Vi .I am not able to run Showing error .Please tell what is going wrong as I m having latest labview 8.6 .
    Regards
    Sharmila.karale

    Hi Adnan,
    Here are the examples of Vi which I have downloaded from the forum for my reference
    Regards
    Sharmila.Krale
    Attachments:
    SAVE TO EXCEL.llb ‏128 KB
    excel.llb ‏1618 KB

  • HELP HELP REQUIRED!!!!!! Reading and Writing  from and into a Telnet Window

    Hi,
    I need to read and write into a Telnet window .But the Telnet window is a exe program that is been given by the Windows while installing the OS. Another thing is that I need to read and write into/from the Telnet window at a specific X and Y positions which will be defined in the database . I did searched for a dll of Telnet which can contain some APIs to achieve the task but I was unable to fine one.
    Even if u wont be able to provide me the perfect solution , Please guide me how to read and write from a executable window .
    Any help will be highly appreciated.
    Thanking in Advance.
    Mannu26.

    Hi Guys ,
    Thanks for the comments , atleast I got few but none were of any use to me. If u can Please help me on this topic it will be very kind of you .
    Take Care.
    Manoj.

  • Reading and Writing from a text file at the same time

    I know who to use the Scanner and PrintWriter to read from and write to a .txt file. But these are limited. How can I read and write at the same time? Such as open a file and change every third character or change every second word to something else and then write it back. I found this [http://java.sun.com/docs/books/tutorial/essential/io/|http://java.sun.com/docs/books/tutorial/essential/io/] but its a little over my head. Is this the only way to do it?

    wrote:
    You are using buffered reads and writes I would assume, right? Also, how do you think most programs handle this sort of thing? I don't believe I'm using buffering.
    My code looks something like this
    //...necessary imports
    //then
    Scanner inFile = new Scanner (new file("filename1.txt"));
    PrintWriter outFile = new PrintWriter ("filename2.txt");
    //then stuff like
    int x = inFile.hasNextInt();
    outFile.println(x);
    camickr wrote:If you are changing the data "in place", that is none of the data in the file is shifted, then you can use a RandomAccessFile.
    Otherwise, you've been given the answer above.What is RandomAccessFile? Is it what I have a link to? Basically what I do is I write a bunch of numbers to a txt file and then change the numbers I don't need anymore to 0. So say I had 0 1 2 3 4 5 6 7 etc. I would like to to open the txt file and change every second one to 0 so then I'd have only odd numbers and 0s.
    I looked at the documentation for RandomAccessFile and it seems like it might be what I need.
    Thankyou both for your help so far. I took a java course in high school and they only taught me one way to get data from text files and that is what I just showed you. So maybe this questions are really stupid. lol
    Edited by: qw3n on Jun 13, 2009 7:46 PM

  • Reading and writing u16 binary file to a new file

    Hello all,
    a very simple thing that I just don't seem to be able to figure out. I have a file containing 1024bytes of unsigned 16bit words. I can read it successfully with the right value  being displayed. But then I try to write these values to a new file, I can no longer read the same value (in fact it's all grayed out 0) from the newly written file. The newly written file has the right size 1024 bytes, but I don't seem to obtain the right information. I made sure the endian are the same, little-endian.
     Attached is my basic VI, and the .dat file is the file containing the binary information. 
    I'm not using copy file because once I get this figure out, I'll need to append more of the Scan.dat file to one single file. 
    Thank you!
    Solved!
    Go to Solution.
    Attachments:
    read_write_binary_u16.zip ‏11 KB

    I would put some wait time between the write and the read.  It may be a good idea to actually close the file in between.
    I have a feeling that you may not have allowed enough time to actually have the file written out before you read it again.  That or since it is still open, the file pointer is at the end of the file and you are trying to read all the bytes starting at the end, which means you get nothing.
    Not sure of the exact issue, but those two things comes to mind.

  • Reading and displaying from a file

    I want my program to be able to read from a file stored on disk and display the contents of the file to a terminal window. I use blueJ if that makes any difference. Can anyone help me with the code to do that please.

    Look at the java.io package.
    In particular the FileReader, BufferedReader, PrintWriter, and OutputStreamWriter classes.
    Read the I/O tutorial (see links on the left).

  • Reading and printing from a file

    I have a method that reads temperatures from a data file and prints them to the monitor. I use a while loop to read each line of the file, but for some reason it doesnt skip the loop when readLine returns null. My question is how do i get the method to stop reading before it returns null...
       public static void printFile(String textFile) throws IOException
            String inputString="";
            BufferedReader inputDataFile=
            new BufferedReader(new FileReader(CENTIGRADE_DATA_FILE));
            while(inputString!=null)
                inputString= inputDataFile.readLine();
                System.out.println(inputString);
            inputDataFile.close();
       

    ok cool thanks for pointing that out guys i appreciate it...now i need to take those temps and convert them from Strings to doubles so they can be converted i tried this but im getting a NumberFormatException error...
    public static void buildReport() throws IOException
            double centigradeTemp=0.00;
            String inputTemp="";
            //Open centigrade temps to be read and converted
            BufferedReader inputDataFile=
            new BufferedReader(new FileReader(CENTIGRADE_DATA_FILE));
            //Open file writer to write report
            PrintWriter outFile=new PrintWriter(new FileWriter("TempReport.txt"));
            //While loop to read a temp, convert it, and write it in the report
            while((inputTemp= inputDataFile.readLine())!=null)
                centigradeTemp=Integer.parseInt(inputTemp);           
                outFile.println(fahrenheit(centigradeTemp));
            outFile.close();
        public static double fahrenheit(double centigrade)
            double fahrenTemp=0.00;
            fahrenTemp=(9/5)*centigrade + 32;
            return fahrenTemp;
     

  • Help on reading and writing to a file !!!!!!!!!!!!!!!!

    hi there
    anyone can help me on how to write and read from a file? how can i read one string at a time instead of a char. thank you.

    Use the StringTokenizer to break up the line
    File newFile = new File("text.txt");
    BufferedReader in = new BufferedReader(new FileReader (newFile));
    String line;
    while((line = in.readLine()) != null){
    StringTokenizer st = new StringTokenizer(inputLine, " ");
    while(st.hasMoreTokens()){
    // do something with the token
    // e.g:
    // String lc = st.nextToken().toLowerCase()
    hope that helps

  • Reading and writing non-English files

    Hi there..
         I wonder if anyone can tell me how to read and write non-English language files like French or Arabic files...
    Im also interested in knowing how can i convert from Unicode to ASCII and vice versa..
         thanx.. Mourad

    hi there ..
    thanx for ur cooperation .. but actually i have tried the following code and it didnt work; so, im looking for more help :)
    esp. if there are any notes about the files themselves for example;
    by the way i used Notepad files in unicode format..
    my code is :
    import java.io.*;
    public class MainClass {
    public static void main(String args[]){
    String inputfile = "arabic.txt";
    String outfile = "outfile.txt";
    try{
    RandomAccessFile raf = new RandomAccessFile(inputfile, "r");
    InputStreamReader isr = new InputStreamReader(
    new FileInputStream(inputfile), "Cp1256");
    OutputStreamWriter osw = new OutputStreamWriter(
    new FileOutputStream(outfile), "Cp1256");
    for(int i=0; i<raf.length(); i++)
    osw.write(isr.read());
    osw.close();
    }catch(UnsupportedEncodingException uee){
    System.out.println("UEException: "+ uee.getMessage());
    }catch(FileNotFoundException fnfe){
    System.out.println("FNFException: "+ fnfe.getMessage());
    }catch(IOException ioe){
    System.out.println("IOException: "+ ioe.getMessage());
    thanx again..Mourad

  • Need Help: UTL_FILE Reading and Writing to Text File

    Hello I am using version 11gR2 using the UTL_FILE function to read from a text file then write the lines where it begins with word 'foo' and end my writing to the text file where the line with the word 'ZEN' is found. Now, I have several lines that begin with 'foo' and 'ZEN' Which make for one full paragraph, and in this paragraph there's a line that begins with 'DE4.2'. Therefore,
    I need to write all paragraphs that include the line 'DE4.2' in their beginning and ending lines 'foo' and 'ZEN'
    FOR EXAMPLE:
    FOO/234E53LLID
    THIS IS MY SECOND LINE
    THIS IS MY THIRD LINE
    DE4.2 THIS IS MY FOURTH LINE
    THIS IS MY FIFTH LINE
    ZEN/DING3434343
    FOO/234E53LLID
    THIS IS MY SECOND LINE
    THIS IS MY THIRD LINE
    THIS IS MY FIFTH LINE
    ZEN/DING3434343
    I am only interested in writing the first paragraph tha includes line DE4.2 in one of ther lines Not the Second paragraph that does not include the 'DE4.2'
    Here's my code thus far:
    CREATE OR REPLACE PROCEDURE my_app2 IS
    infile utl_file.file_type;
    outfile utl_file.file_type;
    buffer VARCHAR2(30000);
    b_paragraph_started BOOLEAN := FALSE; -- flag to indicate that required paragraph is started
    BEGIN
    -- open a file to read
    infile := utl_file.fopen('TEST_DIR', 'mytst.txt', 'r');
    -- open a file to write
    outfile := utl_file.fopen('TEST_DIR', 'out.txt', 'w');
    -- check file is opened
    IF utl_file.is_open(infile)
    THEN
    -- loop lines in the file
    LOOP
    BEGIN
    utl_file.get_line(infile, buffer);
         --BEGINPOINT APPLICATION
    IF buffer LIKE 'foo%' THEN
              b_paragraph_started := TRUE;          
         END IF;
         --LOOK FOR GRADS APPS
              IF b_paragraph_started AND buffer LIKE '%DE4%' THEN
              utl_file.put_line(outfile,buffer, FALSE);
    END IF;
         --ENDPOINT APPLICATION      
              IF buffer LIKE 'ZEN%' THEN
         b_paragraph_started := FALSE;
              END IF;
    utl_file.fflush(outfile);
    EXCEPTION
    WHEN no_data_found THEN
    EXIT;
    END;
    END LOOP;
    END IF;
    utl_file.fclose(infile);
    utl_file.fclose(outfile);
    EXCEPTION
    WHEN OTHERS THEN
    raise_application_error(-20099, 'Unknown UTL_FILE Error');
    END my_app2;
    When I run this code I only get one line: DE4.2 I AM MISSING THE ENTIRE PARAGRAPH
    PLEASE ADVISE...

    Hi,
    Look at where you're calling utl_file.put_line. The only time you're writing anything is immediately after you find the the key word 'DE4', and then you're writing just that line.
    You need to store the entire paragraph, and when you reach the end of the paragraph, write the whole thing only if you found the key word, like this:
    CREATE OR REPLACE PROCEDURE my_app2 IS
        TYPE  line_collection  
        IS       TABLE OF VARCHAR2 (30000)
               INDEX BY BINARY_INTEGER;
        infile               utl_file.file_type;
        outfile                      utl_file.file_type;
        input_paragraph          line_collection;
        input_paragraph_cnt          PLS_INTEGER     := 0;          -- Number of lines stored in input_paragraph
        b_paragraph_started      BOOLEAN      := FALSE;     -- flag to indicate that required paragraph is started
        found_key_word          BOOLEAN          := FALSE;     -- Does this paragraph contain the magic word?
    BEGIN
        -- open a file to read
        infile := utl_file.fopen('TEST_DIR', 'mytst.txt', 'r');
        -- open a file to write
        outfile := utl_file.fopen('TEST_DIR', 'out.txt', 'w');
        -- check file is opened
        IF utl_file.is_open(infile)
        THEN
         -- loop lines in the file
         LOOP
             BEGIN
              input_paragraph_cnt := input_paragraph_cnt + 1;
                 utl_file.get_line (infile, input_paragraph (input_paragraph_cnt));
              --BEGINPOINT APPLICATION
              IF LOWER (input_paragraph (input_paragraph_cnt)) LIKE 'foo%' THEN
                  b_paragraph_started := TRUE;
              END IF;
              --LOOK FOR GRADS APPS
              IF b_paragraph_started
              THEN
                  IF  input_paragraph (input_paragraph_cnt) LIKE '%DE4%'
                  THEN
                   found_key_word := TRUE;
                  END IF;
                  --ENDPOINT APPLICATION
                  IF input_paragraph (input_paragraph_cnt) LIKE 'ZEN%' THEN
                      b_paragraph_started := FALSE;
                   IF  found_key_word
                   THEN
                       FOR j IN 1 .. input_paragraph_cnt
                       LOOP
                           utl_file.put_line (outfile, input_paragraph (j), FALSE);
                       END LOOP;
                   END IF;
                   found_key_word := FALSE;
                   input_paragraph_cnt := 0;
                  END IF;
              ELSE     -- paragraph is not started
                  input_paragraph_cnt := 0;
              END IF;
              EXCEPTION
                  WHEN no_data_found THEN
                   EXIT;
              END;
          END LOOP;
        END IF;
        utl_file.fclose (infile);
        utl_file.fclose (outfile);
    --EXCEPTION
    --    WHEN OTHERS THEN
    --        raise_application_error(-20099, 'Unknown UTL_FILE Error');
    END my_app2;
    SHOW ERRORSIf you don't have an EXCEPTION section, the default error handling will print an error message, spcifying exactly what the error was, and which line of your code caused the error. By using your own EXCEPTION section, you're hiding all that information. I admit, the error messages aren't always as informative as we'd like, but they're never less informative than "Unknown UTL_FILE Error'. Don't use your own EXCEPTION handling unless you can improve on the default.
    Remember that anything inside quotes is case-sensitive. If your file contains upper-case 'FOO', then it won't be "LIKE 'foo%' ".
    Edited by: Frank Kulash on Dec 7, 2011 1:35 PM
    You may have noticed that this site normally doesn't display multiple spaces in a row.
    Whenever you post formatted text (such as your code) on this site, type these 6 characters:
    \{code}
    (small letters only, inside curly brackets) before and after each section of formatted text, to preserve spacing.

  • UTL_FILE: Reading and Writing client-side Files

    Hi All,
    Please tell me how to read & write UTL_FILE at client-side
    Regards

    And you need this XML to be generated on and read from a client machine? You can't generate the file on the server, move it to the new server, and import it?
    If you need to generate files on the client machine, the client application would have to do the file I/O. Java has a number of libraries for generating XML and parsing XML that could be used, for example, but that implies that a Java application has been deployed to the client machine.
    Justin

Maybe you are looking for