home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-08-14 | 15.1 KB | 506 lines |
- /*---------------------------------------------------------------------------
-
- Written by the Personal Journal developers of Dow Jones & Company, Inc.
-
- Dow Jones makes no representations or warranties about
- the suitability of this software, either express or
- implied, including but not limited to the implied warranties
- of merchantability, fitness for a particular purpose,
- or non-infringement. Dow Jones will not be liable for
- any damages suffered by a user as a result of using,
- modifying or distributing this software or its derivatives.
-
-
-
- @(#)StoryParser.java 0.00 20-Dec-95
-
- A parser that reads from an InputStream
- and writes to a StoryContainer.
-
- This code is based on StdoutParser.java, which in turn was
- generated from StdoutParser.cup by JavaCup v0.9b
- Tue Dec 26 13:17:16 1995
-
- Authors:
-
- rphall Rick Hall
-
-
- Version Ident:
-
- $Header$
-
-
- History:
-
- 12/20/95 rphall Initial Creation
-
- ---------------------------------------------------------------------------*/
-
- package pj.io;
-
- import pj.io.IncompatiblePaperStoryException;
- import pj.io.MalformedPaperStoryException;
- import pj.io.Paper;
- import pj.io.PaperStory;
- import pj.io.StoryContainer;
- import pj.io.StoryScanner;
-
- import collections.ImplementationError;
- import java.io.InputStream;
- import java.lang.IllegalArgumentException;
- import java_cup.runtime.*;
-
- public class StoryParser extends java_cup.runtime.lr_parser
- {
-
- // --- Instance variables
-
- InputStream is;
- StoryContainer sc;
- StoryScanner scanner;
- PaperStory currentStory;
-
- // --- Instance of action encapsulation class
- protected CUP$actions action_obj;
-
- /** production table */
- protected static final short _production_table[][] =
- {
- {5, 2}, {0, 2}, {5, 1}, {9, 0}, {4, 4},
- {3, 1}, {3, 2}, {10, 0}, {2, 3}, {1, 2},
- {1, 2}, {1, 2}, {1, 2}, {1, 1}, {1, 1},
- {1, 1}, {1, 1}, {7, 3}, {6, 3}, {8, 2},
- {8, 1}
- };
-
-
- /** parse action table */
- protected static final short[][] _action_table =
- {
- /*0*/{2,3,-1,0},
- /*1*/{0,29,2,3,-1,0},
- /*2*/{8,-4,-1,0},
- /*3*/{0,-3,2,-3,-1,0},
- /*4*/{8,6,-1,0},
- /*5*/{9,-8,-1,0},
- /*6*/{3,11,4,10,5,-6,10,16,11,15,-1,0},
- /*7*/{5,9,-1,0},
- /*8*/{0,-5,2,-5,-1,0},
- /*9*/{12,22,-1,0},
- /*10*/{12,22,-1,0},
- /*11*/{3,-17,4,-17,5,-17,10,-17,11,-17,-1,0},
- /*12*/{3,11,4,10,5,-7,10,20,11,19,-1,0},
- /*13*/{3,-16,4,-16,5,-16,10,-16,11,-16,-1,0},
- /*14*/{3,-15,4,-15,5,-15,10,-15,11,-15,-1,0},
- /*15*/{3,-14,4,-14,5,-14,10,-14,11,-14,-1,0},
- /*16*/{3,-13,4,-13,5,-13,10,-13,11,-13,-1,0},
- /*17*/{3,-12,4,-12,5,-12,10,-12,11,-12,-1,0},
- /*18*/{3,-11,4,-11,5,-11,10,-11,11,-11,-1,0},
- /*19*/{3,-10,4,-10,5,-10,10,-10,11,-10,-1,0},
- /*20*/{6,23,12,24,-1,0},
- /*21*/{6,-21,7,-21,12,-21,-1,0},
- /*22*/{3,-18,4,-18,5,-18,10,-18,11,-18,-1,0},
- /*23*/{6,-20,7,-20,12,-20,-1,0},
- /*24*/{7,26,12,24,-1,0},
- /*25*/{3,-19,4,-19,5,-19,10,-19,11,-19,-1,0},
- /*26*/{9,28,-1,0},
- /*27*/{3,-9,4,-9,5,-9,10,-9,11,-9,-1,0},
- /*28*/{0,-2,-1,0},
- /*29*/{0,-1,2,-1,-1,0},
- };
-
- /** reduce_goto table */
- protected static final short[][] _reduce_table =
- {
- /*0*/{4,3,5,1,-1,-1},
- /*1*/{4,29,-1,-1},
- /*2*/{9,4,-1,-1},
- /*3*/{-1,-1},
- /*4*/{2,6,3,7,-1,-1},
- /*5*/{10,26,-1,-1},
- /*6*/{1,12,6,11,7,13,-1,-1},
- /*7*/{-1,-1},
- /*8*/{-1,-1},
- /*9*/{8,24,-1,-1},
- /*10*/{8,20,-1,-1},
- /*11*/{-1,-1},
- /*12*/{6,16,7,17,-1,-1},
- /*13*/{-1,-1},
- /*14*/{-1,-1},
- /*15*/{-1,-1},
- /*16*/{-1,-1},
- /*17*/{-1,-1},
- /*18*/{-1,-1},
- /*19*/{-1,-1},
- /*20*/{-1,-1},
- /*21*/{-1,-1},
- /*22*/{-1,-1},
- /*23*/{-1,-1},
- /*24*/{-1,-1},
- /*25*/{-1,-1},
- /*26*/{-1,-1},
- /*27*/{-1,-1},
- /*28*/{-1,-1},
- /*29*/{-1,-1},
- };
-
- // --- Public constructors
-
- //public StoryParser() {super();}
-
- public StoryParser(InputStream input, StoryContainer output)
- {
- is = input;
- sc = output;
- scanner = new StoryScanner(is);
- currentStory = null;
- System.out.println("Debug-StoryParser:constructed");
- }
-
- public StoryParser(StoryContainer output)
- {
- this(System.in,output);
- }
-
- // --- Public operations
-
- /** access to production table */
- public short[][] production_table()
- {
- return _production_table;
- }
-
-
- /** access to parse action table */
- public short[][] action_table()
- {
- return _action_table;
- }
-
-
- /** access to reduce_goto table */
- public short[][] reduce_table()
- {
- return _reduce_table;
- }
-
-
- /** action encapsulation object initializer */
- protected void init_actions()
- {
- action_obj = new CUP$actions(this);
- }
-
- /** invoke a user supplied parse action */
- public java_cup.runtime.symbol do_action(
- int act_num,
- java_cup.runtime.lr_parser parser,
- java.util.Stack stack,
- int top)
- throws java.lang.Exception
- {
- /* call code in generated class */
- return action_obj.CUP$do_action(act_num, parser, stack, top);
- }
-
- /** start state */
- public int start_state()
- {
- return 0;
- }
-
- /** start production */
- public int start_production()
- {
- return 1;
- }
-
- /** EOF symbol index */
- public int EOF_sym()
- {
- return 0;
- }
-
- /** error symbol index */
- public int error_sym()
- {
- return 1;
- }
-
-
- /** user initialization */
- public void user_init() throws java.lang.Exception
- {
- scanner.init();
- }
-
- /** scan to get the next token */
- public java_cup.runtime.token scan() throws java.lang.Exception
- {
- return scanner.next_token();
- }
- }; //StoryParser
-
-
- /** JavaCup generated class to encapsulate user supplied action code.*/
- class CUP$actions
- {
-
- // --- Instance variables
- private StoryParser parser;
-
- /** Constructor */
- CUP$actions(StoryParser sp)
- {
- parser = sp;
- }
-
-
-
- /** Method with the actual generated action code. */
- public final java_cup.runtime.symbol CUP$do_action(
- int CUP$act_num,
- java_cup.runtime.lr_parser CUP$parser,
- java.util.Stack CUP$stack,
- int CUP$top)
- throws java.lang.Exception
- {
- /* object for return from actions */
- java_cup.runtime.symbol CUP$result;
-
- /* select the action based on the action number */
- switch (CUP$act_num)
- {
- /*. . . . . . . . . . . . . . . . . . . .*/
- case 20: // lines ::= LINE
- {
- CUP$result = new str_token(/*lines*/8);
-
- ((str_token)CUP$result).str_val = (/*l*/(str_token)CUP$stack.elementAt(CUP$top-0)).str_val;
-
- }
- return CUP$result;
-
- /*. . . . . . . . . . . . . . . . . . . .*/
- case 19: // lines ::= lines LINE
- {
- CUP$result = new str_token(/*lines*/8);
-
- ((str_token)CUP$result).str_val = (/*ll*/(str_token)CUP$stack.elementAt(CUP$top-1)).str_val + (/*l*/(str_token)CUP$stack.elementAt(CUP$top-0)).str_val;
-
- }
- return CUP$result;
-
- /*. . . . . . . . . . . . . . . . . . . .*/
- case 18: // attrib_body ::= START_BODY lines STOP_BODY
- {
- CUP$result = new str_token(/*attrib_body*/6);
-
- ((str_token)CUP$result).str_val = (/*body*/(str_token)CUP$stack.elementAt(CUP$top-1)).str_val;
-
- }
- return CUP$result;
-
- /*. . . . . . . . . . . . . . . . . . . .*/
- case 17: // attrib_title ::= START_TITLE lines STOP_TITLE
- {
- CUP$result = new str_token(/*attrib_title*/7);
-
- ((str_token)CUP$result).str_val = (/*title*/(str_token)CUP$stack.elementAt(CUP$top-1)).str_val;
-
- }
- return CUP$result;
-
- /*. . . . . . . . . . . . . . . . . . . .*/
- case 16: // attribs_opt ::= attrib_body
- {
- CUP$result = new symbol(/*attribs_opt*/1);
-
- parser.currentStory.setBody((/*body*/(str_token)CUP$stack.elementAt(CUP$top-0)).str_val);
-
- }
- return CUP$result;
-
- /*. . . . . . . . . . . . . . . . . . . .*/
- case 15: // attribs_opt ::= attrib_title
- {
- CUP$result = new symbol(/*attribs_opt*/1);
-
- parser.currentStory.setTitle((/*title*/(str_token)CUP$stack.elementAt(CUP$top-0)).str_val);
-
- }
- return CUP$result;
-
- /*. . . . . . . . . . . . . . . . . . . .*/
- case 14: // attribs_opt ::= ATTRIB_KEYS
- {
- CUP$result = new symbol(/*attribs_opt*/1);
-
- parser.currentStory.setKeys((/*keys*/(str_token)CUP$stack.elementAt(CUP$top-0)).str_val);
-
- }
- return CUP$result;
-
- /*. . . . . . . . . . . . . . . . . . . .*/
- case 13: // attribs_opt ::= ATTRIB_TYPE
- {
- CUP$result = new symbol(/*attribs_opt*/1);
-
- parser.currentStory.setType((/*type*/(str_token)CUP$stack.elementAt(CUP$top-0)).str_val);
-
- }
- return CUP$result;
-
- /*. . . . . . . . . . . . . . . . . . . .*/
- case 12: // attribs_opt ::= attribs_opt attrib_body
- {
- CUP$result = new symbol(/*attribs_opt*/1);
-
- parser.currentStory.setBody((/*body*/(str_token)CUP$stack.elementAt(CUP$top-0)).str_val);
-
- }
- return CUP$result;
-
- /*. . . . . . . . . . . . . . . . . . . .*/
- case 11: // attribs_opt ::= attribs_opt attrib_title
- {
- CUP$result = new symbol(/*attribs_opt*/1);
-
- parser.currentStory.setTitle((/*title*/(str_token)CUP$stack.elementAt(CUP$top-0)).str_val);
-
- }
- return CUP$result;
-
- /*. . . . . . . . . . . . . . . . . . . .*/
- case 10: // attribs_opt ::= attribs_opt ATTRIB_KEYS
- {
- CUP$result = new symbol(/*attribs_opt*/1);
-
- parser.currentStory.setKeys((/*keys*/(str_token)CUP$stack.elementAt(CUP$top-0)).str_val);
-
- }
- return CUP$result;
-
- /*. . . . . . . . . . . . . . . . . . . .*/
- case 9: // attribs_opt ::= attribs_opt ATTRIB_TYPE
- {
- CUP$result = new symbol(/*attribs_opt*/1);
-
- parser.currentStory.setType((/*type*/(str_token)CUP$stack.elementAt(CUP$top-0)).str_val);
-
- }
- return CUP$result;
-
- /*. . . . . . . . . . . . . . . . . . . .*/
- case 8: // attribs_reqd ::= ATTRIB_SECTION NT$1 ATTRIB_SUBSECT
- {
- CUP$result = new symbol(/*attribs_reqd*/2);
-
- parser.currentStory.setSubsect((/*sub*/(str_token)CUP$stack.elementAt(CUP$top-0)).str_val);
-
- }
- return CUP$result;
-
- /*. . . . . . . . . . . . . . . . . . . .*/
- case 7: // NT$1 ::=
- {
- CUP$result = new java_cup.runtime.token(/*NT$1*/10);
-
- parser.currentStory.setSection((/*sec*/(str_token)CUP$stack.elementAt(CUP$top-0)).str_val);
-
- }
- return CUP$result;
-
- /*. . . . . . . . . . . . . . . . . . . .*/
- case 6: // data_story ::= attribs_reqd attribs_opt
- {
- CUP$result = new symbol(/*data_story*/3);
-
- }
- return CUP$result;
-
- /*. . . . . . . . . . . . . . . . . . . .*/
- case 5: // data_story ::= attribs_reqd
- {
- CUP$result = new symbol(/*data_story*/3);
-
- }
- return CUP$result;
-
- /*. . . . . . . . . . . . . . . . . . . .*/
- case 4: // story ::= START_STORY NT$0 data_story STOP_STORY
- {
- CUP$result = new symbol(/*story*/4);
- }
- return CUP$result;
-
- /*. . . . . . . . . . . . . . . . . . . .*/
- case 3: // NT$0 ::=
- {
- CUP$result = new java_cup.runtime.token(/*NT$0*/9);
-
- parser.currentStory = new PaperStory();
-
- }
- return CUP$result;
-
- /*. . . . . . . . . . . . . . . . . . . .*/
- case 2: // story_list ::= story
- {
- CUP$result = new symbol(/*story_list*/5);
-
- addStoryToContainer(parser.currentStory,parser.sc);
- parser.currentStory = null;
-
- }
- return CUP$result;
-
- /*. . . . . . . . . . . . . . . . . . . .*/
- case 1: // $START ::= story_list EOF
- {
- CUP$result = new java_cup.runtime.token(/*$START*/0);
-
- }
- /* ACCEPT */
- CUP$parser.done_parsing();
- return CUP$result;
-
- /*. . . . . . . . . . . . . . . . . . . .*/
- case 0: // story_list ::= story_list story
- {
- CUP$result = new symbol(/*story_list*/5);
-
- addStoryToContainer(parser.currentStory,parser.sc);
- parser.currentStory = null;
-
- }
- return CUP$result;
-
- /* . . . . . .*/
- default:
- throw new Exception(
- "Invalid action number found in internal parse table");
-
- } //switch
- } //java_cup.runtime.symbol CUP$do_action
-
- // --- Private operations
-
- // Private method to add parser.currentStory to StoryContainer
- private void addStoryToContainer(PaperStory ps, StoryContainer c)
- {
- try {
- ps.checkImplementation();
- c.addStory(ps);
- }
-
- catch( ImplementationError e) {}
- catch( MalformedPaperStoryException e) {}
- catch( IncompatiblePaperStoryException e) {}
- catch( IllegalArgumentException e) {}
-
- }
- };//class CUP$actions
-
-