| | 1 | #charset "us-ascii" |
| | 2 | |
| | 3 | /* |
| | 4 | * Copyright (c) 2000, 2006 Michael J. Roberts |
| | 5 | * |
| | 6 | * This file is part of TADS 3. |
| | 7 | * |
| | 8 | * The header defines the GrammarProd intrinsic class and some associated |
| | 9 | * properties and constants. |
| | 10 | */ |
| | 11 | |
| | 12 | #ifndef _GRAMPROD_H_ |
| | 13 | #define _GRAMPROD_H_ |
| | 14 | |
| | 15 | /* include our base class definition */ |
| | 16 | #include "systype.h" |
| | 17 | |
| | 18 | /* |
| | 19 | * The GrammarProd intrinsic class is a specialized type that's used to |
| | 20 | * create parsers. An object of this type is created automatically by the |
| | 21 | * TADS 3 compiler for each 'grammar' statement. This class encapsulates |
| | 22 | * the prototype token list and mapping information defined in a 'grammar' |
| | 23 | * statement, and provides a method to match its prototype to an actual |
| | 24 | * input token string. |
| | 25 | */ |
| | 26 | intrinsic class GrammarProd 'grammar-production/030001': Object |
| | 27 | { |
| | 28 | /* |
| | 29 | * Parse the token list, starting at this production, using the given |
| | 30 | * dictionary to look up tokens. Returns a list of match objects. If |
| | 31 | * there are no matches to the grammar, simply returns an empty list. |
| | 32 | */ |
| | 33 | parseTokens(tokenList, dict); |
| | 34 | |
| | 35 | /* |
| | 36 | * Retrieve a detailed description of the production. This returns a |
| | 37 | * list of GrammarAltInfo objects that describe the rule alternatives |
| | 38 | * that make up this production. |
| | 39 | */ |
| | 40 | getGrammarInfo(); |
| | 41 | } |
| | 42 | |
| | 43 | /* |
| | 44 | * Token slot types. Each token slot in an alternative has a type, which |
| | 45 | * determines what it matches in an input token list. getGrammarInfo() |
| | 46 | * returns these type codes in the GrammarAltTokInfo objects. |
| | 47 | */ |
| | 48 | |
| | 49 | #define GramTokTypeProd 1 /* token matches a sub-production */ |
| | 50 | #define GramTokTypeSpeech 2 /* token matches a specific part of speech */ |
| | 51 | #define GramTokTypeLiteral 3 /* token matches a literal string */ |
| | 52 | #define GramTokTypeTokEnum 4 /* token matches a token class enum */ |
| | 53 | #define GramTokTypeStar 5 /* token matches all remaining input tokens */ |
| | 54 | #define GramTokTypeNSpeech 6 /* matches any of several parts of speech */ |
| | 55 | |
| | 56 | |
| | 57 | /* |
| | 58 | * Properties for the first and last token indices, and the complete |
| | 59 | * original token list. |
| | 60 | * |
| | 61 | * Each match tree object will have the firstTokenIndex and lastTokenIndex |
| | 62 | * properties set to the bounding token indices for its subtree. Each |
| | 63 | * match tree object will also have tokenList set to the original token |
| | 64 | * list passed to the parseTokens() that created the match tree, and |
| | 65 | * tokenMatchList set to a list of the Dictionary's comparator's |
| | 66 | * matchValues() result for each token match. |
| | 67 | */ |
| | 68 | property firstTokenIndex, lastTokenIndex, tokenList, tokenMatchList; |
| | 69 | export firstTokenIndex 'GrammarProd.firstTokenIndex'; |
| | 70 | export lastTokenIndex 'GrammarProd.lastTokenIndex'; |
| | 71 | export tokenList 'GrammarProd.tokenList'; |
| | 72 | export tokenMatchList 'GrammarProd.tokenMatchList'; |
| | 73 | |
| | 74 | |
| | 75 | #endif /* _GRAMPROD_H_ */ |