Computer Science 301 - 2005

Extra tutorials for Swot Week (4) - LL(1) conditions and rewritten EBNF

Rewrite the following grammars so as to eliminate the Wirth meta-brackets { } and [ ] and hence (or otherwise) test the grammars for being LL(1) compliant. If they are not LL(1) compliant, can you find equivalent LL(1) compliant grammars?

You can find the sources for these grammars in the file tut31.zip.

  COMPILER Course
  /* Grammar describing history of a university course */

  PRODUCTIONS
    Course       =  Introduction Section { Section } Conclusion .
    Introduction =  "lecture" [ "handout" ] .
    Section      =  { "lecture" | "practical" "test" | "tutorial" | "handout" } "test" .
    Conclusion   =  [ "panic" ] "examination" .
  END Course.



COMPILER RE /* Regular expression grammar */ CHARACTERS control = CHR(0) .. CHR(31) . noquote1 = ANY - control - "'" . noquote2 = ANY - control - '"' . meta = "()*|.;[]-?+" . simple = ANY - control - "'" - '"' - meta . backslash = CHR(92) . TOKENS atomic = simple . escaped = "'" noquote1 "'" | '"' noquote2 '"' . COMMENTS FROM backslash TO backslash IGNORE control PRODUCTIONS RE = { Expression ";" } EOF . Expression = Term { "|" Term } . Term = Factor { [ "." ] Factor } . Factor = Element [ "*" | "?" | "+" ] . Element = Atom | Range | "(" Expression ")" . Range = "[" OneRange { OneRange } "]" . OneRange = Atom [ "-" Atom ] . Atom = atomic | escaped . END RE.


COMPILER Play /* Grammar for Shakespearian play */ PRODUCTIONS Play = Act Act Act "interval" Act Act . Act = Scene { Scene } . Scene = { "speech" } "entry" { Action } . Action = "speech" | "entry" | "exit" | "death" | "gesticulation" . END Play.

Ignoring any LL(1) problems - how would you attribute this last grammar to check that there were no actors left on the stage at the end of every act?


Home  © P.D. Terry