Path: utzoo!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!tut.cis.ohio-state.edu!pt.cs.cmu.edu!andrew.cmu.edu!bobg+ From: bobg+@andrew.cmu.edu (Robert Steven Glickstein) Newsgroups: comp.unix.questions Subject: YACC question Message-ID: <8ZgGBgG00VsnQDgUNO@andrew.cmu.edu> Date: 15 Jan 90 01:12:12 GMT Organization: Information Technology Center, Carnegie Mellon, Pittsburgh, PA Lines: 48 Here is a fragment of Yacc code: %token PLUS MINUS %% expr: mulexpr PLUS mulexpr | mulexpr MINUS mulexpr It's very straightforward; the yylex() routine must be written to return the constant PLUS when it encounters a '+' in the input, and the constant MINUS when it encounters a '-' in the input. However, Yacc allows you to rewrite the above fragment as %% expr: mulexpr '+' mulexpr | mulexpr '-' mulexpr My question is, where does Yacc find the '+' and the '-' characters? Apparently they're not gotten via a call to yylex(). Does Yacc simply do a getchar()? I ask because I have written a parser which can be configured to read from various input sources (standard input, file, string). There are many places in the parser where token-name constants are used when a single character will do; however, if the single character is retrieved by getchar() or some other hardwired mechanism, I'll have to stick to the yylex() approach (since my yylex() knows where to read characters from). Please e-mail your replies. Thanks in advance. _______________________________ Bob Glickstein, System Designer Information Technology Center room 220 Carnegie Mellon University Pittsburgh, PA 15213-3890 (412) 268-6743 Internet: bobg+@andrew.cmu.edu Bitnet: bobg%andrew.cmu.edu@cmuccvma.bitnet UUCP: ...!harvard!andrew.cmu.edu!bobg I could dance till the cows come home. On second thought, I'd rather dance with the cows till you come home. -- Groucho Marx