Post Expression help

does anyone know any sites that can give me the source code for PostFix expression?

Ok, here is one that I had to do for school. It may have different data structure files because I had to use the library that was from my text book. Hope this helps.
import java.lang.Math;
import javax.swing.*;
import java.io.*;
import ds.util.ALStack;
import java.util.StringTokenizer;
import java.text.DecimalFormat;
public class PostFix
      * This program will read in a string from prompt the user for a file
      * that they would like to read into the program.  If the file is
      * not there than an error will be displayed and the user will
      * be allowed to try again.  If correct, the program will use the
      * file and evaluate the postfix expressions.  It will give error
      * feedback or the correct answer.  It will be displayed by creating
      * a separate text file with the correct answers and error feedback.
     public static void main(String[] args) throws IOException, Exception
          // used to keep track of the file name and equations
          String fileName, outputFileName= "", tempEquation;
          // used to make sure the file is valid in the folder
          boolean goodFile = false;
          // loops until good file is found
          while(!goodFile)
               //prompts the user for file name
               fileName = JOptionPane.showInputDialog("Enter the file name: ");
               try{
                    // reads in the file name and lines
                    FileReader freader = new FileReader(fileName);
                    // Checks for the file name and makes the results consistent
                    if(fileName.toUpperCase().equals("POSTFIX1.TXT"))
                         outputFileName = "Result1.txt";
                    if(fileName.toUpperCase().equals("POSTFIX2.TXT"))
                         outputFileName = "Result2.txt";               
                    if(fileName.toUpperCase().equals("POSTFIX3.TXT"))
                         outputFileName = "Result3.txt";
                    FileWriter fwriter = new FileWriter(outputFileName);
                    PrintWriter outputFile = new PrintWriter(fwriter);
                    BufferedReader inputFile = new BufferedReader(freader);
                    tempEquation = inputFile.readLine();
                    goodFile = true;
                    // loops through each file line (equation)
                    while(tempEquation != null)
                         System.out.println(Calculation(tempEquation));
                         outputFile.println(Calculation(tempEquation));
                         tempEquation = inputFile.readLine();
                    outputFile.close();
               // catches an invalid file name
               catch(IOException e)
                    JOptionPane.showMessageDialog(null, "ERROR");
      * This method will take a string (s) and tokenize it using the delimiters
      * ((space) * / ^).  If the operator is found than the method will
      * pop() two numbers and evaluate the sub expression then push() it
      * back into the stack.  If the methods finds a number it will simply
      * just push() it onto the stack.  After the loop the method pops the
      * last remaining item in the stack and returns the answer.  If the stack
      * recognizes an operator and the stack size is less than two at any time
      * then it will report error that there is not enough operands.  If the
      * stack does not recognize and operators and cannot parse the token as
      * a double than it will report that there is an illegal operand/operator.   
     public static String Calculation(String s)
          // create the stack
          ALStack <Double> theStack = new ALStack <Double>();
          // create the variables for calculation
          double operand1, operand2, answer = 0.0;
          // create token to be read
          String token = "";
          // create tokenizer and delimiters
          StringTokenizer strTokenizer = new StringTokenizer(s, " */^", true);
          // decimal format for proper format.  (Three decimal places)
          DecimalFormat formatter = new DecimalFormat("#,##0.000");
          // loops through until there is no more tokens
          while(strTokenizer.hasMoreTokens())
                   token = strTokenizer.nextToken();
                    if(token.equals("+"))
                         if(theStack.size() < 2)
                              return s + " = error: missing operand";
                         operand1 = theStack.pop();
                         operand2 = theStack.pop();
                         answer = operand2 + operand1;
                         theStack.push(answer);
                    else if(token.equals("-"))
                         if(theStack.size() < 2)
                              return s + " = error: missing operand";
                         operand1 = theStack.pop();
                         operand2 = theStack.pop();
                         answer = operand2 - operand1;
                         theStack.push(answer);
                    else if(token.equals("*"))
                         if(theStack.size() < 2)
                              return s + " = error: missing operand";
                         operand1 = theStack.pop();
                         operand2 = theStack.pop();
                         answer = operand2 * operand1;
                         theStack.push(answer);
                    else if(token.equals("/"))
                         if(theStack.size() < 2)
                              return s + " = error: missing operand";
                         operand1 = theStack.pop();
                         operand2 = theStack.pop();
                         if(operand1 == 0)
                              return s + " = error: division by zero";
                         answer = operand2 / operand1;
                         theStack.push(answer);
                    else if(token.equals("^"))
                         if(theStack.size() < 2)
                              return s + " = error: missing operand";
                         operand1 = theStack.pop();
                         operand2 = theStack.pop();
                         answer = Math.pow(operand2, operand1);
                         theStack.push(answer);
                    // if white space than nothing happens
                    else if(token.equals(" "))
                    else
                         try
                              theStack.push(Double.parseDouble(token));
                         catch(Exception e)
                              return s + " = error: illegal operand";
          // returns error because only the answer should be left
          if(theStack.size() > 1)
               return s + " = error: too many operands";
          // returns a correct answer following the original equation
          return s + " = " + formatter.format(theStack.pop());
}

