## page was renamed from Assignments/AssignmentRequirements ## vim: nowrap tabstop=2 shiftwidth=2 expandtab textwidth=100000 #acl All:read All compiler programming projects must meet these requirements on a '''standard student account''' of a CTB60 ("alamode") machine. <> = Examples = <> <> == Output Formatting == Suppose a compiler assignment dictates: {{{#!wiki tip Your `PROGRAM` should accept two arguments: the first is a file containing a grammar, the second is a valid sentence of terminals from Σ. `PROGRAM` should emit the following values: 1. The total number of productions performed by the grammar. 1. The maximum size of the parser engine stack during the parse. 1. The type and number of each non-terminal node in the parse tree. }}} Then '''both''' of the following outputs would be acceptable (they differ only in the amount of programmer debug messages spewed): {{{ $ ./PROGRAM grammar.cfg "int a=3, b=4; a+b<6 if b, a = a, b; else { a=b=0; } output("else");" OUTPUT 63 54 :DECL: 1 :EXPR: 6 :OUTPUT: 1 :STR: 1 :PROG: 1 :IFELSE: 1 :EQN: 5 $ }}} {{{ $ ./PROGRAM grammar.cfg "int a=3, b=4; a+b<6 if b, a = a, b; else { a=b=0; } output("else");" Read grammar 'grammar.cfg' 6 nonterm 17 terminals EQN production a 3 EQN production b 4 EQN production b a EQN production a b EQN production b 0 EQN production a b STR production else OUTPUT counting non-leaf nodes... 63 OUTPUT 54 OUTPUT nonterm/0/7 :DECL: 1 OUTPUT nonterm/1/7 :EXPR: 6 OUTPUT nonterm/2/7 :OUTPUT: 1 OUTPUT nonterm/3/7 :STR: 1 OUTPUT nonterm/4/7 :PROG: 1 OUTPUT nonterm/5/7 :IFELSE: 1 OUTPUT nonterm/6/7 :EQN: 5 fini $ }}} But this one is '''not acceptable''' for two different (unique) reasons, do you see why? {{{ $./PROGRAM grammar.cfg "int a=3, b=4; a+b<6 if b, a = a, b; else { a=b=0; } output("else");" Read grammar 'grammar.cfg' 6 nonterm 17 terminals DECL production int EQN 1 ;s EQN production a 3 EQN production b 4 DECL production int EQN EXPR production < EXPR production + EQN production b a EQN production a b 2 ;s EQN production b 0 EQN production a b IF production EXPR EQN EQN 3 ;s STR production else OUTPUT production STR 4 ;s Parse tree complete 63 nt nodes 38 term leaves OUTPUT 63 OUTPUT 54 OUTPUT nonterm 0 of 7 :DECL: 1 OUTPUT nonterm 1 of 7 :EXPR: 6 OUTPUT nonterm 2 of 7 :OUTPUT: 1 OUTPUT nonterm 3 of 7 :STR: 1 OUTPUT nonterm 4 of 7 :PROG: 1 OUTPUT nonterm 5 of 7 :IFELSE: 1 OUTPUT nonterm 6 of 7 :EQN: 5 fini $ }}} {{{#!wiki comment * OUTPUT production debug line will have the 4 interpreted as "total number of productions" result * the "bare" numerical values in the `nonterm x of y` debug messages will be considered part of the result sequence }}}