File: PresentationParser.h

package info (click to toggle)
magnus 20060324-3
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 19,404 kB
  • ctags: 20,466
  • sloc: cpp: 130,118; ansic: 37,076; tcl: 10,970; perl: 1,109; makefile: 963; sh: 403; yacc: 372; csh: 57; awk: 33; asm: 10
file content (108 lines) | stat: -rw-r--r-- 3,597 bytes parent folder | download | duplicates (3)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// Copyright (C) 1994 The New York Group Theory Cooperative
// See magnus/doc/COPYRIGHT for the full notice.

// Contents: Definition of parser for presentations.
//
// Principal Author: Roger Needham
//
// Status: useable
//
// Revision History:
//

#ifndef _PRESENTATION_PARSER_H_
#define _PRESENTATION_PARSER_H_

#include "Set.h"
#include "WordParser.h"
#include "FreeGroup.h"
#include "FPGroup.h"


// The grammar for Word and FPGroup:
//
// Literals are delimited by ''.
// The symbols ., *, +, -, |, ?, [, ], (, and ) are part of regular expressions
// unless quoted.
//
// <whitespace>     ::= ' ' | '\t' | '\n' | '#'.*'\n'
// <index>          ::= 0 | [1-9]+[0-9]*
// <integer>        ::= <index> | -<index>
// <generator>      ::= [a-zA-Z]+<index>?
// <atom>           ::= '1' | <generator> | '('<word>')' |
//                      '['<word>','<word>(','<word>)*']'
// <term>           ::= <atom>('^'<atom>)* | <term>'^'<integer>
// <word>           ::= <term>('*'<term>)* | <term>(<whitespace><term>)*
// <relator>        ::= <word>('='<word>)?
// <generator list> ::= (<generator>(','<generator>)*)?
// <word list>      ::= <word>(','<word list>)?
// <relator list>   ::= <word>('='<word>)* |
//                      (<word>('='<word>)*(','<word>('='<word>)*)?)?
// <FPGroup>        ::= '<'<generator list>('|' | ';' | ':')<relator list>'>' |
//                      '<'<generator list>'>'
//
// - whitespace may occur anywhere except within lexemes.
// 
// Semantic conventions:
//
// - x^y is y^-1 x y.
// - ^ is left-associative, so a^t^2 is (a^t)^2.
// - [x,y] is x^-1 y^-1 x y.
// - [x1, x2, ..., xn] is left-normed: [[x1,x2], x3, ..., xn].
// - Given the print name of a generator, the print name of its inverse
//   has each character changed to the opposite case.
//   Thus aB2^-1 is the same as Ab2.


class PresentationParser : public WordParser {

public:

  enum BraceType { SET, PAREN };

public:

  PresentationParser(istream &istr) : WordParser(istr) { }
  // Initialize the parser with the istream from which to read.

  // Destructor supplied by compiler.

  VectorOf<Chars> parseGeneratorList( Chars& );
  // Read a generator list.

  SetOf<Word> parseWordSet( const VectorOf<Chars>&, Chars& );
  // Read a list of words in the given generator names.
  // The list is terminated when a word is followed by any non-whitespace
  // char other than ','.

  VectorOf<Word> parseWordList( const VectorOf<Chars>&, Chars& );
  // Read a list of words in the given generator names.
  // The list is terminated when a word is followed by any non-whitespace
  // char other than ','.

  SetOf<Word> parseSetOfWords( const VectorOf<Chars>&, Chars& );
  // Read a list of words in the given generator names delimited by '{', '}'.

  VectorOf<Word> parseVectorOfWords( const VectorOf<Chars>&, Chars&, 
				     BraceType brace = SET );
  // Read a list of words in the given generator names delimited by '{', '}'
  // or '(', ')'.

  virtual Word parseRelator( const VectorOf<Chars>&, Chars& );
  // Read a relator in the given generator names.

  SetOf<Word> parseRelatorList( const VectorOf<Chars>&, Chars& );
  // Read a list of words and relations in the given generator names.
  // The list is terminated when anything (non-whitespace) other than
  // a relator or ',' is encountered.

  FreeGroupRep* parseFreeGroup( Chars& );

  FPGroupRep* parseFPGroup( Chars& );
  // Read a group presentation and return it as a new group rep object.
private:
  bool getGeneratorRange( const Chars& , VectorOf<Chars>&, Chars& );
  bool getRangeOf( const Chars& ,Chars&, int& );
};

#endif