Similar Messages

  • Set Post Expression of Step (Not Next or Previous Step)

    Is it possible to set the post expression of a step, which is not the Next or Previous step?  
    I know this is possible
    RunState.NextStep.PostExpression = "Enter Post Expression Here"
     I am looking for something like
    RunState.Step("StepID").PostExpression = "Enter Post Expression Here"
    Does anyone know if there's a way to accomplish something to that effect?
    Thanks!
    Solved!
    Go to Solution.

    RunState.Sequence.GetStepByUniqueId("ID").PostExpression = "Blah"
    Hope this helps,
    jigg
    CTA, CLA
    teststandhelp.com
    ~Will work for kudos and/or BBQ~

  • How can i access the stepname within a steps post-expression?

    How can i access the stepname within a steps post-expression?
    i only saw the step-id of the step: Step.TS.Id
    is there a pssibility to get the stepname from the id?
    thank you!

    Hi Fischer,
    use the expression NameOf(Step).
    Regards
    Ray Farmer
    Regards
    Ray Farmer

  • Form is not working of multiple form check boxs, source posted. HELP.

    Form is not working of multiple form check boxs, source posted. HELP.
    I'm trying to have golive form be able to check one, two or all of the options in Graphics field.
    As is it will only post results from the last checked box.
    Here's the page
    http://www.perfection-press.com/Pages/ContactForm.html
    Here's where source in golive has scanning,design,filesupplied.
    [code removed to fix forum topic display]

    Since the checkboxes all have the same name, the values are over-writing each other when being passed to the PHP script. The best way to fix that is to add a pair of empty square [] brackets after the checkbox names, so make the names "graphics[]" instead of "graphics". That tells PHP that the values are being passed as a list (an array) instead of a single value. As long as your processing script knows what to do from there (and it does), should solve the problem.
    By the way, I noticed that two of the checkboxes were named "graphics" and the other was "graphic" (singular). You'll want to fix that too so they're all the same.

  • When posting for Help on Network Magic Please Include

    Hi All,
    When posting for help on these forums include:
    Your Network Magic Version installed: 4.6.7324.0
    The type of connection to the Internet, like DSL, Cable, or Verizon FIOS Internet Connection.
    The Brand of Modem and its Model Number the router is connected to.
    The Brand, Model, Hardware Revision of your Router and include the Firmware Version: D-Link DI-624 Rev. C Firmware 2.70
    The Method of connection your problem computer has to the Router: Wired or Wireless.
    The Connection in use on the problem computer: Ethernet Port is a PCI Adapter Card, A D-Link DWL-G520 Rev. B
    Operating system and version and Service Pack Level, if any. Ex. Windows XP Professional x64 Edition Service Pack 1
    Software Firewall in use: McAfee Personal Firewall 9.0.136 Build
    Also if any Anti-Virus Program or Spyware Program is actively protecting your computer. (Some Programs like Spybot does cause problems, not being able to go to specific sites.)
    Include your location in the post or fill out your Profile for this forum and include the location. (Reason: Not all Routers from a given manufacturer are available everywhere.)
    Post the link to your Router Model, if an off-brand Router or not found in the USA on the Manufacturer's USA's Website. (Why? Posters helping each other, aren't working for Pure Networks or Network Magic, so make it easier on the posters helping on.)
    And any other information you think is important if answering your own post, and the nature of the problem, itself.
    By posting all this information, you can hopefully get help from someone that has the same equipment that you have and theirs is working. Not everyone has the same equipment.
    thecreator - Running Network Magic version -5.5..9195.0-Pure0 on Windows XP Home Edition SP 3
    Running Network Magic version -5.5.9195.0-Pure0 on Wireless Computer with McAfee Personal Firewall Build 11.5.131 Wireless Computer has D-Link DWA-552 connecting to D-Link DIR-655 A3 Router.

    mhchiang,
    If you have multiple systems that all show the same symptoms,
    then it is probably not a problem in the computers.
    You may need to investigate the rest of your network hardware
    and your campus network software.
    Your campus network administrators may have made some recent changes.
    Ethernet switches may have power supply problems, or they're getting old.
    Firewall software may heve had recent changes to its configuration.
    If the cabling goes over long distances, from building to building,
    there may be damage to wiring.

  • Get step name of currently executing step from post expression tab

    Hi,
    I am trying to create a custom step type that records the step name and step results in an array. I have been having trouble trying to access the Step Name property from the post-expressions tab.
    One option is to use locals.resultslist[], however, that is only populated once the step executes and hence i cannot access its name through post-expressions. Is there any other property that contains the step name, that may be populated correctly before the post expression  is executed?

    I just realized, this has been posted under LabView. Please disregard this, I am putting it under Test Stand.

  • Will an Airport Express help with the signal I am not receiving on my Smart TV?

    Will the Express help with internet issue's I have with my new Smart TV?

    If you already have another Apple AirPort router that is providing your wireless signal, then a new AirPort Express could extend that wireless signal to provide a stronger wireless signal to the TV....assuming that the TV connects using wireless.
    Is this what you are asking?
    Or, would the Express provide other services to "help"?

  • The post-expression for the step 'Set Station Global Models' could not be evaluated.

    When running a TestStand sequence, I get the following error message:
    The post-expression for the step 'Set Station Global Models' could not be evaluated.
    Variable or property types do not match or are not compatible.
    Error Code:  -17321; Variable or property types do not match or are not compatible.
    Although I do understand what the above is telling me, fixing the root cause is somewhat another thing.
    I'll explain the scenario.  The code is developped in TS4.1.0, although that should be irrelevant.
    I inherited a TestStand project which calls LabVIEW modules.  The original sequence works fine on the test pc (which is remotely located).  The local and remote PC's share the same StationGlobals.ini.
    Here is why it is strange..  I do get the error message on the local PC whether I use the old or the new code.  I was assuming that using the same StationGlobals.ini would have fixed that, but it didn't. 
    When I run the old code on the remote PC, I do not get that message, but I do get it with the new code.  I don't recall modifying code that affected the StationGlobals.  My goal is to fix it on both machines (at least the remote one).
    This is the expression that it does not like:
    StationGlobals.Models=Locals.Models,
    However, that very same expression exists in the original code.  The one thing that did change is the addition of a new model number in the Locals.Models.newNumber.  I suspect that this contributes to the error.  But why does it give me an error when I run the original sequence locally?  Maybe I should try running it again..
    In either case, any suggestions to overcome the error?
    Thanks.
    RayR
    Solved!
    Go to Solution.

    Please ignore post.
    I found the problem..  There was a mismatch with the number of models.  Easy fix.  It's all good.
    For someone else who might tumble onto this thread for the same reason, here's an explanation.
    I added a new model with its variants to the list of Locals.Models.  In total, there were 16 additions to the list.
    I also added these to the StationGlobals.  Which meant that my StationGlobals no longer matched the one on the remote PC. 
    Where the error came in is that there was one missing model in the StationGlobals, so the size (number of models) did not match that of the Locals. 
    Slight oversight in the sea of models that are listed (I'm not even going to count them).  Now fixed. 
    ... and embarrassed ...
    I may as well give myself an "Accepted Solution".
    Spoiler (Highlight to read)
    Since I've been naughty all year it will be my only Christmas gift..
    Since I've been naughty all year it will be my only Christmas gift..

  • Use Post Expression to convert 1.000 to 99999

    I have a program that reports a 1.000 if the value returned is 1.#INF, by using the Val() function.
    Can I use Post Expression to check to see if Step.Result.Numeric == 1.000 and if it is then convert it to 99999?
    Currently I have Val( Step.Result.Numeric ) in the post expression box.  My version of TestStand is too old to use an If statement.  In most cases the value returned will not be 1.#INF so I want to make sure I don't convert every result to 99999.
    Thanks in advance.

    Hi,
    Try 
    (Step.Result.Numeric == 1.000) ? (Step.Result.Numeric = 99999) : 0
    Regards
    Ray
    Regards
    Ray Farmer

  • My ipad 2 and ipod touch keeps on dropping wifi connection,  would getting an apple router or maybe airport express help?

    ipad 2 and ipod touch  keeps on dropping wifi, would upgrading to an apple router/airport express help?  all my other pc's work well with my current network.

    Have you checked for a firmware update for your current router?
    What make, model, version router do you have?

  • Interpreting a Post-Expression step

    I am fairly new to Teststand.  How do I interpret this post expression.  There is a custom data type that has been created.  I understand the part till the "False" after "Evaluate(Step.DataSource):False.   However, I am not sure if the step after the following comma containing a string comparison is the beginning of an else if.  Please provide assistance in referring me to some documentation to understand this step.
    Step
    .DataSource !="Step.Result.String"? Step.Result.String = Evaluate(Step.DataSource):False,(StrComp(Step.Result.String, Step.Limits.String,(Step.Comp =="CaseSensitive"?0:1))==0)?"Passed":"Failed"
    Solved!
    Go to Solution.

    There are two statements.  The first is a way to assign Step.Result.String to the value of the data source if it isn't used for evaluation.  The comma starts a new statement, which evaluates the step result based on whether the Step.Result.String is equal to Step.Limits.String.
    The ? : syntax refers to a conditional, in the following way- (Condition)?(True case)False case).

  • Expression help needed - control speed of a pan via a slider

    I've done this in the past but can't locate my old project, and my head is throbbing from last nite.....
    I'd like to apply an expression to my null's position. I want it to pan horizontally at a speed specified with a slider control. I'd like it to be able to start, stop, and then continue. Doesn't need to ease in, but it'd be nice.
    Speed = effect("Speed")("Slider");
    OffsetX = effect("Offset")("Point")[0];
    fps = 24;
    x = OffsetX - (Speed * time * fps);
    [x,243]
    My problem multiplying "speed" with time means that when it stops (speed=0), it returns to the start position.... I need it to stay in place, and then continue when I animate the speed value back up.
    Please help my hungover brain....

    Here's a quick and dirty method:
    >v = effect("Velocity")("Point");
    vSum = 0;
    for(t = 0; t <= time; t+=thisComp.frameDuration) vSum += v.valueAtTime(t);
    value+vSum*thisComp.frameDuration
    Unfortunately, it is pretty slow to calculate, and just gets slower the further you go down the timeline. Also, it doesn't actually produce continuous motion, so it doesn't play well with motion blur.
    I'm working on a much more efficient expression that does work with motion blur, but I can't seem to get it to behave once you get past the last keyframe. If I have a breakthrough, I'll post it.

  • Column Visibility Expression help - SSRS

    I have a report in SSRS that has 12 columns. On each column, I have a corresponding column visibility expression like so:
     =IIF(InStr(JOIN(Parameters!HideColumns.Value,
    ","),"01")=0, False, True)
    Where I have the "01" I change to "02","03","04","05","06","07","08","09","10","11"
    & "12" respectfully across my column. The intent is to pass a parameter and allow the end user to "Hide" the column from visibility to allow them the flexibility on printing records. The issue I am having is I need a default that allows
    them to not hide anything, meaning print all 12 columns. Right now, its forcing me to pick one column to hide, is there something I could add to this to say, All? Hope this makes sense.

    Hi,
    For default value of this parameter(Parameters!HideColumns.Value)
    add  a value that is not in 01 to 12 .
    As an example if you  add 13 to the  default value   of the parameter, than  your expression will not hide the column 
       =IIF(InStr("13",
    ","),"01")=0, False, True) 
       =IIF(InStr("13",
    ","),"02")=0, False, True)  and so on.
    Many Thanks
    Chandra
    Please mark the post has answered if this post helps to solve your issue

  • AirPort Express: Help with terminology

    Hi all,
    I've read lots of great posts here, but the terminology isn't always consistent, and I need help understanding the difference between the products.
    I would like to buy an AirPort Express base station (ie: router) and stream audio to two different rooms.
    Now, the AirPort Express is the remote device I would plug into the wall, right?
    From what I understand, I can buy an base station which comes with the remote device. If I want to buy a second remote device, what should I do a search for?
    Appreciate any feedback. Sorry for the newbie style question.
    Steve

    Checkout KB 107908, Identifying AirPort hardware.
    The base station is that "flying saucer" like device Apple sells, right?
    Those have been discontinued. The "flying saucer"s that Apple has sold in the past are the graphite 802.11b AirPort base station (ABS), dual Ethernet (snow) ABS, and 802.11b/g AirPort Extreme base station (AEBS).
    There's a smaller device that plugs into the wall, and has an ethernet port and an audio output. Right so far?
    I believe you are referring to the AX. Don't let its small size and shape fool you. It is also a base station.
    If so, what are these devices called? I'd like to buy the router and two of the remote devices with audio outputs.
    If all of your computers are connecting wirelessly, you can buy 3 AX.
    If any of your computers need to connect viaEthernet, you need an AEBS and 2 AX.

  • Can't enable the ethernet socket on my Airport Express; Help!!

    Am I correct in assuming that I can plug a non-wireless enabled laptop into my Airport Express Ethernet port and access my home wi-fi network?
    I have a new(ish) Airport Extreme which is plugged into my Siemens Gigaet SE587 router. At the moment I use my old Airport Express to play stream iTunes into another room. We've just bought a disturbingly large TV which is internet enabled and was hoping to plug it into the Airport Express. Before doing this I disabled the AirPort on my laptop and plugged an ethernet cable into the Express expecting it to pick up the internet. It didn't!
    I've spent the last few hours playing with the Airport Utility and reading posts on this forum; one suggested selecting an "enable ethernet" box in Airport Utility but I have no such option.
    Can anyone help??
    Cheers
    Gethin

    I've spent the last few hours playing with the Airport Utility and reading posts on this forum; one suggested selecting an "enable ethernet" box in Airport Utility but I have no such option.
    You need the 802.11n version of the AirPort Express to do what you want. Look on the side of your device for the Model No in the faint print. You'll need Model No A 1264 to do what you want. It sounds like you have A 1088.

Maybe you are looking for