fri.patterns.interpreter.parsergenerator.syntax.builder
Class SyntaxBuilder

java.lang.Object
  |
  +--fri.patterns.interpreter.parsergenerator.syntax.builder.SyntaxBuilder

public class SyntaxBuilder
extends java.lang.Object

Connects SyntaxSeparation and LexerBuilder. SyntaxBuilder builds a Syntax object from a text input which can be File, InputStream, Reader, String, StringBuffer. Mind that you DO NOT need a SyntaxBuilder to create a Syntax from a String [][] or a List of rule Lists!

Following symbols can be used within the syntax specification text (spaces are ignored):

                a ::= b? ;	// a derives to one or none b
                a ::= b* ;	// a derives to any number of b including zero
                a ::= b+ ;	// a derives to any number of b excluding zero
                a ::= (b c)* d ;	// grouping of b and c by parenthesis
                a ::= b | c |  ;	// a derives to b or c or nothing
                start ::= "BEGIN" ;	// a fixed terminal string
                letter ::= 'a' .. 'z' ;	// character set a-z
                newline ::= '\r' | '\n' | '\r' '\n' ;	// newlines of all wellknown platforms
                positive ::= digit - '0' ;	// digit but not zero
                id ::= `identifier` ;	// using the pre-built lexer rules for identifier (lexer ruleref)
                source ::= char - comment ;	// source is all characters, but without comments
        
This EBNF-like language is case-sensitive and differs from EBNF only at these symbols: . { } < > [ ]. Archetype was the notation used by the w3c.

Author:
(c) 2002, Fritz Ritzberger

Constructor Summary
SyntaxBuilder(java.lang.Object syntaxInput)
          Parse a syntax specification text and process it to a Syntax object.
 
Method Summary
 java.util.List getInitialNonterminals()
          Returns the list of initial nonterminals (before parenthesis and quantifiers get resolved).
 Lexer getLexer()
          Returns a Lexer for the built syntax.
 Syntax getParserSyntax()
          Returns only the ready-made parser syntax (to feed the parser tables).
 Syntax getSyntax()
          Returns the whole syntax (both parser and lexer syntax).
static void main(java.lang.String[] args)
          Creates SyntaxBuilderParserTables.java (in this directory) from the rules defined in SyntaxBuilderSemantic.
 Syntax resolveSingulars()
          Resolves all singular rules (only one symbol on right side, only one occurence).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SyntaxBuilder

public SyntaxBuilder(java.lang.Object syntaxInput)
              throws SyntaxException,
                     LexerException,
                     ParserBuildException,
                     java.io.IOException
Parse a syntax specification text and process it to a Syntax object. The syntax, a Lexer, a parserSyntax and a token-symbol list will be retrieveable after construction.

Parameters:
syntaxInput - text to parse and build a syntax from, File, InputStream, Reader, String, StringBuffer. If InputStream is used, no Reader will be wrapped around (raw byte input).
Method Detail

getLexer

public Lexer getLexer()
               throws LexerException,
                      SyntaxException
Returns a Lexer for the built syntax.

LexerException
SyntaxException

getParserSyntax

public Syntax getParserSyntax()
                       throws SyntaxException
Returns only the ready-made parser syntax (to feed the parser tables).

SyntaxException

getSyntax

public Syntax getSyntax()
Returns the whole syntax (both parser and lexer syntax).


getInitialNonterminals

public java.util.List getInitialNonterminals()
Returns the list of initial nonterminals (before parenthesis and quantifiers get resolved). This is for internal use in SourceGenerator.


resolveSingulars

public Syntax resolveSingulars()
Resolves all singular rules (only one symbol on right side, only one occurence). This must be called directly after construction to have an effect.


main

public static void main(java.lang.String[] args)
Creates SyntaxBuilderParserTables.java (in this directory) from the rules defined in SyntaxBuilderSemantic.