Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!rutgers!mit-eddie!genrad!decvax!ima!johnl From: edw@ius2.cs.cmu.edu (Eddie Wyatt) Newsgroups: comp.compilers,comp.unix.questions Subject: Re: lex/yacc question Message-ID: <1131@ius2.cs.cmu.edu> Date: Wed, 29-Apr-87 01:53:55 EDT Article-I.D.: ius2.1131 Posted: Wed Apr 29 01:53:55 1987 Date-Received: Sat, 2-May-87 02:38:18 EDT References: <558@ima.UUCP> Sender: johnl@ima.UUCP Organization: Carnegie-Mellon University, CS/RI Lines: 50 Approved: compilers@ima.UUCP Xref: mnetor comp.compilers:9 comp.unix.questions:2076 In article <558@ima.UUCP>, johnl@ima writes: >[any easy way to make a listing in an assembler written in yacc and lex?] Try production rules of the form %term LEXDEFADDRESS LEXDEFDATA COLON addrprod : address COLON data LEXDEFNEWLINE { generate_code ($1,$3); /* write code at end of production. If you want, make generate_code smart so that it buffers output and writes only when the buffer is full. */ } ; address : LEXDEFADDRESS { $$ = make_address(); /* read the chars from yytext[] and convert them into an address */ } ; data : LEXDEFDATA { $$ = make_data(); /* read the chars from yytest[] and convert them into data */ } ; I assume that your production is of the form: addrprod : LEXDEFADDRESS COLON LEXDEFDATA in which case, any semantic rules will not be executed until the lex symbol LEXDEFDATA is identified hence the chars that make up the lex symbol LEXDEFADDRESS are lost to the parser (I know you've hacked it so the lex code takes care of it, yuk). General comment, lex and yacc are probably too powerful for writing an assembler. You will pay for all the generality of lex and yacc in how fast your assembler runs. Eddie Wyatt, edw@ius2.cs.cmu.edu [Lex might slow you down, but I have never, ever, seen a compiler where hand-coding the parser rather than using yacc would make the compiler noticably faster. Yacc parses pretty fast, and parsing isn't that big a part of compile time anway. -John] -- Send compilers articles to ima!compilers or, in a pinch, to Levine@YALE.ARPA Plausible paths are { ihnp4 | decvax | cbosgd | harvard | yale | cca}!ima Please send responses to the originator of the message -- I cannot forward mail accidentally sent back to compilers. Meta-mail to ima!compilers-request