-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbstractSyntaxAnalyser.java
More file actions
50 lines (43 loc) · 1.44 KB
/
Copy pathAbstractSyntaxAnalyser.java
File metadata and controls
50 lines (43 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/**
*
* (Abstract) Syntax analyser for exercise course 312.
*
* This class has been provided to students
*
* @Author: Roger Garside, John Mariani, John Vidler, Paul Rayson
*
*
**/
import java.io.* ;
public abstract class AbstractSyntaxAnalyser
{
/** The lexical analyser to process input using. */
LexicalAnalyser lex ;
/** A cache of the token to be processed next. */
Token nextToken ;
/** A code generator, descendant of AbstractGenerate. */
Generate myGenerate = null;
/** Begin processing the first (top level) token.*/
public abstract void _statementPart_() throws IOException, CompilationException;
/** Accept a token based on context. Requires implementation. */
public abstract void acceptTerminal(int symbol) throws IOException, CompilationException;
/** Parses the given PrintStream with this instance's LexicalAnalyser.
@param ps The PrintStream object to read tokens from.
@throws IOException in the event that the PrintStream object can no longer read.
*/
public void parse( PrintStream ps ) throws IOException
{
myGenerate = new Generate();
try {
nextToken = lex.getNextToken() ;
_statementPart_() ;
acceptTerminal(Token.eofSymbol) ;
myGenerate.reportSuccess() ;
}
catch( CompilationException ex )
{
ps.println( "Compilation Exception" );
ps.println( ex.toTraceString() );
}
} // end of method parse
} // end of class AbstractSyntaxAnalyser