Straight Line Interpreter

Hi All
I am doing exercise of book "Modern Compiler Implementation in JAVA" by Andrew Appel. It is first exercise and have to develop two functions maxargs to find the maximum number of arguments for print statements ..I am not able to understand the logic to use for recursive print statements.
like if there is print inside print ..how should i go ahead for developing this function ?
Till now i have tried this
static int maxargs(Stm s)
if (s instanceof CompoundStm)
CompoundStm stm = (CompoundStm) s;
return Math.max(maxargs(stm.stm2, stm.stm1));
else if (s instance of AssignStm)
here is the case where the recursive prints are possible.

Hi yogsma,
I made it:
public static int maxargs(Stm s) {
          if (s instanceof CompoundStm) {
               CompoundStm stm = (CompoundStm) s;
               return Math.max(maxargs(stm.stm1), maxargs(stm.stm2));
          } else if (s instanceof AssingStm) {
               AssingStm astm = (AssingStm) s;
               return (maxargs(astm.exp));
          } else if (s instanceof PrintStm) {
               PrintStm pstm = (PrintStm) s;               
               return Math.max(maxargs(pstm.exps), lenght_exp_list(pstm.exps));
          } else {
               return 0;
     private static int maxargs(Exp e) {
          if (e instanceof IdExp) {
               return 1;
          } else if (e instanceof NumExp) {
               return 1;
          } else if (e instanceof OpExp) {
               OpExp oexp = (OpExp) e;
               return Math.max(maxargs(oexp.left), maxargs(oexp.right));
          } else if (e instanceof EseqExp) {
               EseqExp esq = (EseqExp) e;
               return Math.max(maxargs(esq.stm), maxargs(esq.exp));
          } else {
               return 0;
     private static int maxargs(ExpList e) {
          if(e instanceof PairExpList){
               PairExpList expl = (PairExpList) e;
               return Math.max(maxargs(expl.head), maxargs(expl.tail));
          } else if (e instanceof LastExpList) {
               LastExpList lexp = (LastExpList) e;
               return maxargs(lexp.head);
          } else {
               return 0;
     private static int lenght_exp_list(ExpList e){
          if(e instanceof PairExpList){
               return 1 + lenght_exp_list(((PairExpList)e).tail);
          } else {
               return 1;
     }

Similar Messages

  • Shooting mouse cursor beyond intended straight line between two points.

    I copied this forum question from Lightroom, and I hope this is ok because I did not know how to express the problem I am experiencing:
    "The photoshop brush tool interprets shift-click as a brush stroke that connects the previous brush mouse-up position with the current mouse-down (the shift-click) as a straight line stroke.
    [My experience is that every so often, maybe every three or four "shift-clicks" to get my mouse to create a straight line to my next placed mouse position, the Mouse goes Wild, and shoots way beyond my intended next position, and depending on how zoomed in on the image i am, I frequently loose my place where I had been working.  It becomes quite frustrating as this is a very frequent occurrence.  I have heard others with this version CS3 as well as CS2 having the same "shooting Cursor" which is accompanied by some cursing of my own.  As said below, Time savings is the reason for this technique.  If this problem has been dealt with already, I am sorry to have clogged up the forum, but please re-direct me with the key words to find that thread.  How do I cause this shooting cursor to stay within my mouse placement?]
    I find this a HUGE time-saver in creating masks as it doesn't require that I have a steady hand. I'm frustrated that LR does not offer the same capability. This feature would complement the auto-mask feature (kinda works). I could create a mask in a fraction of the time if LR included this feature.
    Another irritation of occurrence is when setting lines from the rulers, the image will suddenly zoom in by a small amount.  In other words, there are several areas where the software seems to have a mind of it's own, and behaves in an erratic fashion not at all related to the intended action and result.
    I am operating a Mac 10.5.7
    Model Identifier: MacPro3,1
      Processor Name: Quad-Core Intel Xeon
      Processor Speed: 2.8 GHz
      Number Of Processors: 2
      Total Number Of Cores: 8
      L2 Cache (per processor): 12 MB
      Memory: 2 GB
      Bus Speed: 1.6 GHz
    ATI Radeon HD 2600 XT:
    2x2.8 GHZ Quad-Core Intel Xeon
    2 GB 800 MHz DDR2 FB-DIMM

    Thanks for your quick reply.  I am attaching screen shots of my 
    current mouse setting, and a graphic of how the behavior is 
    demonstrated.  The image is one in which quick mask is being used to 
    create a selection, and I am using the paint brush and find it easier 
    to use the brush with the technique of clicking the brush at one point 
    then holding the shift key while I click the brush at the desired next 
    point which should allow the brush to paint a straight line between 
    the two points.  The technique works for 3 or 4 clicks, when at the 
    next click, it is as if it was just shot clean out of the realm of the 
    desired area.  It is almost funny, except that this is a technique I 
    find most useful and frequently helpful, and is not confined to the 
    paint brush, but the eraser as well.  This does occur also with my 
    computer at work, a pc, and a Microsoft mouse.  I have been using 
    Photoshop for 12 years, and this problem did not start until I started 
    using CS3 extended.  We have upgraded two HP pcs at work to CS4 
    extended, and each uses a different mouse, and both exhibit the same 
    behavior as experienced by other persons working at those stations, 
    and while using Photoshop.
    I do hope you could look into this a bit further, Mark, as my 
    explanation of the problem may not be clearly presented for you to 
    fully understand just what I am experiencing.
    Thank you for your help.
    Fred

  • Problem with creating a straight line with polygamo lasso

    I am having a problem with polygamo lasso. when i create a triangle or a rechtangle in straight line it is turn out the line become not straight. I don't what did i wrong, was always working fine till today. YOu can see the pic the top line lookslike a step.

    Ihope I did right, was not sure how to save as channel.

  • How to draw only straight line instead of angled one??

    Dear friends,
    I saw a very good code posted by guru here(I think is camickr),
    But I tried to change it and I hope to draw only straight line instead of angled one, can you help how to do it??
    Thanks so much.
    import java.util.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    public class DrawingArea extends JPanel
         Vector angledLines;
         Point startPoint = null;
         Point endPoint = null;
         Graphics g;
         public DrawingArea()
              angledLines = new Vector();
              setPreferredSize(new Dimension(500,500));
              MyMouseListener ml = new MyMouseListener();
              addMouseListener(ml);
              addMouseMotionListener(ml);
              setBackground(Color.white);
         public void paintComponent(Graphics g)
              // automatically called when repaint
              super.paintComponent(g);
              g.setColor(Color.black);
              AngledLine line;
              if (startPoint != null && endPoint != null)
                   // draw the current dragged line
                   g.drawLine(startPoint.x, startPoint.y, endPoint.x,endPoint.y);
              for (Enumeration e = angledLines.elements(); e.hasMoreElements();)
                   // draw all the angled lines
                   line = (AngledLine)e.nextElement();
                   g.drawPolyline(line.xPoints, line.yPoints, line.n);
         class MyMouseListener extends MouseInputAdapter
              public void mousePressed(MouseEvent e)
                   if (SwingUtilities.isLeftMouseButton(e))
                        startPoint = e.getPoint();
              public void mouseReleased(MouseEvent e)
                   if (SwingUtilities.isLeftMouseButton(e))
                        if (startPoint != null)
                             AngledLine line = new AngledLine(startPoint, e.getPoint(), true);
                             angledLines.add(line);
                             startPoint = null;
                             repaint();
              public void mouseDragged(MouseEvent e)
                   if (SwingUtilities.isLeftMouseButton(e))
                        if (startPoint != null)
                             endPoint = e.getPoint();
                             repaint();
              public void mouseClicked( MouseEvent e )
                   if (g == null)
                        g = getGraphics();
                   g.drawRect(10,10,20,20);
         class AngledLine
              // inner class for angled lines
              public int[] xPoints, yPoints;
              public int n = 3;
              public AngledLine(Point startPoint, Point endPoint, boolean left)
                   xPoints = new int[n];
                   yPoints = new int[n];
                   xPoints[0] = startPoint.x;
                   xPoints[2] = endPoint.x;
                   yPoints[0] = startPoint.y;
                   yPoints[2] = endPoint.y;
                   if (left)
                        xPoints[1] = startPoint.x;
                        yPoints[1] = endPoint.y;
                   else
                        xPoints[1] = endPoint.x;
                        yPoints[1] = startPoint.y;
         public static void main(String[] args)
              JFrame frame = new JFrame("Test angled lines");
              frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
              DrawingArea d = new DrawingArea();
              frame.getContentPane().add( d );
              frame.pack();
              frame.setVisible(true);
    }

    Change the AngledLine class to store two points instead of 3 points (I would rename the class to be StraightLine). The code is much simpler because you just store the starting and ending points and you don't need to calculate the middle point.

  • When I record an audio track, there is a waveform. When I stop recording, the waveform disappears and becomes a straight line. It also disappears from the track edit window. But the sound is there. How can I stop the waveform from disappearing?

    When I record an audio track using Logic Pro X, there is a visible waveform which appears as I record. When I stop recording, the waveform disappears and becomes a straight line. It also disappears from the track edit window. But the sound is still there. How can I stop the waveform from disappearing? And can I do something to view it after it has disappeared? Anyone know the anser?

    In Logic:
    Preferences/Audio Set Recording Delay to 0 <zero>
    This should always be set to zero unless a specific set of circumstances exist and you're audio drivers do not report position correctly.
    On occasion, usually when importing a Logic 9 project, Logic-X randomly changes this to a negative/positive number.  It's actually a bug in Logic, as it should always display the waveform.

  • Ssrs 2008 r2 straight line within a matrix

    In an SSRS 2008 R2 new report have placed a matrix on the end of the report for information the user wants to see at the end of the report. The user wants to place a straight line between the different infomation sections in the tablix. Here are the problems
    I am having:
    1. In a row I would like to merge 2 cells together so that a line placed within the matrix is the same length. The problem is that I do not know how to merge the cells.
    2. When I drag a line into a cell in the matrix, the line is not straight. The line points to an angle. I have tried to change the properties of the line on the endpoint values but that has not worked. Thus can you tell me how to make the line placed within
    a matrix cell to be straight?

    Take a look at this post for inserting a horizontal (or vertical) line into a tablix cell:
    http://social.msdn.microsoft.com/Forums/sqlserver/en-US/397d6dc4-766a-43c9-9706-5370a2bfaeb4/insert-line-into-table?forum=sqlreportingservices
    For merging cells, you simply select a set of contiguous cells, right-click, merge cells. There is a catch of course. The catch is that all of the cells you are trying to merge must be in the same scope. Below are some screenshots showing a simple Matrix
    with 1 column group and 1 row group.
    As you can see in this screenshot, I have selected 2 adjacent cells that are both in the same scope, and merge cells is available.
    In this screenshot, I have selected 2 adjacent cells that are not in the same scope. The left cell is only scoped by the row group while the cell on the right is scoped by both the row and the column group. As a result, I cannot merge the cells.
    "You will find a fortune, though it will not be the one you seek." -
    Blind Seer, O Brother Where Art Thou
    Please Mark posts as answers or helpful so that others may find the fortune they seek.

  • How to get rid of or at least easily fix random Position A to Positon B 'archs'?(want straight line)

    Hey,
    I hope i can describe my question correctly: is there a way to tell after effects that i want to default every position edit to be a straight path/arch (i'm actually looking for a lack of 'arch'--I just want a straight line) instead of defaulting to a seemingly random arch that i then find very tedious if not impossible to fix, even by manipulating vertice box 'arms' while holding alt? in other words, can i tell the program that, from now on, 'position A' and 'position B' must be traveled between in a straight line ONLY, never any erronious archs? i hope i described it well enough without being too familar with technical terms
    thanks

    Rick's pointing you in the right direction.
    Details are here:
    http://help.adobe.com/en_US/aftereffects/cs/using/WS3878526689cb91655866c1103906c6dea-7d99 a.html#WS3878526689cb91655866c1103906c6dea-7d98a

  • My Macbook Pro (OSX 10.6.7 2.26 GHz Intel Core 2 Duo) has started misbehaving on me. When I'm working, the cursor will start spontaneously moving to the left in a straight line, and randomly right clicking on things.  If I close the computer and open it b

    my Macbook Pro (OSX 10.6.7 2.26 GHz Intel Core 2 Duo) has started misbehaving on me. When I'm working, the cursor will start spontaneously moving to the in a straight line, and randomly right clicking on things.
    If I close the computer and open it back up, it sometimes stops for a little while, then will spontaneously start again. Any help would be truly appreciated. Thanks!

    See this knowledge base article. Also, you might want to update to 10.6.8 (don't know that that will fix your problem, but it's the latest version of Snow Leopard).
    Clinton

  • Can I extend the slideshow horizontal in a straight line but not full page up and down?

    Can I extend the slideshow horizontal in a straight line across the page end to end, but not full page up and down?

    Hi
    Please check these videos for help :
    https://www.youtube.com/watch?v=BDgERSf2a5k
    https://www.youtube.com/watch?v=diUtfwFGI1w
    Thanks,
    Sanjit

  • Why can I only paint straight lines in Photoshop CS6?

    I am trying to paint something that I have wanted to for a while now, and Photoshop is presenting some troubles for me. I can not paint curves, and instead, only straight lines without pen pressure (Size, opacity, the likes.) The result of my efforts is the same as if I were to draw a dot (click once in other words), press shift, and make another dot somewhere else. It's just straight lines no matter what.
    I am currently on an Emachines computer running Windows 7, Photoshop CS6 and this is the first time I have bothered with the brush tool in Photoshop.
    I hope this information is useful for someone to help me so that I may paint freely. Thank you for reading.

    Trevor Dennis wrote:
    Bulbabooty wrote:
    What do you mean by the first sentence you said?
    It is possible that the Shift key is stuck on your keyboard.  If you add a Type layer and some text, you'll see if that is the case or not.  Unlikely I'd have thought, but things can get jammed between the keys, and you need to eliminate this possibility before moving on to other possibilities.
    Oh, I see. No, the shift key is not the problem it seems. I have a feeling that it's the brush I'm using.

  • Simplifying Straight Line Paths

    Hey all,
    new to the forum and really struggling with something at the moment, Using Illustrator CS4
    I've imported a map from a DWG prepared in Archicad (vector based architecture software)
    This map shows roads and buildings (they are paths in illustrator) and as you would imagine the roads are curved but rather than being drawn with curves they are composed of many many straight line paths and as I'm meaning to have a model laser cut from the Illustrator file I need to join these paths into longer paths so the laser cutting doesn't take forever.
    As far as I can see it's fairly simple to simplify the number of anchor points on a curved path using the Object>Path>Simplify tool but simplifying multiple straight line paths that only have the slightest deviation in angle seems harder, or at least I can't work it out.
    I have attached an image, The areas highlighted in green are examples of areas where there are too many paths and just one or two paths would be fine. It would be fine to either convert the paths to curved paths or just simply reduce the number of straight line paths that compose the curves.
    Hope someone can help, Thx for your time
    The

    Apart from the current problem, you should take a look at the free plugin "Kartografie-Funktionen" if you do this kind of stuff regularly. http://www.ika.ethz.ch/plugins/index.html
    It has a tool for simplifying paths, which works slightly different than Illustrator's

  • Making a straight line aligned with text and adjusting length

    i am trying to make a simple straight line above some text in after effects cs5 that lines up with the beginning and end of the text. Not touching or anything. Nothing special. then a line perpendicular to it of a different stroke size.
    Also i want it to draw or fill in.
    first of all, if i dont get the line length perfect the first time, and i try to adjust the length, then the stroke width changes, also the scale.
    this is maddening because if i am making other pieces that i will animate together, i want them to be the same. and every time i try to adjust the line length, it changes everything...
    or do i just make all lines and type graphics in illustrator or photoshop and import them...and make a mask.  I almost think that all those extra steps might be easier...(sarcasm)
    any tips on this as this super basic task is turning into a headache?
    thx in advance.

    Well, because if you dont get it exactly correct and you want to make it longer or shorter, not only does that change, but the stroke starts scaling. So now you have simply a shorter line, you have a line that appears the same but is inevitably different point sizes and different scales that are maddening to match. I am animating several iterations of a kind of type/line template in 3d space. So i have made each on its own composition that is not 3d.
    i thought you would be able to just click on the end of the line/path and make the line itself shorter or longer like in illustrator. Also when the scale changes, it changes its position slightly from its anchor point....

  • Newbe - straight line with different curves at each end

    I'm generally not using Illustrator as I'm sure you can tell. I need several curly brackets, but none will really do as they will cover varioius lengths and should be the same size. It looks like the easiest way will simply be to create one putting two straight lines together, but I cannot even determine how to get a curved end at one end of the line - yet alone a second different curve on the other end. Thanks. Rick

    shiesl,
    For the curly bracket shape you may consider quarter circles at the ends, and a pair at the middle, all with the same radius.
    You may:
    1) Create a circle with the Ellipse Tool and cut it into quarters at the Anchor Points; you may then use all the bits or just one or two of them with copies,
    2) Place the first quarter with the inner end where you want the first straight part to start (on one side of the intended straight part),
    3) Place the second quarter (corresponding to a 180 degrees rotation) oppositely (on the other side of the intended straight part) where you want the firrst straight part to end,
    4) With the Direct Selection Tool select both inner ends and Object>Path>Join, now you have one half curly bracket,
    5) Object>Transform>Reflect, Align the two halves, and Join them at the midlle.
    For different lengths, you may Direct Select the two Anchor Points at either end and move them away from the middle (you may use arrow, Object>Transform>Move, or other ways).
    If you just want roundings at the ends, you may simplify the suggestion here, just having the second one on the same side in 3) and finish with 4).

  • SDO_NN and SDO_WITHIN_DISTANCE return distance on way or on straight line?

    Hi to all,
    I want ask you if the distance between 2 points computed with SDO_NN and SDO_WITHIN_DISTANCE is a distance on the way that connects these two points (for example 35 miles) or is a distance on a straight line that connects these two points (for example 20 miles)?
    thank you very much.

    Ok Jack, thank you.
    I understood. For straight line I mean a distance that doesn't pass for the streets but on the earth without considering the streets (distance as the crow flies).
    Do you confirm that this result is a distance as the crow flies?
    Thank you very much.

  • Loan transaction - straight line or reducing balance method

    Hi all,
    i have a question here.  It is regarding interest rate instrument product in SAP-TRM.
    For interest rate instrument/ loan product can we set whether the interest can be charged either on straight line method or reducing balance method?
    Your soonest feedback is highly appreciated.
    Thanks.

    Hi,
    Both are supported. For straight line method you can choose the Interest Form - Amount and for Reducing balance method choose - Fix or Variable Rate option in interest structure.
    Regards
    Prasad AV

Maybe you are looking for

  • Problems when searching for non-Latin characters

    In my studies I often need to search for Japanese terms. I usually do this from the Smart Search Field to go straight to Google. However, Safari seems not to be able to handle the Japanese characters. For example, I might type 日本 into the Smart Searc

  • Programming HR reports in Discoverer

    Which tables in Oracle hold the information for employee gross wage and tax data. Does Oracle store the information for the FHI,FICA, FIT, FUTA, SIT, and SUTA taxes?

  • Question mark in tab of my website

    I have seen a few mentions of this, but no solution. Although it's not a huge problem, if anyone knows what is causing this and how to go about correcting it, I would be grateful. My little site works fine in every regard. The only problem I have is

  • Can you export whole folders with meta data in tact

    Can you export folders or groups of photos including all the meta data eg keywords, gps etc to a new folder? I then could copy these to my xbox for viewing for example? cheers

  • Maintenance Plant

    Hi, I have a cement plant which has maintenance team. It has small power generation plant also. The maintenance is done by the cement plant staff. How can I configure it in SAP? Best Regards, Khalil