Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Pascal Ansi -iso > Re: READLN not ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 5 Topic 148 of 211
Post > Topic >>

Re: READLN not reading

by CBFalconer <cbfalconer@[EMAIL PROTECTED] > Mar 30, 2005 at 04:51 PM

Profetas wrote:
> 
> I have a simple menu program that loops and ask the user to type
> a command, but after the first command is typed the readln doesn't
> read it properly. That doesn't affect much, but it is driving me
> mad. has anybode had the same problem?
> 
> I am using freepascal BTW.
> 
> Thanks (the code is below)
.... snip code ...

With minor editing and correction of your code, some annotated, the
following works.  Note that it works on ALL versions of Pascal, and
uses nothing that is not available in ISO7185 (Standard) Pascal. 
It is properly indented to show the level of control.  Read the
comments I have added.

PROGRAM LexDemo(input, output);  
(* You are using these files, so mention them *)

  {PROCEDURE Menu();}
  PROCEDURE menu;  (* Pascal is not C, no parens *)

    BEGIN
    WRITELN('  Logical calculator      by Lucas S Silvs ');
    WRITELN('+------------------------------------------+');
    WRITELN('+           Main Menu                      +');
    WRITELN('+------------------------------------------+');
    WRITELN('| D -=> Display menu                       |');
    WRITELN('| L -=> Lex keyboard input                 |');
    WRITELN('| P -=> Parser the tokens into parse tree  |');
    WRITELN('| E -=> Ealuate the parser tree            |');
    WRITELN('| B -=> Bind an identifier to a value      |');
    WRITELN('| S -=> Show the values of all identifiers |');
    WRITELN('| Q -=> Quit                               |');
    WRITELN('| Print (m)enu                             |');
    WRITELN('| (l)ex token from standard input          |');
    WRITELN('| lex token(s) from standard input         |');
    WRITELN('| (r)ead string                            |');
    WRITELN('| lex tokens from s(t)ring                 |');
    WRITELN('+------------------------------------------+');
    END {Menu};

  (* 1-----------1 *)  (* Separators are handy for human use *)

  {PROCEDURE Main_Loop();}
  PROCEDURE MainLoop;  (* Pascal is not C *)

    VAR
      Option, Tokens : CHAR;         (* Tokens was undefined *)
      Commands       : SET OF char;  (* to guard case statement *)

    (* 2-----------2 *)

    (* dummies for parsing *)
    PROCEDURE yylex; BEGIN writeln('yylex'); END;
    PROCEDURE yyparser(Token : char);
       BEGIN writeln('yyparse'); END;

    (* 2-----------2 *)

    BEGIN (* mainloop *)
    Option := 'd';
    Commands := ['L', 'P', 'l', 's', 'r', 'd'];
    Tokens := ' '; (* initialize it *)
    WHILE Option <> 'q' DO BEGIN
      (* Portable to all flavors guard of case *)
      IF NOT (option IN commands) THEN BEGIN
        writeln('Unknown option');
        menu;
        END
      ELSE
        CASE Option OF
          (* Remove those empty parens, Pascal is not C *)
'L' :     yylex;
'P' :     yyparser(Tokens);
'l' :     Menu;
's' :     Menu;
'r' :     Menu;
'd' :     Menu;
          END; (* CASE, ELSE *)

      WRITE('Type your command: ==> ');
      READLN(Option);
      END (* WHILE *)
    END {Main_Loop};

  (* 1-----------1 *)

  BEGIN
  MainLoop;  (* No parens, Pascal is not C *)
  END. {LexDemo}

-- 
"If you want to post a followup via groups.google.com, don't use
 the broken "Reply" link at the bottom of the article.  Click on 
 "show options" at the top of the article, then click on the 
 "Reply" at the bottom of the article headers." - Keith Thompson




 5 Posts in Topic:
READLN not reading
"Profetas" <  2005-03-30 10:21:17 
Re: READLN not reading
Hanford Carr <"hw  2005-03-30 10:53:42 
Re: READLN not reading
CBFalconer <cbfalconer  2005-03-30 16:51:59 
Re: READLN not reading
Il Razziatore <ilrazzi  2005-03-31 01:50:28 
Re: READLN not reading
CBFalconer <cbfalconer  2005-03-31 01:50:29 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat May 17 2:39:16 CDT 2008.